t_algorithms_doc.html
来自「张量分析工具」· HTML 代码 · 共 475 行 · 第 1/2 页
HTML
475 行
0.6381 -0.0241 0.7699 0.9587 0.0000 -0.0000 0.0000 0.0000 P.U{2} = 0.0000 -0.0000 0.9388 -0.0899 0.2834 0.7000 -0.1957 0.7085 P.U{3} = 0.0487 0.8893 0.0000 0.0000 0.9988 0.4573</pre><h2>Alternating least squares for Tucker model<a name="6"></a></h2> <p>The function <tt>tucker_als</tt> computes the best rank(R1,R2,..,Rn) approximation of tensor X, according to the specified dimensions in vector R. The input X can be a tensor, sptensor, ktensor, or ttensor. The result returned in T is a ttensor. </p><pre class="codeinput">X = sptenrand([5 4 3], 10)</pre><pre class="codeoutput">X is a sparse tensor of size 5 x 4 x 3 with 10 nonzeros (1,3,1) 0.7400 (3,1,2) 0.4319 (3,2,1) 0.6343 (3,3,2) 0.8030 (4,1,2) 0.0839 (4,2,1) 0.9455 (4,4,2) 0.9159 (4,4,3) 0.6020 (5,3,3) 0.2536 (5,4,3) 0.8735</pre><pre class="codeinput">T = tucker_als(X,2) <span class="comment">%<-- best rank(2,2,2) approximation</span></pre><pre class="codeoutput">Alternating Least-Squares: Iter 1: fit = 2.810591e-001 fitdelta = 2.8e-001 Iter 2: fit = 3.474829e-001 fitdelta = 6.6e-002 Iter 3: fit = 3.628582e-001 fitdelta = 1.5e-002 Iter 4: fit = 3.700452e-001 fitdelta = 7.2e-003 Iter 5: fit = 3.727897e-001 fitdelta = 2.7e-003 Iter 6: fit = 3.737295e-001 fitdelta = 9.4e-004 Iter 7: fit = 3.740582e-001 fitdelta = 3.3e-004 Iter 8: fit = 3.741751e-001 fitdelta = 1.2e-004 Iter 9: fit = 3.742168e-001 fitdelta = 4.2e-005T is a ttensor of size 5 x 4 x 3 T.core is a tensor of size 2 x 2 x 2 T.core(:,:,1) = 1.1796 -0.0116 0.4219 -0.0175 T.core(:,:,2) = 0.0098 1.0308 -0.0191 -0.4827 T.U{1} = 0.0069 -0.0204 -0.0000 0.0000 0.2980 -0.6769 0.8904 -0.0567 0.3439 0.7336 T.U{2} = 0.0439 0.0018 0.0204 0.9997 0.1129 0.0109 0.9924 -0.0219 T.U{3} = 0.0109 0.9999 0.6015 -0.0016 0.7988 -0.0124</pre><pre class="codeinput">T = tucker_als(X,[2 2 1]) <span class="comment">%<-- best rank(2,2,1) approximation</span></pre><pre class="codeoutput">Alternating Least-Squares: Iter 1: fit = 1.812756e-001 fitdelta = 1.8e-001 Iter 2: fit = 2.272937e-001 fitdelta = 4.6e-002 Iter 3: fit = 2.412379e-001 fitdelta = 1.4e-002 Iter 4: fit = 2.436064e-001 fitdelta = 2.4e-003 Iter 5: fit = 2.444688e-001 fitdelta = 8.6e-004 Iter 6: fit = 2.449320e-001 fitdelta = 4.6e-004 Iter 7: fit = 2.451964e-001 fitdelta = 2.6e-004 Iter 8: fit = 2.453474e-001 fitdelta = 1.5e-004 Iter 9: fit = 2.454331e-001 fitdelta = 8.6e-005T is a ttensor of size 5 x 4 x 3 T.core is a tensor of size 2 x 2 x 1 T.core(:,:,1) = 1.1975 -0.0004 -0.0001 0.7710 T.U{1} = 0.0024 0.0387 0.0000 0.0000 0.0728 0.9885 0.9137 -0.1170 0.3999 0.0872 T.U{2} = 0.0760 0.4549 0.0347 0.0306 0.0869 0.8828 0.9927 -0.1131 T.U{3} = 0.0343 0.8414 0.5394</pre><pre class="codeinput">T = tucker_als(X,2,struct(<span class="string">'dimorder'</span>,[3 2 1]))</pre><pre class="codeoutput">Alternating Least-Squares: Iter 1: fit = 3.268831e-001 fitdelta = 3.3e-001 Iter 2: fit = 3.604384e-001 fitdelta = 3.4e-002 Iter 3: fit = 3.708956e-001 fitdelta = 1.0e-002 Iter 4: fit = 3.731357e-001 fitdelta = 2.2e-003 Iter 5: fit = 3.738515e-001 fitdelta = 7.2e-004 Iter 6: fit = 3.741016e-001 fitdelta = 2.5e-004 Iter 7: fit = 3.741906e-001 fitdelta = 8.9e-005T is a ttensor of size 5 x 4 x 3 T.core is a tensor of size 2 x 2 x 2 T.core(:,:,1) = 1.1797 -0.0054 0.4208 -0.0338 T.core(:,:,2) = 0.0015 1.0306 -0.0375 -0.4818 T.U{1} = 0.0069 -0.0208 0 0 0.2981 -0.6769 0.8904 -0.0566 0.3439 0.7336 T.U{2} = 0.0440 0.0028 0.0323 0.9992 0.1134 0.0181 0.9921 -0.0347 T.U{3} = 0.0298 0.9994 0.6017 -0.0051 0.7982 -0.0335</pre><pre class="codeinput">T = tucker_als(X,2,struct(<span class="string">'dimorder'</span>,[3 2 1],<span class="string">'init'</span>,<span class="string">'eigs'</span>))</pre><pre class="codeoutput"> Computing 2 leading e-vectors for factor 2. Computing 2 leading e-vectors for factor 1.Alternating Least-Squares: Iter 1: fit = 3.726300e-001 fitdelta = 3.7e-001 Iter 2: fit = 3.741337e-001 fitdelta = 1.5e-003 Iter 3: fit = 3.742335e-001 fitdelta = 1.0e-004T is a ttensor of size 5 x 4 x 3 T.core is a tensor of size 2 x 2 x 2 T.core(:,:,1) = 1.1798 0.0000 0.4220 -0.0000 T.core(:,:,2) = -0.0000 1.0311 -0.0000 -0.4828 T.U{1} = 0.0000 0 0 0.0000 0.2970 -0.6795 0.8913 -0.0548 0.3426 0.7316 T.U{2} = 0.0427 0.0000 -0.0000 1.0000 0.1082 0.0000 0.9932 0.0000 T.U{3} = 0.0000 1.0000 0.6045 -0.0000 0.7966 -0.0000</pre><pre class="codeinput">U0 = {rand(5,2),rand(4,2),[]}; <span class="comment">%<-- Initial guess for factors of T</span>T = tucker_als(X,2,struct(<span class="string">'dimorder'</span>,[3 2 1],<span class="string">'init'</span>,{U0}))</pre><pre class="codeoutput">Alternating Least-Squares: Iter 1: fit = 3.647914e-001 fitdelta = 3.6e-001 Iter 2: fit = 3.722524e-001 fitdelta = 7.5e-003 Iter 3: fit = 3.735753e-001 fitdelta = 1.3e-003 Iter 4: fit = 3.740042e-001 fitdelta = 4.3e-004 Iter 5: fit = 3.741559e-001 fitdelta = 1.5e-004 Iter 6: fit = 3.742100e-001 fitdelta = 5.4e-005T is a ttensor of size 5 x 4 x 3 T.core is a tensor of size 2 x 2 x 2 T.core(:,:,1) = 1.1797 -0.0042 0.4214 -0.0265 T.core(:,:,2) = 0.0012 1.0308 -0.0293 -0.4823 T.U{1} = 0.0054 -0.0162 0.0000 0 0.2980 -0.6769 0.8904 -0.0567 0.3439 0.7337 T.U{2} = 0.0440 0.0022 0.0253 0.9995 0.1131 0.0141 0.9923 -0.0272 T.U{3} = 0.0233 0.9997 0.6016 -0.0040 0.7985 -0.0262</pre><p class="footer"><br> Published with MATLAB® 7.2<br></p> </div> <!--##### SOURCE BEGIN #####%% Algorithms for computing tensor decompositions
%% Alternating least squares for PARAFAC/CANDECOMP
% The function |parafac_als| computes an estimate of the best rank-R
% PARAFAC model of a tensor X using an alternating least-squares
% algorithm. The input X can be a tensor, sptensor, ktensor, or
% ttensor. The result P is a ktensor.
rand('state',0);
X = sptenrand([5 4 3], 10)
%%
P = parafac_als(X,2)
%%
P = parafac_als(X,2,struct('dimorder',[3 2 1]))
%%
P = parafac_als(X,2,struct('dimorder',[3 2 1],'init','nvecs'))
%%
U0 = {rand(5,2),rand(4,2),[]}; %<REPLACE_WITH_DASH_DASH Initial guess for factors of P
P = parafac_als(X,2,struct('dimorder',[3 2 1],'init',{U0}))
%% Alternating least squares for Tucker model
% The function |tucker_als| computes the best rank(R1,R2,..,Rn)
% approximation of tensor X, according to the specified dimensions in
% vector R. The input X can be a tensor, sptensor, ktensor, or
% ttensor. The result returned in T is a ttensor.
X = sptenrand([5 4 3], 10)
%%
T = tucker_als(X,2) %<REPLACE_WITH_DASH_DASH best rank(2,2,2) approximation
%%
T = tucker_als(X,[2 2 1]) %<REPLACE_WITH_DASH_DASH best rank(2,2,1) approximation
%%
T = tucker_als(X,2,struct('dimorder',[3 2 1]))
%%
T = tucker_als(X,2,struct('dimorder',[3 2 1],'init','eigs'))
%%
U0 = {rand(5,2),rand(4,2),[]}; %<REPLACE_WITH_DASH_DASH Initial guess for factors of T
T = tucker_als(X,2,struct('dimorder',[3 2 1],'init',{U0}))
##### SOURCE END #####--> </body></html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?