forked from alexbeutel/FlexiFaCT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakebig.py
68 lines (53 loc) · 1.26 KB
/
makebig.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env python
import sys
import numpy as np
import math
import shlex
import random
def main():
nonzeros = 10000000
nonzeros2 = 10000000
D = 10000
rank = 30
print "Generate Parameters"
U = 0.5 * np.random.random_sample((D,rank))
V = 0.5 * np.random.random_sample((D,rank))
W = 0.5 * np.random.random_sample((D,rank))
A = 0.5 * np.random.random_sample((D,rank))
outdata = 'tensor.txt'
outdata2= 'matrix.txt'
used = set()
print "Generate Tensor"
output = open(outdata, 'w')
cnt = 0
while True:
i = random.randint(0,D-1)
j = random.randint(0,D-1)
k = random.randint(0,D-1)
st = str(i) + "," + str(j) + "," + str(k)
if st not in used:
cnt = cnt + 1
used.add(st)
val = np.sum(U[i] * V[j] * W[k])
output.write(str(i) + '\t' + str(j) + '\t' + str(k) + '\t' + str(val) + '\n')
if cnt > nonzeros:
break
output.close()
print "Generate Matrix"
output = open(outdata2, 'w')
cnt = 0
used = set()
while True:
i = random.randint(0,D-1)
j = random.randint(0,D-1)
st = str(i) + "," + str(j)
if st not in used:
cnt = cnt + 1
used.add(st)
val = np.sum(U[i] * A[j])
output.write(str(i) + '\t' + str(j) + '\t' + str(val) + '\n')
if cnt > nonzeros2:
break
output.close()
if __name__ == '__main__':
main()