teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

2

コードを追加

2020/06/26 16:27

投稿

physics303
physics303

スコア89

title CHANGED
File without changes
body CHANGED
@@ -18,4 +18,32 @@
18
18
  モードn積の定義やRでの実装は以下を参考にしています.
19
19
  https://www.alexejgossmann.com/tensor_decomposition_tucker/
20
20
 
21
- np.tensordot で対応できると良いのですが...
21
+ np.tensordot で対応できると良いのですが...
22
+
23
+ ### 実装
24
+ たとえば,n=3 だあれば,こんな感じかと思います.
25
+ 絶対にもっと良い実装方法があるとは思うのですが...
26
+
27
+ ```Python
28
+ l1 = 3
29
+ l2 = 3
30
+ l3 = 3
31
+ l4 = 3
32
+ J = 2
33
+ X = np.random.uniform(0,1,(l1,l2,l3,l4))
34
+ M = np.random.uniform(0,1,(J,l3))
35
+
36
+ def mode_3_prodcut(X,M,mode=3):
37
+ A = np.zeros((l1,l2,J,l4))
38
+ for i1 in range(l1):
39
+ for i2 in range(l2):
40
+ for j in range(J):
41
+ for i4 in range(l4):
42
+ term = 0
43
+ for i3 in range(l3):
44
+ term += X[i1,i2,i3,i4] * M[j,i3]
45
+
46
+ A[i1,i2,j,i4] = term
47
+
48
+ return A
49
+ ```

1

参照に追加

2020/06/26 16:27

投稿

physics303
physics303

スコア89

title CHANGED
File without changes
body CHANGED
@@ -16,4 +16,6 @@
16
16
 
17
17
  ### 参照
18
18
  モードn積の定義やRでの実装は以下を参考にしています.
19
- https://www.alexejgossmann.com/tensor_decomposition_tucker/
19
+ https://www.alexejgossmann.com/tensor_decomposition_tucker/
20
+
21
+ np.tensordot で対応できると良いのですが...