forked from nmayhall-vt/nbody_tucker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test1.py
executable file
·76 lines (61 loc) · 2.04 KB
/
test1.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
68
69
70
71
72
73
74
75
76
#! /usr/bin/env python
import numpy as np
import scipy
import scipy.linalg
import scipy.io
import copy as cp
from tucker import *
np.random.seed(2)
A = np.random.rand(8,8,8,8,8)
dims = A.shape
n_modes = len(A.shape)
#Acore, Atfac = tucker_decompose(A,0,1)
Acore, Atfac = tucker_decompose_list(A,(1,1,1,1,1))
B = tucker_recompose(Acore,Atfac)
print "\n Norm of Error tensor due to compression: %12.3e\n" %np.linalg.norm(B-A)
C = B
#1-Body
for si,i in enumerate(dims):
dims2 = np.ones(n_modes)
dims2[si]=-1
Bcore, Btfac = tucker_decompose_list(A,dims2)
C = C + tucker_recompose(Bcore,Btfac)
#2-Body
for si,i in enumerate(dims):
for sj,j in enumerate(dims):
if si>sj:
dims2 = np.ones(n_modes)
dims2[si]=-1
dims2[sj]=-1
Bcore, Btfac = tucker_decompose_list(A,dims2)
C = C + tucker_recompose(Bcore,Btfac)
#3-Body
for si,i in enumerate(dims):
for sj,j in enumerate(dims):
if si>sj:
for sk,k in enumerate(dims):
if sj>sk:
dims2 = np.ones(n_modes)
dims2[si]=-1
dims2[sj]=-1
dims2[sk]=-1
Bcore, Btfac = tucker_decompose_list(A,dims2)
C = C + tucker_recompose(Bcore,Btfac)
#4-Body
if 1:
for si,i in enumerate(dims):
for sj,j in enumerate(dims):
if si>sj:
for sk,k in enumerate(dims):
if sj>sk:
for sl,l in enumerate(dims):
if sk>sl:
dims2 = np.ones(n_modes)
dims2[si]=-1
dims2[sj]=-1
dims2[sk]=-1
dims2[sl]=-1
Bcore, Btfac = tucker_decompose_list(A,dims2)
C = C + tucker_recompose(Bcore,Btfac)
print "\n Norm of Error tensor due to 111 compression: %12.3e\n" %np.linalg.norm(B-A)
print "\n Norm of Error tensor due to 3body compression: %12.3e\n" %np.linalg.norm(C-A)