global dimensionality-reduction (GDR) algorithm 示例


In [1]:
import numpy as np
import pandas as pd
from scipy import linalg
from scipy import optimize 
import functools

import tensorly
from tensorly.decomposition import partial_tucker
from tensorly.decomposition import tucker
tensorly.set_backend('numpy')


Using mxnet backend.
Using numpy backend.

生成数据集


In [2]:
tensor_steam_length = 300

factors_tensor_list = []
for i in np.arange(tensor_steam_length):
    a = np.random.normal(size=[69], scale=0.5)
    b = np.random.normal(size=[16], scale=0.5)
    c = np.random.normal(size=[32], scale=0.5)
    x = np.zeros([1, 69, 16, 32])
    x[0,:,0,0] = a
    x[0,1,:,1] = b
    x[0,2,2,:] = c
    factors_tensor_list.append(x)
factors_tensor = np.concatenate(factors_tensor_list)

targets = np.random.normal(scale=0.01, size=[300,1])

3.3 $\sum$ 循环向量化

$U^i_k\in\mathbb{R}^{batch \times I_k \times J_k}$

$U^{iT}_k\in\mathbb{R}^{batch \times J_k \times I_k}$

$M^i_k = U^i_k U^{iT}_k\in \mathbb{R}^{batch \times I_k \times I_k}$

$M^i_{k(0)} \in \mathbb{R}^{batch \times I_kI_k}$

令 $N = batch$

  • $D_{U_k} = \sum\limits ^N_{i=1}d_{i,i}U^{i}_kU^{iT}_k \\=\sum\limits ^N_{i=1}d_{i,i}M^i_k\\= mat \{(vec(diag(D)))^T M_{k(0)}\}$
  • $W_{U_k} = \sum\limits^N_{i=1}\sum\limits ^N_{j=1}w_{i,j}U^i_kU^{jT}_k\\= \sum\limits^N_{i=1}(\sum\limits ^N_{j=i}w_{i,j})U^i_kU^{jT}_k\\= \sum\limits^N_{i=1}(\sum\limits ^N_{j=i}w_{i,j})U^i_kU^{jT}_k\\=\sum\limits^N_{i=1}w_iU^i_kU^{jT}_k\\=\sum\limits^N_{i=1}w_i M^i_{k}\\=mat\{w M_{k(0)} \}$

其中

  • $w_{i,j} = \begin{cases}1,\ if\ \ i \le j \ and \ \|y_i -y_j \| \le 5\% \\0, \ otherwise \end{cases} $
  • $\sum\limits ^N_{j=1}w_{i,j} = w_i= sum(w_{i,:}, axis=1)$

In [3]:
def get_weighting_of_geometric_structure (targets):
    W = (targets - targets.T) / targets.T # 广播
    W = np.abs(W) - 0.05 # 转换绝对值并判断相似度
    W[W>0.0]=0
    W[W<0.0]=1
    upper_traingular_matrix = np.eye(W.shape[0]).cumsum(1) # 上三角矩阵掩码
    return W * upper_traingular_matrix

def get_var_of_adjusting_geometric_structure(targets):
    W = get_weighting_of_geometric_structure(targets)
    return np.expand_dims(W.sum(0),axis=0)

D = get_var_of_adjusting_geometric_structure(targets)
W = get_weighting_of_geometric_structure(targets)

循环tucker分解

计划迁移PyTorch构建批次处理


In [4]:
factors_tensor = tensorly.tensor(factors_tensor)

core_list = []
mode_factors_list = []
for i in range(factors_tensor.shape[0]):
    print (i)
    core, mode_factors= tucker(factors_tensor[i])
    core = np.expand_dims(core, axis=0)
    core_list.append(core)
    mode_factors_list.append(mode_factors)


0
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
连接张量流

In [5]:
batch_length = tensor_steam_length
a_list = []
b_list = []
c_list = []
for i in range(batch_length):
    a = np.expand_dims(mode_factors_list[i][0], axis=0)
    b = np.expand_dims(mode_factors_list[i][1], axis=0)
    c = np.expand_dims(mode_factors_list[i][2], axis=0)
    a_list.append(a)
    b_list.append(b)
    c_list.append(c)
    
U1 = np.concatenate(a_list)
U2 = np.concatenate(b_list)
U3 = np.concatenate(c_list)

M1 = U1 * np.transpose(U1, axes=[0,2,1])
M2 = U2 * np.transpose(U2, axes=[0,2,1])
M3 = U3 * np.transpose(U3, axes=[0,2,1])

暂时没有找到较好的批次处理tucker分解的方法,这里特例处理


In [6]:
D_U1_core = np.matmul(D, tensorly.base.unfold(M1, mode=0))
I_k = np.int(np.sqrt(D_U1_core.shape[1]))
D_U1 = tensorly.base.fold(D_U1_core, mode=0, shape=[I_k, I_k])

D_U2_core = np.matmul(D, tensorly.base.unfold(M2, mode=0))
I_k = np.int(np.sqrt(D_U2_core.shape[1]))
D_U2 = tensorly.base.fold(D_U2_core, mode=0, shape=[I_k, I_k])

D_U3_core = np.matmul(D, tensorly.base.unfold(M3, mode=0))
I_k = np.int(np.sqrt(D_U3_core.shape[1]))
D_U3 = tensorly.base.fold(D_U3_core, mode=0, shape=[I_k, I_k])

In [7]:
vec_W = np.expand_dims(W.sum(axis=0), axis=0)

W_U1_core = np.matmul(vec_W, tensorly.base.unfold(M1, mode=0))
I_k = np.int(np.sqrt(W_U1_core.shape[1]))
W_U1 = tensorly.base.fold(W_U1_core, mode=0, shape=[I_k, I_k])

W_U2_core = np.matmul(vec_W, tensorly.base.unfold(M2, mode=0))
I_k = np.int(np.sqrt(W_U2_core.shape[1]))
W_U2 = tensorly.base.fold(W_U2_core, mode=0, shape=[I_k, I_k])

W_U3_core = np.matmul(vec_W, tensorly.base.unfold(M3, mode=0))
I_k = np.int(np.sqrt(W_U3_core.shape[1]))
W_U3 = tensorly.base.fold(W_U3_core, mode=0, shape=[I_k, I_k])

二次规划优化估计修正矩阵$V_k$

添加约束条件 $trace(V^TD_UV)=1$ 获得目标函数的唯一优化结果,这是获取因子矩阵对应的修正矩阵的优化问题转化为:

  • $min\ J(V) = trace(V^TD_UV-V^TW_UV)$
  • $s.t. \ trace(V^TD_UV)=1$

In [8]:
def objective_function(V, D_U, W_U, J_K):
    newshape = [D_U.shape[0], J_K]
    V = np.reshape(V,newshape=newshape)
    left = np.matmul(np.matmul(V.T, D_U),V)
    right = np.matmul(np.matmul(V.T, W_U),V)
    return np.trace(left + right)

def constraints(V, D_U):
    newshape = [D_U.shape[0], J_K]
    V = np.reshape(V,newshape=newshape)
    left = np.matmul(np.matmul(V.T, D_U),V)
    return np.trace(left)- 1.0

$V_1$


In [9]:
objective_function_1 = functools.partial(
    objective_function, D_U = D_U1, W_U = W_U1, J_K = 10)

constraints_1 = functools.partial(constraints, D_U = D_U1)

cons_1 = ({'type':'ineq', 'fun':constraints_1})
initial_1 = np.random.normal(scale=0.1, size=D_U1.shape[0]*10).reshape(D_U1.shape[0],10)

V1 = optimize.minimize(objective_function_1, initial_1).x.reshape(D_U1.shape[0],10)

$V_2$


In [10]:
objective_function_2 = functools.partial(
    objective_function, D_U = D_U2, W_U = W_U2, J_K = 10)

constraints_2 = functools.partial(constraints, D_U = D_U2)

cons_2 = ({'type':'ineq', 'fun':constraints_2})
initial_2 = np.random.normal(scale=0.1, size=D_U2.shape[0]*10).reshape(D_U2.shape[0],10)

V2 = optimize.minimize(objective_function_2, initial_2).x.reshape(D_U2.shape[0],10)

$V_3$


In [11]:
objective_function_3 = functools.partial(
    objective_function, D_U = D_U3, W_U = W_U3, J_K = 10)

constraints_3 = functools.partial(constraints, D_U = D_U3)

cons_3 = ({'type':'ineq', 'fun':constraints_3})
initial_3 = np.random.normal(scale=0.1, size=D_U3.shape[0]*10).reshape(D_U3.shape[0],10)

V3 = optimize.minimize(objective_function_3, initial_3).x.reshape(D_U3.shape[0],10)

$\bar{\mathcal{X}_i} = \mathcal{C}_i \times_1 (V^T_1U^i_1) \times_2 (V^T_2U^i_2) \times_3 (V^T_3U^i_3)$


In [12]:
new_U1 =  np.matmul(V1.T, U1)
new_U2 =  np.matmul(V2.T, U2)
new_U3 =  np.matmul(V3.T, U3)

In [13]:
unfold_mode1 = tensorly.base.partial_unfold(factors_tensor, mode=0, skip_begin=1)
times_mode1 = np.matmul(new_U1, unfold_mode1)
times1_shape = (factors_tensor.shape[0] ,new_U1.shape[1], factors_tensor.shape[2], factors_tensor.shape[3])
times1 = tensorly.base.partial_fold(times_mode1, 0, times1_shape, skip_begin=1, skip_end=0)

unfold_mode2 = tensorly.base.partial_unfold(times1, mode=1, skip_begin=1)
times_mode2 = np.matmul(new_U2, unfold_mode2)
times2_shape = (factors_tensor.shape[0] ,new_U1.shape[1] ,new_U2.shape[1], factors_tensor.shape[3])
times2 = tensorly.base.partial_fold(times_mode2, 1, times2_shape, skip_begin=1, skip_end=0)

In [14]:
unfold_mode3 = tensorly.base.partial_unfold(times2, mode=2, skip_begin=1)
times_mode3 = np.matmul(new_U3, unfold_mode3)
times3_shape = (factors_tensor.shape[0] ,new_U1.shape[1], new_U2.shape[1], new_U3.shape[1])
times3 = tensorly.base.partial_fold(times_mode3, 2, times3_shape, skip_begin=1, skip_end=0)

In [15]:
new_factors_tensor = times3

动态关系捕获和降维 $\mathcal{X}\in\mathbb{R}^{I_1 \times I_2 \times I_3} \to \bar{\mathcal{X}} \in \mathbb{R}^{J_1 \times J_2 \times J_3}$


In [16]:
factors_tensor.shape


Out[16]:
(300, 69, 16, 32)

In [17]:
new_factors_tensor.shape


Out[17]:
(300, 10, 10, 10)

In [18]:
new_factors_tensor


Out[18]:
array([[[[  1.20088711e+18,  -9.39257236e+18,   4.17323386e+18, ...,
            1.22671463e+19,   2.83522318e+18,  -8.96128282e+18],
         [ -1.85584727e+18,   1.48577156e+19,  -6.74303253e+18, ...,
           -1.81974692e+19,  -4.55194623e+18,   1.27374179e+19],
         [ -3.03252593e+18,   2.51420172e+19,  -1.17587833e+19, ...,
           -2.78207473e+19,  -7.86770073e+18,   1.80138729e+19],
         ..., 
         [  3.18533307e+18,  -2.46754559e+19,   1.08643517e+19, ...,
            3.30711160e+19,   7.40156045e+18,  -2.45479422e+19],
         [  1.61892482e+18,  -1.39250973e+19,   6.70826945e+18, ...,
            1.37387725e+19,   4.45022985e+18,  -7.98855173e+18],
         [ -2.59008049e+18,   1.89475885e+19,  -7.87689904e+18, ...,
           -2.93666789e+19,  -5.46299794e+18,   2.35803904e+19]],

        [[ -4.72346653e+17,   2.48191702e+18,  -5.90022662e+17, ...,
           -7.57496975e+18,  -5.07422353e+17,   7.53730440e+18],
         [ -1.70434742e+18,   2.08464029e+19,  -1.23844376e+19, ...,
           -6.50153833e+17,  -7.76953097e+18,  -1.17743673e+19],
         [ -8.92076885e+18,   9.62919181e+19,  -5.37522035e+19, ...,
           -3.22334445e+19,  -3.42590301e+19,  -1.95282395e+19],
         ..., 
         [ -2.95305900e+18,   2.38000711e+19,  -1.08491152e+19, ...,
           -2.86876834e+19,  -7.31556902e+18,   1.98645145e+19],
         [  8.33229805e+18,  -8.76173688e+19,   4.81963856e+19, ...,
            3.53538522e+19,   3.08364917e+19,   1.05815372e+19],
         [  1.03336876e+19,  -9.97973197e+19,   5.21507365e+19, ...,
            6.36175076e+19,   3.38249575e+19,  -1.57705402e+19]],

        [[  1.18964404e+18,  -9.59180496e+18,   4.38543203e+18, ...,
            1.14895657e+19,   2.95349296e+18,  -7.91184521e+18],
         [ -2.42254282e+18,   2.11194528e+19,  -1.02864943e+19, ...,
           -1.98999645e+19,  -6.80210479e+18,   1.09954487e+19],
         [ -5.43105718e+18,   5.03919992e+19,  -2.56565712e+19, ...,
           -3.79366733e+19,  -1.67582848e+19,   1.48783756e+19],
         ..., 
         [  2.74805539e+18,  -2.10605468e+19,   9.18508087e+18, ...,
            2.89989134e+19,   6.27511772e+18,  -2.18668379e+19],
         [  3.75626767e+18,  -3.61469614e+19,   1.88458727e+19, ...,
            2.34116162e+19,   1.22310251e+19,  -6.15184561e+18],
         [ -3.30910349e+17,  -3.40409802e+18,   3.96944550e+18, ...,
           -1.65781076e+19,   2.19252494e+18,   2.17781476e+19]],

        ..., 
        [[ -3.67312294e+18,   3.04512221e+19,  -1.42605098e+19, ...,
           -3.36030164e+19,  -9.53628125e+18,   2.16939340e+19],
         [  9.14226186e+18,  -8.34420107e+19,   4.20318595e+19, ...,
            6.67759205e+19,   2.75328281e+19,  -2.93292209e+19],
         [  2.36749612e+19,  -2.28084972e+20,   1.19081775e+20, ...,
            1.46583898e+20,   7.72486114e+19,  -3.74023606e+19],
         ..., 
         [ -7.32278243e+18,   5.54051153e+19,  -2.38684481e+19, ...,
           -7.88293326e+19,  -1.63679534e+19,   6.05472872e+19],
         [ -1.77219466e+19,   1.75151194e+20,  -9.28977985e+19, ...,
           -1.00073942e+20,  -6.00110462e+19,   1.38663302e+19],
         [ -5.33980040e+18,   7.35387112e+19,  -4.57486148e+19, ...,
            1.56718755e+19,  -2.83935213e+19,  -6.28530030e+19]],

        [[ -1.08810315e+18,   8.69004209e+18,  -3.93808307e+18, ...,
           -1.07023909e+19,  -2.65937524e+18,   7.51822581e+18],
         [  2.04563573e+18,  -1.74528068e+19,   8.35812749e+18, ...,
            1.76559523e+19,   5.55380918e+18,  -1.05295809e+19],
         [  4.26050395e+18,  -3.86658143e+19,   1.93861425e+19, ...,
            3.16734382e+19,   1.27164174e+19,  -1.44697500e+19],
         ..., 
         [ -2.63211172e+18,   2.02489745e+19,  -8.86059078e+18, ...,
           -2.76198151e+19,  -6.04751085e+18,   2.07147273e+19],
         [ -2.80857329e+18,   2.65482404e+19,  -1.36829188e+19, ...,
           -1.85547853e+19,  -8.90786783e+18,   6.13638629e+18],
         [  9.53668459e+17,  -3.34836631e+18,  -2.00892497e+17, ...,
            1.88114874e+19,   2.10347771e+17,  -2.03835513e+19]],

        [[  1.11274186e+18,  -8.18365535e+18,   3.41600126e+18, ...,
            1.25470807e+19,   2.36655464e+18,  -1.00255531e+19],
         [ -6.75230113e+17,   2.31667523e+18,   2.02908351e+17, ...,
           -1.35120670e+19,  -1.16482796e+17,   1.47045607e+19],
         [  1.52916856e+18,  -2.22601845e+19,   1.41502911e+19, ...,
           -7.25157280e+18,   8.73605580e+18,   2.20265930e+19],
         ..., 
         [  3.68086921e+18,  -2.89116445e+19,   1.28881109e+19, ...,
            3.73709118e+19,   8.74794881e+18,  -2.71264583e+19],
         [ -2.34802290e+18,   2.70404882e+19,  -1.55945908e+19, ...,
           -4.76016603e+18,  -9.85795247e+18,  -1.05896794e+19],
         [ -6.39636645e+18,   5.71789459e+19,  -2.83444499e+19, ...,
           -4.95533416e+19,  -1.86528996e+19,   2.46406581e+19]]],


       [[[  9.99455160e+17,   8.65125923e+17,  -2.68625403e+18, ...,
           -2.18778907e+18,   1.42901845e+18,  -1.27919095e+18],
         [ -1.10065411e+18,  -9.60352860e+17,   2.98362937e+18, ...,
            2.48296215e+18,  -1.61102757e+18,   1.41055774e+18],
         [ -1.79957527e+18,  -1.45551541e+18,   4.35469593e+18, ...,
            2.40609091e+18,  -1.72565919e+18,   2.21648939e+18],
         ..., 
         [  3.70591350e+18,   2.92578134e+18,  -8.79586073e+18, ...,
           -4.51885785e+18,   3.36571094e+18,  -4.57614727e+18],
         [ -1.87938900e+18,  -1.54546924e+18,   4.76568989e+18, ...,
            3.27105173e+18,  -2.25262312e+18,   2.37919187e+18],
         [ -2.94408845e+18,  -2.40830791e+18,   7.34259970e+18, ...,
            4.69117343e+18,  -3.26930117e+18,   3.68871457e+18]],

        [[ -3.92668097e+18,  -2.35039366e+18,   6.08316818e+18, ...,
           -5.30618967e+18,   1.91706083e+18,   4.34316165e+18],
         [  5.24423028e+18,   3.08491411e+18,  -7.88785164e+18, ...,
            7.82604621e+18,  -2.96295745e+18,  -5.76274375e+18],
         [ -1.57015409e+19,  -8.26216952e+18,   2.01070955e+19, ...,
           -3.38696359e+19,   1.42931128e+19,   1.69012901e+19],
         ..., 
         [  3.60912404e+19,   1.89471365e+19,  -4.54980455e+19, ...,
            8.04821468e+19,  -3.44710752e+19,  -3.85879948e+19],
         [ -3.52777455e+18,  -1.49116633e+18,   2.83365743e+18, ...,
           -1.29397110e+19,   6.14489281e+18,   3.50413288e+18],
         [ -1.29913589e+19,  -6.48064447e+18,   1.50138320e+19, ...,
           -3.31483266e+19,   1.46412647e+19,   1.37058126e+19]],

        [[  2.53868674e+16,   2.65924445e+17,  -1.09195748e+18, ...,
           -3.22677574e+18,   1.74841113e+18,  -1.84125402e+17],
         [  1.92714816e+17,  -1.78937774e+17,   9.27773088e+17, ...,
            4.05273207e+18,  -2.13833805e+18,  -3.40124983e+16],
         [ -5.12621357e+18,  -3.15606660e+18,   8.35340787e+18, ...,
           -5.61806805e+18,   1.77968113e+18,   5.74365437e+18],
         ..., 
         [  1.16358658e+19,   7.03101147e+18,  -1.85173834e+19, ...,
            1.40418592e+19,  -4.69389771e+18,  -1.30044904e+19],
         [ -2.62473283e+18,  -1.83609362e+18,   5.26837116e+18, ...,
            2.44623262e+17,  -7.98793731e+17,   3.10719616e+18],
         [ -5.68548538e+18,  -3.71972141e+18,   1.02475302e+19, ...,
           -3.13994647e+18,   2.81992242e+17,   6.53386357e+18]],

        ..., 
        [[  2.03739028e+18,   3.00107440e+17,   7.52572368e+17, ...,
            1.48996401e+19,  -7.57115773e+18,  -1.65989750e+18],
         [ -3.53223179e+18,  -1.00104029e+18,   7.58025253e+17, ...,
           -1.94077371e+19,   9.64123077e+18,   3.19639903e+18],
         [  2.79653558e+19,   1.64543353e+19,  -4.27807988e+19, ...,
            3.89823219e+19,  -1.40559373e+19,  -3.10395593e+19],
         ..., 
         [ -6.29737282e+19,  -3.64379016e+19,   9.35769658e+19, ...,
           -9.64627043e+19,   3.64044246e+19,   6.94360145e+19],
         [  1.14245744e+19,   7.43093630e+18,  -2.04632508e+19, ...,
            6.66651864e+18,  -7.39308756e+17,  -1.31260279e+19],
         [  2.82041169e+19,   1.73071238e+19,  -4.61519108e+19, ...,
            2.99913386e+19,  -9.13591910e+18,  -3.17546140e+19]],

        [[ -4.28463225e+17,  -5.20862836e+17,   1.80094208e+18, ...,
            2.96435457e+18,  -1.71404504e+18,   6.50325246e+17],
         [  3.44238721e+17,   5.13472570e+17,  -1.85162636e+18, ...,
           -3.63982334e+18,   2.05862556e+18,  -5.84179046e+17],
         [  4.15948850e+18,   2.70407060e+18,  -7.44009197e+18, ...,
            2.46207043e+18,  -2.89613246e+17,  -4.77619382e+18],
         ..., 
         [ -8.97980094e+18,  -5.68443172e+18,   1.54213627e+19, ...,
           -7.29854372e+18,   1.69505359e+18,   1.02169945e+19],
         [  2.34349884e+18,   1.72202164e+18,  -5.04746816e+18, ...,
           -1.28028900e+18,   1.28528999e+18,  -2.82420861e+18],
         [  4.83685460e+18,   3.34329513e+18,  -9.50821951e+18, ...,
            1.93298594e+17,   1.11269164e+18,  -5.68719928e+18]],

        [[  2.41479014e+18,   1.64138491e+18,  -4.57267689e+18, ...,
            6.79727914e+17,   2.19289576e+17,  -2.79680770e+18],
         [ -3.05156308e+18,  -2.02444336e+18,   5.55805522e+18, ...,
           -1.55044463e+18,   1.00474619e+17,   3.49832905e+18],
         [  5.45075662e+18,   2.49922187e+18,  -5.50670536e+18, ...,
            1.62658647e+19,  -7.36805972e+18,  -5.67064590e+18],
         ..., 
         [ -1.27851878e+19,  -5.99182874e+18,   1.30953305e+19, ...,
           -3.78725131e+19,   1.72658191e+19,   1.32219499e+19],
         [  1.21245164e+17,  -5.05135168e+17,   2.31700644e+18, ...,
            7.98344196e+18,  -4.31065162e+18,   2.60155584e+17],
         [  3.42351642e+18,   1.01764499e+18,  -1.06908931e+18, ...,
            1.76730561e+19,  -8.68047810e+18,  -3.18665336e+18]]],


       [[[ -5.52863108e+17,   6.99011993e+17,   8.07162785e+17, ...,
           -6.64117408e+17,  -5.91179126e+17,   8.04634025e+17],
         [  3.20757605e+17,  -3.65364962e+17,  -4.58511991e+17, ...,
            3.79357676e+17,   3.37644213e+17,  -4.51179391e+17],
         [  2.13591340e+18,  -1.55266659e+18,  -2.83350890e+18, ...,
            2.40177179e+18,   2.12882458e+18,  -2.66398295e+18],
         ..., 
         [ -2.65238484e+18,   2.57462869e+18,   3.67887705e+18, ...,
           -3.07512406e+18,  -2.73084516e+18,   3.55866682e+18],
         [  6.31491304e+17,  -6.78328159e+17,  -8.92182942e+17, ...,
            7.41382099e+17,   6.59040668e+17,  -8.72537937e+17],
         [  1.09926584e+18,  -1.75046261e+18,  -1.69420882e+18, ...,
            1.37217289e+18,   1.22410058e+18,  -1.73961989e+18]],

        [[  1.35781328e+18,   1.34057131e+19,   1.77721631e+18, ...,
           -5.21530404e+17,  -5.94783642e+17,   3.87829489e+18],
         [ -4.90032676e+17,  -4.60789199e+18,  -5.83673834e+17, ...,
            1.55988671e+17,   1.83273883e+17,  -1.31076790e+18],
         [  3.21121103e+18,   3.90295936e+19,   6.02515807e+18, ...,
           -2.27507876e+18,  -2.39850209e+18,   1.20075647e+19],
         ..., 
         [  7.77560517e+17,   2.67468570e+18,  -2.25943998e+17, ...,
            4.13269391e+17,   3.36438994e+17,   2.84446676e+17],
         [ -6.65848187e+17,  -5.81155319e+18,  -6.81813916e+17, ...,
            1.47415643e+17,   1.88412422e+17,  -1.60678093e+18],
         [ -5.35807083e+18,  -5.51773995e+19,  -7.57989546e+18, ...,
            2.38135209e+18,   2.65559122e+18,  -1.61853677e+19]],

        [[ -2.86104175e+17,   4.02780239e+18,   1.32912852e+18, ...,
           -8.65508777e+17,  -8.02107953e+17,   1.83565714e+18],
         [  2.38625580e+17,  -1.52415252e+18,  -6.52330951e+17, ...,
            4.60614675e+17,   4.20627067e+17,  -8.20532174e+17],
         [  3.15663379e+18,   7.73266705e+18,  -1.69412631e+18, ...,
            2.12286684e+18,   1.78876978e+18,  -5.53843551e+16],
         ..., 
         [ -2.76356404e+18,   3.51393608e+18,   4.03975041e+18, ...,
           -3.32239128e+18,  -2.95782371e+18,   4.02970486e+18],
         [  5.41540462e+17,  -2.16395512e+18,  -1.15841682e+18, ...,
            8.61048417e+17,   7.79289922e+17,  -1.36081701e+18],
         [ -7.63155622e+16,  -1.53236936e+19,  -3.72212820e+18, ...,
            2.10334165e+18,   2.00536582e+18,  -5.85866058e+18]],

        ..., 
        [[  1.48223150e+17,  -2.16970667e+19,  -5.56392484e+18, ...,
            3.23977525e+18,   3.06966235e+18,  -8.54287379e+18],
         [ -5.11044836e+17,   7.93000249e+18,   2.55676046e+18, ...,
           -1.65089436e+18,  -1.53218841e+18,   3.56369959e+18],
         [ -1.26053676e+19,  -4.96702075e+19,   2.09275620e+18, ...,
           -5.80315076e+18,  -4.59951176e+18,  -7.05335290e+18],
         ..., 
         [  8.87157354e+18,  -1.34894362e+19,  -1.35175239e+19, ...,
            1.09799974e+19,   9.79414034e+18,  -1.37913390e+19],
         [ -1.42882423e+18,   1.08182412e+19,   4.32642156e+18, ...,
           -2.99911678e+18,  -2.74750413e+18,   5.56826364e+18],
         [  3.48889975e+18,   8.50639484e+19,   1.71509102e+19, ...,
           -8.54490659e+18,  -8.37914260e+18,   2.95611957e+19]],

        [[  3.35838288e+17,  -2.60750361e+18,  -1.03300292e+18, ...,
            7.14134633e+17,   6.54550983e+17,  -1.33384932e+18],
         [ -2.38059090e+17,   1.01685107e+18,   5.25616202e+17, ...,
           -3.87765815e+17,  -3.51484146e+17,   6.23566129e+17],
         [ -2.51879043e+18,  -4.13960716e+18,   1.85675250e+18, ...,
           -1.98280212e+18,  -1.70220410e+18,   8.30237592e+17],
         ..., 
         [  2.43940176e+18,  -2.86292236e+18,  -3.50652449e+18, ...,
            2.89867467e+18,   2.57855434e+18,  -3.46456146e+18],
         [ -5.11453745e+17,   1.49150721e+18,   9.56787058e+17, ...,
           -7.34586625e+17,  -6.61263349e+17,   1.07141997e+18],
         [ -2.83649031e+17,   9.64819727e+18,   2.72344702e+18, ...,
           -1.66319151e+18,  -1.56050736e+18,   4.00920982e+18]],

        [[ -9.91006712e+17,  -5.24816977e+18,  -1.69409634e+17, ...,
           -2.65039911e+17,  -1.79809842e+17,  -1.07452046e+18],
         [  4.46728683e+17,   1.71201768e+18,  -8.65684324e+16, ...,
            2.12091054e+17,   1.69723221e+17,   2.31459748e+17],
         [  1.92407291e+17,  -1.79220558e+19,  -4.67688541e+18, ...,
            2.74662352e+18,   2.59882105e+18,  -7.12373103e+18],
         ..., 
         [ -2.28809327e+18,   7.46694053e+17,   2.80710075e+18, ...,
           -2.44288002e+18,  -2.15625339e+18,   2.49912593e+18],
         [  7.51361845e+17,   1.99877243e+18,  -3.64022665e+17, ...,
            4.82665127e+17,   4.04412267e+17,   4.81067534e+16],
         [  3.11361699e+18,   2.24308522e+19,   2.01005845e+18, ...,
           -1.23702208e+16,  -2.39514662e+17,   5.67600244e+18]]],


       ..., 
       [[[ -1.12646850e+17,   1.18088830e+17,   6.79233070e+16, ...,
           -2.17116228e+17,  -2.45196186e+17,   3.60756335e+17],
         [ -4.72940003e+18,   4.78217188e+18,   3.17521351e+18, ...,
           -6.45280846e+18,  -7.98919136e+18,   4.46993650e+18],
         [ -7.79024257e+18,   7.88966118e+18,   5.20709633e+18, ...,
           -1.08083303e+19,  -1.33124670e+19,   8.07254416e+18],
         ..., 
         [  1.05811160e+19,  -1.06963554e+19,  -7.10921156e+18, ...,
            1.44024659e+19,   1.78465565e+19,  -9.87024952e+18],
         [ -3.97169833e+18,   4.01361304e+18,   2.67099713e+18, ...,
           -5.38923714e+18,  -6.68513734e+18,   3.64059242e+18],
         [ -6.88948231e+18,   6.95397445e+18,   4.64835052e+18, ...,
           -9.22357168e+18,  -1.14881698e+19,   5.81427521e+18]],

        [[  4.75482044e+17,  -9.38188135e+17,   5.34013393e+17, ...,
            6.43156198e+18,   5.52156384e+18,  -2.25790540e+19],
         [ -2.26661751e+18,   2.44052650e+18,   1.24414287e+18, ...,
           -4.93216012e+18,  -5.31803821e+18,   9.13855854e+18],
         [ -2.22135212e+18,   1.21681699e+18,   3.40993758e+18, ...,
            1.01419822e+19,   7.04349411e+18,  -4.84858935e+19],
         ..., 
         [  5.37150980e+18,  -5.98994809e+18,  -2.56440605e+18, ...,
            1.43827920e+19,   1.48271943e+19,  -3.20627635e+19],
         [ -2.16210297e+18,   2.50809158e+18,   8.51478150e+17, ...,
           -7.05015671e+18,  -7.00709843e+18,   1.77681494e+19],
         [ -4.79214784e+18,   6.31224391e+18,   4.81948081e+17, ...,
           -2.51290837e+19,  -2.32783733e+19,   7.57254051e+19]],

        [[ -1.40225982e+16,  -9.08348759e+16,   2.05449289e+17, ...,
            1.29401162e+18,   1.04337485e+18,  -4.99586532e+18],
         [ -5.86184417e+18,   5.96300758e+18,   3.86870332e+18, ...,
           -8.43867192e+18,  -1.02584115e+19,   7.21446773e+18],
         [ -9.29587445e+18,   9.16714587e+18,   6.67455097e+18, ...,
           -9.73254845e+18,  -1.32919665e+19,  -2.51925391e+18],
         ..., 
         [  1.31868423e+19,  -1.34648120e+19,  -8.60926648e+18, ...,
            1.96423321e+19,   2.36212701e+19,  -1.87739685e+19],
         [ -4.98472963e+18,   5.11478626e+18,   3.20784893e+18, ...,
           -7.74911942e+18,  -9.19602148e+18,   8.34639805e+18],
         [ -8.89379417e+18,   9.33081042e+18,   5.34082267e+18, ...,
           -1.63867393e+19,  -1.84877367e+19,   2.46571628e+19]],

        ..., 
        [[ -2.59862423e+17,   8.94066254e+17,  -1.00338455e+18, ...,
           -8.31461607e+18,  -6.92737149e+18,   3.06835654e+19],
         [  2.09269608e+19,  -2.13699840e+19,  -1.36586432e+19, ...,
            3.11583282e+19,   3.74639822e+19,  -2.97018601e+19],
         [  3.23116894e+19,  -3.12603689e+19,  -2.43255021e+19, ...,
            2.60756233e+19,   3.98392850e+19,   3.85609525e+19],
         ..., 
         [ -4.72446209e+19,   4.85509527e+19,   3.02657012e+19, ...,
           -7.43303822e+19,  -8.78670991e+19,   8.24427485e+19],
         [  1.79401858e+19,  -1.85871031e+19,  -1.12118172e+19, ...,
            3.01799709e+19,   3.49746722e+19,  -3.88375328e+19],
         [  3.26119508e+19,  -3.50046853e+19,  -1.81107384e+19, ...,
            7.01909319e+19,   7.60688940e+19,  -1.29202203e+20]],

        [[  4.14503708e+16,   2.05581302e+16,  -1.44383635e+17, ...,
           -7.31133629e+17,  -5.72038699e+17,   2.97281269e+18],
         [  5.17378188e+18,  -5.25286551e+18,  -3.43373064e+18, ...,
            7.32926897e+18,   8.96034055e+18,  -5.92392591e+18],
         [  8.29187293e+18,  -8.24565774e+18,  -5.82569754e+18, ...,
            9.55067354e+18,   1.25662049e+19,  -1.08149452e+18],
         ..., 
         [ -1.16190327e+19,   1.18271857e+19,   7.65442927e+18, ...,
           -1.68574160e+19,  -2.04506352e+19,   1.48381864e+19],
         [  4.38269617e+18,  -4.47633912e+18,  -2.85907436e+18, ...,
            6.55452177e+18,   7.87522044e+18,  -6.35179539e+18],
         [  7.76342264e+18,  -8.05176688e+18,  -4.83600864e+18, ...,
            1.31538601e+19,   1.52077305e+19,  -1.71518442e+19]],

        [[ -2.87893696e+17,   4.90336640e+17,  -1.78291780e+17, ...,
           -2.91890595e+18,  -2.54962939e+18,   9.94700994e+18],
         [ -2.56985530e+18,   2.53479197e+18,   1.84440900e+18, ...,
           -2.71776906e+18,  -3.70295335e+18,  -5.69692047e+17],
         [ -4.88070128e+18,   5.38571744e+18,   2.43712982e+18, ...,
           -1.24393095e+19,  -1.29860770e+19,   2.68244917e+19],
         ..., 
         [  5.62075920e+18,  -5.44191153e+18,  -4.22431854e+18, ...,
            4.61974770e+18,   7.00842929e+18,   6.35108762e+18],
         [ -2.04726432e+18,   1.93033544e+18,   1.63510058e+18, ...,
           -1.01365092e+18,  -2.00253971e+18,  -4.88920394e+18],
         [ -3.10530829e+18,   2.50193889e+18,   3.27467606e+18, ...,
            3.86344531e+18,   1.37382734e+18,  -2.81009174e+19]]],


       [[[ -2.34662545e+18,   3.78842621e+18,  -2.92935785e+18, ...,
           -6.74710630e+18,  -1.93072474e+18,   4.79301512e+18],
         [  1.44980435e+18,  -1.80397088e+18,   2.35650916e+18, ...,
            3.58549600e+18,   1.92569399e+18,  -3.75241807e+18],
         [  6.83837085e+18,  -9.44374184e+18,   1.01611185e+19, ...,
            1.79256892e+19,   7.80484556e+18,  -1.63188080e+19],
         ..., 
         [ -3.50254634e+18,   5.64301640e+18,  -4.38441051e+18, ...,
           -1.00585090e+19,  -2.89784656e+18,   7.17145281e+18],
         [ -5.06908417e+17,   7.52449252e+15,  -1.45807953e+18, ...,
           -5.75572658e+17,  -1.52370774e+18,   2.22984323e+18],
         [  2.05076224e+18,  -4.28150222e+18,   1.57287951e+18, ...,
            6.95333393e+18,   3.63269864e+17,  -2.75988121e+18]],

        [[  1.14093763e+19,  -2.19985118e+19,   1.05970358e+19, ...,
            3.66940388e+19,   4.49994382e+18,  -1.80276921e+19],
         [ -1.32371772e+19,   2.73691714e+19,  -1.04147716e+19, ...,
           -4.45801220e+19,  -2.70025409e+18,   1.81949298e+19],
         [ -5.16466176e+19,   1.05069595e+20,  -4.23775962e+19, ...,
           -1.72067021e+20,  -1.28735784e+19,   7.35128981e+19],
         ..., 
         [  1.71645465e+19,  -3.31354856e+19,   1.59019429e+19, ...,
            5.52480859e+19,   6.71527608e+18,  -2.70626213e+19],
         [  1.18106481e+19,  -2.55607240e+19,   8.12924807e+18, ...,
            4.10147304e+19,   8.50288913e+17,  -1.45508363e+19],
         [  1.21286315e+18,  -5.67510824e+18,  -2.27394567e+18, ...,
            7.52433498e+18,  -4.07955257e+18,   3.00469957e+18]],

        [[  1.77077763e+17,  -1.14389851e+18,  -6.51758634e+17, ...,
            1.44300205e+18,  -1.02487078e+18,   9.01623273e+17],
         [ -1.59172068e+18,   4.59219025e+18,   7.15743427e+16, ...,
           -6.77633467e+18,   1.45072561e+18,   2.71676303e+17],
         [ -4.92627620e+18,   1.48903027e+19,   9.13255894e+17, ...,
           -2.17071582e+19,   5.41669363e+18,  -1.60146338e+17],
         ..., 
         [  2.96007692e+17,  -1.79115772e+18,  -9.65922575e+17, ...,
            2.28103970e+18,  -1.54766302e+18,   1.32836841e+18],
         [  2.27850458e+18,  -6.11766904e+18,   3.60062249e+17, ...,
            9.20234799e+18,  -1.45585553e+18,  -1.05848904e+18],
         [  2.52776646e+18,  -6.02796549e+18,   1.16985275e+18, ...,
            9.38098710e+18,  -5.81237337e+17,  -2.28954711e+18]],

        ..., 
        [[ -7.43874516e+18,   1.70861834e+19,  -4.11195992e+18, ...,
           -2.69020364e+19,   8.14894199e+17,   7.70589655e+18],
         [  1.33766510e+19,  -3.21063687e+19,   5.98975805e+18, ...,
            4.98804396e+19,  -3.34929418e+18,  -1.18240631e+19],
         [  4.77767670e+19,  -1.13855498e+20,   2.22338110e+19, ...,
            1.77277277e+20,  -1.08390015e+19,  -4.34469504e+19],
         ..., 
         [ -1.12960707e+19,   2.59743497e+19,  -6.21358493e+18, ...,
           -4.08802854e+19,   1.27773009e+18,   1.16576577e+19],
         [ -1.48651844e+19,   3.62348000e+19,  -6.09575195e+18, ...,
           -5.60417050e+19,   4.47567820e+18,   1.23279782e+19],
         [ -9.36037725e+18,   2.40071111e+19,  -2.63559960e+18, ...,
           -3.65947683e+19,   4.43478119e+18,   6.02087227e+18]],

        [[  6.43344271e+17,  -5.08021396e+17,   1.34304067e+18, ...,
            1.27249821e+18,   1.25337833e+18,  -2.09552361e+18],
         [  5.19388650e+17,  -2.26148311e+18,  -8.00373132e+17, ...,
            3.04058024e+18,  -1.51513167e+18,   1.03591405e+18],
         [  8.52592056e+17,  -6.17901113e+18,  -3.82537915e+18, ...,
            7.67309488e+18,  -5.85453921e+18,   5.33544031e+18],
         ..., 
         [  9.40534753e+17,  -7.02603274e+17,   2.00417787e+18, ...,
            1.81660497e+18,   1.88701500e+18,  -3.12249482e+18],
         [ -1.24645693e+18,   3.78107818e+18,   2.45234840e+17, ...,
           -5.50655946e+18,   1.38936214e+18,  -6.09696399e+16],
         [ -2.22088415e+18,   5.10130829e+18,  -1.22799989e+18, ...,
           -8.03248686e+18,   2.43015886e+17,   2.30109571e+18]],

        [[ -6.64648217e+18,   1.22640461e+19,  -6.73444323e+18, ...,
           -2.07768904e+19,  -3.37381227e+18,   1.13141493e+19],
         [  6.75858063e+18,  -1.30804344e+19,   6.22755145e+18, ...,
            2.17902082e+19,   2.59874098e+18,  -1.06069436e+19],
         [  2.72536695e+19,  -5.20999818e+19,   2.57681711e+19, ...,
            8.71626921e+19,   1.13595327e+19,  -4.37214749e+19],
         ..., 
         [ -9.97842560e+18,   1.84255449e+19,  -1.00972369e+19, ...,
           -3.12076435e+19,  -5.04720767e+18,   1.69668212e+19],
         [ -5.44120883e+18,   1.09604121e+19,  -4.57542757e+18, ...,
           -1.80089024e+19,  -1.50494070e+18,   7.90525734e+18],
         [  1.01567009e+18,  -7.73135444e+17,   2.15210843e+18, ...,
            1.98046981e+18,   2.02042652e+18,  -3.35404027e+18]]],


       [[[  3.14585383e+15,  -2.36689691e+16,   8.32403433e+15, ...,
            1.37787962e+16,  -4.82416931e+15,  -1.39888310e+16],
         [  3.74917300e+17,  -1.38358078e+18,   1.16490369e+17, ...,
            1.25674902e+18,  -4.74741226e+17,  -5.58888374e+17],
         [  5.45332541e+17,  -2.00482632e+18,   1.79041362e+17, ...,
            1.84068919e+18,  -6.76629635e+17,  -8.21143803e+17],
         ..., 
         [ -2.38531435e+18,   8.91386500e+18,  -8.36834905e+17, ...,
           -8.05446825e+18,   3.00196125e+18,   3.66919754e+18],
         [  1.48986736e+18,  -5.59694175e+18,   5.41940286e+17, ...,
            5.04011428e+18,  -1.87577821e+18,  -2.31577105e+18],
         [  2.18911522e+18,  -8.19359762e+18,   7.82217594e+17, ...,
            7.40198789e+18,  -2.74999770e+18,  -3.38363827e+18]],

        [[ -1.59979461e+18,  -6.20476631e+18,   7.52919359e+18, ...,
           -1.44380057e+18,   1.79077808e+18,  -7.59549758e+18],
         [  3.43774156e+18,   1.23782102e+19,  -1.55514107e+19, ...,
            3.40620889e+18,  -3.87156206e+18,   1.55397228e+19],
         [  4.96537700e+18,   1.78269515e+19,  -2.24076901e+19, ...,
            4.95727687e+18,  -5.57423039e+18,   2.23826547e+19],
         ..., 
         [ -4.76196861e+18,  -1.23946571e+19,   1.83783658e+19, ...,
           -6.27040051e+18,   5.44216139e+18,  -1.75955074e+19],
         [ -1.09146105e+18,  -8.01143639e+18,   7.64738356e+18, ...,
            2.44121005e+17,   1.15421493e+18,  -8.30227476e+18],
         [  2.15000593e+18,   2.75600573e+18,  -6.40310217e+18, ...,
            3.76268978e+18,  -2.50093147e+18,   5.59143864e+18]],

        [[ -3.70501893e+17,  -1.47764705e+18,   1.77007074e+18, ...,
           -3.21829854e+17,   4.13385236e+17,  -1.79199459e+18],
         [  1.22511512e+18,   1.34030340e+18,  -3.50524114e+18, ...,
            2.20905032e+18,  -1.43813816e+18,   3.00550991e+18],
         [  1.77251957e+18,   1.91987896e+18,  -5.04029991e+18, ...,
            3.22132465e+18,  -2.06389185e+18,   4.31435202e+18],
         ..., 
         [ -3.79163158e+18,   7.10978902e+18,   3.35821192e+18, ...,
           -1.05091242e+19,   4.64329559e+18,   4.89708745e+15],
         [  1.41753392e+18,  -8.15746945e+18,   2.39663785e+18, ...,
            5.71579630e+18,  -1.83627209e+18,  -4.54137239e+18],
         [  2.96007814e+18,  -8.55372403e+18,  -6.20096105e+17, ...,
            9.18758968e+18,  -3.67300125e+18,  -2.48997551e+18]],

        ..., 
        [[  2.25770556e+18,   8.88947263e+18,  -1.07110187e+19, ...,
            1.99730645e+18,  -2.52211509e+18,   1.08260828e+19],
         [ -6.27502518e+18,  -1.23965837e+19,   2.16260562e+19, ...,
           -9.51868798e+18,   7.26404782e+18,  -1.99590469e+19],
         [ -9.08051113e+18,  -1.78006123e+19,   3.11138278e+19, ...,
           -1.39114671e+19,   1.04307118e+19,  -2.86801042e+19],
         ..., 
         [  1.56571564e+19,  -1.56854530e+19,  -2.29461924e+19, ...,
            3.89553984e+19,  -1.89228188e+19,   1.12650374e+19],
         [ -4.01208447e+18,   3.22523998e+19,  -1.28705988e+19, ...,
           -1.91567219e+19,   5.36304266e+18,   2.04196385e+19],
         [ -1.12209214e+19,   2.66725930e+19,   6.16122581e+18, ...,
           -3.29686907e+19,   1.38095033e+19,   4.69994757e+18]],

        [[  2.35771001e+17,   9.48792817e+17,  -1.13138152e+18, ...,
            2.02710915e+17,  -2.62298719e+17,   1.14670843e+18],
         [ -8.82916345e+17,  -4.80798982e+17,   2.20666800e+18, ...,
           -1.74687339e+18,   1.04780408e+18,  -1.76821152e+18],
         [ -1.28269628e+18,  -6.70938492e+17,   3.16206515e+18, ...,
           -2.57313908e+18,   1.49887626e+18,  -2.52088912e+18],
         ..., 
         [  3.06980315e+18,  -6.96661017e+18,  -1.91406374e+18, ...,
            8.90280927e+18,  -3.78043055e+18,  -1.00409118e+18],
         [ -1.31067424e+18,   6.73078014e+18,  -1.67733216e+18, ...,
           -5.02161704e+18,   1.68262462e+18,   3.52939670e+18],
         [ -2.48741919e+18,   7.69608262e+18,   1.78803918e+17, ...,
           -7.89060637e+18,   3.09129179e+18,   2.51661446e+18]],

        [[  7.00711214e+17,   2.68785193e+18,  -3.27804583e+18, ...,
            6.42008723e+17,  -7.84972437e+17,   3.30227117e+18],
         [ -1.20183476e+18,  -6.49951981e+18,   6.87924364e+18, ...,
           -4.85063051e+17,   1.31385972e+18,  -7.22565580e+18],
         [ -1.73755842e+18,  -9.35816340e+18,   9.91283918e+18, ...,
           -7.21315790e+17,   1.89341651e+18,  -1.04075197e+19],
         ..., 
         [  1.88268801e+17,   1.24690681e+19,  -8.68075625e+18, ...,
           -3.64321918e+18,   4.39622520e+15,   1.05828010e+19],
         [  1.65640493e+18,  -9.38442122e+17,  -2.90761099e+18, ...,
            3.88558020e+18,  -1.98995070e+18,   1.78815917e+18],
         [  7.94134392e+17,  -7.68847464e+18,   3.40953483e+18, ...,
            4.21115346e+18,  -1.08944256e+18,  -5.11431478e+18]]]])

In [ ]:


In [ ]:


In [ ]: