-
Notifications
You must be signed in to change notification settings - Fork 0
/
kll-compression.py~
55 lines (40 loc) · 1.43 KB
/
kll-compression.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
#!/bin/python
import numpy as np
import givens
import itertools
import pickle, sys
from itertools import combinations
ANGS_TABLE = {}
LTABLE = {}
ANGS_TABLE_FILE = ".kll-angs-table-file"
LTABLE_FILE = ".kll-ltable-file"
def generate_data_lookup(NUMBER_OF_ANGLES = 10, MATRIX_SIZE = 8):
global ANGS_TABLE, LTABLE
ANGLES = np.arange(0,2*np.pi,2*np.pi/NUMBER_OF_ANGLES)
ANGS_TABLE = {}
print "generating angles table"
for ang in ANGLES:
ANGS_TABLE[ang] = np.identity(MATRIX_SIZE)
for i,j in combinations(xrange(MATRIX_SIZE),2):
ANGS_TABLE[ang] = np.dot(ANGS_TABLE[ang],givens.givens(i,j,ang,MATRIX_SIZE))
#print ang,ANGS_TABLE[ang]
LTABLE = {}
print "generating ltable"
number_of_entries = NUMBER_OF_ANGLES**(MATRIX_SIZE-1)
print "number of entries: %u"%(number_of_entries)
i = 0
for angs in itertools.product(ANGS_TABLE,repeat=MATRIX_SIZE-1):
i+=1
if (i%(number_of_entries/100) == 0):
sys.stdout.write('.')
sys.stdout.flush()
MAT = np.identity(MATRIX_SIZE)
for ang in angs:
MAT = np.dot(MAT,ANGS_TABLE[ang])
LTABLE[angs] = MAT
pickle.dump(ANGS_TABLE,open(ANGS_TABLE_FILE,"wb"), protocol = 2)
pickle.dump(ANGS_TABLE,open(LTABLE_FILE,"wb"), protocol = 2)
print len(ANGS_TABLE), len(LTABLE)
def read_data_lookup_file():
global ANGS_TABLE, LTABLE
generate_data_lookup()