📄 c_ttensor_doc.html
字号:
<html xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <!--This HTML is auto-generated from an M-file.To make changes, update the M-file and republish this document. --> <title>Tucker Tensors</title> <meta name="generator" content="MATLAB 7.2"> <meta name="date" content="2007-01-10"> <meta name="m-file" content="C_ttensor_doc"><style>body { background-color: white; margin:10px;}h1 { color: #990000; font-size: x-large;}h2 { color: #990000; font-size: medium;}/* Make the text shrink to fit narrow windows, but not stretch too far in wide windows. On Gecko-based browsers, the shrink-to-fit doesn't work. */ p,h1,h2,div.content div { /* for MATLAB's browser */ width: 600px; /* for Mozilla, but the "width" tag overrides it anyway */ max-width: 600px; /* for IE */ width:expression(document.body.clientWidth > 620 ? "600px": "auto" );}pre.codeinput { background: #EEEEEE; padding: 10px;}@media print { pre.codeinput {word-wrap:break-word; width:100%;}} span.keyword {color: #0000FF}span.comment {color: #228B22}span.string {color: #A020F0}span.untermstring {color: #B20000}span.syscmd {color: #B28C00}pre.codeoutput { color: #666666; padding: 10px;}pre.error { color: red;}p.footer { text-align: right; font-size: xx-small; font-weight: lighter; font-style: italic; color: gray;} </style></head> <body> <div class="content"> <h1>Tucker Tensors</h1> <introduction> <p>Tucker format is a decomposition of a tensor X as the product of a core tensor G and matrices (e.g., A,B,C) in each dimension. In other words, a tensor X is expressed as: </p> <p><img vspace="5" hspace="5" src="C_ttensor_doc_eq96890.png"> </p> <p>In MATLAB notation, <tt>X=ttm(G,{A,B,C})</tt>. The <tt>ttensor</tt> class stores the components of the tensor X and can perform many operations, e.g., <tt>ttm</tt>, without explicitly forming the tensor X. </p> </introduction> <h2>Contents</h2> <div> <ul> <li><a href="#1">Creating a ttensor with a tensor core</a></li> <li><a href="#2">Alternate core formats: sptensor, ktensor, or ttensor</a></li> <li><a href="#5">Creating a one-dimensional ttensor</a></li> <li><a href="#6">Constituent parts of a ttensor</a></li> <li><a href="#8">Creating a ttensor from its constituent parts</a></li> <li><a href="#9">Creating an empty ttensor.</a></li> <li><a href="#10">Use full or tensor to convert a ttensor to a tensor</a></li> <li><a href="#13">Use double to convert a ttensor to a (multidimensional) array</a></li> <li><a href="#14">Use ndims and size to get the size of a ttensor</a></li> <li><a href="#17">Subscripted reference to a ttensor</a></li> <li><a href="#20">Subscripted assignment for a ttensor</a></li> <li><a href="#23">Using end for last index</a></li> <li><a href="#24">Basic operations (uplus, uminus, mtimes) for a ttensor.</a></li> <li><a href="#27">Use permute to reorder the modes of a ttensor</a></li> <li><a href="#28">Displaying a ttensor</a></li> </ul> </div> <h2>Creating a ttensor with a tensor core<a name="1"></a></h2><pre class="codeinput">core = tensor(rand(3,2,1),[3 2 1]); <span class="comment">%<-- The core tensor.</span>U = {rand(5,3), rand(4,2), rand(3,1)}; <span class="comment">%<-- The matrices.</span>X = ttensor(core,U) <span class="comment">%<-- Create the ttensor.</span></pre><pre class="codeoutput">X is a ttensor of size 5 x 4 x 3 X.core is a tensor of size 3 x 2 x 1 X.core(:,:,1) = 0.0142 0.9771 0.5962 0.2219 0.8162 0.7037 X.U{1} = 0.5221 0.1722 0.8948 0.9329 0.9688 0.2861 0.7134 0.3557 0.2512 0.2280 0.0490 0.9327 0.4496 0.7553 0.1310 X.U{2} = 0.9408 0.4551 0.7019 0.0811 0.8477 0.8511 0.2093 0.5620 X.U{3} = 0.3193 0.3749 0.8678</pre><h2>Alternate core formats: sptensor, ktensor, or ttensor<a name="2"></a></h2><pre class="codeinput">core1 = sptenrand([3 2 1],3); <span class="comment">%<-- Create a 3 x 2 x 1 sptensor.</span>Y = ttensor(core1,U) <span class="comment">%<-- Core is a sptensor.</span></pre><pre class="codeoutput">Y is a ttensor of size 5 x 4 x 3 Y.core is a sparse tensor of size 3 x 2 x 1 with 3 nonzeros (1,1,1) 0.3751 (1,2,1) 0.8234 (2,1,1) 0.0466 Y.U{1} = 0.5221 0.1722 0.8948 0.9329 0.9688 0.2861 0.7134 0.3557 0.2512 0.2280 0.0490 0.9327 0.4496 0.7553 0.1310 Y.U{2} = 0.9408 0.4551 0.7019 0.0811 0.8477 0.8511 0.2093 0.5620 Y.U{3} = 0.3193 0.3749 0.8678</pre><pre class="codeinput">V = {rand(3,2),rand(2,2),rand(1,2)}; <span class="comment">%<-- Create some random matrices.</span>core2 = ktensor(V); <span class="comment">%<-- Create a 3 x 2 x 1 ktensor.</span>Y = ttensor(core2,U) <span class="comment">%<-- Core is a ktensor.</span></pre><pre class="codeoutput">Y is a ttensor of size 5 x 4 x 3 Y.core is a ktensor of size 3 x 2 x 1 Y.core.lambda = [ 1 1 ] Y.core.U{1} = 0.5979 0.8888 0.9492 0.1016 0.2888 0.0653 Y.core.U{2} = 0.2343 0.0631 0.9331 0.2642 Y.core.U{3} = 0.9995 0.2120 Y.U{1} = 0.5221 0.1722 0.8948 0.9329 0.9688 0.2861 0.7134 0.3557 0.2512 0.2280 0.0490 0.9327 0.4496 0.7553 0.1310 Y.U{2} = 0.9408 0.4551 0.7019 0.0811 0.8477 0.8511 0.2093 0.5620 Y.U{3} = 0.3193 0.3749 0.8678</pre><pre class="codeinput">core3 = ttensor(tensor(1:8,[2 2 2]),V); <span class="comment">%<-- Create a 3 x 2 x 1 ttensor.</span>Y = ttensor(core3,U) <span class="comment">%<-- Core is a ttensor.</span></pre><pre class="codeoutput">Y is a ttensor of size 5 x 4 x 3 Y.core is a ttensor of size 3 x 2 x 1 Y.core.core is a tensor of size 2 x 2 x 2 Y.core.core(:,:,1) = 1 3 2 4 Y.core.core(:,:,2) = 5 7 6 8 Y.core.U{1} = 0.5979 0.8888 0.9492 0.1016 0.2888 0.0653 Y.core.U{2} = 0.2343 0.0631 0.9331 0.2642 Y.core.U{3} = 0.9995 0.2120 Y.U{1} = 0.5221 0.1722 0.8948 0.9329 0.9688 0.2861 0.7134 0.3557 0.2512 0.2280 0.0490 0.9327 0.4496 0.7553 0.1310 Y.U{2} = 0.9408 0.4551 0.7019 0.0811 0.8477 0.8511 0.2093 0.5620 Y.U{3} = 0.3193 0.3749 0.8678</pre><h2>Creating a one-dimensional ttensor<a name="5"></a></h2><pre class="codeinput">Z = ttensor(tensor(rand(2,1),2), rand(4,2)) <span class="comment">%<-- One-dimensional ttensor.</span></pre><pre class="codeoutput">Z is a ttensor of size 4 Z.core is a tensor of size 2 Z.core(:) = 0.4984 0.2905 Z.U{1} = 0.6728 0.1309 0.9580 0.0954 0.7666 0.0149 0.6661 0.2882</pre><h2>Constituent parts of a ttensor<a name="6"></a></h2><pre class="codeinput">X.core <span class="comment">%<-- Core tensor.</span></pre><pre class="codeoutput">ans is a tensor of size 3 x 2 x 1 ans(:,:,1) = 0.0142 0.9771 0.5962 0.2219 0.8162 0.7037</pre><pre class="codeinput">X.U <span class="comment">%<-- Cell array of matrices.</span></pre><pre class="codeoutput">ans = [5x3 double] [4x2 double] [3x1 double]</pre><h2>Creating a ttensor from its constituent parts<a name="8"></a></h2><pre class="codeinput">Y = ttensor(X.core,X.U) <span class="comment">%<-- Recreate a tensor from its parts.</span></pre><pre class="codeoutput">Y is a ttensor of size 5 x 4 x 3 Y.core is a tensor of size 3 x 2 x 1 Y.core(:,:,1) = 0.0142 0.9771 0.5962 0.2219 0.8162 0.7037 Y.U{1} = 0.5221 0.1722 0.8948 0.9329 0.9688 0.2861 0.7134 0.3557 0.2512 0.2280 0.0490 0.9327 0.4496 0.7553 0.1310 Y.U{2} = 0.9408 0.4551 0.7019 0.0811 0.8477 0.8511 0.2093 0.5620 Y.U{3} = 0.3193 0.3749 0.8678</pre><h2>Creating an empty ttensor.<a name="9"></a></h2><pre class="codeinput">X = ttensor <span class="comment">%<-- empty ttensor</span></pre><pre class="codeoutput">X is a ttensor of size [empty tensor] X.core is a tensor of size [empty tensor] X.core = []</pre><h2>Use full or tensor to convert a ttensor to a tensor<a name="10"></a></h2><pre class="codeinput">X = ttensor(core,U) <span class="comment">%<-- Create a tensor</span></pre><pre class="codeoutput">X is a ttensor of size 5 x 4 x 3 X.core is a tensor of size 3 x 2 x 1 X.core(:,:,1) = 0.0142 0.9771 0.5962 0.2219 0.8162 0.7037 X.U{1} = 0.5221 0.1722 0.8948 0.9329 0.9688 0.2861 0.7134 0.3557 0.2512 0.2280 0.0490 0.9327 0.4496 0.7553 0.1310 X.U{2} = 0.9408 0.4551 0.7019 0.0811 0.8477 0.8511 0.2093 0.5620 X.U{3} = 0.3193 0.3749 0.8678</pre><pre class="codeinput">full(X) <span class="comment">%<-- Converts to a tensor.</span></pre><pre class="codeoutput">ans is a tensor of size 5 x 4 x 3 ans(:,:,1) = 0.4236 0.2188 0.5476 0.2676 0.4406 0.2191 0.5840 0.2934 0.2668 0.1204 0.3746 0.1995 0.3678 0.2009 0.4567 0.2128 0.2709 0.1444 0.3425 0.1631 ans(:,:,2) = 0.4974 0.2569 0.6430 0.3142 0.5173 0.2573 0.6857 0.3445 0.3132 0.1414 0.4398 0.2343 0.4318 0.2359 0.5363 0.2498 0.3181 0.1696 0.4022 0.1915 ans(:,:,3) = 1.1514 0.5948 1.4883 0.7272 1.1975 0.5956 1.5872 0.7974 0.7251 0.3273 1.0180 0.5423 0.9996 0.5461 1.2413 0.5783 0.7363 0.3925 0.9310 0.4434</pre><pre class="codeinput">tensor(X) <span class="comment">%<-- Also converts to a tensor.</span></pre><pre class="codeoutput">ans is a tensor of size 5 x 4 x 3 ans(:,:,1) = 0.4236 0.2188 0.5476 0.2676 0.4406 0.2191 0.5840 0.2934 0.2668 0.1204 0.3746 0.1995 0.3678 0.2009 0.4567 0.2128 0.2709 0.1444 0.3425 0.1631 ans(:,:,2) = 0.4974 0.2569 0.6430 0.3142 0.5173 0.2573 0.6857 0.3445 0.3132 0.1414 0.4398 0.2343 0.4318 0.2359 0.5363 0.2498 0.3181 0.1696 0.4022 0.1915 ans(:,:,3) = 1.1514 0.5948 1.4883 0.7272 1.1975 0.5956 1.5872 0.7974 0.7251 0.3273 1.0180 0.5423 0.9996 0.5461 1.2413 0.5783 0.7363 0.3925 0.9310 0.4434</pre><h2>Use double to convert a ttensor to a (multidimensional) array<a name="13"></a></h2><pre class="codeinput">double(X) <span class="comment">%<-- Converts to a MATLAB array</span></pre><pre class="codeoutput">ans(:,:,1) = 0.4236 0.2188 0.5476 0.2676 0.4406 0.2191 0.5840 0.2934 0.2668 0.1204 0.3746 0.1995 0.3678 0.2009 0.4567 0.2128
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -