質問編集履歴
2
コード
title
CHANGED
File without changes
|
body
CHANGED
@@ -4,18 +4,14 @@
|
|
4
4
|
何か解決策があれば教えてください。
|
5
5
|
import numpy as np
|
6
6
|
print "Finished Importing Numpy"
|
7
|
-
|
7
|
+
|
8
|
-
#import scipy as sp
|
9
|
-
#print "Finished Importing Scipy"
|
10
8
|
import re #regular expression
|
11
9
|
print "Finished Importing Regex"
|
12
10
|
import struct
|
13
11
|
print "Finished Importing Struct"
|
14
12
|
from collections import Counter
|
15
13
|
print "Finished Importing Counter"
|
16
|
-
#import matplotlib.pyplot as plt
|
17
14
|
import time
|
18
|
-
#import math
|
19
15
|
|
20
16
|
class Factoranalysis:
|
21
17
|
def __init__(self,dataarr):
|
@@ -27,7 +23,6 @@
|
|
27
23
|
def eigenvals(self):
|
28
24
|
print "eigenvals"
|
29
25
|
la = np.linalg.eigvalsh(np.corrcoef(self.dataarr))#np.corrcoef(self.dataarr)#
|
30
|
-
#U, s, V = np.linalg.svd(np.corrcoef(self.dataarr))#, full_matrices=False)
|
31
26
|
return la
|
32
27
|
def parallelanalysis(self,repnum):
|
33
28
|
laave=0.
|
@@ -41,10 +36,4 @@
|
|
41
36
|
for num in range(0,100):
|
42
37
|
U, s, V = np.linalg.svd(np.corrcoef(np.random.randn(100,100)))
|
43
38
|
laave = laave + s
|
44
|
-
#print s
|
45
|
-
print laave/100
|
39
|
+
print laave/100
|
46
|
-
#print np.corrcoef(np.random.randn(1600,100))
|
47
|
-
#sum=0.
|
48
|
-
#for num in range(0, 1000000000):
|
49
|
-
# sum=sum+np.random.randn()
|
50
|
-
#print sum/1000000000
|
1
コード追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,4 +1,50 @@
|
|
1
1
|
パイソンの2.7、64BITでnumpyの演算を行ったところ、やたら時間(2000秒)がかかりました。演算時のパソコン内のメモリを確認したところ、16GBあるところ、9GBの使用(うちバックグラウンドで5GB使用していたのでパイソン自体は4GB程度)で止まっていました。16GBあるので、更に使用した方が早くなると思うのですが、どのようにすれば、パイソンに使用するメモリを上げることができるでしょうか?それとも、メモリは関係なく、演算が遅かったのでしょうか?確認したところ、演算で遅いところは、
|
2
2
|
np.linalg.eigvalsh
|
3
3
|
の演算で、巨大な行列の固有値を求めるところでした。
|
4
|
-
何か解決策があれば教えてください。
|
4
|
+
何か解決策があれば教えてください。
|
5
|
+
import numpy as np
|
6
|
+
print "Finished Importing Numpy"
|
7
|
+
#from scipy import signal
|
8
|
+
#import scipy as sp
|
9
|
+
#print "Finished Importing Scipy"
|
10
|
+
import re #regular expression
|
11
|
+
print "Finished Importing Regex"
|
12
|
+
import struct
|
13
|
+
print "Finished Importing Struct"
|
14
|
+
from collections import Counter
|
15
|
+
print "Finished Importing Counter"
|
16
|
+
#import matplotlib.pyplot as plt
|
17
|
+
import time
|
18
|
+
#import math
|
19
|
+
|
20
|
+
class Factoranalysis:
|
21
|
+
def __init__(self,dataarr):
|
22
|
+
print "StartinitFA"
|
23
|
+
self.dataarr=dataarr
|
24
|
+
self.numval=dataarr.shape[0]
|
25
|
+
self.numobs=dataarr.shape[1]
|
26
|
+
print "FAinitFIN"
|
27
|
+
def eigenvals(self):
|
28
|
+
print "eigenvals"
|
29
|
+
la = np.linalg.eigvalsh(np.corrcoef(self.dataarr))#np.corrcoef(self.dataarr)#
|
30
|
+
#U, s, V = np.linalg.svd(np.corrcoef(self.dataarr))#, full_matrices=False)
|
31
|
+
return la
|
32
|
+
def parallelanalysis(self,repnum):
|
33
|
+
laave=0.
|
34
|
+
for num in range(0,repnum):
|
35
|
+
print laave
|
36
|
+
laave = np.linalg.eigvalsh(np.corrcoef(np.random.randn(self.numval,self.numval))) + laave
|
37
|
+
return laave/repnum
|
38
|
+
|
39
|
+
if __name__ == '__main__':
|
40
|
+
laave=0.
|
41
|
+
for num in range(0,100):
|
42
|
+
U, s, V = np.linalg.svd(np.corrcoef(np.random.randn(100,100)))
|
43
|
+
laave = laave + s
|
44
|
+
#print s
|
45
|
+
print laave/100
|
46
|
+
#print np.corrcoef(np.random.randn(1600,100))
|
47
|
+
#sum=0.
|
48
|
+
#for num in range(0, 1000000000):
|
49
|
+
# sum=sum+np.random.randn()
|
50
|
+
#print sum/1000000000
|