matlab cp分解,matlab實現CP分解 代碼

使用tensor-box,在matlab中實現cp分解

1、X = sptenrand([5 4 3], 10)

//隨機生成一個稀疏三維張量5*4* 3,其中有10條數據

X is a sparse tensor of size 5 x 4 x 3 with 10 nonzeros

(1,4,1) 0.4966

(2,2,3) 0.8998

(3,2,3) 0.8216

(3,3,1) 0.6449

(3,3,3) 0.8180

(3,4,1) 0.6602

(4,1,2) 0.3420

(4,1,3) 0.2897

(5,2,2) 0.3412

(5,3,2) 0.5341

2、P = parafac_als(X,2)

//用ALS交替最小二乘來分解張量,分解參數R=2,即分解為兩個秩一張量;其中分解參數最多可以設置為min(5*4;5* 3;4*3)

CP_ALS:

Iter 1: fit = 3.219563e-001 fitdelta = 3.2e-001

Iter 2: fit = 3.645517e-001 fitdelta = 4.3e-002

Iter 3: fit = 3.732887e-001 fitdelta = 8.7e-003

Iter 4: fit = 3.809608e-001 fitdelta = 7.7e-003

Iter 5: fit = 4.021826e-001 fitdelta = 2.1e-002

Iter 6: fit = 4.427524e-001 fitdelta = 4.1e-002

Iter 7: fit = 4.734919e-001 fitdelta = 3.1e-002

Iter 8: fit = 4.848760e-001 fitdelta = 1.1e-002

Iter 9: fit = 4.890031e-001 fitdelta = 4.1e-003

Iter 10: fit = 4.907726e-001 fitdelta = 1.8e-003

Iter 11: fit = 4.916244e-001 fitdelta = 8.5e-004

Iter 12: fit = 4.920996e-001 fitdelta = 4.8e-004

Iter 13: fit = 4.924246e-001 fitdelta = 3.2e-004

Iter 14: fit = 4.926962e-001 fitdelta = 2.7e-004

Iter 15: fit = 4.929575e-001 fitdelta = 2.6e-004

Iter 16: fit = 4.932285e-001 fitdelta = 2.7e-004

Iter 17: fit = 4.935198e-001 fitdelta = 2.9e-004

Iter 18: fit = 4.938385e-001 fitdelta = 3.2e-004

Iter 19: fit = 4.941904e-001 fitdelta = 3.5e-004

Iter 20: fit = 4.945813e-001 fitdelta = 3.9e-004

Iter 21: fit = 4.950178e-001 fitdelta = 4.4e-004

Iter 22: fit = 4.955072e-001 fitdelta = 4.9e-004

Iter 23: fit = 4.960583e-001 fitdelta = 5.5e-004

Iter 24: fit = 4.966814e-001 fitdelta = 6.2e-004

Iter 25: fit = 4.973882e-001 fitdelta = 7.1e-004

Iter 26: fit = 4.981921e-001 fitdelta = 8.0e-004

Iter 27: fit = 4.991075e-001 fitdelta = 9.2e-004

Iter 28: fit = 5.001490e-001 fitdelta = 1.0e-003

Iter 29: fit = 5.013282e-001 fitdelta = 1.2e-003

Iter 30: fit = 5.026502e-001 fitdelta = 1.3e-003

Iter 31: fit = 5.041052e-001 fitdelta = 1.5e-003

Iter 32: fit = 5.056587e-001 fitdelta = 1.6e-003

Iter 33: fit = 5.072418e-001 fitdelta = 1.6e-003

Iter 34: fit = 5.087490e-001 fitdelta = 1.5e-003

Iter 35: fit = 5.100586e-001 fitdelta = 1.3e-003

Iter 36: fit = 5.110745e-001 fitdelta = 1.0e-003

Iter 37: fit = 5.117692e-001 fitdelta = 6.9e-004

Iter 38: fit = 5.121888e-001 fitdelta = 4.2e-004

Iter 39: fit = 5.124165e-001 fitdelta = 2.3e-004

Iter 40: fit = 5.125308e-001 fitdelta = 1.1e-004

Iter 41: fit = 5.125856e-001 fitdelta = 5.5e-005

Final fit = 5.125856e-001

P is a ktensor of size 5 x 4 x 3

P.lambda = [ 1.3189 1.1109 ]

P.U{1} =

0.0019 0.2743

0.6406 -0.0177

0.7679 0.9615

-0.0000 0.0000

-0.0000 -0.0000

P.U{2} =

-0.0000 0.0000

0.9413 -0.0855

0.2693 0.7083

-0.2036 0.7007

P.U{3} =

0.0402 0.8828

-0.0000 -0.0000

0.9992 0.4698

你可能感兴趣的:(matlab,cp分解)