-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscan_wrapper.py
More file actions
executable file
·66 lines (52 loc) · 1.62 KB
/
scan_wrapper.py
File metadata and controls
executable file
·66 lines (52 loc) · 1.62 KB
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
import numpy as np
import scipy.io
import scipy.sparse
import h5py
from pathlib import Path
from H_sparse_gen import H_sparse_gen
from generate_haar import generate_haar
from scan_samp import scan_samp
def _decompose_pre_computed_H(pre_computed_H, f=None):
data = pre_computed_H["H"]["data"][:].astype(int)
ir = pre_computed_H["H"]["ir"][:]
jc = pre_computed_H["H"]["jc"][:]
atomInfo = pre_computed_H["atomInfo"][:].astype(int)
# this part is designed to handle .mat files of sparse matricies created via matlab
# if len(jc) == f:
# jc_extended = np.empty(len(ir), dtype=int)
# for i, j in enumerate(jc[:-1]):
# nextj = jc[i+1]
# jc_extended[j:nextj] = i
# jc = jc_extended
# atomInfo = atomInfo.T
H_all = scipy.sparse.coo_array((data, (ir, jc)))
return H_all, atomInfo
def scan_wrapper(data):
data = np.array(data)
t1, f = data.shape
t = 2**int(np.log2(t1))
data = data[:t, :]
prefix = Path("precomputedH")
if (prefix / f"H_{f}b.mat").exists():
with h5py.File(prefix / f"H_{f}b.mat","r") as pre_computed_H:
H_all, HatomInfo = _decompose_pre_computed_H(pre_computed_H)
else:
H, atomInfo = H_sparse_gen(f)
H_var = f"H_{f}b.mat"
ir, jc = H.coords
with h5py.File(prefix / H_var, "w") as f:
f.create_group("H")
f["H"]["ir"] = ir
f["H"]["jc"] = jc
f["H"]["data"] = H.data
f["atomInfo"] = atomInfo
H_all = H
HatomInfo = atomInfo
lambdaa = 0.0000001
rho = 10*lambdaa
threshold=0.15
beta = 1
Phi = generate_haar(t)
Phi = Phi.T
#Phi is txp
return scan_samp(data, H_all, HatomInfo, Phi, threshold, rho, lambdaa, beta)