├── .gitattributes ├── .gitignore ├── BRTF ├── BayesRCP.m ├── BayesRCP_TC.m ├── calRRSE.m ├── gaussSample.m ├── mykhatrirao │ ├── khatrirao_fast.m │ ├── khatrirao_space.m │ ├── kr.m │ └── test.m ├── subtightplot.m ├── tensor_plot │ ├── hintonDiagram.m │ ├── hintonw3d.m │ ├── plotFactor.m │ ├── plotGamma.m │ ├── plotYXS.m │ ├── rescaleorder.m │ ├── showbgfg.m │ ├── slice3.m │ ├── surf3.m │ └── voxel3.m └── tensor_toolbox_2.5 │ ├── @ktensor │ ├── Contents.m │ ├── arrange.m │ ├── datadisp.m │ ├── disp.m │ ├── display.m │ ├── double.m │ ├── end.m │ ├── extract.m │ ├── fixsigns.m │ ├── full.m │ ├── innerprod.m │ ├── isequal.m │ ├── ktensor.m │ ├── minus.m │ ├── mtimes.m │ ├── mttkrp.m │ ├── ncomponents.m │ ├── ndims.m │ ├── norm.m │ ├── normalize.m │ ├── nvecs.m │ ├── permute.m │ ├── plus.m │ ├── redistribute.m │ ├── score.m │ ├── size.m │ ├── subsasgn.m │ ├── subsref.m │ ├── times.m │ ├── tocell.m │ ├── ttm.m │ ├── ttv.m │ ├── uminus.m │ └── uplus.m │ ├── @sptenmat │ ├── Contents.m │ ├── aatx.m │ ├── disp.m │ ├── display.m │ ├── double.m │ ├── end.m │ ├── full.m │ ├── nnz.m │ ├── norm.m │ ├── size.m │ ├── sptenmat.m │ ├── subsasgn.m │ ├── subsref.m │ ├── tsize.m │ ├── uminus.m │ └── uplus.m │ ├── @sptensor │ ├── Contents.m │ ├── and.m │ ├── collapse.m │ ├── contract.m │ ├── ctranspose.m │ ├── disp.m │ ├── display.m │ ├── divide.m │ ├── double.m │ ├── elemfun.m │ ├── end.m │ ├── eq.m │ ├── find.m │ ├── full.m │ ├── ge.m │ ├── gt.m │ ├── innerprod.m │ ├── isequal.m │ ├── ldivide.m │ ├── le.m │ ├── lt.m │ ├── minus.m │ ├── mldivide.m │ ├── mrdivide.m │ ├── mtimes.m │ ├── mttkrp.m │ ├── ndims.m │ ├── ne.m │ ├── nnz.m │ ├── norm.m │ ├── not.m │ ├── nvecs.m │ ├── ones.m │ ├── or.m │ ├── permute.m │ ├── plus.m │ ├── private │ │ ├── allsubs.m │ │ ├── extract.m │ │ ├── irenumber.m │ │ ├── renumber.m │ │ └── subdims.m │ ├── rdivide.m │ ├── reshape.m │ ├── scale.m │ ├── size.m │ ├── spmatrix.m │ ├── sptensor.m │ ├── squeeze.m │ ├── subsasgn.m │ ├── subsref.m │ ├── times.m │ ├── transpose.m │ ├── ttm.m │ ├── ttt.m │ ├── ttv.m │ ├── uminus.m │ ├── uplus.m │ └── xor.m │ ├── @tenmat │ ├── Contents.m │ ├── ctranspose.m │ ├── disp.m │ ├── display.m │ ├── double.m │ ├── end.m │ ├── minus.m │ ├── mtimes.m │ ├── norm.m │ ├── plus.m │ ├── size.m │ ├── subsasgn.m │ ├── subsref.m │ ├── tenmat.m │ ├── tsize.m │ ├── uminus.m │ └── uplus.m │ ├── @tensor │ ├── Contents.m │ ├── and.m │ ├── collapse.m │ ├── contract.m │ ├── ctranspose.m │ ├── disp.m │ ├── display.m │ ├── double.m │ ├── end.m │ ├── eq.m │ ├── find.m │ ├── full.m │ ├── ge.m │ ├── gt.m │ ├── innerprod.m │ ├── isequal.m │ ├── issymmetric.m │ ├── ldivide.m │ ├── le.m │ ├── lt.m │ ├── minus.m │ ├── mldivide.m │ ├── mrdivide.m │ ├── mtimes.m │ ├── mttkrp.m │ ├── ndims.m │ ├── ne.m │ ├── nnz.m │ ├── norm.m │ ├── not.m │ ├── nvecs.m │ ├── or.m │ ├── permute.m │ ├── plus.m │ ├── power.m │ ├── rdivide.m │ ├── reshape.m │ ├── scale.m │ ├── size.m │ ├── squeeze.m │ ├── subsasgn.m │ ├── subsref.m │ ├── symmetrize.m │ ├── tenfun.m │ ├── tensor.m │ ├── times.m │ ├── transpose.m │ ├── ttm.m │ ├── ttsv.m │ ├── ttt.m │ ├── ttv.m │ ├── uminus.m │ ├── uplus.m │ └── xor.m │ ├── @ttensor │ ├── Contents.m │ ├── disp.m │ ├── display.m │ ├── double.m │ ├── end.m │ ├── full.m │ ├── innerprod.m │ ├── isequal.m │ ├── mtimes.m │ ├── mttkrp.m │ ├── ndims.m │ ├── norm.m │ ├── nvecs.m │ ├── permute.m │ ├── size.m │ ├── subsasgn.m │ ├── subsref.m │ ├── ttensor.m │ ├── ttm.m │ ├── ttv.m │ ├── uminus.m │ └── uplus.m │ ├── COPYRIGHT.txt │ ├── Contents.m │ ├── INSTALL.txt │ ├── LICENSE.txt │ ├── RELEASE_NOTES.txt │ ├── cp_als.m │ ├── cp_apr.m │ ├── cp_nmu.m │ ├── cp_opt.m │ ├── cp_wopt.m │ ├── create_guess.m │ ├── create_problem.m │ ├── doc │ ├── A1_tensor_doc.m │ ├── A2_sptensor_doc.m │ ├── B1_tenmat_doc.m │ ├── B2_sptenmat_doc.m │ ├── C_ttensor_doc.m │ ├── D_ktensor_doc.m │ ├── M1_multiply_doc.m │ ├── M2_identities_doc_future.m │ ├── N_nvecs_doc.m │ ├── Q_collapse_scale_doc.m │ ├── S_test_problems_doc.m │ ├── T1_algorithms_doc.m │ ├── T2_opt_algorithms_doc.m │ ├── T3_wopt_algorithms_doc.m │ ├── T4_cpapr_doc.m │ ├── V_SSHOPM_doc.m │ ├── html │ │ ├── A1_tensor_doc.html │ │ ├── A2_sptensor_doc.html │ │ ├── B1_tenmat_doc.html │ │ ├── B2_sptenmat_doc.html │ │ ├── C_ttensor_doc.html │ │ ├── C_ttensor_doc_eq15566.png │ │ ├── D_ktensor_doc.html │ │ ├── D_ktensor_doc_eq09466.png │ │ ├── D_ktensor_doc_eq51104.png │ │ ├── D_ktensor_doc_eq64665.png │ │ ├── D_ktensor_doc_eq81501.png │ │ ├── M1_multiply_doc.html │ │ ├── N_nvecs_doc.html │ │ ├── Q_collapse_scale_doc.html │ │ ├── S_test_problems_doc.html │ │ ├── T1_algorithms_doc.html │ │ ├── T2_opt_algorithms_doc.html │ │ ├── T3_wopt_algorithms_doc.html │ │ ├── T4_cpapr_doc.html │ │ ├── V_SSHOPM_doc.html │ │ ├── V_SSHOPM_doc.png │ │ ├── V_SSHOPM_doc_01.png │ │ └── V_SSHOPM_doc_02.png │ └── images │ │ ├── Workspace.png │ │ ├── banner-background.jpg │ │ └── logo.gif │ ├── export_data.m │ ├── helpindex.xml │ ├── helptoc.xml │ ├── import_data.m │ ├── info.xml │ ├── khatrirao.m │ ├── met │ ├── Contents.m │ ├── ttm_me.m │ ├── ttm_me_mem.m │ ├── ttm_me_partition.m │ ├── tucker_me.m │ └── tucker_me_test.m │ ├── parafac_als.m │ ├── sptendiag.m │ ├── sptenrand.m │ ├── sshopm.m │ ├── sshopmc.m │ ├── tendiag.m │ ├── teneye.m │ ├── tenones.m │ ├── tenrand.m │ ├── tensor_toolbox_product_page.html │ ├── tenzeros.m │ ├── tt_RandOrthMat.m │ ├── tt_assignment_type.m │ ├── tt_ccong.m │ ├── tt_combinator.m │ ├── tt_cp_fg.m │ ├── tt_cp_fun.m │ ├── tt_cp_vec_to_fac.m │ ├── tt_cp_wfg.m │ ├── tt_cp_wfg_sparse.m │ ├── tt_cp_wfg_sparse_setup.m │ ├── tt_cp_wfun.m │ ├── tt_create_missing_data_pattern.m │ ├── tt_dimscheck.m │ ├── tt_fac_to_vec.m │ ├── tt_ind2sub.m │ ├── tt_intvec2str.m │ ├── tt_loglikelihood.m │ ├── tt_matrix2cellstr.m │ ├── tt_size2str.m │ ├── tt_sizecheck.m │ ├── tt_sub2ind.m │ ├── tt_subscheck.m │ ├── tt_subsubsref.m │ ├── tt_valscheck.m │ └── tucker_als.m ├── DemoBayesRCP.m ├── DemoBayesRCP_TC.m ├── DemoVBM.m ├── Readme.txt ├── loadpath.m └── videos ├── Lobby.mat ├── ShoppingMall.mat ├── WaterSurface.mat └── hall.mat /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | 5 | # Folder config file 6 | Desktop.ini 7 | 8 | # Recycle Bin used on file shares 9 | $RECYCLE.BIN/ 10 | 11 | # Windows Installer files 12 | *.cab 13 | *.msi 14 | *.msm 15 | *.msp 16 | 17 | # Windows shortcuts 18 | *.lnk 19 | 20 | # ========================= 21 | # Operating System Files 22 | # ========================= 23 | 24 | # OSX 25 | # ========================= 26 | 27 | .DS_Store 28 | .AppleDouble 29 | .LSOverride 30 | 31 | # Thumbnails 32 | ._* 33 | 34 | # Files that might appear in the root of a volume 35 | .DocumentRevisions-V100 36 | .fseventsd 37 | .Spotlight-V100 38 | .TemporaryItems 39 | .Trashes 40 | .VolumeIcon.icns 41 | 42 | # Directories potentially created on remote AFP share 43 | .AppleDB 44 | .AppleDesktop 45 | Network Trash Folder 46 | Temporary Items 47 | .apdisk 48 | -------------------------------------------------------------------------------- /BRTF/calRRSE.m: -------------------------------------------------------------------------------- 1 | 2 | 3 | function rrse = calRRSE(Xhat, X) 4 | 5 | err = Xhat(:) - X(:); 6 | rmse = sqrt(mean(err.^2)); 7 | rrse = sqrt(sum(err.^2)/sum(X(:).^2)); -------------------------------------------------------------------------------- /BRTF/gaussSample.m: -------------------------------------------------------------------------------- 1 | function S = gaussSample(arg1, arg2, arg3) 2 | % Returns n samples (in the rows) from a multivariate Gaussian distribution 3 | % 4 | % Examples: 5 | % S = gaussSample(mu, Sigma, 10) 6 | % S = gaussSample(model, 100) 7 | % S = gaussSample(struct('mu',[0], 'Sigma', eye(1)), 3) 8 | 9 | % This file is from pmtk3.googlecode.com 10 | 11 | 12 | switch nargin 13 | case 3, mu = arg1; Sigma = arg2; n = arg3; 14 | case 2, model = arg1; mu = model.mu; Sigma = model.Sigma; n = arg2; 15 | case 1, model = arg1; mu = model.mu; Sigma = model.Sigma; n = 1; 16 | otherwise 17 | error('bad num args') 18 | end 19 | 20 | A = chol(Sigma, 'lower'); 21 | Z = randn(length(mu), n); 22 | S = bsxfun(@plus, mu(:), A*Z)'; 23 | 24 | 25 | end 26 | -------------------------------------------------------------------------------- /BRTF/mykhatrirao/khatrirao_space.m: -------------------------------------------------------------------------------- 1 | function P = khatrirao_space(A,X) 2 | 3 | 4 | % kr(A{N},...,A{1})' * X_(N)' 5 | 6 | N = length(A); 7 | % xdim = ndims(X); 8 | 9 | [~,col] = size(A{1}); 10 | 11 | Anew = cell(1,col); 12 | for i=1:col 13 | Anew{i} = cellfun(@(x) x(:,i), A,'UniformOutput',false); 14 | end 15 | 16 | X = tensor(X); 17 | 18 | P = cellfun(@(x) double(ttm(X, x, [1:N], 't')), Anew, 'UniformOutput',false); 19 | P= squeeze(cell2mat(P)); 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /BRTF/mykhatrirao/kr.m: -------------------------------------------------------------------------------- 1 | function X = kr(U,varargin) 2 | %KR Khatri-Rao product. 3 | % kr(A,B) returns the Khatri-Rao product of two matrices A and B, of 4 | % dimensions I-by-K and J-by-K respectively. The result is an I*J-by-K 5 | % matrix formed by the matching columnwise Kronecker products, i.e. 6 | % the k-th column of the Khatri-Rao product is defined as 7 | % kron(A(:,k),B(:,k)). 8 | % 9 | % kr(A,B,C,...) and kr({A B C ...}) compute a string of Khatri-Rao 10 | % products A o B o C o ..., where o denotes the Khatri-Rao product. 11 | % 12 | % See also kron. 13 | 14 | % Version: 21/10/10 15 | % Authors: Laurent Sorber (Laurent.Sorber@cs.kuleuven.be) 16 | 17 | if ~iscell(U), U = [U varargin]; end 18 | K = size(U{1},2); 19 | if any(cellfun('size',U,2)-K) 20 | error('kr:ColumnMismatch', ... 21 | 'Input matrices must have the same number of columns.'); 22 | end 23 | J = size(U{end},1); 24 | X = reshape(U{end},[J 1 K]); 25 | for n = length(U)-1:-1:1 26 | I = size(U{n},1); 27 | A = reshape(U{n},[1 I K]); 28 | X = reshape(bsxfun(@times,A,X),[I*J 1 K]); 29 | J = I*J; 30 | end 31 | X = reshape(X,[size(X,1) K]); 32 | -------------------------------------------------------------------------------- /BRTF/mykhatrirao/test.m: -------------------------------------------------------------------------------- 1 | 2 | 3 | a = randn(40000,100); 4 | b = randn(200,100); 5 | c = randn(8000000,2); 6 | A = {a,b}; 7 | C = reshape(c, [40000,200,2]); 8 | 9 | %% 10 | tic; 11 | out1 = khatrirao(A,'r'); 12 | toc 13 | 14 | %% 15 | tic; 16 | out2 = c'*khatrirao_fast(A,'r'); 17 | toc 18 | 19 | %% X * (kr(a,b)) 20 | tic 21 | Anew = cell(1,100); 22 | for i=1:100 23 | Anew{i} = cellfun(@(x) x(:,i), A,'UniformOutput',false); 24 | end 25 | 26 | X = tensor(C); 27 | [out0 ]= cellfun(@(x) double(ttm(X, x, [1 2], 't')), Anew, 'UniformOutput',false); 28 | out0= squeeze(cell2mat(out0))'; 29 | toc 30 | 31 | isequal(out0,out2) 32 | 33 | 34 | 35 | %% 36 | out0 = khatrirao_space(A,C)'; 37 | 38 | %% 39 | plot(out0(:)-out2(:)) 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | %% 50 | tic; 51 | A = mat2cell(a,40000,ones(1,50)); 52 | B = mat2cell(b,200,ones(1,50)); 53 | % C = cellfun(@(x,y) KronProd({x',y'},[1,2])*randn(800,2), A,B); 54 | C = cellfun(@(x,y) (KronProd({x',y'},[1,2])*randn(40000,200))', A,B, 'UniformOutput',false); 55 | C = cell2mat(C); 56 | toc 57 | -------------------------------------------------------------------------------- /BRTF/tensor_plot/plotFactor.m: -------------------------------------------------------------------------------- 1 | function perf = plotFactor(Ztruth, varargin) 2 | 3 | % For example: 4 | % Ztruth = cell(1,3); 5 | % Ztruth{1} = randn(10,3); 6 | % plotFactor(Ztruth, Zest1, Zest2,... ) 7 | 8 | nMethod = length(varargin); 9 | Zest = varargin; 10 | 11 | for i=1:nMethod 12 | [Ztruth,Zest{i}] = rescaleorder(Ztruth, Zest{i}); 13 | end 14 | 15 | N = length(Ztruth); 16 | nCom = size(Ztruth{1},2); 17 | 18 | perf = zeros(nCom, N); 19 | for n=1:N 20 | perf(:,n) = diag(corr(Zest{1}{n},Ztruth{n})); 21 | end 22 | 23 | 24 | 25 | %% plot the factors 26 | figure('Position',[200 450 600 500]); 27 | str = {'-r*','-bs','-go','-y+'}; 28 | k=1; 29 | for r=1:nCom 30 | for n =1:N 31 | subplot(nCom, N,k); 32 | plot(Ztruth{n}(:,r),str{1}); 33 | hold on; 34 | for m=1:nMethod 35 | plot(Zest{m}{n}(:,r),str{m+1}); 36 | end 37 | 38 | axis tight; hold off; 39 | 40 | if k==1, title('Mode #1'); ylabel('Com. #1'); end 41 | if k==2, title('Mode #2'); end 42 | if k==3, title('Mode #3'); end 43 | if k==4, ylabel('Com. #2'); end 44 | if k==7, ylabel('Com. #3'); end 45 | 46 | k = k+1; 47 | end 48 | end 49 | legend({'True factors', 'Inferred factors'}); 50 | 51 | %% plot the factors 52 | % figure; 53 | % k=1; 54 | % for n=1:N 55 | % for m =0:nMethod 56 | % subplot(N, nMethod+1,k); 57 | % if m==0 58 | % plot(Ztruth{n}); ylabel(['Mode-' num2str(n)]); title('Ground truth'); 59 | % axis tight; box on; 60 | % else 61 | % plot(Zest{m}{n}); 62 | % axis tight; box on; 63 | % end 64 | % k = k+1; 65 | % end 66 | % end 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | -------------------------------------------------------------------------------- /BRTF/tensor_plot/plotYXS.m: -------------------------------------------------------------------------------- 1 | function h = plotYXS(varargin) 2 | 3 | nTensor = length(varargin); 4 | % scrsz = get(0,'ScreenSize'); 5 | h = figure('Position',[200 200 150*nTensor 150]); 6 | 7 | strName = cell(1,4); 8 | strName{1} = 'Observed Tensor'; 9 | strName{2} = 'Low Rank'; 10 | strName{3} = 'Sparse'; 11 | strName{4} = 'Noise'; 12 | 13 | parThresh = zeros(1,nTensor); 14 | parThresh(3) =0.2; 15 | 16 | 17 | for i = 1:nTensor 18 | subplot(1,nTensor,i); 19 | voxel3(abs(varargin{i}),'thresh',parThresh(i), 'degree',5); 20 | title(strName{i},'Fontsize',11); 21 | xlabel(''); ylabel(''); zlabel(''); 22 | set(gca,'xtick',[]);set(gca,'ytick',[]);set(gca,'ztick',[]); 23 | box on; 24 | end 25 | 26 | if nTensor==4 27 | annotation(h,'textbox',[0.28 0.45 0.045 0.165],... 28 | 'String',{'='}, 'FontSize', 20, 'LineStyle', 'none', ... 29 | 'FitBoxToText','on'); 30 | annotation(h,'textbox',[0.49 0.45 0.045 0.165],... 31 | 'String',{'+'}, 'FontSize', 20, 'LineStyle', 'none', ... 32 | 'FitBoxToText','on'); 33 | annotation(h,'textbox',[0.69 0.45 0.045 0.165],... 34 | 'String',{'+'}, 'FontSize', 20, 'LineStyle', 'none', ... 35 | 'FitBoxToText','on'); 36 | end -------------------------------------------------------------------------------- /BRTF/tensor_plot/rescaleorder.m: -------------------------------------------------------------------------------- 1 | function [Ztruth,Zest] = rescaleorder(Ztruth, Zest) 2 | 3 | 4 | N = length(Ztruth); 5 | nCom = size(Ztruth{1},2); 6 | 7 | 8 | % standard the factors 9 | for n=1:N 10 | Zest{n} = zscore(Zest{n}); 11 | Ztruth{n} = zscore(Ztruth{n}); 12 | 13 | Zest{n} = bsxfun(@minus, Zest{n}, min(Zest{n})); 14 | Zest{n} = bsxfun(@rdivide, Zest{n}, max(Zest{n})-min(Zest{n})); 15 | Zest{n} = 2*Zest{n}-1; 16 | 17 | Ztruth{n} = bsxfun(@minus, Ztruth{n}, min(Ztruth{n})); 18 | Ztruth{n} = bsxfun(@rdivide, Ztruth{n}, max(Ztruth{n})-min(Ztruth{n})); 19 | Ztruth{n} = 2*Ztruth{n}-1; 20 | end 21 | 22 | for n=1:N 23 | % rearrange the component order 24 | COV = corr(Zest{n},Ztruth{n}); 25 | [~,idx]= max(abs(COV)); 26 | Zest{n} = Zest{n}(:,idx); 27 | % rearrange the component sign 28 | idx = sub2ind(size(COV), idx', [1:nCom]'); 29 | Zest{n} = Zest{n}.*repmat(sign(COV(idx))',size(Zest{n},1),1); 30 | end 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /BRTF/tensor_plot/showbgfg.m: -------------------------------------------------------------------------------- 1 | 2 | function showbgfg(V, X, S) 3 | 4 | figure('position', [200, 300, 600, 200]); 5 | 6 | 7 | if ndims(X)==4 8 | nFrames = size(X,4); 9 | S = (S - min(S(:)))/(max(S(:))-min(S(:))); 10 | 11 | for i=1:nFrames 12 | subplot(1,3,1); imshow(uint8(V(:,:,:,i))); 13 | subplot(1,3,2); imshow(uint8(X(:,:,:,i))); title(['Frame: ', num2str(i)],'Color','b','FontSize',12); 14 | subplot(1,3,3); imshow(S(:,:,:,i)); 15 | pause(0.01); 16 | end 17 | 18 | else 19 | nFrames = size(X,3); 20 | S = (S - min(S(:)))/(max(S(:))-min(S(:))); 21 | for i=1:nFrames 22 | subplot(1,3,1); imshow(uint8(V(:,:,i))); 23 | subplot(1,3,2); imshow(uint8(X(:,:,i))); 24 | subplot(1,3,3); imshow(S(:,:,i),[]); 25 | pause(0.01); 26 | end 27 | 28 | end 29 | 30 | disp('Done'); -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@ktensor/arrange.m: -------------------------------------------------------------------------------- 1 | function X = arrange(X,foo) 2 | %ARRANGE Arranges the rank-1 components of a ktensor. 3 | % 4 | % ARRANGE(X) normalizes the columns of the factor matrices and then sorts 5 | % the ktensor components by magnitude, greatest to least. 6 | % 7 | % ARRANGE(X,N) absorbs the weights into the Nth factor matrix instead of 8 | % lambda. 9 | % 10 | % ARRANGE(X,P) rearranges the components of X according to the 11 | % permutation P. P should be a permutation of 1 to NCOMPOMENTS(X). 12 | % 13 | % See also KTENSOR, NCOMPONENTS. 14 | % 15 | %MATLAB Tensor Toolbox. 16 | %Copyright 2012, Sandia Corporation. 17 | 18 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 19 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 20 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 21 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 22 | % work by or on behalf of the U.S. Government. Export of this data may 23 | % require a license from the United States Government. 24 | % The full license terms can be found in the file LICENSE.txt 25 | 26 | 27 | %% Just rearrange and return if second argument is a permutation 28 | if exist('foo','var') && (length(foo) > 1) 29 | X.lambda = X.lambda(foo); 30 | for i = 1 : ndims(X) 31 | X.u{i} = X.u{i}(:,foo); 32 | end 33 | return; 34 | end 35 | 36 | %% Ensure that matrices are normalized 37 | X = normalize(X); 38 | 39 | %% Sort 40 | [X.lambda, idx] = sort(X.lambda, 1, 'descend'); 41 | for i = 1 : ndims(X) 42 | X.u{i} = X.u{i}(:,idx); 43 | end 44 | 45 | %% Absorb the weight into one factor, if requested 46 | if exist('foo','var') 47 | r = length(X.lambda); 48 | X.u{end} = X.u{end} * spdiags(X.lambda,0,r,r); 49 | X.lambda = ones(size(X.lambda)); 50 | end 51 | 52 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@ktensor/disp.m: -------------------------------------------------------------------------------- 1 | function disp(t, name) 2 | %DISP Command window display for a ktensor. 3 | % 4 | % DISP(T) displays a Kruskal tensor with no name. 5 | % 6 | % DISP(T,NAME) display a Kruskal tensor with the given name. 7 | % 8 | % See also DISP, KTENSOR/DISPLAY, KTENSOR 9 | % 10 | %MATLAB Tensor Toolbox. 11 | %Copyright 2012, Sandia Corporation. 12 | 13 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 14 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 15 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 16 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 17 | % work by or on behalf of the U.S. Government. Export of this data may 18 | % require a license from the United States Government. 19 | % The full license terms can be found in the file LICENSE.txt 20 | 21 | 22 | if ~exist('name','var') 23 | name = 'ans'; 24 | end 25 | 26 | fprintf('%s is a ktensor of size %s\n', name, tt_size2str(size(t))); 27 | fprintf('\t%s.lambda = %s\n',name, ['[ ' num2str(t.lambda') ' ]'] ); 28 | 29 | if (ndims(t) > 0) 30 | for j = 1 : ndims(t) 31 | fprintf('\t%s.U{%d} = \n', name, j); 32 | output = tt_matrix2cellstr(t.u{j}); 33 | fprintf('\t\t%s\n',output{:}); 34 | end 35 | end 36 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@ktensor/display.m: -------------------------------------------------------------------------------- 1 | function display(t) 2 | %DISPLAY Command window display for a ktensor. 3 | % 4 | % DISPLAY(T) displays a Kruskal tensor with its name. 5 | % 6 | % See also DISPLAY, KTENSOR/DISP, KTENSOR. 7 | % 8 | %MATLAB Tensor Toolbox. 9 | %Copyright 2012, Sandia Corporation. 10 | 11 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 12 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 13 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 14 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 15 | % work by or on behalf of the U.S. Government. Export of this data may 16 | % require a license from the United States Government. 17 | % The full license terms can be found in the file LICENSE.txt 18 | 19 | 20 | disp(t,inputname(1)); 21 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@ktensor/double.m: -------------------------------------------------------------------------------- 1 | function A = double(X) 2 | %DOUBLE Convert a ktensor to a double array. 3 | % 4 | % A = double(X) converts X to a standard multidimensional array. 5 | % 6 | % See also KTENSOR. 7 | % 8 | %MATLAB Tensor Toolbox. 9 | %Copyright 2012, Sandia Corporation. 10 | 11 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 12 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 13 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 14 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 15 | % work by or on behalf of the U.S. Government. Export of this data may 16 | % require a license from the United States Government. 17 | % The full license terms can be found in the file LICENSE.txt 18 | 19 | 20 | if isempty(X.lambda) % check for empty tensor 21 | A = []; 22 | return; 23 | end 24 | 25 | sz = [size(X) 1]; 26 | A = X.lambda' * khatrirao(X.u,'r')'; 27 | A = reshape(A,sz); 28 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@ktensor/end.m: -------------------------------------------------------------------------------- 1 | function e = end(X,k,n) 2 | %END Last index of indexing expression for ktensor. 3 | % 4 | % The expression X(end,:,:) will call END(X,1,3) to determine 5 | % the value of the first index. 6 | % 7 | % See also KTENSOR, KTENSOR/SUBSREF, END. 8 | % 9 | %MATLAB Tensor Toolbox. 10 | %Copyright 2012, Sandia Corporation. 11 | 12 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 13 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 14 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 15 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 16 | % work by or on behalf of the U.S. Government. Export of this data may 17 | % require a license from the United States Government. 18 | % The full license terms can be found in the file LICENSE.txt 19 | 20 | 21 | %TODO (after 2.0 release): Resolve ambiguity w.r.t X{end}and X(end,1,1) 22 | %for 1st-order tensors. 23 | 24 | if n > ndims(X) 25 | error('Subscript out of range.'); 26 | end 27 | 28 | if (n ~= 1) 29 | e = size(X,k); 30 | else 31 | e = ndims(X); 32 | end 33 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@ktensor/extract.m: -------------------------------------------------------------------------------- 1 | function new_X = extract(X,idx) 2 | %EXTRACT Creates a new ktensor with only the specified components. 3 | % 4 | % Y = EXTRACT(X,S) selected the subset of components in X as defined by 5 | % S. It should be the case that S is a subset of [1,...,NCOMPONENTS(X)]. 6 | % 7 | % See also KTENSOR, NCOMPONENTS. 8 | % 9 | %MATLAB Tensor Toolbox. 10 | %Copyright 2012, Sandia Corporation. 11 | 12 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 13 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 14 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 15 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 16 | % work by or on behalf of the U.S. Government. Export of this data may 17 | % require a license from the United States Government. 18 | % The full license terms can be found in the file LICENSE.txt 19 | 20 | 21 | %% Set-up 22 | N = ndims(X); 23 | %% Extract 24 | new_lambda = X.lambda(idx); 25 | new_U = cell(N,1); 26 | for i = 1 : N 27 | new_U{i} = X.u{i}(:,idx); 28 | end 29 | new_X = ktensor(new_lambda, new_U); 30 | 31 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@ktensor/full.m: -------------------------------------------------------------------------------- 1 | function t = full(t) 2 | %FULL Convert a ktensor to a (dense) tensor. 3 | % 4 | % T = FULL(C) converts a ktensor to a (dense) tensor. 5 | % 6 | % Examples 7 | % X = ktensor([3; 2], rand(4,2), rand(5,2), rand(3,2)); 8 | % Y = full(A) %<-- equivalent dense tensor 9 | % 10 | % See also KTENSOR, TENSOR. 11 | % 12 | %MATLAB Tensor Toolbox. 13 | %Copyright 2012, Sandia Corporation. 14 | 15 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 16 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 17 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 18 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 19 | % work by or on behalf of the U.S. Government. Export of this data may 20 | % require a license from the United States Government. 21 | % The full license terms can be found in the file LICENSE.txt 22 | 23 | 24 | sz = size(t); 25 | data = t.lambda' * khatrirao(t.u,'r')'; 26 | t = tensor(data,sz); 27 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@ktensor/innerprod.m: -------------------------------------------------------------------------------- 1 | function res = innerprod(X,Y) 2 | %INNERPROD Efficient inner product with a ktensor. 3 | % 4 | % R = INNERPROD(X,Y) efficiently computes the inner product between 5 | % two tensors X and Y. If Y is a ktensor, the inner product is 6 | % computed using inner products of the factor matrices, X{i}'*Y{i}. 7 | % Otherwise, the inner product is computed using ttv with all of 8 | % the columns of X's factor matrices, X{i}. 9 | % 10 | % See also KTENSOR, KTENSOR/TTV 11 | % 12 | %MATLAB Tensor Toolbox. 13 | %Copyright 2012, Sandia Corporation. 14 | 15 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 16 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 17 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 18 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 19 | % work by or on behalf of the U.S. Government. Export of this data may 20 | % require a license from the United States Government. 21 | % The full license terms can be found in the file LICENSE.txt 22 | 23 | 24 | if ~isequal(size(X),size(Y)) 25 | error('X and Y must be the same size.'); 26 | end 27 | 28 | % X is a ktensor 29 | switch class(Y) 30 | 31 | case {'ktensor'} 32 | M = X.lambda * Y.lambda'; 33 | for n = 1:ndims(X) 34 | M = M .* (X.u{n}' * Y.u{n}); 35 | end 36 | res = sum(M(:)); 37 | 38 | case {'tensor','sptensor','ttensor'} 39 | R = length(X.lambda); 40 | vecs = cell(1,ndims(X)); 41 | res = 0; 42 | for r = 1:R 43 | for n = 1:ndims(X) 44 | vecs{n} = X.u{n}(:,r); 45 | end 46 | res = res + X.lambda(r) * ttv(Y,vecs); 47 | end 48 | 49 | otherwise 50 | disp(['Inner product not available for class ' class(Y)]); 51 | end 52 | 53 | return; 54 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@ktensor/isequal.m: -------------------------------------------------------------------------------- 1 | function [tf, tf_lambda, tf_U] = isequal(A,B) 2 | %ISEQUAL True if each component of two ktensor's is numerically equal. 3 | % 4 | %MATLAB Tensor Toolbox. 5 | %Copyright 2012, Sandia Corporation. 6 | 7 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 8 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 9 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 10 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 11 | % work by or on behalf of the U.S. Government. Export of this data may 12 | % require a license from the United States Government. 13 | % The full license terms can be found in the file LICENSE.txt 14 | 15 | tf = false; 16 | tf_lambda = false; 17 | tf_U = false; 18 | 19 | if ~isa(B,'ktensor') 20 | return; 21 | end 22 | 23 | tf_lambda = isequal(A.lambda, B.lambda); 24 | if ncomponents(A) == ncomponents(B) 25 | tf_U = cellfun(@isequal, A.u, B.u); 26 | end 27 | tf = tf_lambda & all(tf_U); 28 | 29 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@ktensor/minus.m: -------------------------------------------------------------------------------- 1 | function C = minus(A,B) 2 | %MINUS Binary subtraction for ktensor. 3 | % 4 | % C = MINUS(A,B) computes C = A - B. A and B must both be ktensors 5 | % and have the same size, and the result is another ktensor of the 6 | % same size. 7 | % 8 | % C = MINUS(A,B) is called for the syntax 'A - B' when A or B is a 9 | % ktensor. 10 | % 11 | % See also KTENSOR, SIZE, ISEQUAL. 12 | % 13 | %MATLAB Tensor Toolbox. 14 | %Copyright 2012, Sandia Corporation. 15 | 16 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 17 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 18 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 19 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 20 | % work by or on behalf of the U.S. Government. Export of this data may 21 | % require a license from the United States Government. 22 | % The full license terms can be found in the file LICENSE.txt 23 | 24 | 25 | if (isa(A,'ktensor') && isa(B,'ktensor')) 26 | 27 | if ~isequal(size(A),size(B)) 28 | error('Tensor size mismatch.') 29 | end 30 | 31 | lambda = [A.lambda; -B.lambda]; 32 | M = ndims(A); 33 | u = cell(M,1); 34 | for m = 1 : M 35 | u{m} = [A.u{m} B.u{m}]; 36 | end 37 | C = ktensor(lambda,u); 38 | return; 39 | 40 | end 41 | 42 | error('Use minus(full(A),full(B)).'); 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@ktensor/mtimes.m: -------------------------------------------------------------------------------- 1 | function C = mtimes(A,B) 2 | %MTIMES Implement A*B (scalar multiply) for ktensor. 3 | % 4 | % C = mtimes(A,B) computes A * B where A is a Kruskal tensor and B is 5 | % a scalar (or vice versa). The result C is the same size as A. 6 | % 7 | % See also KTENSOR. 8 | % 9 | %MATLAB Tensor Toolbox. 10 | %Copyright 2012, Sandia Corporation. 11 | 12 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 13 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 14 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 15 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 16 | % work by or on behalf of the U.S. Government. Export of this data may 17 | % require a license from the United States Government. 18 | % The full license terms can be found in the file LICENSE.txt 19 | 20 | 21 | % Note: We can do scalar times a tensor, but anything more complex is 22 | % an error. 23 | 24 | if isa(B,'numeric') && isequal(size(B),[1 1]) 25 | C = ktensor(B * A.lambda, A.u); 26 | elseif isa(A,'numeric') && isequal(size(A),[1 1]) 27 | C = ktensor(A * B.lambda, B.u); 28 | else 29 | error('Use mtimes(full(A),full(B)).'); 30 | end 31 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@ktensor/mttkrp.m: -------------------------------------------------------------------------------- 1 | function V = mttkrp(X,U,n) 2 | %MTTKRP Matricized tensor times Khatri-Rao product for ktensor. 3 | % 4 | % V = MTTKRP(X,U,n) efficiently calculates the matrix product of the 5 | % n-mode matricization of X with the Khatri-Rao product of all 6 | % entries in U, a cell array of matrices, except the nth. How to 7 | % most efficiently do this computation depends on the type of tensor 8 | % involved. 9 | % 10 | % See also KTENSOR, KTENSOR/TTV 11 | % 12 | %MATLAB Tensor Toolbox. 13 | %Copyright 2012, Sandia Corporation. 14 | 15 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 16 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 17 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 18 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 19 | % work by or on behalf of the U.S. Government. Export of this data may 20 | % require a license from the United States Government. 21 | % The full license terms can be found in the file LICENSE.txt 22 | 23 | 24 | N = ndims(X); 25 | 26 | if (n==1) 27 | R = size(U{2},2); 28 | else 29 | R = size(U{1},2); 30 | end 31 | 32 | % Compute matrix of weights 33 | W = repmat(X.lambda,1,R); 34 | for i = [1:n-1,n+1:N] 35 | W = W .* (X.u{i}' * U{i}); 36 | end 37 | 38 | % Find each column of answer by multiplying columns of X.u{n} with weights 39 | V = X.u{n} * W; 40 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@ktensor/ncomponents.m: -------------------------------------------------------------------------------- 1 | function n = ncomponents(t) 2 | %NCOMPONENTS Number of components for a ktensor. 3 | % 4 | % NCOMPONENTS(T) returns the number of compontents in the ktensor T. 5 | % 6 | % See also KTENSOR 7 | % 8 | %MATLAB Tensor Toolbox. 9 | %Copyright 2012, Sandia Corporation. 10 | 11 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 12 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 13 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 14 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 15 | % work by or on behalf of the U.S. Government. Export of this data may 16 | % require a license from the United States Government. 17 | % The full license terms can be found in the file LICENSE.txt 18 | 19 | 20 | n = length(t.lambda); 21 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@ktensor/ndims.m: -------------------------------------------------------------------------------- 1 | function n = ndims(t) 2 | %NDIMS Number of dimensions for a ktensor. 3 | % 4 | % NDIMS(T) returns the number of dimensions of tensor T. 5 | % 6 | % See also KTENSOR 7 | % 8 | %MATLAB Tensor Toolbox. 9 | %Copyright 2012, Sandia Corporation. 10 | 11 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 12 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 13 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 14 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 15 | % work by or on behalf of the U.S. Government. Export of this data may 16 | % require a license from the United States Government. 17 | % The full license terms can be found in the file LICENSE.txt 18 | 19 | 20 | n = numel(t.u); 21 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@ktensor/norm.m: -------------------------------------------------------------------------------- 1 | function nrm = norm(A) 2 | %NORM Frobenius norm of a ktensor. 3 | % 4 | % NORM(T) returns the Frobenius norm of a ktensor. 5 | % 6 | % See also KTENSOR. 7 | % 8 | %MATLAB Tensor Toolbox. 9 | %Copyright 2012, Sandia Corporation. 10 | 11 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 12 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 13 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 14 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 15 | % work by or on behalf of the U.S. Government. Export of this data may 16 | % require a license from the United States Government. 17 | % The full license terms can be found in the file LICENSE.txt 18 | 19 | 20 | % Retrieve the factors of A 21 | U = A.u; 22 | 23 | % Compute the matrix of correlation coefficients 24 | coefMatrix = A.lambda * A.lambda'; 25 | for i = 1:ndims(A) 26 | coefMatrix = coefMatrix .* (U{i}'*U{i}); 27 | end 28 | 29 | nrm = sqrt(abs(sum(coefMatrix(:)))); 30 | 31 | return; 32 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@ktensor/permute.m: -------------------------------------------------------------------------------- 1 | function b = permute(a,order) 2 | %PERMUTE Permute dimensions of a ktensor. 3 | % 4 | % B = PERMUTE(A,ORDER) rearranges the dimensions of A so that they 5 | % are in the order specified by the vector ORDER. The tensor 6 | % produced has the same values of A but the order of the subscripts 7 | % needed to access any particular element are rearranged as 8 | % specified by ORDER. 9 | % 10 | % See also KTENSOR. 11 | % 12 | %MATLAB Tensor Toolbox. 13 | %Copyright 2012, Sandia Corporation. 14 | 15 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 16 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 17 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 18 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 19 | % work by or on behalf of the U.S. Government. Export of this data may 20 | % require a license from the United States Government. 21 | % The full license terms can be found in the file LICENSE.txt 22 | 23 | 24 | N = ndims(a); 25 | 26 | if ~isequal(1:N,sort(order)) 27 | error('Invalid permuation'); 28 | end 29 | 30 | b = ktensor(a.lambda, a.u(order)); 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@ktensor/plus.m: -------------------------------------------------------------------------------- 1 | function C = plus(A,B) 2 | %PLUS Binary addition for ktensor. 3 | % 4 | % C = PLUS(A,B) adds two ktensors of the same size, and the 5 | % result is a ktensor of the same size. 6 | % 7 | % See also KTENSOR. 8 | % 9 | %MATLAB Tensor Toolbox. 10 | %Copyright 2012, Sandia Corporation. 11 | 12 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 13 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 14 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 15 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 16 | % work by or on behalf of the U.S. Government. Export of this data may 17 | % require a license from the United States Government. 18 | % The full license terms can be found in the file LICENSE.txt 19 | 20 | 21 | if (isa(A,'ktensor') && isa(B,'ktensor')) 22 | 23 | if ~isequal(size(A),size(B)) 24 | error('Tensor size mismatch.') 25 | end 26 | 27 | lambda = [A.lambda; B.lambda]; 28 | M = ndims(A); 29 | u = cell(M,1); 30 | for m = 1 : M 31 | u{m} = [A.u{m} B.u{m}]; 32 | end 33 | C = ktensor(lambda, u); 34 | return; 35 | end 36 | 37 | error('Use plus(full(A),full(B)).'); 38 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@ktensor/redistribute.m: -------------------------------------------------------------------------------- 1 | function X = redistribute(X,mode) 2 | %REDISTRIBUTE Distribute lambda values to a specified mode. 3 | % 4 | % K = REDISTRIBUTE(K,N) absorbs the weights from the lambda vector 5 | % into mode N. Set the lambda vector to all ones. 6 | % 7 | % See also KTENSOR, NORMALIZE. 8 | % 9 | %MATLAB Tensor Toolbox. 10 | %Copyright 2012, Sandia Corporation. 11 | 12 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 13 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 14 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 15 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 16 | % work by or on behalf of the U.S. Government. Export of this data may 17 | % require a license from the United States Government. 18 | % The full license terms can be found in the file LICENSE.txt 19 | 20 | for r = 1:length(X.lambda) 21 | X.u{mode}(:,r) = X.u{mode}(:,r) * X.lambda(r); 22 | X.lambda(r) = 1; 23 | end 24 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@ktensor/size.m: -------------------------------------------------------------------------------- 1 | function m = size(t,idx) 2 | %SIZE Size of ktensor. 3 | % 4 | % D = SIZE(T) returns the size of the tensor. 5 | % 6 | % I = SIZE(T,DIM) returns the size of the dimension specified by 7 | % the scalar DIM. 8 | % 9 | % See also KTENSOR, KTENSOR/NDIMS. 10 | % 11 | %MATLAB Tensor Toolbox. 12 | %Copyright 2012, Sandia Corporation. 13 | 14 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 15 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 16 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 17 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 18 | % work by or on behalf of the U.S. Government. Export of this data may 19 | % require a license from the United States Government. 20 | % The full license terms can be found in the file LICENSE.txt 21 | 22 | 23 | if isempty(t.lambda) 24 | m = []; 25 | end 26 | 27 | if exist('idx','var') 28 | m = size(t.u{idx}, 1); 29 | else 30 | for i = 1 : ndims(t) 31 | m(i) = size(t.u{i}, 1); 32 | end 33 | end 34 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@ktensor/subsasgn.m: -------------------------------------------------------------------------------- 1 | function t = subsasgn(t,s,b) 2 | %SUBSASGN Subscripted assignement for ktensor. 3 | % 4 | % See also KTENSOR. 5 | % 6 | %MATLAB Tensor Toolbox. 7 | %Copyright 2012, Sandia Corporation. 8 | 9 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 10 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 11 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 12 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 13 | % work by or on behalf of the U.S. Government. Export of this data may 14 | % require a license from the United States Government. 15 | % The full license terms can be found in the file LICENSE.txt 16 | 17 | 18 | switch s(1).type 19 | case '.' 20 | switch s(1).subs 21 | case 'lambda' 22 | if length(s) == 1 23 | t = ktensor(b, t.u); 24 | else 25 | newlambda = subsasgn(t.lambda, s(2:end), b); 26 | t = ktensor(newlambda, t.u); 27 | end 28 | case {'u','U'} 29 | if length(s) == 1 30 | t = ktensor(t.lambda, b); 31 | else 32 | tmpu = subsasgn(t.u, s(2:end), b); 33 | t = ktensor(t.lambda, tmpu); 34 | end 35 | otherwise 36 | error(['No such field: ', s(1).subs]); 37 | end 38 | case '()' 39 | error('Cannot change individual entries in a ktensor.') 40 | case '{}' 41 | new_s(1).type = '.'; 42 | new_s(1).subs = 'u'; 43 | new_s(2:length(s)+1) = s; 44 | t = subsasgn(t, new_s, b); 45 | otherwise 46 | error('Invalid subsasgn.'); 47 | end 48 | 49 | 50 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@ktensor/subsref.m: -------------------------------------------------------------------------------- 1 | function a = subsref(t,s) 2 | %SUBSREF Subscripted reference for a ktensor. 3 | % 4 | % Examples 5 | % X = ktensor([3; 2], rand(4,2), rand(5,2), rand(3,2)); 6 | % X.lambda returns the lambda array ([3;2]). 7 | % X.U returns a cell array of 3 matrices. 8 | % X.U{1} returns the matrix corresponding to the first mode. 9 | % X(2,3,1) calculates and returns that single element of A. 10 | % 11 | % See also KTENSOR. 12 | % 13 | %MATLAB Tensor Toolbox. 14 | %Copyright 2012, Sandia Corporation. 15 | 16 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 17 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 18 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 19 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 20 | % work by or on behalf of the U.S. Government. Export of this data may 21 | % require a license from the United States Government. 22 | % The full license terms can be found in the file LICENSE.txt 23 | 24 | 25 | switch s(1).type 26 | case '.' 27 | switch s(1).subs 28 | case 'lambda' 29 | a = tt_subsubsref(t.lambda,s); 30 | case {'u','U'} 31 | a = tt_subsubsref(t.u,s); 32 | otherwise 33 | error(['No such field: ', s(1).subs]); 34 | end 35 | case '()' 36 | a = 0; 37 | for k = 1 : length(t.lambda) 38 | b = t.lambda(k); 39 | for i = 1 : length(s.subs) 40 | b = b * t.u{i}(s.subs{i},k); 41 | end 42 | a = a + b; 43 | end 44 | case '{}' 45 | a = subsref(t.u,s); 46 | otherwise 47 | error('Invalid subsref.'); 48 | end 49 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@ktensor/times.m: -------------------------------------------------------------------------------- 1 | function C = times(A,B) 2 | %TIMES Element-wise multiplication for ktensor. 3 | % 4 | % TIMES(A,B) denotes element-by-element multiplication. 5 | % 6 | % C = TIMES(A,B) is called for the syntax 'A .* B' when A or B is a 7 | % tensor. 8 | % 9 | % See also KTENSOR, SPTENSOR/TIMES. 10 | % 11 | %MATLAB Tensor Toolbox. 12 | %Copyright 2012, Sandia Corporation. 13 | 14 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 15 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 16 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 17 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 18 | % work by or on behalf of the U.S. Government. Export of this data may 19 | % require a license from the United States Government. 20 | % The full license terms can be found in the file LICENSE.txt 21 | 22 | 23 | if ~isequal(size(A),size(B)) 24 | error('Must be two tensors of the same size'); 25 | end 26 | 27 | switch class(B) 28 | case {'sptensor','tensor'} 29 | % Call back to sptensor version. 30 | C = times(B,A); 31 | return; 32 | otherwise 33 | error('Invalid second argument for ktensor/times'); 34 | end 35 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@ktensor/tocell.m: -------------------------------------------------------------------------------- 1 | function U = tocell(X,N) 2 | %TOCELL Convert X to a cell array. 3 | % 4 | % TOCELL(X) converts X to a cell array, evenly distributing the 5 | % weight in lambda. 6 | % 7 | % TOCELL(X,N) absorbs the weights into the Nth factor matrix. 8 | % 9 | % See also KTENSOR, NORMALIZE. 10 | % 11 | %MATLAB Tensor Toolbox. 12 | %Copyright 2012, Sandia Corporation. 13 | 14 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 15 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 16 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 17 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 18 | % work by or on behalf of the U.S. Government. Export of this data may 19 | % require a license from the United States Government. 20 | % The full license terms can be found in the file LICENSE.txt 21 | 22 | 23 | if exist('N','var') 24 | X = normalize(X,N); 25 | U = X.u; 26 | return; 27 | end 28 | 29 | if isequal(X.lambda,ones(size(X.lambda))) 30 | U = X.u; 31 | return; 32 | end 33 | 34 | 35 | lsplit = nthroot(X.lambda,ndims(X)); 36 | R = length(X.lambda); 37 | U = X.u; 38 | D = diag(lsplit); 39 | for n = 1:ndims(X) 40 | U{n} = U{n} * D; 41 | end 42 | 43 | 44 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@ktensor/uminus.m: -------------------------------------------------------------------------------- 1 | function t = uminus(t) 2 | %UMINUS Unary minus for ktensor. 3 | % 4 | % See also KTENSOR. 5 | % 6 | %MATLAB Tensor Toolbox. 7 | %Copyright 2012, Sandia Corporation. 8 | 9 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 10 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 11 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 12 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 13 | % work by or on behalf of the U.S. Government. Export of this data may 14 | % require a license from the United States Government. 15 | % The full license terms can be found in the file LICENSE.txt 16 | 17 | 18 | t.lambda = -t.lambda; 19 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@ktensor/uplus.m: -------------------------------------------------------------------------------- 1 | function t = uplus(t) 2 | %UPLUS Unary plus for a ktensor. 3 | % 4 | % See also KTENSOR. 5 | % 6 | %MATLAB Tensor Toolbox. 7 | %Copyright 2012, Sandia Corporation. 8 | 9 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 10 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 11 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 12 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 13 | % work by or on behalf of the U.S. Government. Export of this data may 14 | % require a license from the United States Government. 15 | % The full license terms can be found in the file LICENSE.txt 16 | 17 | 18 | % This function does nothing! 19 | 20 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@sptenmat/Contents.m: -------------------------------------------------------------------------------- 1 | % @SPTENMAT 2 | % 3 | % Files 4 | % aatx - Implicitly compute A * A' * x for sptenmat. 5 | % disp - Command window display of a sptenmat. 6 | % display - Command window display of a sptenmat. 7 | % double - Convert a sptenmat to a sparse matrix. 8 | % end - Last index of indexing expression for sptenmat. 9 | % full - Convert a sptenmat to a (dense) tenmat. 10 | % nnz - Return number of nonzeros in a sptenmat. 11 | % norm - Frobenius norm of a sptenmat. 12 | % size - Return size of sptenmat. 13 | % sptenmat - Matricized sparse tensor stored as a sparse 2D array. 14 | % subsasgn - Subscripted assignment for sptenmat. 15 | % subsref - Subscripted reference for a sptenmat. 16 | % tsize - Tensor size of sptenmat. 17 | % uminus - Unary minus (-) for sptenmat. 18 | % uplus - Unary plus (+) for sptenmat. 19 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@sptenmat/aatx.m: -------------------------------------------------------------------------------- 1 | function z = aatx(a,x) 2 | %AATX Implicitly compute A * A' * x for sptenmat. 3 | % 4 | % Z = AATX(A,X) takes a sptenmat object A and computes A * A' * 5 | % X. This is done without converting A to a standard MATLAB sparse 6 | % matrix. 7 | % 8 | % This function is likely most useful as an argument to a routine 9 | % such as EIGS. 10 | % 11 | % See also SPTENMAT, SPTENSOR/EIGS. 12 | % 13 | %MATLAB Tensor Toolbox. 14 | %Copyright 2012, Sandia Corporation. 15 | 16 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 17 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 18 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 19 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 20 | % work by or on behalf of the U.S. Government. Export of this data may 21 | % require a license from the United States Government. 22 | % The full license terms can be found in the file LICENSE.txt 23 | 24 | 25 | subs = a.subs; 26 | s1 = subs(:,1); 27 | s2 = subs(:,2); 28 | m = size(a,1); 29 | n = size(a,2); 30 | vals = a.vals; 31 | 32 | v1 = x(s1); 33 | v1 = vals .* v1; 34 | y = accumarray(s2, v1, [n 1]); 35 | 36 | v2 = y(s2); 37 | v2 = vals .* v2; 38 | z = accumarray(s1, v2, [m 1]); 39 | 40 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@sptenmat/display.m: -------------------------------------------------------------------------------- 1 | function display(t) 2 | %DISPLAY Command window display of a sptenmat. 3 | % 4 | % DISPLAY(T) displays the tensor with its name. 5 | % 6 | % See also SPTENMAT/DISP. 7 | % 8 | %MATLAB Tensor Toolbox. 9 | %Copyright 2012, Sandia Corporation. 10 | 11 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 12 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 13 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 14 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 15 | % work by or on behalf of the U.S. Government. Export of this data may 16 | % require a license from the United States Government. 17 | % The full license terms can be found in the file LICENSE.txt 18 | 19 | 20 | disp(t,inputname(1)); 21 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@sptenmat/double.m: -------------------------------------------------------------------------------- 1 | function A = double(T) 2 | %DOUBLE Convert a sptenmat to a sparse matrix. 3 | % 4 | % A = double(T) converts T stored as a SPTENMAT to a sparse matrix. 5 | % 6 | % See also SPTENMAT. 7 | % 8 | %MATLAB Tensor Toolbox. 9 | %Copyright 2012, Sandia Corporation. 10 | 11 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 12 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 13 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 14 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 15 | % work by or on behalf of the U.S. Government. Export of this data may 16 | % require a license from the United States Government. 17 | % The full license terms can be found in the file LICENSE.txt 18 | 19 | 20 | m = prod(T.tsize(T.rdims)); 21 | n = prod(T.tsize(T.cdims)); 22 | if isempty(T.subs) 23 | A = sparse(m,n); 24 | else 25 | A = sparse(T.subs(:,1), T.subs(:,2), T.vals, m, n); 26 | end 27 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@sptenmat/end.m: -------------------------------------------------------------------------------- 1 | function e = end(X,k,n) 2 | %END Last index of indexing expression for sptenmat. 3 | % 4 | % The expression X(end,:) will call END(X,1,2) to determine 5 | % the value of the first index. 6 | % 7 | % See also SPTENMAT, SPTENMAT/SUBSREF, END. 8 | % 9 | %MATLAB Tensor Toolbox. 10 | %Copyright 2012, Sandia Corporation. 11 | 12 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 13 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 14 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 15 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 16 | % work by or on behalf of the U.S. Government. Export of this data may 17 | % require a license from the United States Government. 18 | % The full license terms can be found in the file LICENSE.txt 19 | 20 | 21 | if n > 2 22 | error('Subscript out of range.'); 23 | end 24 | e = size(X,k); 25 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@sptenmat/full.m: -------------------------------------------------------------------------------- 1 | function B = full(A) 2 | %FULL Convert a sptenmat to a (dense) tenmat. 3 | % 4 | % B = FULL(A) converts a sptenmat A to a (dense) tenmat B. 5 | % 6 | % See also SPTENMAT, TENMAT. 7 | % 8 | %MATLAB Tensor Toolbox. 9 | %Copyright 2012, Sandia Corporation. 10 | 11 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 12 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 13 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 14 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 15 | % work by or on behalf of the U.S. Government. Export of this data may 16 | % require a license from the United States Government. 17 | % The full license terms can be found in the file LICENSE.txt 18 | 19 | 20 | % Extract the order and size of A 21 | siz = size(A); 22 | 23 | % Create a dense zero tensor B that is the same size as A 24 | B = tenmat(zeros([siz,1,1]), A.rdims, A.cdims, A.tsize); 25 | 26 | % Extract the linear indices of entries in A 27 | idx = tt_sub2ind(siz,A.subs); 28 | 29 | % Copy the values of A into B using linear indices 30 | B(idx) = A.vals; 31 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@sptenmat/nnz.m: -------------------------------------------------------------------------------- 1 | function n = nnz(a) 2 | %NNZ Return number of nonzeros in a sptenmat. 3 | % 4 | % nnz(A) returns the number of nonzeros in A. 5 | % 6 | % See also SPTENMAT. 7 | % 8 | %MATLAB Tensor Toolbox. 9 | %Copyright 2012, Sandia Corporation. 10 | 11 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 12 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 13 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 14 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 15 | % work by or on behalf of the U.S. Government. Export of this data may 16 | % require a license from the United States Government. 17 | % The full license terms can be found in the file LICENSE.txt 18 | 19 | 20 | n = length(a.vals); 21 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@sptenmat/norm.m: -------------------------------------------------------------------------------- 1 | function nrm = norm(T) 2 | %NORM Frobenius norm of a sptenmat. 3 | % 4 | % NORM(T) returns the Frobenius norm of a matricized sparse tensor. 5 | % 6 | % See also SPTENMAT, NORM. 7 | % 8 | %MATLAB Tensor Toolbox. 9 | %Copyright 2012, Sandia Corporation. 10 | 11 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 12 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 13 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 14 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 15 | % work by or on behalf of the U.S. Government. Export of this data may 16 | % require a license from the United States Government. 17 | % The full license terms can be found in the file LICENSE.txt 18 | 19 | 20 | nrm = norm(T.vals); 21 | 22 | return; 23 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@sptenmat/size.m: -------------------------------------------------------------------------------- 1 | function siz = size(a,idx) 2 | %SIZE Return size of sptenmat. 3 | % 4 | % D = SIZE(T) returns the size of the tensor. 5 | % 6 | % I = size(T,DIM) returns the sizes of the dimensions specified by DIM. 7 | % 8 | % See also SPTENMAT. 9 | % 10 | %MATLAB Tensor Toolbox. 11 | %Copyright 2012, Sandia Corporation. 12 | 13 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 14 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 15 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 16 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 17 | % work by or on behalf of the U.S. Government. Export of this data may 18 | % require a license from the United States Government. 19 | % The full license terms can be found in the file LICENSE.txt 20 | 21 | 22 | if isempty(a.tsize) 23 | siz = []; 24 | return; 25 | end 26 | 27 | m = prod(a.tsize(a.rdims)); 28 | n = prod(a.tsize(a.cdims)); 29 | siz = [m n]; 30 | 31 | if exist('idx','var') 32 | siz = siz(idx); 33 | end 34 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@sptenmat/subsref.m: -------------------------------------------------------------------------------- 1 | function a = subsref(t,s) 2 | %SUBSREF Subscripted reference for a sptenmat. 3 | % 4 | % Examples 5 | % A.subs <-- returns the nonzero values as an array 6 | % A.vals <-- returns the corresponding 2D subscripts 7 | % A.tsize <-- returns the size original tensor 8 | % A.rdims <-- tensor dimensions that were mapped to rows 9 | % A.cdims <-- tensor dimensions that were mapped to columns 10 | % 11 | % See also SPTENMAT. 12 | % 13 | %MATLAB Tensor Toolbox. 14 | %Copyright 2012, Sandia Corporation. 15 | 16 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 17 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 18 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 19 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 20 | % work by or on behalf of the U.S. Government. Export of this data may 21 | % require a license from the United States Government. 22 | % The full license terms can be found in the file LICENSE.txt 23 | 24 | 25 | switch s(1).type 26 | case '.' 27 | switch s(1).subs 28 | case 'vals' 29 | a = tt_subsubsref(t.vals,s); 30 | case 'tsize' 31 | a = t.tsize; 32 | case 'rdims' 33 | a = t.rdims; 34 | case 'cdims' 35 | a = t.cdims; 36 | case 'subs' 37 | a = tt_subsubsref(t.subs,s); 38 | otherwise 39 | error(['No such field: ', s.subs]); 40 | end 41 | otherwise 42 | error('Invalid subsref into tenmat.') 43 | end 44 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@sptenmat/tsize.m: -------------------------------------------------------------------------------- 1 | function sz = tsize(a,idx) 2 | %TSIZE Tensor size of sptenmat. 3 | % 4 | % D = TSIZE(X) returns the size of the tensor being stored as a 5 | % matrix. 6 | % 7 | % M = TSIZE(X,DIM) returns the length of the dimension(s) specified 8 | % by DIM. For example, SIZE(X,1) returns the size of the first 9 | % dimension of the tensor. 10 | % 11 | % See also SPTENMAT, SPTENMAT/SIZE. 12 | % 13 | %MATLAB Tensor Toolbox. 14 | %Copyright 2012, Sandia Corporation. 15 | 16 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 17 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 18 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 19 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 20 | % work by or on behalf of the U.S. Government. Export of this data may 21 | % require a license from the United States Government. 22 | % The full license terms can be found in the file LICENSE.txt 23 | 24 | 25 | if isempty(a.tsize) 26 | sz = []; 27 | return; 28 | end 29 | 30 | if exist('idx', 'var') 31 | sz = a.tsize(idx); 32 | else 33 | sz = a.tsize; 34 | end 35 | 36 | return; 37 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@sptenmat/uminus.m: -------------------------------------------------------------------------------- 1 | function t = uminus(t) 2 | %UMINUS Unary minus (-) for sptenmat. 3 | % 4 | % See also SPTENMAT. 5 | % 6 | %MATLAB Tensor Toolbox. 7 | %Copyright 2012, Sandia Corporation. 8 | 9 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 10 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 11 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 12 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 13 | % work by or on behalf of the U.S. Government. Export of this data may 14 | % require a license from the United States Government. 15 | % The full license terms can be found in the file LICENSE.txt 16 | 17 | 18 | t.vals = -t.vals; 19 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@sptenmat/uplus.m: -------------------------------------------------------------------------------- 1 | function t = uplus(t) 2 | %UPLUS Unary plus (+) for sptenmat. 3 | % 4 | % See also TENSOR. 5 | % 6 | %MATLAB Tensor Toolbox. 7 | %Copyright 2012, Sandia Corporation. 8 | 9 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 10 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 11 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 12 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 13 | % work by or on behalf of the U.S. Government. Export of this data may 14 | % require a license from the United States Government. 15 | % The full license terms can be found in the file LICENSE.txt 16 | 17 | 18 | % This function does nothing! 19 | 20 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@sptensor/and.m: -------------------------------------------------------------------------------- 1 | function C = and(A,B) 2 | %AND Logical AND (&) for sptensors. 3 | % 4 | % See also SPTENSOR. 5 | % 6 | %MATLAB Tensor Toolbox. 7 | %Copyright 2012, Sandia Corporation. 8 | 9 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 10 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 11 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 12 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 13 | % work by or on behalf of the U.S. Government. Export of this data may 14 | % require a license from the United States Government. 15 | % The full license terms can be found in the file LICENSE.txt 16 | 17 | 18 | %% Observations for sparse matrix case. 19 | % The result of a & 5 is sparse. 20 | % The result of a & 0 is sparse. 21 | % The result of a & full(a) is sparse. 22 | 23 | %% Case 1: One argument is a scalar 24 | if isscalar(B) 25 | if B == 0 26 | C = sptensor([],[],size(A)); 27 | else 28 | C = sptensor(A.subs,true,size(A)); 29 | end 30 | return; 31 | end 32 | 33 | % Call back with the arguments reversed. 34 | if isscalar(A) 35 | C = and(B,A); 36 | return; 37 | end 38 | 39 | %% Case 2: Both x and y are tensors of some sort 40 | % Check that the sizes match 41 | if ~isequal(size(A),size(B)) 42 | error('Must be tensors of the same size'); 43 | end 44 | 45 | if isa(A,'sptensor') && isa(B,'sptensor') 46 | C = sptensor([A.subs; B.subs], [A.vals; B.vals], size(A), ... 47 | @(x) length(x) == 2); 48 | return; 49 | end 50 | 51 | if isa(B,'tensor') 52 | BB = sptensor(A.subs,B(A.subs),size(A)); 53 | C = and(A,BB); 54 | return; 55 | end 56 | 57 | %% Otherwise 58 | error('The arguments must be two sptensors or an sptensor and a scalar.'); 59 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@sptensor/ctranspose.m: -------------------------------------------------------------------------------- 1 | function ctranspose(x) 2 | %CTRANSPOSE is not defined for sparse tensors. 3 | % 4 | % See also SPTENSOR/PERMUTE. 5 | % 6 | %MATLAB Tensor Toolbox. 7 | %Copyright 2012, Sandia Corporation. 8 | 9 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 10 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 11 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 12 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 13 | % work by or on behalf of the U.S. Government. Export of this data may 14 | % require a license from the United States Government. 15 | % The full license terms can be found in the file LICENSE.txt 16 | 17 | 18 | error('Transpose on sparse tensor is not defined'); 19 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@sptensor/display.m: -------------------------------------------------------------------------------- 1 | function display(t) 2 | %DISPLAY Command window display of a sparse tensor. 3 | % 4 | % DISPLAY(T) displays the tensor with its name. 5 | % 6 | % See also SPTENSOR, SPTENSOR/DISP. 7 | % 8 | %MATLAB Tensor Toolbox. 9 | %Copyright 2012, Sandia Corporation. 10 | 11 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 12 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 13 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 14 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 15 | % work by or on behalf of the U.S. Government. Export of this data may 16 | % require a license from the United States Government. 17 | % The full license terms can be found in the file LICENSE.txt 18 | 19 | 20 | disp(t,inputname(1)); 21 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@sptensor/divide.m: -------------------------------------------------------------------------------- 1 | function Y = divide(X,K,epsilon) 2 | %DIVIDE Divide an SPTENSOR by a nonnegative KTENSOR. 3 | % 4 | % Y = DIVIDE(X,K,EPSILON) divides the sparse tensor X by the 5 | % nonnegative ktensor K. Avoids divide-by-zero errors by dividing 6 | % by MIN(EPSILON,K-VALUE) at each nonzero of X. 7 | % 8 | %MATLAB Tensor Toolbox. 9 | %Copyright 2012, Sandia Corporation. 10 | 11 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 12 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 13 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 14 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 15 | % work by or on behalf of the U.S. Government. Export of this data may 16 | % require a license from the United States Government. 17 | % The full license terms can be found in the file LICENSE.txt 18 | 19 | % Assumes K is a nonnegative ktensor 20 | 21 | Y = X; 22 | 23 | subs = Y.subs; 24 | vals = zeros(size(Y.vals)); 25 | R = numel(K.lambda); 26 | N = ndims(Y); 27 | for r = 1:R 28 | tvals = ones(size(vals)) * K.lambda(r); 29 | for n = 1:N 30 | v = K{n}(:,r); 31 | tvals = tvals .* v(subs(:,n)); 32 | end 33 | vals = vals + tvals; 34 | end 35 | Y.vals = Y.vals ./ max(epsilon, vals); 36 | 37 | return; 38 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@sptensor/double.m: -------------------------------------------------------------------------------- 1 | function a = double(s) 2 | %DOUBLE Converts a sparse tensor to a dense multidimensional array. 3 | % 4 | % See also SPTENSOR, SPTENSOR/FULL. 5 | % 6 | %MATLAB Tensor Toolbox. 7 | %Copyright 2012, Sandia Corporation. 8 | 9 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 10 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 11 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 12 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 13 | % work by or on behalf of the U.S. Government. Export of this data may 14 | % require a license from the United States Government. 15 | % The full license terms can be found in the file LICENSE.txt 16 | 17 | 18 | a = zeros([size(s) 1 1]); 19 | if nnz(s) > 0 20 | a(tt_sub2ind(size(s),s.subs)) = s.vals; 21 | end 22 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@sptensor/elemfun.m: -------------------------------------------------------------------------------- 1 | function a = elemfun(a,fun) 2 | %ELEMFUN Manipulate the nonzero elements of a sparse tensor. 3 | % 4 | % X = ELEMFUN(X,@FUN) modifies the elements of X according to the 5 | % function @FUN which should take and array and output an equally 6 | % sized array. 7 | % 8 | % Examples 9 | % X = sptenrand([10,10,10],10); 10 | % X = elemfun(X,@sqrt) %<-- square root of every entry 11 | % X = elemfun(X, @(x) x+1) %<-- increase every entry by 1 12 | % X = elemfun(X, @(x) x ~= 0) %<-- change every nonzero to be 1 13 | % 14 | % See also SPTENSOR, SPFUN. 15 | % 16 | %MATLAB Tensor Toolbox. 17 | %Copyright 2012, Sandia Corporation. 18 | 19 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 20 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 21 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 22 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 23 | % work by or on behalf of the U.S. Government. Export of this data may 24 | % require a license from the United States Government. 25 | % The full license terms can be found in the file LICENSE.txt 26 | 27 | 28 | 29 | if ~isa(a,'sptensor') 30 | error('First argument must be a sparse tensor.'); 31 | end 32 | 33 | a.vals = fun(a.vals); 34 | idx = find(a.vals); 35 | if isempty(idx) 36 | a.vals = []; 37 | a.subs = []; 38 | else 39 | a.vals = a.vals(idx); 40 | a.subs = a.subs(idx,:); 41 | end 42 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@sptensor/end.m: -------------------------------------------------------------------------------- 1 | function e = end(X,k,n) 2 | %END Last index of indexing expression for sparse tensor. 3 | % 4 | % The expression X(end,:,:) will call END(X,1,3) to determine 5 | % the value of the first index. 6 | % 7 | % See also SPTENSOR, SPTENSOR/SUBSREF, END. 8 | % 9 | %MATLAB Tensor Toolbox. 10 | %Copyright 2012, Sandia Corporation. 11 | 12 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 13 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 14 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 15 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 16 | % work by or on behalf of the U.S. Government. Export of this data may 17 | % require a license from the United States Government. 18 | % The full license terms can be found in the file LICENSE.txt 19 | 20 | 21 | if n > ndims(X) 22 | error('Subscript out of range.'); 23 | end 24 | e = X.size(k); 25 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@sptensor/find.m: -------------------------------------------------------------------------------- 1 | function [subs,vals] = find(t) 2 | %FIND Find subscripts of nonzero elements in a sparse tensor. 3 | % 4 | % [SUBS,VALS] = FIND(T) returns the subscripts and corresponding 5 | % values of the nonzero elements of T. 6 | % 7 | % Note that unlike the standard MATLAB find function for an array, 8 | % find does not return linear indices. Instead, it returns an M x N 9 | % array where M is the number of nonzero values and N = ndims(T). 10 | % Thus, I(k,:) specifies the subscript of value V(k). 11 | % 12 | % See also SPTENSOR, FIND. 13 | % 14 | %MATLAB Tensor Toolbox. 15 | %Copyright 2012, Sandia Corporation. 16 | 17 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 18 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 19 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 20 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 21 | % work by or on behalf of the U.S. Government. Export of this data may 22 | % require a license from the United States Government. 23 | % The full license terms can be found in the file LICENSE.txt 24 | 25 | 26 | subs = t.subs; 27 | vals = t.vals; 28 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@sptensor/full.m: -------------------------------------------------------------------------------- 1 | function B = full(A) 2 | %FULL Convert a sparse tensor to a (dense) tensor. 3 | % 4 | % B = FULL(A) converts a sptensor A to a (dense) tensor B. 5 | % 6 | % See also SPTENSOR, TENSOR. 7 | % 8 | %MATLAB Tensor Toolbox. 9 | %Copyright 2012, Sandia Corporation. 10 | 11 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 12 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 13 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 14 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 15 | % work by or on behalf of the U.S. Government. Export of this data may 16 | % require a license from the United States Government. 17 | % The full license terms can be found in the file LICENSE.txt 18 | 19 | 20 | % Extract the order and size of A 21 | siz = size(A); 22 | 23 | % Create a dense zero tensor B that is the same size as A 24 | B = tensor(zeros([siz,1,1]),siz); 25 | 26 | if isempty(A.subs) 27 | return; 28 | end 29 | 30 | % Extract the linear indices of entries in A 31 | idx = tt_sub2ind(siz,A.subs); 32 | 33 | % Copy the values of A into B using linear indices 34 | B(idx) = A.vals; 35 | 36 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@sptensor/isequal.m: -------------------------------------------------------------------------------- 1 | function z = isequal(x,y) 2 | %ISEQUAL for sptensors. 3 | % 4 | % ISEQUAL(A,B) compares the sparse tensors A and B for equality. 5 | % 6 | % See also SPTENSOR. 7 | % 8 | %MATLAB Tensor Toolbox. 9 | %Copyright 2012, Sandia Corporation. 10 | 11 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 12 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 13 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 14 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 15 | % work by or on behalf of the U.S. Government. Export of this data may 16 | % require a license from the United States Government. 17 | % The full license terms can be found in the file LICENSE.txt 18 | 19 | 20 | %% Observations for sparse matrix case. 21 | % The result of isequal(a,full(a)) is true! 22 | 23 | %% 24 | if ~isequal(x.size,y.size) 25 | z = false; 26 | elseif isa(x,'sptensor') && isa(y,'sptensor') 27 | z = (nnz(x-y) == 0); 28 | elseif isa(y,'tensor') 29 | z = isequal(full(x),y); 30 | else 31 | z = false; 32 | end 33 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@sptensor/ldivide.m: -------------------------------------------------------------------------------- 1 | function C = ldivide(A,B) 2 | %LDIVIDE Array right division for sparse tensors. 3 | % 4 | % LDIVIDE(A,B) is called for the syntax 'A .\ B' when A or B is a sparse 5 | % tensor. A and B must have the same size, unless one is a scalar. 6 | % 7 | % See also SPTENSOR. 8 | % 9 | %MATLAB Tensor Toolbox. 10 | %Copyright 2012, Sandia Corporation. 11 | 12 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 13 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 14 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 15 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 16 | % work by or on behalf of the U.S. Government. Export of this data may 17 | % require a license from the United States Government. 18 | % The full license terms can be found in the file LICENSE.txt 19 | 20 | 21 | C = rdivide(B,A); 22 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@sptensor/mldivide.m: -------------------------------------------------------------------------------- 1 | function C = mldivide(A,B) 2 | %MLDIVIDE Slash left division for sparse tensors. 3 | % 4 | % MlDIVIDE(A,B) is called for the syntax 'A \ B' when A is a scalar and B 5 | % is a sparse tensor. 6 | % 7 | % Example 8 | % X = sptenrand([4 3 2],5); 9 | % 3 \ X 10 | % 11 | % See also SPTENSOR. 12 | % 13 | %MATLAB Tensor Toolbox. 14 | %Copyright 2012, Sandia Corporation. 15 | 16 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 17 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 18 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 19 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 20 | % work by or on behalf of the U.S. Government. Export of this data may 21 | % require a license from the United States Government. 22 | % The full license terms can be found in the file LICENSE.txt 23 | 24 | 25 | if isscalar(A) 26 | newsubs = B.subs; 27 | newvals = B.vals / A; 28 | if A == 0 29 | nansubs = setdiff(allsubs(A),newsubs,'rows'); 30 | newsubs = [newsubs; nansubs]; 31 | newvals = [newvals; repmat(NaN,size(nansubs,1),1)]; 32 | end 33 | C = sptensor(newsubs,newvals,B.size); 34 | return; 35 | end 36 | 37 | error('MLDIVIDE only supports the scalar case for sparse tensors'); 38 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@sptensor/mrdivide.m: -------------------------------------------------------------------------------- 1 | function C = mrdivide(A,B) 2 | %MRDIVIDE Slash right division for sparse tensors. 3 | % 4 | % MRDIVIDE(A,B) is called for the syntax 'A / B' when A is a sparse 5 | % tensor and B is a scalar. 6 | % 7 | % Example 8 | % X = sptenrand([4 3 2],5); 9 | % X / 3 10 | % 11 | % See also SPTENSOR. 12 | % 13 | %MATLAB Tensor Toolbox. 14 | %Copyright 2012, Sandia Corporation. 15 | 16 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 17 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 18 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 19 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 20 | % work by or on behalf of the U.S. Government. Export of this data may 21 | % require a license from the United States Government. 22 | % The full license terms can be found in the file LICENSE.txt 23 | 24 | 25 | if isscalar(B) 26 | newsubs = A.subs; 27 | newvals = A.vals / B; 28 | if B == 0 29 | nansubs = setdiff(allsubs(A),newsubs,'rows'); 30 | newsubs = [newsubs; nansubs]; 31 | newvals = [newvals; repmat(NaN,size(nansubs,1),1)]; 32 | end 33 | C = sptensor(newsubs,newvals,A.size); 34 | return; 35 | end 36 | 37 | error('MRDIVIDE only supports the scalar case for sparse tensors'); 38 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@sptensor/mtimes.m: -------------------------------------------------------------------------------- 1 | function C = mtimes(A,B) 2 | %MTIMES sptensor-scalar multiplication. 3 | % 4 | % C = MTIMES(A,B) is called for the syntax 'A * B' when A or B is a 5 | % sparse tensor and the other argument is a scalar. 6 | % 7 | % For tensor-matrix multiplication, use TTM. 8 | % For tensor-tensor multiplication, use TTT. 9 | % For tensor-tensor array multiplication, use TIMES or 'A .* B'. 10 | % 11 | % See also SPTENSOR, SPTENSOR/TTM, SPTENSOR/TTT, SPTENSOR/TIMES 12 | % 13 | %MATLAB Tensor Toolbox. 14 | %Copyright 2012, Sandia Corporation. 15 | 16 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 17 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 18 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 19 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 20 | % work by or on behalf of the U.S. Government. Export of this data may 21 | % require a license from the United States Government. 22 | % The full license terms can be found in the file LICENSE.txt 23 | 24 | 25 | if isscalar(B) 26 | C = sptensor(A.subs, A.vals * B, size(A)); 27 | return; 28 | end 29 | 30 | if isscalar(A) 31 | C = sptensor(B.subs, B.vals * A, size(B)); 32 | return; 33 | end 34 | 35 | error('MTIMES only supports the scalar case for sparse tensors'); 36 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@sptensor/mttkrp.m: -------------------------------------------------------------------------------- 1 | function V = mttkrp(X,U,n) 2 | %MTTKRP Matricized tensor times Khatri-Rao product for sparse tensor. 3 | % 4 | % V = MTTKRP(X,U,n) efficiently calculates the matrix product of the 5 | % n-mode matricization of X with the Khatri-Rao product of all 6 | % entries in U, a cell array of matrices, except the nth. How to 7 | % most efficiently do this computation depends on the type of tensor 8 | % involved. 9 | % 10 | % See also SPTENSOR, TENSOR/MTTKRP, SPTENSOR/TTV 11 | % 12 | %MATLAB Tensor Toolbox. 13 | %Copyright 2012, Sandia Corporation. 14 | 15 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 16 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 17 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 18 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 19 | % work by or on behalf of the U.S. Government. Export of this data may 20 | % require a license from the United States Government. 21 | % The full license terms can be found in the file LICENSE.txt 22 | 23 | 24 | % In the sparse case, it is most efficient to do a series of TTV operations 25 | % rather than forming the Khatri-Rao product. 26 | 27 | N = ndims(X); 28 | 29 | if (n == 1) 30 | R = size(U{2},2); 31 | else 32 | R = size(U{1},2); 33 | end 34 | 35 | V = zeros(size(X,n),R); 36 | for r = 1:R 37 | % Set up cell array with appropriate vectors for ttv multiplication 38 | Z = cell(N,1); 39 | for i = [1:n-1,n+1:N] 40 | Z{i} = U{i}(:,r); 41 | end 42 | % Perform ttv multiplication 43 | V(:,r) = double(ttv(X, Z, -n)); 44 | end 45 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@sptensor/ndims.m: -------------------------------------------------------------------------------- 1 | function n = ndims(t) 2 | %NDIMS Number of dimensions of a sparse tensor. 3 | % 4 | % NDIMS(T) returns the number of dimensions of sparse tensor T. 5 | % 6 | % Examples: 7 | % T = sptenrand([3 2 2],5); 8 | % ndims(T) %<-- should return 3 9 | % 10 | % See also SPTENSOR. 11 | % 12 | %MATLAB Tensor Toolbox. 13 | %Copyright 2012, Sandia Corporation. 14 | 15 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 16 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 17 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 18 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 19 | % work by or on behalf of the U.S. Government. Export of this data may 20 | % require a license from the United States Government. 21 | % The full license terms can be found in the file LICENSE.txt 22 | 23 | 24 | n = size(t.size,2); 25 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@sptensor/nnz.m: -------------------------------------------------------------------------------- 1 | function a = nnz(t) 2 | %NNZ Number of nonzeros in sparse tensor. 3 | % 4 | % NNZ(T) is the number of nonzero elements in T. 5 | % 6 | % See also SPTENSOR, SPTENSOR/FIND. 7 | % 8 | %MATLAB Tensor Toolbox. 9 | %Copyright 2012, Sandia Corporation. 10 | 11 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 12 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 13 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 14 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 15 | % work by or on behalf of the U.S. Government. Export of this data may 16 | % require a license from the United States Government. 17 | % The full license terms can be found in the file LICENSE.txt 18 | 19 | 20 | if isempty(t.subs) 21 | a = 0; 22 | else 23 | a = size(t.subs,1); 24 | end 25 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@sptensor/norm.m: -------------------------------------------------------------------------------- 1 | function nrm = norm(T) 2 | %NORM Frobenius norm of a sparse tensor. 3 | % 4 | % NORM(T) returns the Frobenius norm of a sparse tensor. 5 | % 6 | % See also SPTENSOR, NORM. 7 | % 8 | %MATLAB Tensor Toolbox. 9 | %Copyright 2012, Sandia Corporation. 10 | 11 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 12 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 13 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 14 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 15 | % work by or on behalf of the U.S. Government. Export of this data may 16 | % require a license from the United States Government. 17 | % The full license terms can be found in the file LICENSE.txt 18 | 19 | 20 | nrm = norm(T.vals); 21 | 22 | return; 23 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@sptensor/not.m: -------------------------------------------------------------------------------- 1 | function y = not(x) 2 | %NOT Logical NOT (~) for sptensors. 3 | % 4 | % ~X performs a logical not on the input tensor X. The result always 5 | % returned as a sparse tensor. 6 | % 7 | % See also SPTENSOR. 8 | % 9 | %MATLAB Tensor Toolbox. 10 | %Copyright 2012, Sandia Corporation. 11 | 12 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 13 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 14 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 15 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 16 | % work by or on behalf of the U.S. Government. Export of this data may 17 | % require a license from the United States Government. 18 | % The full license terms can be found in the file LICENSE.txt 19 | 20 | 21 | %% Observations for sparse matrix case. 22 | % The result of ~a is sparse. 23 | 24 | %% Then compute those indicies that are not in x 25 | subs = setdiff(allsubs(x),x.subs,'rows'); 26 | 27 | %% Assemble final result 28 | y = sptensor(subs,true,x.size); 29 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@sptensor/ones.m: -------------------------------------------------------------------------------- 1 | function t = ones(t) 2 | %ONES Replace nonzero elements of sparse tensor with ones. 3 | % 4 | % S = ONES(T) generates a sparse tensor with the same sparsity 5 | % structure as T, but with ones in the nonzero position. 6 | % 7 | % See also SPTENSOR, SPONES. 8 | % 9 | %MATLAB Tensor Toolbox. 10 | %Copyright 2012, Sandia Corporation. 11 | 12 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 13 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 14 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 15 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 16 | % work by or on behalf of the U.S. Government. Export of this data may 17 | % require a license from the United States Government. 18 | % The full license terms can be found in the file LICENSE.txt 19 | 20 | 21 | t.vals = ones(size(t.vals)); 22 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@sptensor/or.m: -------------------------------------------------------------------------------- 1 | function C = or(A,B) 2 | %OR Logical OR (|) for sptensors. 3 | % 4 | % See also SPTENSOR. 5 | % 6 | %MATLAB Tensor Toolbox. 7 | %Copyright 2012, Sandia Corporation. 8 | 9 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 10 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 11 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 12 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 13 | % work by or on behalf of the U.S. Government. Export of this data may 14 | % require a license from the United States Government. 15 | % The full license terms can be found in the file LICENSE.txt 16 | 17 | 18 | %% Observations for sparse matrix case. 19 | % The result of a | 5 is dense! 20 | % The result of a | 0 is dense! 21 | % The result of a | full(a) is dense! 22 | % The result of a | a is sparse. 23 | 24 | %% Case 1: One argument is a scalar 25 | if isscalar(B) || isa(B,'tensor') 26 | C = full(A) | B; 27 | return; 28 | end 29 | if isscalar(A) 30 | C = A | full(B); 31 | return; 32 | end 33 | 34 | %% Case 2: Both A and B are sparse tensors 35 | if ~isequal(size(A),size(B)) 36 | error('Must be tensors of the same size'); 37 | end 38 | 39 | if isa(A,'sptensor') && isa(B,'sptensor') 40 | C = sptensor([A.subs; B.subs], 1, size(A), @(x) length(x) >= 1); 41 | return; 42 | end 43 | 44 | %% Otherwise 45 | error('The arguments must be two sptensors or an sptensor and a scalar.'); 46 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@sptensor/permute.m: -------------------------------------------------------------------------------- 1 | function t = permute(t,order) 2 | %PERMUTE Rearrange the dimensions of a sparse tensor. 3 | % 4 | % B = PERMUTE(A,ORDER) rearranges the dimensions of A so that they 5 | % are in the order specified by the vector ORDER. The result has the 6 | % same values of A, but the order of the subscripts needed to access 7 | % any particular element are rearranged as specified by ORDER. 8 | % 9 | % See also SPTENSOR, PERMUTE. 10 | % 11 | %MATLAB Tensor Toolbox. 12 | %Copyright 2012, Sandia Corporation. 13 | 14 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 15 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 16 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 17 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 18 | % work by or on behalf of the U.S. Government. Export of this data may 19 | % require a license from the United States Government. 20 | % The full license terms can be found in the file LICENSE.txt 21 | 22 | 23 | % Error checking 24 | if (ndims(order) ~= 2) || (size(order,1) ~= 1) 25 | error('ORDER must be a row vector'); 26 | end 27 | 28 | % Check that the permuation is valid 29 | if ~isequal(sort(order),1:ndims(t)) 30 | error('Invalid permutation.'); 31 | end 32 | 33 | % Do the permutation 34 | if ~isempty(t.subs) 35 | t.subs = t.subs(:,order); 36 | end 37 | t.size = t.size(order); 38 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@sptensor/private/allsubs.m: -------------------------------------------------------------------------------- 1 | function s = allsubs(x) 2 | %ALLSUBS Generate all possible subscripts for a sparse tensor X. 3 | % 4 | % See also SPTENSOR. 5 | % 6 | %MATLAB Tensor Toolbox. 7 | %Copyright 2012, Sandia Corporation. 8 | 9 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 10 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 11 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 12 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 13 | % work by or on behalf of the U.S. Government. Export of this data may 14 | % require a license from the United States Government. 15 | % The full license terms can be found in the file LICENSE.txt 16 | 17 | 18 | %% Generate all possible indicies 19 | 20 | % Preallocate (discover any memory issues here!) 21 | s = zeros(prod(x.size),ndims(x)); 22 | 23 | % Generate appropriately sized ones vectors. 24 | o = cell(ndims(x),1); 25 | for n = 1:ndims(x) 26 | o{n} = ones(size(x,n),1); 27 | end 28 | 29 | % Generate each column of the subscripts in turn 30 | for n = 1:ndims(x) 31 | i = o; 32 | i{n} = (1:size(x,n))'; 33 | s(:,n) = khatrirao(i); 34 | end 35 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@sptensor/private/extract.m: -------------------------------------------------------------------------------- 1 | function a = extract(t,srchsubs) 2 | %EXTRACT Extract value for a sptensor. 3 | % 4 | % EXTRACT(X,SUBS) returns a list of values. 5 | % 6 | % See also SPTENSOR/SUBSREF. 7 | % 8 | %MATLAB Tensor Toolbox. 9 | %Copyright 2012, Sandia Corporation. 10 | 11 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 12 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 13 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 14 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 15 | % work by or on behalf of the U.S. Government. Export of this data may 16 | % require a license from the United States Government. 17 | % The full license terms can be found in the file LICENSE.txt 18 | 19 | 20 | 21 | % Check range of requested subscripts 22 | p = size(srchsubs,1); 23 | 24 | % Check that all subscripts are positive and less than the max 25 | invalid = (srchsubs < 0) | (srchsubs > ones(p,1)*t.size); 26 | badloc = find(sum(invalid,2)); 27 | if ~isempty(badloc) 28 | fprintf('The following subscripts are invalid: \n'); 29 | badsubs = srchsubs(badloc,:); 30 | badidx = tt_sub2ind(size(t),badsubs); 31 | for i = 1:numel(badloc) 32 | fprintf('\tsubscript = %s (linear index = %d)\n',... 33 | tt_intvec2str(badsubs(i,:)), badidx(i)); 34 | end 35 | error('Invalid subscripts'); 36 | end 37 | 38 | % Set the default answer to zero 39 | a = zeros(p,1); 40 | 41 | % Find which indices already exist and their locations 42 | [tf,loc] = ismember(srchsubs,t.subs,'rows'); 43 | 44 | % Fill in the non-zero elements in the answer 45 | nzsubs = find(tf); 46 | a(nzsubs,1) = t.vals(loc(nzsubs)); 47 | 48 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@sptensor/private/irenumber.m: -------------------------------------------------------------------------------- 1 | function newsubs = irenumber(t, sz, range) 2 | %RENUMBER indices for sptensor subsasgn 3 | % 4 | % See also SPTENSOR/SUBSASGN 5 | % 6 | %MATLAB Tensor Toolbox. 7 | %Copyright 2012, Sandia Corporation. 8 | 9 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 10 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 11 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 12 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 13 | % work by or on behalf of the U.S. Government. Export of this data may 14 | % require a license from the United States Government. 15 | % The full license terms can be found in the file LICENSE.txt 16 | 17 | 18 | nz = nnz(t); 19 | if (nz == 0) 20 | newsubs = []; 21 | return; 22 | end 23 | 24 | newsubs = t.subs; 25 | for i = 1 : numel(range) 26 | r = range{i}; 27 | if ischar(r) && r == ':' 28 | continue; 29 | elseif numel(r) == 1 30 | newsubs = [newsubs(:,1:i-1), r*ones(nz,1), newsubs(:,i:end)]; 31 | else 32 | newsubs(:,i) = r(newsubs(:,i)); 33 | end 34 | end 35 | 36 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@sptensor/reshape.m: -------------------------------------------------------------------------------- 1 | function a = reshape(a,new_size,old_modes) 2 | %RESHAPE Reshape sparse tensor. 3 | % 4 | % RESHAPE(X,SIZ) reshapes the sparse tensor to the given size. PROD(SIZ) 5 | % must be the same as PROD(SIZE(X)). 6 | % 7 | % RESHAPE(X,SIZ,MODES) reshapes only the specifies modes and appends the 8 | % new reshaped modes to the end of the indices. 9 | % 10 | % See also SPTENSOR, SPTENSOR/PERMUTE, RESHAPE. 11 | % 12 | %MATLAB Tensor Toolbox. 13 | %Copyright 2012, Sandia Corporation. 14 | 15 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 16 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 17 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 18 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 19 | % work by or on behalf of the U.S. Government. Export of this data may 20 | % require a license from the United States Government. 21 | % The full license terms can be found in the file LICENSE.txt 22 | 23 | 24 | if ~exist('old_modes','var') 25 | old_modes = 1:ndims(a); 26 | keep_modes = []; 27 | else 28 | keep_modes = setdiff(1:ndims(a),old_modes); 29 | end 30 | old_size = a.size(old_modes); 31 | keep_size = a.size(keep_modes); 32 | 33 | 34 | if prod(new_size) ~= prod(old_size) 35 | error('prod(SIZ) must be the same size of prod(SIZE(X,MODES))'); 36 | end 37 | 38 | inds = tt_sub2ind(old_size,a.subs(:,old_modes)); 39 | new_subs = tt_ind2sub(new_size,inds); 40 | 41 | a.size = [keep_size new_size]; 42 | a.subs = [a.subs(:,keep_modes) new_subs]; 43 | 44 | 45 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@sptensor/size.m: -------------------------------------------------------------------------------- 1 | function m = size(t,idx) 2 | %SIZE Sparse tensor dimensions. 3 | % 4 | % D = SIZE(T) returns the size of the tensor. 5 | % 6 | % I = size(T,DIM) returns the sizes of the dimensions specified by DIM. 7 | % 8 | % See also SPTENSOR, SPTENSOR/NDIMS. 9 | % 10 | %MATLAB Tensor Toolbox. 11 | %Copyright 2012, Sandia Corporation. 12 | 13 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 14 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 15 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 16 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 17 | % work by or on behalf of the U.S. Government. Export of this data may 18 | % require a license from the United States Government. 19 | % The full license terms can be found in the file LICENSE.txt 20 | 21 | 22 | if exist('idx','var') 23 | m = t.size(idx); 24 | else 25 | m = t.size; 26 | end 27 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@sptensor/spmatrix.m: -------------------------------------------------------------------------------- 1 | function s = spmatrix(a) 2 | %SPMATRIX Converts a two-way sparse tensor to sparse matrix. 3 | % 4 | % SPMATRIX(X) converts a sparse tensor to a sparse matrix. The sparse 5 | % tensor must be two-dimensional. 6 | % 7 | % See also SPTENSOR, SPTENSOR/RESHAPE, SPTENMAT 8 | % 9 | %MATLAB Tensor Toolbox. 10 | %Copyright 2012, Sandia Corporation. 11 | 12 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 13 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 14 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 15 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 16 | % work by or on behalf of the U.S. Government. Export of this data may 17 | % require a license from the United States Government. 18 | % The full license terms can be found in the file LICENSE.txt 19 | 20 | 21 | if ndims(a) ~= 2 22 | error('Sparse tensor must be two dimensional.'); 23 | end 24 | 25 | 26 | if isempty(a.subs) 27 | s = sparse(a.size(1), a.size(2)); 28 | else 29 | s = sparse(a.subs(:,1), a.subs(:,2), a.vals, a.size(1), a.size(2)); 30 | end 31 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@sptensor/squeeze.m: -------------------------------------------------------------------------------- 1 | function Y = squeeze(X) 2 | %SQUEEZE Remove singleton dimensions from a sparse tensor. 3 | % 4 | % Y = SQUEEZE(X) returns a sparse tensor Y with the same elements as 5 | % X but with all the singleton dimensions removed. A singleton 6 | % is a dimension such that size(X,dim)==1. 7 | % 8 | % If X has *only* singleton dimensions, then Y is a scalar. 9 | % 10 | % Examples 11 | % squeeze( sptenrand([2,1,3],0.5) ) %<-- returns a 2-by-3 sptensor 12 | % squeeze( sptensor([1 1 1],1,[1 1 1]) ) %<-- returns a scalar 13 | % See also SPTENSOR. 14 | % 15 | %MATLAB Tensor Toolbox. 16 | %Copyright 2012, Sandia Corporation. 17 | 18 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 19 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 20 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 21 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 22 | % work by or on behalf of the U.S. Government. Export of this data may 23 | % require a license from the United States Government. 24 | % The full license terms can be found in the file LICENSE.txt 25 | 26 | 27 | if all(X.size > 1) 28 | % No singleton dimensions to squeeze 29 | Y = X; 30 | else 31 | idx = find(X.size > 1); 32 | if numel(idx) == 0 33 | % Scalar case - only singleton dimensions 34 | Y = X.vals; 35 | else 36 | siz = X.size(idx); 37 | if isempty(X.vals) 38 | Y = sptensor([],[],siz); 39 | else 40 | Y = sptensor(X.subs(:,idx), X.vals, siz); 41 | end 42 | end 43 | end 44 | 45 | return; 46 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@sptensor/transpose.m: -------------------------------------------------------------------------------- 1 | function transpose(x) 2 | %TRANSPOSE is not defined on sparse tensors. 3 | % 4 | % See also SPTENSOR/PERMUTE. 5 | % 6 | %MATLAB Tensor Toolbox. 7 | %Copyright 2012, Sandia Corporation. 8 | 9 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 10 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 11 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 12 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 13 | % work by or on behalf of the U.S. Government. Export of this data may 14 | % require a license from the United States Government. 15 | % The full license terms can be found in the file LICENSE.txt 16 | 17 | 18 | error('Transpose on sparse tensor is not defined'); 19 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@sptensor/uminus.m: -------------------------------------------------------------------------------- 1 | function t = uminus(t) 2 | %UMINUS Unary minus (-) for sptensor. 3 | % 4 | % See also SPTENSOR. 5 | % 6 | %MATLAB Tensor Toolbox. 7 | %Copyright 2012, Sandia Corporation. 8 | 9 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 10 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 11 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 12 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 13 | % work by or on behalf of the U.S. Government. Export of this data may 14 | % require a license from the United States Government. 15 | % The full license terms can be found in the file LICENSE.txt 16 | 17 | 18 | t.vals = -t.vals; 19 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@sptensor/uplus.m: -------------------------------------------------------------------------------- 1 | function t = uplus(t) 2 | %UPLUS Unary plus (+) for sptensor. 3 | % 4 | % See also SPTENSOR. 5 | % 6 | %MATLAB Tensor Toolbox. 7 | %Copyright 2012, Sandia Corporation. 8 | 9 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 10 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 11 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 12 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 13 | % work by or on behalf of the U.S. Government. Export of this data may 14 | % require a license from the United States Government. 15 | % The full license terms can be found in the file LICENSE.txt 16 | 17 | 18 | % This function does nothing! 19 | 20 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@sptensor/xor.m: -------------------------------------------------------------------------------- 1 | function C = xor(A,B) 2 | %XOR Logical XOR for sptensors. 3 | % 4 | % See also SPTENSOR. 5 | % 6 | %MATLAB Tensor Toolbox. 7 | %Copyright 2012, Sandia Corporation. 8 | 9 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 10 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 11 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 12 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 13 | % work by or on behalf of the U.S. Government. Export of this data may 14 | % require a license from the United States Government. 15 | % The full license terms can be found in the file LICENSE.txt 16 | 17 | 18 | %% Observations for sparse matrix case. 19 | % The result of xor(a,5) is dense! 20 | % The result of xor(a,0) is dense! 21 | % The result of xor(a,full(a)) is dense! 22 | % The result of xor(a,b) is sparse. 23 | 24 | %% Case 1: One argument is a scalar 25 | if isscalar(B) || isa(B,'tensor') 26 | C = xor(full(A),B); 27 | return; 28 | end 29 | if isscalar(A) 30 | C = xor(A,full(B)); 31 | return; 32 | end 33 | 34 | 35 | %% Case 2: Both x and y are tensors of some sort 36 | if ~isequal(size(A),size(B)) 37 | error('Must be tensors of the same size'); 38 | end 39 | 40 | if isa(A,'sptensor') && isa(B,'sptensor') 41 | C = sptensor([A.subs; B.subs], 1, size(A), @(x) length(x) == 1); 42 | return; 43 | end 44 | 45 | if isa(B,'tensor') 46 | Bsubs = find(B ~= 0); 47 | C = sptensor([A.subs; Bsubs], 1, size(A), @(x) length(x) == 1); 48 | return; 49 | end 50 | 51 | %% Otherwise 52 | error('The arguments must be two sptensors or an sptensor and a scalar.'); 53 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@tenmat/Contents.m: -------------------------------------------------------------------------------- 1 | % @TENMAT 2 | % 3 | % Files 4 | % ctranspose - Complex conjugate transpose for tenmat. 5 | % disp - Command window display of a matricized tensor (tenmat). 6 | % display - Command window display of a tenmat. 7 | % double - Convert tenmat to double array. 8 | % end - Last index of indexing expression for tenmat. 9 | % minus - Binary subtraction (-) for tenmat. 10 | % mtimes - Multiplies two tenmat objects. 11 | % norm - Frobenius norm of a tenmat. 12 | % plus - Binary addition (+) for tenmat. 13 | % size - Size of tenmat. 14 | % subsasgn - Subscripted assignment for tenmat. 15 | % subsref - Subscripted reference for tenmat. 16 | % tenmat - Create a matricized tensor. 17 | % tsize - Tensor size of tenmat. 18 | % uminus - Unary minus (-) for tenmat. 19 | % uplus - Unary plus (+) for tenmat. 20 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@tenmat/ctranspose.m: -------------------------------------------------------------------------------- 1 | function a = ctranspose(a) 2 | %CTRANSPOSE Complex conjugate transpose for tenmat. 3 | % 4 | % C = CTRANSPOSE(A) swaps the row and column indices of A. 5 | % 6 | % See also TENMAT. 7 | % 8 | %MATLAB Tensor Toolbox. 9 | %Copyright 2012, Sandia Corporation. 10 | 11 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 12 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 13 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 14 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 15 | % work by or on behalf of the U.S. Government. Export of this data may 16 | % require a license from the United States Government. 17 | % The full license terms can be found in the file LICENSE.txt 18 | 19 | 20 | tmp = a.rindices; 21 | a.rindices = a.cindices; 22 | a.cindices = tmp; 23 | a.data = ctranspose(a.data); 24 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@tenmat/disp.m: -------------------------------------------------------------------------------- 1 | function disp(t,name) 2 | %DISP Command window display of a matricized tensor (tenmat). 3 | % 4 | % DISP(T) displays a tensor as matrix with no name. 5 | % 6 | % DISP(T,NAME) display a tensor as matrix with the given name. 7 | % 8 | % See also TENMAT, TENMAT/DISPLAY. 9 | % 10 | %MATLAB Tensor Toolbox. 11 | %Copyright 2012, Sandia Corporation. 12 | 13 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 14 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 15 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 16 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 17 | % work by or on behalf of the U.S. Government. Export of this data may 18 | % require a license from the United States Government. 19 | % The full license terms can be found in the file LICENSE.txt 20 | 21 | 22 | if ~exist('name','var') 23 | name = 'ans'; 24 | end 25 | 26 | fprintf('%s is a matrix corresponding to a tensor of size %s\n',... 27 | name,tt_size2str(t.tsize)); 28 | fprintf('\t%s.rindices = %s (modes of tensor corresponding to rows)\n',... 29 | name,['[ ' num2str(t.rindices) ' ]']); 30 | fprintf('\t%s.cindices = %s (modes of tensor corresponding to columns)\n',... 31 | name,['[ ' num2str(t.cindices) ' ]']); 32 | 33 | if isempty(t.data) 34 | fprintf('\t%s.data = []\n',name); 35 | else 36 | fprintf('\t%s.data = \n',name); 37 | output = tt_matrix2cellstr(t.data); 38 | fprintf('\t\t%s\n',output{:}); 39 | end 40 | 41 | 42 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@tenmat/display.m: -------------------------------------------------------------------------------- 1 | function display(t) 2 | %DISPLAY Command window display of a tenmat. 3 | % 4 | % See also TENMAT. 5 | % 6 | %MATLAB Tensor Toolbox. 7 | %Copyright 2012, Sandia Corporation. 8 | 9 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 10 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 11 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 12 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 13 | % work by or on behalf of the U.S. Government. Export of this data may 14 | % require a license from the United States Government. 15 | % The full license terms can be found in the file LICENSE.txt 16 | 17 | 18 | disp(t,inputname(1)); 19 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@tenmat/double.m: -------------------------------------------------------------------------------- 1 | function a = double(t) 2 | %DOUBLE Convert tenmat to double array. 3 | % 4 | % See also TENMAT. 5 | % 6 | %MATLAB Tensor Toolbox. 7 | %Copyright 2012, Sandia Corporation. 8 | 9 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 10 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 11 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 12 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 13 | % work by or on behalf of the U.S. Government. Export of this data may 14 | % require a license from the United States Government. 15 | % The full license terms can be found in the file LICENSE.txt 16 | 17 | 18 | a = t.data; 19 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@tenmat/end.m: -------------------------------------------------------------------------------- 1 | function e = end(X,k,n) 2 | %END Last index of indexing expression for tenmat. 3 | % 4 | % The expression X(end,:) will call END(X,1,2) to determine 5 | % the value of the first index. 6 | % 7 | % See also TENMAT, TENMAT/SUBSREF, END. 8 | % 9 | %MATLAB Tensor Toolbox. 10 | %Copyright 2012, Sandia Corporation. 11 | 12 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 13 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 14 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 15 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 16 | % work by or on behalf of the U.S. Government. Export of this data may 17 | % require a license from the United States Government. 18 | % The full license terms can be found in the file LICENSE.txt 19 | 20 | 21 | if n > ndims(X) 22 | error('Subscript out of range.'); 23 | end 24 | e = size(X.data,k); 25 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@tenmat/minus.m: -------------------------------------------------------------------------------- 1 | function Z = minus(X,Y) 2 | %MINUS Binary subtraction (-) for tenmat. 3 | % 4 | % See also TENMAT, TENMAT/TENMATFUN. 5 | % 6 | %MATLAB Tensor Toolbox. 7 | %Copyright 2012, Sandia Corporation. 8 | 9 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 10 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 11 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 12 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 13 | % work by or on behalf of the U.S. Government. Export of this data may 14 | % require a license from the United States Government. 15 | % The full license terms can be found in the file LICENSE.txt 16 | 17 | 18 | fun = @minus; 19 | 20 | % One argument is a scalar 21 | if ((prod(size(X)) == 1 || prod(size(Y)) == 1)) 22 | if (prod(size(Y)) == 1) && isa(X,'tenmat') 23 | Z = X; 24 | Z.data = fun(Z.data,Y); 25 | else 26 | Z = Y; 27 | Z.data = fun(X,Z.data); 28 | end 29 | return; 30 | end 31 | 32 | 33 | % Both arguments are tenmats 34 | Z = tenmat(Y); 35 | if ~(isequal(size(Y),size(Z))) 36 | error('Tenmat size mismatch.') 37 | end 38 | Z.data = fun(X.data,Z.data); 39 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@tenmat/mtimes.m: -------------------------------------------------------------------------------- 1 | function C = mtimes(A,B) 2 | %MTIMES Multiplies two tenmat objects. 3 | % 4 | % C = MTIMES(A,B) computes the product of A and B. The result is a 5 | % TENMAT object and can be transformed into a tensor. 6 | % 7 | % C = MTIMES(A,B) is called for the syntax 'A * B' when A or B is a 8 | % TENMAT object. 9 | % 10 | % See also TENMAT. 11 | % 12 | %MATLAB Tensor Toolbox. 13 | %Copyright 2012, Sandia Corporation. 14 | 15 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 16 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 17 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 18 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 19 | % work by or on behalf of the U.S. Government. Export of this data may 20 | % require a license from the United States Government. 21 | % The full license terms can be found in the file LICENSE.txt 22 | 23 | 24 | % Handle scalar input 25 | if ~isa(B,'tenmat') && numel(B) == 1 26 | C = A; 27 | C.data = C.data * B; 28 | return; 29 | end 30 | if ~isa(A,'tenmat') && numel(A) == 1 31 | C = B; 32 | C.data = C.data * A; 33 | return; 34 | end 35 | 36 | % Handle matrix input 37 | if ~isa(A,'tenmat') 38 | A = tenmat(A,1); 39 | end 40 | 41 | if ~isa(B,'tenmat') 42 | B = tenmat(B,1); 43 | end 44 | 45 | % Error check 46 | if size(A,2) ~= size(B,1) 47 | error(['Size mismatch: Number of columns in A is not equal to' ... 48 | ' the number of rows in B']); 49 | end 50 | 51 | tsiz = [A.tsize(A.rindices) B.tsize(B.cindices)]; 52 | 53 | if ~isempty(tsiz) 54 | C = tenmat; 55 | C.tsize = tsiz; 56 | C.rindices = 1:length(A.rindices); 57 | C.cindices = (1:length(B.cindices)) + length(A.rindices); 58 | C.data = A.data * B.data; 59 | else 60 | C = A.data * B.data; 61 | end 62 | 63 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@tenmat/norm.m: -------------------------------------------------------------------------------- 1 | function n = norm(T) 2 | %NORM Frobenius norm of a tenmat. 3 | % 4 | % NORM(X) returns the Frobenius norm of a tenmat. 5 | % 6 | % See also TENMAT. 7 | % 8 | %MATLAB Tensor Toolbox. 9 | %Copyright 2012, Sandia Corporation. 10 | 11 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 12 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 13 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 14 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 15 | % work by or on behalf of the U.S. Government. Export of this data may 16 | % require a license from the United States Government. 17 | % The full license terms can be found in the file LICENSE.txt 18 | 19 | 20 | v = reshape(T.data, numel(T.data), 1); 21 | n = norm(v); 22 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@tenmat/plus.m: -------------------------------------------------------------------------------- 1 | function Z = plus(X,Y) 2 | %PLUS Binary addition (+) for tenmat. 3 | % 4 | % See also TENMAT, TENMAT/TENMATFUN. 5 | % 6 | %MATLAB Tensor Toolbox. 7 | %Copyright 2012, Sandia Corporation. 8 | 9 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 10 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 11 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 12 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 13 | % work by or on behalf of the U.S. Government. Export of this data may 14 | % require a license from the United States Government. 15 | % The full license terms can be found in the file LICENSE.txt 16 | 17 | 18 | fun = @plus; 19 | 20 | % One argument is a scalar 21 | if ((prod(size(X)) == 1 || prod(size(Y)) == 1)) 22 | if (prod(size(Y)) == 1) && isa(X,'tenmat') 23 | Z = X; 24 | Z.data = fun(Z.data,Y); 25 | else 26 | Z = Y; 27 | Z.data = fun(X,Z.data); 28 | end 29 | return; 30 | end 31 | 32 | 33 | % Both arguments are tenmats 34 | Z = tenmat(Y); 35 | if ~(isequal(size(Y),size(Z))) 36 | error('Tenmat size mismatch.') 37 | end 38 | Z.data = fun(X.data,Z.data); 39 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@tenmat/size.m: -------------------------------------------------------------------------------- 1 | function sz = size(a,idx) 2 | %SIZE Size of tenmat. 3 | % 4 | % D = SIZE(X) returns the two-element row vector D = [M N] 5 | % containing the number of rows and columns in the matrix. 6 | % 7 | % M = SIZE(X,DIM) returns the length of the dimension specified by 8 | % the scalar DIM. For example, SIZE(X,1) returns the number of 9 | % rows. 10 | % 11 | % See also TENMAT, TENMAT/TSIZE. 12 | % 13 | %MATLAB Tensor Toolbox. 14 | %Copyright 2012, Sandia Corporation. 15 | 16 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 17 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 18 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 19 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 20 | % work by or on behalf of the U.S. Government. Export of this data may 21 | % require a license from the United States Government. 22 | % The full license terms can be found in the file LICENSE.txt 23 | 24 | 25 | if isempty(a.data) 26 | sz = []; 27 | elseif exist('idx', 'var') 28 | sz = size(a.data, idx); 29 | else 30 | sz = size(a.data); 31 | end 32 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@tenmat/subsasgn.m: -------------------------------------------------------------------------------- 1 | function t = subsasgn(t,s,b) 2 | %SUBSASGN Subscripted assignment for tenmat. 3 | % 4 | % Examples 5 | % X = tenmat(rand(3,4,2),1); 6 | % X(1:2,1:2) = ones(2,2); <-- Calls SUBSASGN 7 | % 8 | % See also TENMAT, TENMAT/SUBSREF. 9 | % 10 | %MATLAB Tensor Toolbox. 11 | %Copyright 2012, Sandia Corporation. 12 | 13 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 14 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 15 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 16 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 17 | % work by or on behalf of the U.S. Government. Export of this data may 18 | % require a license from the United States Government. 19 | % The full license terms can be found in the file LICENSE.txt 20 | 21 | 22 | switch s.type 23 | case '()' 24 | [m n] = size(t.data); 25 | t.data(s.subs{:}) = b; 26 | if ~isequal([m n],size(t.data)) 27 | error('Ambiguous change in size') 28 | end 29 | otherwise 30 | error('Invalid assignment for tenmat.') 31 | end 32 | 33 | 34 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@tenmat/subsref.m: -------------------------------------------------------------------------------- 1 | function a = subsref(t,s) 2 | %SUBSREF Subscripted reference for tenmat. 3 | % 4 | % Examples 5 | % X(i,j) <-- returns the (i,j) entry in X 6 | % X.data <-- returns a 2D array of the data 7 | % X.tsize <-- returns the size original tensor 8 | % X.rdims <-- tensor dimensions that were mapped to rows 9 | % X.cdims <-- tensor dimensions that were mapped to columns 10 | % 11 | % See also TENMAT. 12 | % 13 | %MATLAB Tensor Toolbox. 14 | %Copyright 2012, Sandia Corporation. 15 | 16 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 17 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 18 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 19 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 20 | % work by or on behalf of the U.S. Government. Export of this data may 21 | % require a license from the United States Government. 22 | % The full license terms can be found in the file LICENSE.txt 23 | 24 | 25 | switch s(1).type 26 | case '.' 27 | switch s(1).subs 28 | case 'data' 29 | a = tt_subsubsref(t.data,s); 30 | case 'tsize' 31 | a = tt_subsubsref(t.tsize,s); 32 | case {'rindices','rdims'} 33 | a = tt_subsubsref(t.rindices,s); 34 | case {'cindices','cdims'} 35 | a = tt_subsubsref(t.cindices,s); 36 | otherwise 37 | error(['No such field: ', s.subs]); 38 | end 39 | case '()' 40 | a = t.data(s.subs{:}); 41 | otherwise 42 | error('Invalid subsref into tenmat.') 43 | end 44 | end 45 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@tenmat/tsize.m: -------------------------------------------------------------------------------- 1 | function sz = tsize(a,idx) 2 | %TSIZE Tensor size of tenmat. 3 | % 4 | % D = TSIZE(X) returns the size of the tensor being stored as a 5 | % matrix. 6 | % 7 | % M = TSIZE(X,DIM) returns the length of the dimension(s) specified 8 | % by DIM. For example, SIZE(X,1) returns the size of the first 9 | % dimension of the tensor. 10 | % 11 | % See also TENMAT, TENMAT/SIZE. 12 | % 13 | %MATLAB Tensor Toolbox. 14 | %Copyright 2012, Sandia Corporation. 15 | 16 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 17 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 18 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 19 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 20 | % work by or on behalf of the U.S. Government. Export of this data may 21 | % require a license from the United States Government. 22 | % The full license terms can be found in the file LICENSE.txt 23 | 24 | 25 | if isempty(a.data) 26 | sz = []; 27 | elseif exist('idx', 'var') 28 | sz = a.tsize(idx); 29 | else 30 | sz = a.tsize; 31 | end 32 | 33 | return; 34 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@tenmat/uminus.m: -------------------------------------------------------------------------------- 1 | function t = uminus(t) 2 | %UMINUS Unary minus (-) for tenmat. 3 | % 4 | % See also TENMAT. 5 | % 6 | %MATLAB Tensor Toolbox. 7 | %Copyright 2012, Sandia Corporation. 8 | 9 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 10 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 11 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 12 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 13 | % work by or on behalf of the U.S. Government. Export of this data may 14 | % require a license from the United States Government. 15 | % The full license terms can be found in the file LICENSE.txt 16 | 17 | 18 | t.data = -t.data; 19 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@tenmat/uplus.m: -------------------------------------------------------------------------------- 1 | function t = uplus(t) 2 | %UPLUS Unary plus (+) for tenmat. 3 | % 4 | % See also TENMAT. 5 | % 6 | %MATLAB Tensor Toolbox. 7 | %Copyright 2012, Sandia Corporation. 8 | 9 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 10 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 11 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 12 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 13 | % work by or on behalf of the U.S. Government. Export of this data may 14 | % require a license from the United States Government. 15 | % The full license terms can be found in the file LICENSE.txt 16 | 17 | 18 | % This function does nothing! 19 | 20 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@tensor/and.m: -------------------------------------------------------------------------------- 1 | function Z = and(X,Y) 2 | %AND Logical AND (&) for tensors. 3 | % 4 | % See also TENSOR. 5 | % 6 | %MATLAB Tensor Toolbox. 7 | %Copyright 2012, Sandia Corporation. 8 | 9 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 10 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 11 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 12 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 13 | % work by or on behalf of the U.S. Government. Export of this data may 14 | % require a license from the United States Government. 15 | % The full license terms can be found in the file LICENSE.txt 16 | 17 | 18 | Z = tenfun(@and,X,Y); 19 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@tensor/ctranspose.m: -------------------------------------------------------------------------------- 1 | function ctranspose(x) 2 | %CTRANSPOSE is not defined for tensors. 3 | % 4 | % See also TENSOR/PERMUTE. 5 | % 6 | %MATLAB Tensor Toolbox. 7 | %Copyright 2012, Sandia Corporation. 8 | 9 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 10 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 11 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 12 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 13 | % work by or on behalf of the U.S. Government. Export of this data may 14 | % require a license from the United States Government. 15 | % The full license terms can be found in the file LICENSE.txt 16 | 17 | 18 | error('Transpose on tensor is not defined'); 19 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@tensor/disp.m: -------------------------------------------------------------------------------- 1 | function disp(X,name) 2 | %DISP Command window display of a tensor. 3 | % 4 | % DISP(X) displays a tensor with no name. 5 | % 6 | % DISP(X,NAME) displays a tensor with the given name. 7 | % 8 | % See also TENSOR, TENSOR/DISPLAY. 9 | % 10 | %MATLAB Tensor Toolbox. 11 | %Copyright 2012, Sandia Corporation. 12 | 13 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 14 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 15 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 16 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 17 | % work by or on behalf of the U.S. Government. Export of this data may 18 | % require a license from the United States Government. 19 | % The full license terms can be found in the file LICENSE.txt 20 | 21 | 22 | if ~exist('name','var') 23 | name = 'ans'; 24 | end 25 | 26 | fprintf(1,'%s is a tensor of size %s\n',name,tt_size2str(X.size)); 27 | 28 | if isempty(X.data) 29 | fprintf(1,'\t%s = []\n',name); 30 | end 31 | 32 | s = shiftdim(num2cell(X.data,1:2),2); 33 | 34 | for i = 1:numel(s) 35 | fprintf('\t%s',name); 36 | if ndims(X) == 1 37 | fprintf('(:)'); 38 | elseif ndims(X) == 2 39 | fprintf('(:,:)'); 40 | elseif ndims(X) > 2 41 | fprintf('(:,:'); 42 | fprintf(',%d',tt_ind2sub(X.size(3:end),i)); 43 | fprintf(')'); 44 | end 45 | fprintf(' = \n'); 46 | output = tt_matrix2cellstr(s{i}); 47 | fprintf('\t%s\n',output{:}); 48 | end 49 | 50 | end 51 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@tensor/display.m: -------------------------------------------------------------------------------- 1 | function display(t) 2 | %DISPLAY Command window display of a tensor. 3 | % 4 | % DISPLAY(X) displays a tensor with its name. 5 | % 6 | % See also TENSOR, TENSOR/DISP. 7 | % 8 | %MATLAB Tensor Toolbox. 9 | %Copyright 2012, Sandia Corporation. 10 | 11 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 12 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 13 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 14 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 15 | % work by or on behalf of the U.S. Government. Export of this data may 16 | % require a license from the United States Government. 17 | % The full license terms can be found in the file LICENSE.txt 18 | 19 | 20 | disp(t,inputname(1)); 21 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@tensor/double.m: -------------------------------------------------------------------------------- 1 | function A = double(X) 2 | %DOUBLE Convert tensor to double array. 3 | % 4 | % A = double(X) converts X to a standard multidimensional array. 5 | % 6 | % See also TENSOR. 7 | % 8 | %MATLAB Tensor Toolbox. 9 | %Copyright 2012, Sandia Corporation. 10 | 11 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 12 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 13 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 14 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 15 | % work by or on behalf of the U.S. Government. Export of this data may 16 | % require a license from the United States Government. 17 | % The full license terms can be found in the file LICENSE.txt 18 | 19 | 20 | A = double(X.data); 21 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@tensor/end.m: -------------------------------------------------------------------------------- 1 | function e = end(X,k,n) 2 | %END Last index of indexing expression for tensor. 3 | % 4 | % The expression X(end,:,:) will call END(X,1,3) to determine 5 | % the value of the first index. 6 | % 7 | % See also TENSOR, TENSOR/SUBSREF, END. 8 | % 9 | %MATLAB Tensor Toolbox. 10 | %Copyright 2012, Sandia Corporation. 11 | 12 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 13 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 14 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 15 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 16 | % work by or on behalf of the U.S. Government. Export of this data may 17 | % require a license from the United States Government. 18 | % The full license terms can be found in the file LICENSE.txt 19 | 20 | 21 | if n > ndims(X) 22 | error('Subscript out of range.'); 23 | end 24 | e = X.size(k); 25 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@tensor/eq.m: -------------------------------------------------------------------------------- 1 | function Z = eq(X,Y) 2 | %EQ Equal (==) for tensors. 3 | % 4 | % See also TENSOR. 5 | % 6 | %MATLAB Tensor Toolbox. 7 | %Copyright 2012, Sandia Corporation. 8 | 9 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 10 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 11 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 12 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 13 | % work by or on behalf of the U.S. Government. Export of this data may 14 | % require a license from the United States Government. 15 | % The full license terms can be found in the file LICENSE.txt 16 | 17 | 18 | Z = tenfun(@eq,X,Y); 19 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@tensor/find.m: -------------------------------------------------------------------------------- 1 | function [subs,vals] = find(t) 2 | %FIND Find subscripts of nonzero elements in a tensor. 3 | % 4 | % S = FIND(X) returns the subscripts of the nonzero values in X. 5 | % 6 | % [S,V] = FIND(X) also returns a column vector of the values. 7 | % 8 | % Examples: 9 | % X = tensor(rand(3,4,2)); 10 | % subs = find(X > 0.5) %<-- find subscripts of values greater than 0.5 11 | % vals = X(subs) %<-- extract the actual values 12 | % 13 | % See also TENSOR/SUBSREF, TENSOR/SUBSASGN 14 | % 15 | %MATLAB Tensor Toolbox. 16 | %Copyright 2012, Sandia Corporation. 17 | 18 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 19 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 20 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 21 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 22 | % work by or on behalf of the U.S. Government. Export of this data may 23 | % require a license from the United States Government. 24 | % The full license terms can be found in the file LICENSE.txt 25 | 26 | 27 | % Find the *linear* indices of the nonzero elements 28 | idx = find(t.data); 29 | 30 | % Convert the linear indices to subscripts 31 | subs = tt_ind2sub(t.size,idx); 32 | 33 | % Extract the corresponding values and return as a column vector 34 | if nargout > 1 35 | if isempty(subs) 36 | vals = []; 37 | else 38 | vals = reshape(t.data(idx), length(idx), 1); 39 | end 40 | end 41 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@tensor/full.m: -------------------------------------------------------------------------------- 1 | function X = full(X) 2 | %FULL Convert to a (dense) tensor. 3 | % 4 | % FULL(X) returns X, i.e., does nothing. 5 | % 6 | % See also SPTENSOR/FULL, KTENSOR/FULL, TTENSOR/FULL. 7 | % 8 | %MATLAB Tensor Toolbox. 9 | %Copyright 2012, Sandia Corporation. 10 | 11 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 12 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 13 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 14 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 15 | % work by or on behalf of the U.S. Government. Export of this data may 16 | % require a license from the United States Government. 17 | % The full license terms can be found in the file LICENSE.txt 18 | 19 | 20 | return; 21 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@tensor/ge.m: -------------------------------------------------------------------------------- 1 | function Z = ge(X,Y) 2 | %GE Greater than or equal (>=) for tensors. 3 | % 4 | % See also TENSOR. 5 | % 6 | %MATLAB Tensor Toolbox. 7 | %Copyright 2012, Sandia Corporation. 8 | 9 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 10 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 11 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 12 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 13 | % work by or on behalf of the U.S. Government. Export of this data may 14 | % require a license from the United States Government. 15 | % The full license terms can be found in the file LICENSE.txt 16 | 17 | 18 | Z = tenfun(@ge,X,Y); 19 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@tensor/gt.m: -------------------------------------------------------------------------------- 1 | function Z = gt(X,Y) 2 | %GT Greater than (>) for tensors. 3 | % 4 | % See also TENSOR. 5 | % 6 | %MATLAB Tensor Toolbox. 7 | %Copyright 2012, Sandia Corporation. 8 | 9 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 10 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 11 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 12 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 13 | % work by or on behalf of the U.S. Government. Export of this data may 14 | % require a license from the United States Government. 15 | % The full license terms can be found in the file LICENSE.txt 16 | 17 | 18 | Z = tenfun(@gt,X,Y); 19 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@tensor/innerprod.m: -------------------------------------------------------------------------------- 1 | function res = innerprod(X,Y) 2 | %INNERPROD Efficient inner product with a tensor. 3 | % 4 | % R = INNERPROD(X,Y) efficiently computes the inner product between 5 | % two tensors X and Y. If Y is a tensor, then inner product is 6 | % computed directly. Otherwise, the inner product method for 7 | % that type of tensor is called. 8 | % 9 | % See also TENSOR, SPTENSOR/INNERPROD, KTENSOR/INNERPROD, TTENSOR/INNERPROD 10 | % 11 | %MATLAB Tensor Toolbox. 12 | %Copyright 2012, Sandia Corporation. 13 | 14 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 15 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 16 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 17 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 18 | % work by or on behalf of the U.S. Government. Export of this data may 19 | % require a license from the United States Government. 20 | % The full license terms can be found in the file LICENSE.txt 21 | 22 | 23 | % X is a tensor 24 | switch class(Y) 25 | 26 | case {'tensor'} 27 | % No need for same size check because it is implicit in the inner 28 | % product below. 29 | x = reshape(X.data, 1, numel(X.data)); 30 | y = reshape(Y.data, numel(Y.data), 1); 31 | res = x*y; 32 | 33 | case {'sptensor','ktensor','ttensor'} 34 | % Reverse arguments to call specialized code 35 | res = innerprod(Y,X); 36 | 37 | otherwise 38 | disp(['Inner product not available for class ' class(Y)]); 39 | 40 | end 41 | 42 | return; 43 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@tensor/isequal.m: -------------------------------------------------------------------------------- 1 | function z = isequal(x,y) 2 | %ISEQUAL for tensors. 3 | % 4 | % ISEQUAL(A,B) compares the tensors A and B for equality. 5 | % 6 | % See also TENSOR. 7 | % 8 | %MATLAB Tensor Toolbox. 9 | %Copyright 2012, Sandia Corporation. 10 | 11 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 12 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 13 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 14 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 15 | % work by or on behalf of the U.S. Government. Export of this data may 16 | % require a license from the United States Government. 17 | % The full license terms can be found in the file LICENSE.txt 18 | 19 | 20 | %% 21 | if ~isequal(x.size,y.size) 22 | z = false; 23 | elseif isa(x,'tensor') && isa(y,'tensor') 24 | z = isequal(x.data,y.data); 25 | elseif isa(y,'sptensor') 26 | z = isequal(x,full(y)); 27 | else 28 | z = false; 29 | end 30 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@tensor/ldivide.m: -------------------------------------------------------------------------------- 1 | function Z = ldivide(X,Y) 2 | %LDIVIDE Left array divide for tensor. 3 | % 4 | % LDIVIDE(A,B) is called for the syntax 'A .\ B' when A or B is a tensor. 5 | % A and B must have the same size, unless one is a scalar. 6 | % 7 | % Examples 8 | % X = tenrand([4 3 2],5); 9 | % X .\ 3 10 | % X .\ X 11 | % 12 | % See also TENSOR, TENSOR/RDIVIDE. 13 | % 14 | %MATLAB Tensor Toolbox. 15 | %Copyright 2012, Sandia Corporation. 16 | 17 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 18 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 19 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 20 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 21 | % work by or on behalf of the U.S. Government. Export of this data may 22 | % require a license from the United States Government. 23 | % The full license terms can be found in the file LICENSE.txt 24 | 25 | 26 | Z = tenfun(@ldivide,X,Y); 27 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@tensor/le.m: -------------------------------------------------------------------------------- 1 | function Z = le(X,Y) 2 | %LE Less than or equal (<=) for tensor. 3 | % 4 | % See also TENSOR. 5 | % 6 | %MATLAB Tensor Toolbox. 7 | %Copyright 2012, Sandia Corporation. 8 | 9 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 10 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 11 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 12 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 13 | % work by or on behalf of the U.S. Government. Export of this data may 14 | % require a license from the United States Government. 15 | % The full license terms can be found in the file LICENSE.txt 16 | 17 | 18 | Z = tenfun(@le,X,Y); 19 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@tensor/lt.m: -------------------------------------------------------------------------------- 1 | function Z = lt(X,Y) 2 | %LT Less than (<) for tensor. 3 | % 4 | % See also TENSOR. 5 | % 6 | %MATLAB Tensor Toolbox. 7 | %Copyright 2012, Sandia Corporation. 8 | 9 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 10 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 11 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 12 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 13 | % work by or on behalf of the U.S. Government. Export of this data may 14 | % require a license from the United States Government. 15 | % The full license terms can be found in the file LICENSE.txt 16 | 17 | 18 | Z = tenfun(@lt,X,Y); 19 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@tensor/minus.m: -------------------------------------------------------------------------------- 1 | function Z = minus(X,Y) 2 | %MINUS Binary subtraction (-) for tensors. 3 | % 4 | % MINUS(A,B) is called for the syntax 'A - B' when A or B is a tensor. A 5 | % and B must have the same size, unless one is a scalar. A scalar can be 6 | % subtracted from a tensor of any size. 7 | % 8 | % See also TENSOR. 9 | % 10 | %MATLAB Tensor Toolbox. 11 | %Copyright 2012, Sandia Corporation. 12 | 13 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 14 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 15 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 16 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 17 | % work by or on behalf of the U.S. Government. Export of this data may 18 | % require a license from the United States Government. 19 | % The full license terms can be found in the file LICENSE.txt 20 | 21 | 22 | Z = tenfun(@minus,X,Y); 23 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@tensor/mldivide.m: -------------------------------------------------------------------------------- 1 | function Z = mldivide(X,Y) 2 | %MLDIVIDE Slash left division for tensors. 3 | % 4 | % MLDIVIDE(A,B) is called for the syntax 'A \ B' when A is a scalar and B 5 | % is a tensor. 6 | % 7 | % Example 8 | % X = tenrand([4 3 2],5); 9 | % 3 \ X 10 | % 11 | % See also TENSOR, TENSOR/LDIVIDE. 12 | % 13 | %MATLAB Tensor Toolbox. 14 | %Copyright 2012, Sandia Corporation. 15 | 16 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 17 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 18 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 19 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 20 | % work by or on behalf of the U.S. Government. Export of this data may 21 | % require a license from the United States Government. 22 | % The full license terms can be found in the file LICENSE.txt 23 | 24 | 25 | if isscalar(X) 26 | Z = tenfun(@ldivide,X,Y); 27 | return; 28 | end 29 | 30 | error('MLDIVIDE only supports the scalar case for tensors'); 31 | 32 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@tensor/mrdivide.m: -------------------------------------------------------------------------------- 1 | function Z = mrdivide(X,Y) 2 | %MRDIVIDE Slash right division for tensors. 3 | % 4 | % MRDIVIDE(A,B) is called for the syntax 'A / B' when A is a tensor and B 5 | % is a scalar. 6 | % 7 | % Example 8 | % X = tenrand([4 3 2],5); 9 | % X / 3 10 | % 11 | % See also TENSOR, TENSOR/RDIVIDE. 12 | % 13 | %MATLAB Tensor Toolbox. 14 | %Copyright 2012, Sandia Corporation. 15 | 16 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 17 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 18 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 19 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 20 | % work by or on behalf of the U.S. Government. Export of this data may 21 | % require a license from the United States Government. 22 | % The full license terms can be found in the file LICENSE.txt 23 | 24 | 25 | if isscalar(Y) 26 | Z = tenfun(@rdivide,X,Y); 27 | return; 28 | end 29 | 30 | error('MRDIVIDE only supports the scalar case for tensors'); 31 | 32 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@tensor/mtimes.m: -------------------------------------------------------------------------------- 1 | function C = mtimes(A,B) 2 | %MTIMES tensor-scalar multiplication. 3 | % 4 | % C = MTIMES(A,B) is called for the syntax 'A * B' when A or B is a 5 | % tensor and the other argument is a scalar. 6 | % 7 | % For tensor-matrix multiplication, use TTM. 8 | % For tensor-tensor multiplication, use TTT. 9 | % For tensor-tensor array multiplication, use TIMES or 'A .* B'. 10 | % 11 | % Examples 12 | % X = tenrand([3,4,2]) 13 | % W = 5 * X 14 | % 15 | % See also TENSOR, TENSOR/TTM, TENSOR/TTT, TENSOR/TIMES 16 | % 17 | %MATLAB Tensor Toolbox. 18 | %Copyright 2012, Sandia Corporation. 19 | 20 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 21 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 22 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 23 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 24 | % work by or on behalf of the U.S. Government. Export of this data may 25 | % require a license from the United States Government. 26 | % The full license terms can be found in the file LICENSE.txt 27 | 28 | 29 | %% 30 | if isscalar(B) 31 | C = A; 32 | C.data = B * C.data; 33 | return; 34 | end 35 | 36 | if isscalar(A) 37 | C = B; 38 | C.data = A * C.data; 39 | return; 40 | end 41 | 42 | error('Mtimes only supports a tensor times a scalar'); 43 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@tensor/mttkrp.m: -------------------------------------------------------------------------------- 1 | function V = mttkrp(X,U,n) 2 | %MTTKRP Matricized tensor times Khatri-Rao product for tensor. 3 | % 4 | % V = MTTKRP(X,U,n) efficiently calculates the matrix product of the 5 | % n-mode matricization of X with the Khatri-Rao product of all 6 | % entries in U, a cell array of matrices, except the nth. How to 7 | % most efficiently do this computation depends on the type of tensor 8 | % involved. 9 | % 10 | % See also TENSOR, TENMAT, KHATRIRAO 11 | % 12 | %MATLAB Tensor Toolbox. 13 | %Copyright 2012, Sandia Corporation. 14 | 15 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 16 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 17 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 18 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 19 | % work by or on behalf of the U.S. Government. Export of this data may 20 | % require a license from the United States Government. 21 | % The full license terms can be found in the file LICENSE.txt 22 | 23 | 24 | N = ndims(X); 25 | if (N < 2) 26 | error('MTTKRP is invalid for tensors with fewer than 2 dimensions'); 27 | end 28 | 29 | if (length(U) ~= N) 30 | error('Cell array is the wrong length'); 31 | end 32 | 33 | if n == 1 34 | R = size(U{2},2); 35 | else 36 | R = size(U{1},2); 37 | end 38 | 39 | for i = 1:N 40 | if i == n, continue; end 41 | if (size(U{i},1) ~= size(X,i)) || (size(U{i},2) ~= R) 42 | error('Entry %d of cell array is wrong size', i); 43 | end 44 | end 45 | 46 | Xn = permute(X,[n 1:n-1,n+1:N]); 47 | Xn = reshape(Xn.data, size(X,n), prod(size(X))/size(X,n)); %#ok 48 | Z = khatrirao(U{[1:n-1,n+1:N]},'r'); 49 | V = Xn*Z; 50 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@tensor/ndims.m: -------------------------------------------------------------------------------- 1 | function n = ndims(t) 2 | %NDIMS Return the number of dimensions of a tensor. 3 | % 4 | % NDIMS(X) returns the number of dimensions of tensor X. 5 | % 6 | % Examples 7 | % A = rand(4,3,1); ndims(A) %<-- Returns 2 8 | % X = tensor(A); ndims(X) %<-- Returns 2 9 | % X = tensor(A,[4 3 1]); ndims(X) %<-- Returns 3 10 | % 11 | % See also TENSOR 12 | % 13 | %MATLAB Tensor Toolbox. 14 | %Copyright 2012, Sandia Corporation. 15 | 16 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 17 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 18 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 19 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 20 | % work by or on behalf of the U.S. Government. Export of this data may 21 | % require a license from the United States Government. 22 | % The full license terms can be found in the file LICENSE.txt 23 | 24 | 25 | n = numel(t.size); 26 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@tensor/ne.m: -------------------------------------------------------------------------------- 1 | function Z = ne(X,Y) 2 | %NE Not equal (~=) for tensors. 3 | % 4 | % See also TENSOR. 5 | % 6 | %MATLAB Tensor Toolbox. 7 | %Copyright 2012, Sandia Corporation. 8 | 9 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 10 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 11 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 12 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 13 | % work by or on behalf of the U.S. Government. Export of this data may 14 | % require a license from the United States Government. 15 | % The full license terms can be found in the file LICENSE.txt 16 | 17 | 18 | Z = tenfun(@ne,X,Y); 19 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@tensor/nnz.m: -------------------------------------------------------------------------------- 1 | function n = nnz(x) 2 | %NNZ Number of nonzeros for tensors. 3 | % 4 | % See also TENSOR, SPTENSOR/NNZ. 5 | % 6 | %MATLAB Tensor Toolbox. 7 | %Copyright 2012, Sandia Corporation. 8 | 9 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 10 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 11 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 12 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 13 | % work by or on behalf of the U.S. Government. Export of this data may 14 | % require a license from the United States Government. 15 | % The full license terms can be found in the file LICENSE.txt 16 | 17 | 18 | n = nnz(x.data); 19 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@tensor/norm.m: -------------------------------------------------------------------------------- 1 | function n = norm(T) 2 | %NORM Frobenius norm of a tensor. 3 | % 4 | % NORM(X) returns the Frobenius norm of a tensor. 5 | % 6 | % See also TENSOR. 7 | % 8 | %MATLAB Tensor Toolbox. 9 | %Copyright 2012, Sandia Corporation. 10 | 11 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 12 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 13 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 14 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 15 | % work by or on behalf of the U.S. Government. Export of this data may 16 | % require a license from the United States Government. 17 | % The full license terms can be found in the file LICENSE.txt 18 | 19 | 20 | v = reshape(T.data, numel(T.data), 1); 21 | n = norm(v); 22 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@tensor/not.m: -------------------------------------------------------------------------------- 1 | function B = not(A) 2 | %NOT Logical NOT (~) for tensors. 3 | % 4 | % See also TENSOR. 5 | % 6 | %MATLAB Tensor Toolbox. 7 | %Copyright 2012, Sandia Corporation. 8 | 9 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 10 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 11 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 12 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 13 | % work by or on behalf of the U.S. Government. Export of this data may 14 | % require a license from the United States Government. 15 | % The full license terms can be found in the file LICENSE.txt 16 | 17 | 18 | B = tensor(not(A.data), size(A)); 19 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@tensor/or.m: -------------------------------------------------------------------------------- 1 | function Z = or(X,Y) 2 | %OR Logical OR (|) for tensors. 3 | % 4 | % See also TENSOR. 5 | % 6 | %MATLAB Tensor Toolbox. 7 | %Copyright 2012, Sandia Corporation. 8 | 9 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 10 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 11 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 12 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 13 | % work by or on behalf of the U.S. Government. Export of this data may 14 | % require a license from the United States Government. 15 | % The full license terms can be found in the file LICENSE.txt 16 | 17 | 18 | Z = tenfun(@or,X,Y); 19 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@tensor/permute.m: -------------------------------------------------------------------------------- 1 | function T = permute(T,order) 2 | %PERMUTE Permute tensor dimensions. 3 | % 4 | % B = PERMUTE(A,ORDER) rearranges the dimensions of A so that they 5 | % are in the order specified by the vector ORDER. The result has the 6 | % same values of A, but the order of the subscripts needed to access 7 | % any particular element are rearranged as specified by ORDER. 8 | % 9 | % See also TENSOR, TENSOR/SIZE, TENSOR/NDIMS, PERMUTE. 10 | % 11 | %MATLAB Tensor Toolbox. 12 | %Copyright 2012, Sandia Corporation. 13 | 14 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 15 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 16 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 17 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 18 | % work by or on behalf of the U.S. Government. Export of this data may 19 | % require a license from the United States Government. 20 | % The full license terms can be found in the file LICENSE.txt 21 | 22 | 23 | if ndims(T) ~= numel(order) 24 | error('Invalid permutation order'); 25 | end 26 | 27 | % Check for special case of permuting an order-1 object (which has 28 | % no effect but confuses MATLAB's permute command which doesn't 29 | % think that there is such a thing as a 1D-array). 30 | if isequal(order,1) 31 | return; 32 | end 33 | 34 | % Check for special case of empty object (which has 35 | % no effect but confuses MATLAB's permute command which doesn't 36 | % think that there is such a thing as an empty array). 37 | if isempty(order) 38 | return; 39 | end 40 | 41 | % Note that permute does error checking on order, so we don't worry 42 | % about it. 43 | T.data = permute(T.data,order); 44 | T.size = T.size(order); 45 | 46 | return; 47 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@tensor/plus.m: -------------------------------------------------------------------------------- 1 | function Z = plus(X,Y) 2 | %PLUS Binary addition (+) for tensors. 3 | % 4 | % PLUS(A,B) is called for the syntax 'A + B' when A or B is a tensor. A 5 | % and B must have the same size, unless one is a scalar. A scalar can be 6 | % added to a tensor of any size. 7 | % 8 | % See also TENSOR. 9 | % 10 | %MATLAB Tensor Toolbox. 11 | %Copyright 2012, Sandia Corporation. 12 | 13 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 14 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 15 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 16 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 17 | % work by or on behalf of the U.S. Government. Export of this data may 18 | % require a license from the United States Government. 19 | % The full license terms can be found in the file LICENSE.txt 20 | 21 | 22 | Z = tenfun(@plus,X,Y); 23 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@tensor/power.m: -------------------------------------------------------------------------------- 1 | function Z = power(X,Y) 2 | %POWER Elementwise power (.^) operator for a tensor. 3 | % 4 | % See also TENSOR. 5 | % 6 | %MATLAB Tensor Toolbox. 7 | %Copyright 2012, Sandia Corporation. 8 | 9 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 10 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 11 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 12 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 13 | % work by or on behalf of the U.S. Government. Export of this data may 14 | % require a license from the United States Government. 15 | % The full license terms can be found in the file LICENSE.txt 16 | 17 | 18 | Z = tenfun(@power,X,Y); 19 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@tensor/rdivide.m: -------------------------------------------------------------------------------- 1 | function Z = rdivide(X,Y) 2 | %RDIVIDE Right array divide for tensors. 3 | % 4 | % RDIVIDE(A,B) is called for the syntax 'A ./ B' when A or B is a tensor. 5 | % A and B must have the same size, unless one is a scalar. 6 | % 7 | % Examples 8 | % X = tenrand([4 3 2],5); 9 | % X ./ 3 10 | % X ./ X 11 | % 12 | % See also TENSOR. 13 | % 14 | %MATLAB Tensor Toolbox. 15 | %Copyright 2012, Sandia Corporation. 16 | 17 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 18 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 19 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 20 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 21 | % work by or on behalf of the U.S. Government. Export of this data may 22 | % require a license from the United States Government. 23 | % The full license terms can be found in the file LICENSE.txt 24 | 25 | 26 | Z = tenfun(@rdivide,X,Y); 27 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@tensor/reshape.m: -------------------------------------------------------------------------------- 1 | function t = reshape(t,siz) 2 | %RESHAPE Change tensor size. 3 | % RESHAPE(X,SIZ) returns the tensor whose elements 4 | % have been reshaped to the appropriate size. 5 | % 6 | % See also SQUEEZE. 7 | % 8 | %MATLAB Tensor Toolbox. 9 | %Copyright 2012, Sandia Corporation. 10 | 11 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 12 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 13 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 14 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 15 | % work by or on behalf of the U.S. Government. Export of this data may 16 | % require a license from the United States Government. 17 | % The full license terms can be found in the file LICENSE.txt 18 | 19 | 20 | if prod(t.size) ~= prod(siz) 21 | error('Number of elements cannot change'); 22 | end 23 | 24 | t.data = reshape(t.data,siz); 25 | t.size = siz; 26 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@tensor/size.m: -------------------------------------------------------------------------------- 1 | function m = size(t,idx) 2 | %SIZE Tensor dimensions. 3 | % 4 | % D = SIZE(T) returns the sizes of each dimension of tensor X in a 5 | % vector D with ndims(X) elements. 6 | % 7 | % I = size(T,DIM) returns the size of the dimension specified by 8 | % the scalar DIM. 9 | % 10 | % Examples 11 | % A = rand(3,4,2,1); T = tensor(A,[3 4 2 1]); 12 | % size(A) %<-- returns a length-3 vector 13 | % size(T) %<-- returns a length-4 vector 14 | % size(A,2) %<-- returns 4 15 | % size(T,2) %<-- same 16 | % size(A,5) %<-- returns 1 17 | % size(T,5) %<-- ERROR! 18 | % 19 | % See also TENSOR, TENSOR/NDIMS, SIZE. 20 | % 21 | %MATLAB Tensor Toolbox. 22 | %Copyright 2012, Sandia Corporation. 23 | 24 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 25 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 26 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 27 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 28 | % work by or on behalf of the U.S. Government. Export of this data may 29 | % require a license from the United States Government. 30 | % The full license terms can be found in the file LICENSE.txt 31 | 32 | 33 | 34 | if exist('idx','var') 35 | m = t.size(idx); 36 | else 37 | m = t.size; 38 | end 39 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@tensor/squeeze.m: -------------------------------------------------------------------------------- 1 | function Y = squeeze(X) 2 | %SQUEEZE Remove singleton dimensions from a tensor. 3 | % 4 | % Y = SQUEEZE(X) returns a tensor Y with the same elements as 5 | % X but with all the singleton dimensions removed. A singleton 6 | % is a dimension such that size(X,dim)==1. 7 | % 8 | % If X has *only* singleton dimensions, then Y is a scalar. 9 | % 10 | % Examples 11 | % squeeze( tenrand([2,1,3]) ) %<-- returns a 2-by-3 tensor 12 | % squeeze( tenrand([1 1]) ) %<-- returns a scalar 13 | % 14 | % See also TENSOR. 15 | % 16 | %MATLAB Tensor Toolbox. 17 | %Copyright 2012, Sandia Corporation. 18 | 19 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 20 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 21 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 22 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 23 | % work by or on behalf of the U.S. Government. Export of this data may 24 | % require a license from the United States Government. 25 | % The full license terms can be found in the file LICENSE.txt 26 | 27 | 28 | if all(X.size > 1) 29 | % No singleton dimensions to squeeze 30 | Y = X; 31 | else 32 | idx = find(X.size > 1); 33 | if numel(idx) == 0 34 | % Scalar case - only singleton dimensions 35 | Y = X.data; 36 | else 37 | siz = X.size(idx); 38 | Y = tensor(squeeze(X.data),siz); 39 | end 40 | end 41 | 42 | return; 43 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@tensor/times.m: -------------------------------------------------------------------------------- 1 | function Z = times(X,Y) 2 | %TIMES Array multiplication for tensors. 3 | % 4 | % TIMES(A,B) is called for the syntax 'A .* B' when A or B is a 5 | % tensor. A and B must have the same size, unless one is a scalar. A 6 | % scalar can be multiplied by a tensor of any size. 7 | % 8 | % See also TENSOR. 9 | % 10 | %MATLAB Tensor Toolbox. 11 | %Copyright 2012, Sandia Corporation. 12 | 13 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 14 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 15 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 16 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 17 | % work by or on behalf of the U.S. Government. Export of this data may 18 | % require a license from the United States Government. 19 | % The full license terms can be found in the file LICENSE.txt 20 | 21 | 22 | if isa(Y,'ktensor') || isa(Y,'ttensor') || isa(Y,'sptensor') 23 | Y = full(Y); 24 | end 25 | 26 | Z = tenfun(@times,X,Y); 27 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@tensor/transpose.m: -------------------------------------------------------------------------------- 1 | function transpose(x) 2 | %TRANSPOSE is not defined on tensors. 3 | % 4 | % See also TENSOR/PERMUTE. 5 | % 6 | %MATLAB Tensor Toolbox. 7 | %Copyright 2012, Sandia Corporation. 8 | 9 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 10 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 11 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 12 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 13 | % work by or on behalf of the U.S. Government. Export of this data may 14 | % require a license from the United States Government. 15 | % The full license terms can be found in the file LICENSE.txt 16 | 17 | 18 | error('Transpose on tensor is not defined'); 19 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@tensor/ttsv.m: -------------------------------------------------------------------------------- 1 | function y = ttsv(A,x,n) 2 | %TTSV Tensor times same vector in multiple modes. 3 | % 4 | % Y = TTSV(A,X) multiples the tensor A by the vector X in all modes. 5 | % 6 | % Y = TTSV(A,X,-1) multiplies the tensor A by the vector X in all modes 7 | % but the first. Returns the answer as a normal MATLAB array (not a 8 | % tensor). 9 | % 10 | % Y = TTSV(A,X,-2) multiplies the tensor A by the vector X in all modes 11 | % but the first two. Returns the answer as a normal MATLAB matrix (not a 12 | % tensor). 13 | % 14 | % Y = TTSV(A,X,-N) multiplies the tensor A by the vector X is all modes 15 | % but the first N. 16 | % 17 | % See also TENSOR/TTV. 18 | % 19 | %MATLAB Tensor Toolbox. 20 | %Copyright 2012, Sandia Corporation. 21 | 22 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 23 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 24 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 25 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 26 | % work by or on behalf of the U.S. Government. Export of this data may 27 | % require a license from the United States Government. 28 | % The full license terms can be found in the file LICENSE.txt 29 | 30 | %% Process inputs (only two simple cases are supported) 31 | if ~exist('n','var') 32 | n = 0; 33 | elseif (n > 0) 34 | error('Invalid usage'); 35 | end 36 | 37 | %% Create X. 38 | P = ndims(A); 39 | [X{1:P}] = deal(x); 40 | 41 | %% Calculate 42 | if (n == 0) 43 | y = ttv(A,X); 44 | elseif (n == -1) || (n == -2) 45 | y = double(ttv(A,X,-(1:-n))); 46 | else 47 | y = ttv(A,X,-(1:-n)); 48 | end 49 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@tensor/uminus.m: -------------------------------------------------------------------------------- 1 | function t = uminus(t) 2 | %UMINUS Unary minus (-) for tensors. 3 | % 4 | % See also TENSOR. 5 | % 6 | %MATLAB Tensor Toolbox. 7 | %Copyright 2012, Sandia Corporation. 8 | 9 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 10 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 11 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 12 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 13 | % work by or on behalf of the U.S. Government. Export of this data may 14 | % require a license from the United States Government. 15 | % The full license terms can be found in the file LICENSE.txt 16 | 17 | 18 | t.data = -t.data; 19 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@tensor/uplus.m: -------------------------------------------------------------------------------- 1 | function t = uplus(t) 2 | %UPLUS Unary plus (+) for tensors. 3 | % 4 | % See also TENSOR. 5 | % 6 | %MATLAB Tensor Toolbox. 7 | %Copyright 2012, Sandia Corporation. 8 | 9 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 10 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 11 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 12 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 13 | % work by or on behalf of the U.S. Government. Export of this data may 14 | % require a license from the United States Government. 15 | % The full license terms can be found in the file LICENSE.txt 16 | 17 | 18 | % This function does nothing! 19 | 20 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@tensor/xor.m: -------------------------------------------------------------------------------- 1 | function Z = xor(X,Y) 2 | %XOR Logical EXCLUSIVE OR for tensors. 3 | % 4 | % See also TENSOR. 5 | % 6 | %MATLAB Tensor Toolbox. 7 | %Copyright 2012, Sandia Corporation. 8 | 9 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 10 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 11 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 12 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 13 | % work by or on behalf of the U.S. Government. Export of this data may 14 | % require a license from the United States Government. 15 | % The full license terms can be found in the file LICENSE.txt 16 | 17 | 18 | Z = tenfun(@xor,X,Y); 19 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@ttensor/Contents.m: -------------------------------------------------------------------------------- 1 | % @TTENSOR 2 | % 3 | % Files 4 | % disp - Command window display of a ttensor. 5 | % display - Command window display of a ttensor. 6 | % double - Convert ttensor to double array. 7 | % end - Last index of indexing expression for ttensor. 8 | % full - Convert a ttensor to a (dense) tensor. 9 | % innerprod - Efficient inner product with a ttensor. 10 | % isequal - True if each component of two ttensor's is numerically equal. 11 | % mtimes - Implement scalar multiplication for a ttensor. 12 | % mttkrp - Matricized tensor times Khatri-Rao product for ttensor. 13 | % ndims - Return the number of dimensions for a ttensor. 14 | % norm - Norm of a ttensor. 15 | % nvecs - Compute the leading mode-n vectors for a ttensor. 16 | % permute - Permute dimensions for a ttensor. 17 | % size - Size of a ttensor. 18 | % subsasgn - Subscripted reference for a ttensor. 19 | % subsref - Subscripted reference for a ttensor. 20 | % ttensor - Tensor stored as a Tucker operator (decomposed). 21 | % ttm - Tensor times matrix for ttensor. 22 | % ttv - Tensor times vector for ttensor. 23 | % uminus - Unary minus for ttensor. 24 | % uplus - Unary plus for ttensor. 25 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@ttensor/disp.m: -------------------------------------------------------------------------------- 1 | function disp(t,name) 2 | %DISP Command window display of a ttensor. 3 | % 4 | % DISP(T) displays a ttensor with no name. 5 | % 6 | % DISP(T,NAME) display a ttensor with the given name. 7 | % 8 | % See also TTENSOR. 9 | % 10 | %MATLAB Tensor Toolbox. 11 | %Copyright 2010, Sandia Corporation. 12 | 13 | % This is the MATLAB Tensor Toolbox by Brett Bader and Tamara Kolda. 14 | % http://csmr.ca.sandia.gov/~tgkolda/TensorToolbox. 15 | % Copyright (2010) Sandia Corporation. Under the terms of Contract 16 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 17 | % work by or on behalf of the U.S. Government. Export of this data may 18 | % require a license from the United States Government. 19 | % The full license terms can be found in tensor_toolbox/LICENSE.txt 20 | % $Id: disp.m,v 1.14 2010/03/19 23:46:31 tgkolda Exp $ 21 | 22 | if ~exist('name','var') 23 | name = 'ans'; 24 | end 25 | 26 | fprintf(1,'%s is a ttensor of size %s\n', name, tt_size2str(size(t))); 27 | disp(t.core, sprintf('\t%s.core',name)); 28 | 29 | for j = 1 : ndims(t) 30 | fprintf('\t%s.U{%d} = \n', name, j); 31 | output = tt_matrix2cellstr(t.u{j}); 32 | fprintf('\t\t%s\n',output{:}); 33 | end 34 | 35 | 36 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@ttensor/display.m: -------------------------------------------------------------------------------- 1 | function display(t) 2 | %DISPLAY Command window display of a ttensor. 3 | % 4 | % See also TTENSOR. 5 | % 6 | %MATLAB Tensor Toolbox. 7 | %Copyright 2010, Sandia Corporation. 8 | 9 | % This is the MATLAB Tensor Toolbox by Brett Bader and Tamara Kolda. 10 | % http://csmr.ca.sandia.gov/~tgkolda/TensorToolbox. 11 | % Copyright (2010) Sandia Corporation. Under the terms of Contract 12 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 13 | % work by or on behalf of the U.S. Government. Export of this data may 14 | % require a license from the United States Government. 15 | % The full license terms can be found in tensor_toolbox/LICENSE.txt 16 | % $Id: display.m,v 1.7 2010/03/19 23:46:31 tgkolda Exp $ 17 | 18 | disp(t,inputname(1)); 19 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@ttensor/double.m: -------------------------------------------------------------------------------- 1 | function A = double(T) 2 | %DOUBLE Convert ttensor to double array. 3 | % 4 | % A = double(T) converts T to a standard multidimensional array. 5 | % 6 | % See also TTENSOR. 7 | % 8 | %MATLAB Tensor Toolbox. 9 | %Copyright 2010, Sandia Corporation. 10 | 11 | % This is the MATLAB Tensor Toolbox by Brett Bader and Tamara Kolda. 12 | % http://csmr.ca.sandia.gov/~tgkolda/TensorToolbox. 13 | % Copyright (2010) Sandia Corporation. Under the terms of Contract 14 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 15 | % work by or on behalf of the U.S. Government. Export of this data may 16 | % require a license from the United States Government. 17 | % The full license terms can be found in tensor_toolbox/LICENSE.txt 18 | % $Id: double.m,v 1.7 2010/03/19 23:46:31 tgkolda Exp $ 19 | 20 | A = double(full(T)); 21 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@ttensor/end.m: -------------------------------------------------------------------------------- 1 | function e = end(X,k,n) 2 | %END Last index of indexing expression for ttensor. 3 | % 4 | % The expression X(end,:,:) will call END(X,1,3) to determine 5 | % the value of the first index. 6 | % 7 | % See also TTENSOR, TTENSOR/SUBSREF, END. 8 | % 9 | %MATLAB Tensor Toolbox. 10 | %Copyright 2010, Sandia Corporation. 11 | 12 | % This is the MATLAB Tensor Toolbox by Brett Bader and Tamara Kolda. 13 | % http://csmr.ca.sandia.gov/~tgkolda/TensorToolbox. 14 | % Copyright (2010) Sandia Corporation. Under the terms of Contract 15 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 16 | % work by or on behalf of the U.S. Government. Export of this data may 17 | % require a license from the United States Government. 18 | % The full license terms can be found in tensor_toolbox/LICENSE.txt 19 | % $Id: end.m,v 1.7 2010/03/19 23:46:31 tgkolda Exp $ 20 | 21 | % Note that this only works with {} because () is not supported by 22 | % subsref. 23 | e = ndims(X); 24 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@ttensor/full.m: -------------------------------------------------------------------------------- 1 | function X = full(T) 2 | %FULL Convert a ttensor to a (dense) tensor. 3 | % 4 | % X = FULL(T) converts ttensor T to (dense) tensor X. 5 | % 6 | % See also TTENSOR, TENSOR. 7 | % 8 | %MATLAB Tensor Toolbox. 9 | %Copyright 2010, Sandia Corporation. 10 | 11 | % This is the MATLAB Tensor Toolbox by Brett Bader and Tamara Kolda. 12 | % http://csmr.ca.sandia.gov/~tgkolda/TensorToolbox. 13 | % Copyright (2010) Sandia Corporation. Under the terms of Contract 14 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 15 | % work by or on behalf of the U.S. Government. Export of this data may 16 | % require a license from the United States Government. 17 | % The full license terms can be found in tensor_toolbox/LICENSE.txt 18 | % $Id: full.m,v 1.11 2010/03/19 23:46:31 tgkolda Exp $ 19 | 20 | % Preallocate to ensure there is enough space 21 | X = tenzeros(size(T)); 22 | 23 | % Now do the calculation 24 | X = ttm(T.core,T.u); 25 | 26 | % Make sure that X is a dense tensor (small chance it could be a sparse 27 | % tensor). 28 | X = tensor(X); 29 | 30 | return; 31 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@ttensor/isequal.m: -------------------------------------------------------------------------------- 1 | function [tf, tf_core, tf_U] = isequal(A,B) 2 | %ISEQUAL True if each component of two ttensor's is numerically equal. 3 | 4 | tf = false; 5 | tf_core = false; 6 | tf_U = false; 7 | 8 | if ~isa(B,'ttensor') 9 | return; 10 | end 11 | 12 | if ndims(A) ~= ndims(B) 13 | return; 14 | end 15 | 16 | tf_core = isequal(A.core, B.core); 17 | tf_U = cellfun(@isequal, A.u, B.u); 18 | tf = tf_core & all(tf_U); 19 | 20 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@ttensor/mtimes.m: -------------------------------------------------------------------------------- 1 | function C = mtimes(A,B) 2 | %MTIMES Implement scalar multiplication for a ttensor. 3 | % 4 | % See also TTENSOR. 5 | % 6 | %MATLAB Tensor Toolbox. 7 | %Copyright 2010, Sandia Corporation. 8 | 9 | % This is the MATLAB Tensor Toolbox by Brett Bader and Tamara Kolda. 10 | % http://csmr.ca.sandia.gov/~tgkolda/TensorToolbox. 11 | % Copyright (2010) Sandia Corporation. Under the terms of Contract 12 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 13 | % work by or on behalf of the U.S. Government. Export of this data may 14 | % require a license from the United States Government. 15 | % The full license terms can be found in tensor_toolbox/LICENSE.txt 16 | % $Id: mtimes.m,v 1.8 2010/03/19 23:46:31 tgkolda Exp $ 17 | 18 | if ~isa(B,'ttensor') && numel(B) == 1 19 | C = ttensor(B * A.core, A.u); 20 | elseif ~isa(A,'ttensor') && numel(A) == 1 21 | C = ttensor(A * B.core, B.u); 22 | else 23 | error('Use mtimes(full(A),full(B)).'); 24 | end 25 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@ttensor/mttkrp.m: -------------------------------------------------------------------------------- 1 | function V = mttkrp(X,U,n) 2 | %MTTKRP Matricized tensor times Khatri-Rao product for ttensor. 3 | % 4 | % V = MTTKRP(X,U,n) efficiently calculates the matrix product of the 5 | % n-mode matricization of X with the Khatri-Rao product of all 6 | % entries in U, a cell array of matrices, except the nth. How to 7 | % most efficiently do this computation depends on the type of tensor 8 | % involved. 9 | % 10 | % See also TTENSOR, TTENSOR/TTV 11 | % 12 | %MATLAB Tensor Toolbox. 13 | %Copyright 2010, Sandia Corporation. 14 | 15 | % This is the MATLAB Tensor Toolbox by Brett Bader and Tamara Kolda. 16 | % http://csmr.ca.sandia.gov/~tgkolda/TensorToolbox. 17 | % Copyright (2010) Sandia Corporation. Under the terms of Contract 18 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 19 | % work by or on behalf of the U.S. Government. Export of this data may 20 | % require a license from the United States Government. 21 | % The full license terms can be found in tensor_toolbox/LICENSE.txt 22 | % $Id: mttkrp.m,v 1.7 2010/03/19 23:46:31 tgkolda Exp $ 23 | 24 | N = ndims(X); 25 | 26 | if (n==1) 27 | R = size(U{2},2); 28 | else 29 | R = size(U{1},2); 30 | end 31 | 32 | % Compute cell array of weights to multiply into core 33 | W = cell(N,1); 34 | for i = [1:n-1,n+1:N] 35 | W{i} = (X.u{i}' * U{i}); 36 | end 37 | Y = mttkrp(X.core,W,n); 38 | 39 | % Find each column of answer by multiplying columns of X.u{n} with weights 40 | V = X.u{n} * Y; 41 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@ttensor/ndims.m: -------------------------------------------------------------------------------- 1 | function n = ndims(t) 2 | %NDIMS Return the number of dimensions for a ttensor. 3 | % 4 | % NDIMS(T) returns the number of dimensions of tensor T. 5 | % 6 | % See also TTENSOR. 7 | % 8 | %MATLAB Tensor Toolbox. 9 | %Copyright 2010, Sandia Corporation. 10 | 11 | % This is the MATLAB Tensor Toolbox by Brett Bader and Tamara Kolda. 12 | % http://csmr.ca.sandia.gov/~tgkolda/TensorToolbox. 13 | % Copyright (2010) Sandia Corporation. Under the terms of Contract 14 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 15 | % work by or on behalf of the U.S. Government. Export of this data may 16 | % require a license from the United States Government. 17 | % The full license terms can be found in tensor_toolbox/LICENSE.txt 18 | % $Id: ndims.m,v 1.7 2010/03/19 23:46:31 tgkolda Exp $ 19 | 20 | n = numel(t.u); 21 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@ttensor/norm.m: -------------------------------------------------------------------------------- 1 | function nrm = norm(X) 2 | %NORM Norm of a ttensor. 3 | % 4 | % See also TTENSOR. 5 | % 6 | %MATLAB Tensor Toolbox. 7 | %Copyright 2010, Sandia Corporation. 8 | 9 | % This is the MATLAB Tensor Toolbox by Brett Bader and Tamara Kolda. 10 | % http://csmr.ca.sandia.gov/~tgkolda/TensorToolbox. 11 | % Copyright (2010) Sandia Corporation. Under the terms of Contract 12 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 13 | % work by or on behalf of the U.S. Government. Export of this data may 14 | % require a license from the United States Government. 15 | % The full license terms can be found in tensor_toolbox/LICENSE.txt 16 | % $Id: norm.m,v 1.9 2010/03/19 23:46:31 tgkolda Exp $ 17 | 18 | 19 | if prod(size(X)) > prod(size(X.core)) 20 | V = cell(ndims(X),1); 21 | for n = 1:ndims(X) 22 | V{n} = X.u{n}'*X.u{n}; 23 | end 24 | Y = ttm(X.core,V); 25 | tmp = innerprod(Y, X.core); 26 | nrm = sqrt(tmp); 27 | else 28 | nrm = norm(full(X)); 29 | end 30 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@ttensor/permute.m: -------------------------------------------------------------------------------- 1 | function b = permute(a,order) 2 | %PERMUTE Permute dimensions for a ttensor. 3 | % 4 | % Y = PERMUTE(X,ORDER) rearranges the dimensions of X so that they 5 | % are in the order specified by the vector ORDER. The tensor 6 | % produced has the same values of X but the order of the subscripts 7 | % needed to access any particular element are rearranged as 8 | % specified by ORDER. 9 | % 10 | % See also TTENSOR. 11 | % 12 | %MATLAB Tensor Toolbox. 13 | %Copyright 2010, Sandia Corporation. 14 | 15 | % This is the MATLAB Tensor Toolbox by Brett Bader and Tamara Kolda. 16 | % http://csmr.ca.sandia.gov/~tgkolda/TensorToolbox. 17 | % Copyright (2010) Sandia Corporation. Under the terms of Contract 18 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 19 | % work by or on behalf of the U.S. Government. Export of this data may 20 | % require a license from the United States Government. 21 | % The full license terms can be found in tensor_toolbox/LICENSE.txt 22 | % $Id: permute.m,v 1.7 2010/03/19 23:46:31 tgkolda Exp $ 23 | 24 | N = ndims(a); 25 | 26 | if ~isequal(1:N,sort(order)) 27 | error('Invalid permuation'); 28 | end 29 | 30 | newcore = permute(a.core,order); 31 | newu = a.u(order); 32 | b = ttensor(newcore,newu); 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@ttensor/size.m: -------------------------------------------------------------------------------- 1 | function m = size(t,idx) 2 | %SIZE Size of a ttensor. 3 | % 4 | % D = SIZE(T) returns the size of the tensor. 5 | % 6 | % I = size(T,DIM) returns the size of the dimension specified by 7 | % the scalar DIM. 8 | % 9 | % See also TTENSOR, TTENSOR/NDIMS. 10 | % 11 | %MATLAB Tensor Toolbox. 12 | %Copyright 2010, Sandia Corporation. 13 | 14 | % This is the MATLAB Tensor Toolbox by Brett Bader and Tamara Kolda. 15 | % http://csmr.ca.sandia.gov/~tgkolda/TensorToolbox. 16 | % Copyright (2010) Sandia Corporation. Under the terms of Contract 17 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 18 | % work by or on behalf of the U.S. Government. Export of this data may 19 | % require a license from the United States Government. 20 | % The full license terms can be found in tensor_toolbox/LICENSE.txt 21 | % $Id: size.m,v 1.8 2010/03/19 23:46:31 tgkolda Exp $ 22 | 23 | if ndims(t) == 0 24 | m = []; 25 | end 26 | 27 | if exist('idx','var') 28 | m = size(t.u{idx}, 1); 29 | else 30 | for i = 1 : ndims(t) 31 | m(i) = size(t.u{i}, 1); 32 | end 33 | end 34 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@ttensor/subsref.m: -------------------------------------------------------------------------------- 1 | function a = subsref(t,s) 2 | %SUBSREF Subscripted reference for a ttensor. 3 | % 4 | % Examples 5 | % core = tensor(rand(2,2,2)); 6 | % X = TTENSOR(core, rand{4,2), rand(5,2),rand(3,2)); 7 | % X.core %<-- returns core array 8 | % X.U %<-- returns a cell array of three matrices 9 | % X.U{1} %<-- returns the matrix corresponding to the first mode. 10 | % 11 | % See also TTENSOR. 12 | % 13 | %MATLAB Tensor Toolbox. 14 | %Copyright 2010, Sandia Corporation. 15 | 16 | % This is the MATLAB Tensor Toolbox by Brett Bader and Tamara Kolda. 17 | % http://csmr.ca.sandia.gov/~tgkolda/TensorToolbox. 18 | % Copyright (2010) Sandia Corporation. Under the terms of Contract 19 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 20 | % work by or on behalf of the U.S. Government. Export of this data may 21 | % require a license from the United States Government. 22 | % The full license terms can be found in tensor_toolbox/LICENSE.txt 23 | % $Id: subsref.m,v 1.10 2010/03/19 23:46:31 tgkolda Exp $ 24 | 25 | switch s(1).type 26 | case '.' 27 | switch s(1).subs 28 | case {'core','lambda'} 29 | a = tt_subsubsref(t.core,s); 30 | case {'U','u'} 31 | a = tt_subsubsref(t.u,s); 32 | otherwise 33 | error(['No such field: ', s.subs]); 34 | end 35 | case '()' 36 | error('Subsref with () not supported for ttensor.'); 37 | case '{}' 38 | new_s(1).type = '.'; 39 | new_s(1).subs = 'u'; 40 | new_s(2:length(s)+1) = s; 41 | a = subsref(t, new_s); 42 | otherwise 43 | error('Invalid subsref.'); 44 | end 45 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@ttensor/uminus.m: -------------------------------------------------------------------------------- 1 | function t = uminus(t) 2 | %UMINUS Unary minus for ttensor. 3 | % 4 | % See also TTENSOR. 5 | % 6 | %MATLAB Tensor Toolbox. 7 | %Copyright 2010, Sandia Corporation. 8 | 9 | % This is the MATLAB Tensor Toolbox by Brett Bader and Tamara Kolda. 10 | % http://csmr.ca.sandia.gov/~tgkolda/TensorToolbox. 11 | % Copyright (2010) Sandia Corporation. Under the terms of Contract 12 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 13 | % work by or on behalf of the U.S. Government. Export of this data may 14 | % require a license from the United States Government. 15 | % The full license terms can be found in tensor_toolbox/LICENSE.txt 16 | % $Id: uminus.m,v 1.8 2010/03/19 23:46:31 tgkolda Exp $ 17 | 18 | t.core = -t.core; 19 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/@ttensor/uplus.m: -------------------------------------------------------------------------------- 1 | function t = uplus(t) 2 | %UPLUS Unary plus for ttensor. 3 | % 4 | % See also TTENSOR. 5 | % 6 | %MATLAB Tensor Toolbox. 7 | %Copyright 2010, Sandia Corporation. 8 | 9 | % This is the MATLAB Tensor Toolbox by Brett Bader and Tamara Kolda. 10 | % http://csmr.ca.sandia.gov/~tgkolda/TensorToolbox. 11 | % Copyright (2010) Sandia Corporation. Under the terms of Contract 12 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 13 | % work by or on behalf of the U.S. Government. Export of this data may 14 | % require a license from the United States Government. 15 | % The full license terms can be found in tensor_toolbox/LICENSE.txt 16 | % $Id: uplus.m,v 1.7 2010/03/19 23:46:31 tgkolda Exp $ 17 | 18 | % This function does nothing! 19 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/INSTALL.txt: -------------------------------------------------------------------------------- 1 | Please remember to cite the appropriate references when you have used 2 | Tensor Toolbox in your work. See "How to Cite" under 3 | http://www.sandia.gov/~tgkolda/TensorToolbox/ for more details. 4 | 5 | To install the Tensor Toolbox for MATLAB: 6 | 7 | 1. Unpack the compressed file. In a linux environment, for example, this can 8 | be done from the command line via: 9 | 10 | unzip tensor_toolbox_2.5.zip 11 | 12 | *or* 13 | 14 | gunzip -c tensor_toolbox_2.5.tar.gz | tar xvf - 15 | 16 | This should create a directory named *tensor_toolbox_2.5*. 17 | 18 | 2. Rename the root directory from *tensor_toolbox_2.5* 19 | to *tensor_toolbox*. 20 | 21 | 3. Start MATLAB. 22 | 23 | 4. Within MATLAB, cd to the *tensor_toolbox* directory and execute the 24 | following commands: 25 | 26 | addpath(pwd) %<-- Add the tensor toolbox to the MATLAB path 27 | cd ../met; addpath(pwd) %<-- [OPTIONAL] Also add the met directory 28 | savepath %<-- Save for future MATLAB sessions 29 | 30 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/cp_wopt.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qbzhao/BRTF/7704a1d7651f61af8c7eec93e116bfcc0d27fcf1/BRTF/tensor_toolbox_2.5/cp_wopt.m -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/doc/N_nvecs_doc.m: -------------------------------------------------------------------------------- 1 | %% Generating the leading mode-n vectors 2 | % The leading mode-n vectors are those vectors that span the subspace of 3 | % the mode-n fibers. In other words, the left singular vectors of the 4 | % n-mode matricization of X. 5 | %% Using nvecs to calculate the leading mode-n vectors 6 | % The |nvecs| command efficient computes the leading n-mode vectors. 7 | rand('state',0); 8 | X = sptenrand([4,3,2],6) %<-- A sparse tensor 9 | %% 10 | nvecs(X,1,2) %<-- The 2 leading mode-1 vectors 11 | %% 12 | nvecs(X,1,3) % <-- The 3 leading mode-1 vectors 13 | %% 14 | nvecs(full(X),1,3) %<-- The same thing for a dense tensor 15 | %% 16 | X = ktensor({rand(3,2),rand(3,2),rand(2,2)}) %<-- A random ktensor 17 | %% 18 | nvecs(X,2,1) %<-- The 1 leading mode-2 vector 19 | %% 20 | nvecs(full(X),2,1) %<-- Same thing for a dense tensor 21 | %% 22 | X = ttensor(tenrand([2,2,2,2]),{rand(3,2),rand(3,2),rand(2,2),rand(2,2)}); %<-- A random ttensor 23 | %% 24 | nvecs(X,4,2) %<-- The 1 leading mode-2 vector 25 | %% 26 | nvecs(full(X),4,2) %<-- Same thing for a dense tensor 27 | %% Using nvecs for the HOSVD 28 | X = tenrand([4 3 2]) %<-- Generate data 29 | %% 30 | U1 = nvecs(X,1,4); %<-- Mode 1 31 | U2 = nvecs(X,2,3); %<-- Mode 2 32 | U3 = nvecs(X,3,2); %<-- Mode 3 33 | S = ttm(X,{pinv(U1),pinv(U2),pinv(U3)}); %<-- Core 34 | Y = ttensor(S,{U1,U2,U3}) %<-- HOSVD of X 35 | %% 36 | norm(full(Y) - X) %<-- Reproduces the same result. 37 | 38 | %% 39 | U1 = nvecs(X,1,2); %<-- Mode 1 40 | U2 = nvecs(X,2,2); %<-- Mode 2 41 | U3 = nvecs(X,3,2); %<-- Mode 3 42 | S = ttm(X,{pinv(U1),pinv(U2),pinv(U3)}); %<-- Core 43 | Y = ttensor(S,{U1,U2,U3}) %<-- Rank-(2,2,2) HOSVD approximation of X 44 | %% 45 | 100*(1-norm(full(Y)-X)/norm(X)) %<-- Percentage explained by approximation -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/doc/T1_algorithms_doc.m: -------------------------------------------------------------------------------- 1 | %% ALS optimization for CP and Tucker tensor decompositions 2 | 3 | %% Alternating least squares for PARAFAC/CANDECOMP 4 | % The function |parafac_als| computes an estimate of the best rank-R 5 | % PARAFAC model of a tensor X using an alternating least-squares 6 | % algorithm. The input X can be a tensor, sptensor, ktensor, or 7 | % ttensor. The result P is a ktensor. 8 | rand('state',0); 9 | X = sptenrand([5 4 3], 10) 10 | %% 11 | P = parafac_als(X,2) 12 | %% 13 | P = parafac_als(X,2,struct('dimorder',[3 2 1])) 14 | %% 15 | P = parafac_als(X,2,struct('dimorder',[3 2 1],'init','nvecs')) 16 | %% 17 | U0 = {rand(5,2),rand(4,2),[]}; %<-- Initial guess for factors of P 18 | P = parafac_als(X,2,struct('dimorder',[3 2 1],'init',{U0})) 19 | %% Alternating least squares for Tucker model 20 | % The function |tucker_als| computes the best rank(R1,R2,..,Rn) 21 | % approximation of tensor X, according to the specified dimensions in 22 | % vector R. The input X can be a tensor, sptensor, ktensor, or 23 | % ttensor. The result returned in T is a ttensor. 24 | X = sptenrand([5 4 3], 10) 25 | %% 26 | T = tucker_als(X,2) %<-- best rank(2,2,2) approximation 27 | %% 28 | T = tucker_als(X,[2 2 1]) %<-- best rank(2,2,1) approximation 29 | %% 30 | T = tucker_als(X,2,struct('dimorder',[3 2 1])) 31 | %% 32 | T = tucker_als(X,2,struct('dimorder',[3 2 1],'init','eigs')) 33 | %% 34 | U0 = {rand(5,2),rand(4,2),[]}; %<-- Initial guess for factors of T 35 | T = tucker_als(X,2,struct('dimorder',[3 2 1],'init',{U0})) 36 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/doc/T4_cpapr_doc.m: -------------------------------------------------------------------------------- 1 | %% Alternating Poisson Regression for fitting CP to sparse count data 2 | 3 | %% Set up a sample problem 4 | % We follow the general procedure outlined by E. C. Chi and T. G. Kolda, 5 | % On Tensors, Sparsity, and Nonnegative Factorizations, arXiv:1112.2414 6 | % [math.NA], December 2011 (http://arxiv.org/abs/1112.2414). 7 | 8 | % Pick the size and rank 9 | sz = [100 80 60]; 10 | R = 5; 11 | 12 | % Generate factor matrices with a few large entries in each column; this 13 | % will be the basis of our soln. 14 | A = cell(3,1); 15 | for n = 1:length(sz) 16 | A{n} = rand(sz(n), R); 17 | for r = 1:R 18 | p = randperm(sz(n)); 19 | nbig = round( (1/R)*sz(n) ); 20 | A{n}(p(1:nbig),r) = 100 * A{n}(p(1:nbig),r); 21 | end 22 | end 23 | lambda = rand(R,1); 24 | S = ktensor(lambda, A); 25 | S = normalize(S,'sort',1); 26 | 27 | % Create sparse test problem based on provided solution. 28 | nz = prod(sz) * .05; 29 | info = create_problem('Soln', S, 'Sparse_Generation', nz); 30 | 31 | % Extract data and solution 32 | X = info.Data; 33 | M_true = info.Soln; 34 | 35 | %% Call CP-APR 36 | 37 | % Compute a solution 38 | M = cp_apr(X, R, 'printitn', 10); 39 | 40 | % Score the solution 41 | factor_match_score = score(M, M_true, 'greedy', true) 42 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/doc/V_SSHOPM_doc.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qbzhao/BRTF/7704a1d7651f61af8c7eec93e116bfcc0d27fcf1/BRTF/tensor_toolbox_2.5/doc/V_SSHOPM_doc.m -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/doc/html/C_ttensor_doc_eq15566.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qbzhao/BRTF/7704a1d7651f61af8c7eec93e116bfcc0d27fcf1/BRTF/tensor_toolbox_2.5/doc/html/C_ttensor_doc_eq15566.png -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/doc/html/D_ktensor_doc_eq09466.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qbzhao/BRTF/7704a1d7651f61af8c7eec93e116bfcc0d27fcf1/BRTF/tensor_toolbox_2.5/doc/html/D_ktensor_doc_eq09466.png -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/doc/html/D_ktensor_doc_eq51104.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qbzhao/BRTF/7704a1d7651f61af8c7eec93e116bfcc0d27fcf1/BRTF/tensor_toolbox_2.5/doc/html/D_ktensor_doc_eq51104.png -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/doc/html/D_ktensor_doc_eq64665.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qbzhao/BRTF/7704a1d7651f61af8c7eec93e116bfcc0d27fcf1/BRTF/tensor_toolbox_2.5/doc/html/D_ktensor_doc_eq64665.png -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/doc/html/D_ktensor_doc_eq81501.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qbzhao/BRTF/7704a1d7651f61af8c7eec93e116bfcc0d27fcf1/BRTF/tensor_toolbox_2.5/doc/html/D_ktensor_doc_eq81501.png -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/doc/html/V_SSHOPM_doc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qbzhao/BRTF/7704a1d7651f61af8c7eec93e116bfcc0d27fcf1/BRTF/tensor_toolbox_2.5/doc/html/V_SSHOPM_doc.png -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/doc/html/V_SSHOPM_doc_01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qbzhao/BRTF/7704a1d7651f61af8c7eec93e116bfcc0d27fcf1/BRTF/tensor_toolbox_2.5/doc/html/V_SSHOPM_doc_01.png -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/doc/html/V_SSHOPM_doc_02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qbzhao/BRTF/7704a1d7651f61af8c7eec93e116bfcc0d27fcf1/BRTF/tensor_toolbox_2.5/doc/html/V_SSHOPM_doc_02.png -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/doc/images/Workspace.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qbzhao/BRTF/7704a1d7651f61af8c7eec93e116bfcc0d27fcf1/BRTF/tensor_toolbox_2.5/doc/images/Workspace.png -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/doc/images/banner-background.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qbzhao/BRTF/7704a1d7651f61af8c7eec93e116bfcc0d27fcf1/BRTF/tensor_toolbox_2.5/doc/images/banner-background.jpg -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/doc/images/logo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qbzhao/BRTF/7704a1d7651f61af8c7eec93e116bfcc0d27fcf1/BRTF/tensor_toolbox_2.5/doc/images/logo.gif -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/helpindex.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Tensor Toolbox 6 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/info.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | R2006a 7 | Tensor 8 | toolbox 9 | $toolbox/matlab/icons/unknownicon.gif 10 | . 11 | 12 | 13 | 14 | 15 | doc tensor_toolbox/ 16 | $toolbox/matlab/icons/webicon.gif 17 | 18 | 19 | 20 | web http://www.sandia.gov/~tgkolda/TensorToolbox 21 | $toolbox/matlab/icons/webicon.gif 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/met/Contents.m: -------------------------------------------------------------------------------- 1 | % MET: Memory Efficient Tucker 2 | % 3 | % Files 4 | % ttm_me - Memory-efficient sptensor times matrix. 5 | % ttm_me_mem - Estimates intermediate memory comsumption for ttm_me. 6 | % ttm_me_partition - Finds best order for ttm_me. 7 | % tucker_me - Memory-efficient Tucker higher-order orthogonal iteration. 8 | % tucker_me_test - Very simple tests of tucker_me. 9 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/met/ttm_me_partition.m: -------------------------------------------------------------------------------- 1 | function [edims, sdims] = ttm_me_partition(U, esz, n) 2 | %TTM_ME_PARTITION Finds best order for ttm_me. 3 | % 4 | % [EDIMS, SDIMS] = TTM_ME_PARTITION(U, ESZ, N) finds the best order for 5 | % memory efficient ttm. ESZ specifies the number of dimensions that 6 | % are to be handled elementwise. U is the cell array of matrices. 7 | % The result returned in EDIMS and SDIMS are the modes that need to 8 | % be handled in element-wise and in slice-wise respectively. The 9 | % orders are in the descending order of the reduction ratio. 10 | % 11 | % See also TUCKER_ME, TTM_ME. 12 | % 13 | % Based on the paper: 14 | % T. G. Kolda and J. Sun. Scalable Tensor Decompositions for Multi-aspect 15 | % Data Mining. In: ICDM 2008: Proceedings of the 8th IEEE International 16 | % Conference on Data Mining, December 2008. 17 | 18 | % $Id: ttm_me_partition.m,v 1.2 2009/07/08 00:03:52 tgkolda Exp $ 19 | 20 | if nargin<3 21 | %default: n is not in 1:length(U) 22 | n = -1; 23 | end 24 | 25 | % compute reduction ratios 26 | dims = setdiff(1:length(U), n); 27 | r = []; 28 | for i=dims 29 | [nr, nc] = size(U{i}); 30 | r(end+1) = nr/nc; 31 | end 32 | 33 | %sort the reduction ratio and 34 | %put the ones w/ highest reduction ratio in edims 35 | [junk, ind] = sort(r,'descend'); 36 | edims = sort(dims(ind(1:min(length(ind),esz)))); 37 | sdims = sort(dims(ind(esz+1:end))); 38 | end -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/parafac_als.m: -------------------------------------------------------------------------------- 1 | function [P,Uinit] = parafac_als(X,R,opts) 2 | %PARAFAC_ALS Deprecated. Use CP_ALS instead. 3 | % 4 | % See also CP_ALS. 5 | % 6 | %MATLAB Tensor Toolbox. 7 | %Copyright 2012, Sandia Corporation. 8 | 9 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 10 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 11 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 12 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 13 | % work by or on behalf of the U.S. Government. Export of this data may 14 | % require a license from the United States Government. 15 | % The full license terms can be found in the file LICENSE.txt 16 | 17 | 18 | if (nargout == 2) & (nargin == 3) 19 | [P,Uinit] = cp_als(X,R,opts); 20 | elseif (nargout == 2) & (nargin == 2) 21 | [P,Uinit] = cp_als(X,R); 22 | elseif (nargout == 2) & (nargin == 1) 23 | [P,Uinit] = cp_als(X); 24 | elseif (nargout == 1) & (nargin == 3) 25 | P = cp_als(X,R,opts); 26 | elseif (nargout == 1) & (nargin == 2) 27 | P = cp_als(X,R); 28 | elseif (nargout == 1) & (nargin == 1) 29 | P = cp_als(X); 30 | end 31 | 32 | 33 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/sptendiag.m: -------------------------------------------------------------------------------- 1 | function X = sptendiag(v,sz) 2 | %SPTENDIAG Creates a sparse tensor with v on the diagonal. 3 | % 4 | % SPTENDIAG(V) creates a sparse tensor with N dimensions, each of 5 | % size N, where N is the number of elements of V. The elements of V 6 | % are placed on the superdiagonal. 7 | % 8 | % SPTENDIAG(V,SZ) is the same as above but creates a tensor of size 9 | % SZ. If SZ is not big enough, the tensor will be enlarged to 10 | % accommodate the elements of V on the superdiagonal. 11 | % 12 | % Examples 13 | % X = sptendiag([0.1 0.22 0.333]) %<-- creates a 3x3x3 sptensor 14 | % 15 | % See also SPTENSOR, TENDIAG. 16 | % 17 | %MATLAB Tensor Toolbox. 18 | %Copyright 2012, Sandia Corporation. 19 | 20 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 21 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 22 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 23 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 24 | % work by or on behalf of the U.S. Government. Export of this data may 25 | % require a license from the United States Government. 26 | % The full license terms can be found in the file LICENSE.txt 27 | 28 | 29 | % Make sure v is a column vector 30 | v = reshape(v,[numel(v) 1]); 31 | 32 | N = numel(v); 33 | if ~exist('sz','var') 34 | sz = repmat(N,1,N); 35 | end 36 | 37 | X = sptensor(sz); 38 | subs = repmat((1:N)', 1, length(sz)); 39 | X(subs) = v; 40 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/tendiag.m: -------------------------------------------------------------------------------- 1 | function X = tendiag(v,sz) 2 | %TENDIAG Creates a tensor with v on the diagonal. 3 | % 4 | % TENDIAG(V) creates a tensor with N dimensions, each of size N, where N 5 | % is the number of elements of V. The elements of V are placed on the 6 | % superdiagonal. 7 | % 8 | % TENDIAG(V,SZ) is the same as above but creates a tensor of size SZ. If 9 | % SZ is not big enough, the tensor will be enlarged to accommodate the 10 | % elements of V on the superdiagonal. 11 | % 12 | % Examples 13 | % X = tendiag([0.1 0.22 0.333]) %<-- creates a 3x3x3 tensor 14 | % 15 | % See also TENSOR, SPTENDIAG. 16 | % 17 | %MATLAB Tensor Toolbox. 18 | %Copyright 2012, Sandia Corporation. 19 | 20 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 21 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 22 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 23 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 24 | % work by or on behalf of the U.S. Government. Export of this data may 25 | % require a license from the United States Government. 26 | % The full license terms can be found in the file LICENSE.txt 27 | 28 | 29 | % Make sure v is a column vector 30 | v = reshape(v,[numel(v) 1]); 31 | 32 | N = numel(v); 33 | if ~exist('sz','var') 34 | sz = repmat(N,1,N); 35 | end 36 | 37 | X = tenzeros(sz); 38 | subs = repmat((1:N)', 1, length(sz)); 39 | X(subs) = v; 40 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/teneye.m: -------------------------------------------------------------------------------- 1 | function A = teneye(M,N) 2 | %TENEYE Create identity tensor of specified size. 3 | % 4 | % We say E is the "identity tensor" if TTSV(E,X,-1) = X for all X such 5 | % that NORM(X) = 1. 6 | % 7 | % TENEYE(M,N) returns a (dense) identity tensor of order M and size N. 8 | % The identity tensor only exists when M is even and returns an error 9 | % otherwise. Due to the complexity of generating all possible indices, 10 | % this only works for relatively small M and N (i.e., N <= 7, M <= 6). 11 | % 12 | % Examples 13 | % E = teneye(4,2); %<-- Create 2 x 2 x 2 x 2 identity tensor 14 | % x = rand(2,1); x = x/norm(x); %<-- Generate random x with norm 1 15 | % norm(ttsv(E,x,-1)-x) %<-- Check that ttsv(E,x,-1) = x 16 | % 17 | % See also tensor, ttsv. 18 | % 19 | %MATLAB Tensor Toolbox. 20 | %Copyright 2012, Sandia Corporation. 21 | 22 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 23 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 24 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 25 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 26 | % work by or on behalf of the U.S. Government. Export of this data may 27 | % require a license from the United States Government. 28 | % The full license terms can be found in the file LICENSE.txt 29 | 30 | %% Check that it's an even tensor 31 | if mod(M,2) ~= 0 32 | error('m must be even'); 33 | end 34 | 35 | %% Generate all possible indices 36 | idx = tt_combinator(N,M,'c','r'); 37 | 38 | %% 39 | A = tenzeros(N*ones(1,M)); 40 | for i = 1:size(idx,1) 41 | p = perms(idx(i,:)); 42 | for j = 1:M/2 43 | s(:,j) = (p(:,2*j-1) == p(:,2*j)); 44 | end 45 | v = sum(sum(s,2)==M/2); 46 | A(p) = v / factorial(M); 47 | end 48 | 49 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/tenones.m: -------------------------------------------------------------------------------- 1 | function X = tenones(varargin) 2 | %TENONES Ones tensor. 3 | % 4 | % X = TENONES(SZ) forms a tensor of size SZ with all ones. 5 | % 6 | % TENONES(SZ) is equivalent to TENSOR(ONES(SZ(1),SZ(2),...),SZ). 7 | % 8 | % See also TENSOR, ONES. 9 | % 10 | %MATLAB Tensor Toolbox. 11 | %Copyright 2012, Sandia Corporation. 12 | 13 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 14 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 15 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 16 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 17 | % work by or on behalf of the U.S. Government. Export of this data may 18 | % require a license from the United States Government. 19 | % The full license terms can be found in the file LICENSE.txt 20 | 21 | 22 | if nargin == 1 23 | sz = varargin{1}; 24 | else 25 | sz = cell2mat(varargin); 26 | end 27 | 28 | if isempty(sz) 29 | X = tensor(); 30 | return; 31 | end 32 | 33 | data = ones([sz 1 1]); 34 | X = tensor(data,sz); 35 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/tenrand.m: -------------------------------------------------------------------------------- 1 | function X = tenrand(varargin) 2 | %TENRAND Uniformly distributed pseudo-random tensor. 3 | % 4 | % X = TENRAND(SZ) forms a tensor of size SZ with pseudo-random 5 | % values drawn from a uniform distribution on the unit interval. 6 | % 7 | % TENRAND(SZ) is equivalent to TENSOR(RAND(SZ(1),SZ(2),...),SZ). 8 | % 9 | % See also TENSOR, SPTENRAND, RAND. 10 | % 11 | %MATLAB Tensor Toolbox. 12 | %Copyright 2012, Sandia Corporation. 13 | 14 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 15 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 16 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 17 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 18 | % work by or on behalf of the U.S. Government. Export of this data may 19 | % require a license from the United States Government. 20 | % The full license terms can be found in the file LICENSE.txt 21 | 22 | 23 | if nargin == 1 24 | sz = varargin{1}; 25 | else 26 | sz = cell2mat(varargin); 27 | end 28 | 29 | data = rand([sz 1 1]); 30 | X = tensor(data,sz); 31 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/tenzeros.m: -------------------------------------------------------------------------------- 1 | function X = tenzeros(varargin) 2 | %TENZEROS Create zeros tensor. 3 | % 4 | % X = TENZEROS(SZ) forms a tensor of size SZ with all zeros. 5 | % 6 | % TENZEROS(SZ) is equivalent to TENSOR(ZEROS(SZ(1),SZ(2),...),SZ). 7 | % 8 | % See also TENSOR, ZEROS. 9 | % 10 | %MATLAB Tensor Toolbox. 11 | %Copyright 2012, Sandia Corporation. 12 | 13 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 14 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 15 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 16 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 17 | % work by or on behalf of the U.S. Government. Export of this data may 18 | % require a license from the United States Government. 19 | % The full license terms can be found in the file LICENSE.txt 20 | 21 | 22 | if nargin == 1 23 | sz = varargin{1}; 24 | else 25 | sz = cell2mat(varargin); 26 | end 27 | 28 | if isempty(sz) 29 | X = tensor; 30 | return; 31 | end 32 | 33 | if nargin == 2 34 | order = sz; 35 | dim = varargin{1}; 36 | sz = dim * ones(1,order); 37 | end 38 | 39 | data = zeros([sz 1 1]); 40 | X = tensor(data,sz); 41 | 42 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/tt_RandOrthMat.m: -------------------------------------------------------------------------------- 1 | function M=tt_RandOrthMat(n, tol) 2 | %TT_RANDORTHMAT Generates random n x n orthogonal real matrix. 3 | % 4 | % M = RANDORTHMAT(n) 5 | % generates a random n x n orthogonal real matrix. 6 | % 7 | % M = RANDORTHMAT(n,tol) 8 | % explicitly specifies a thresh value that measures linear dependence 9 | % of a newly formed column with the existing columns. Defaults to 1e-6. 10 | % 11 | % In this version the generated matrix distribution *is* uniform over the manifold 12 | % O(n) w.r.t. the induced R^(n^2) Lebesgue measure, at a slight computational 13 | % overhead (randn + normalization, as opposed to rand ). 14 | % 15 | % (c) Ofek Shilon , 2006. 16 | % 17 | %This code is *not* copyrighted by Sandia, but it is distributed with: 18 | %MATLAB Tensor Toolbox. 19 | %Copyright 2012, Sandia Corporation. 20 | 21 | 22 | 23 | if nargin==1 24 | tol=1e-6; 25 | end 26 | 27 | M = zeros(n); % prealloc 28 | 29 | % gram-schmidt on random column vectors 30 | 31 | vi = randn(n,1); 32 | % the n-dimensional normal distribution has spherical symmetry, which implies 33 | % that after normalization the drawn vectors would be uniformly distributed on the 34 | % n-dimensional unit sphere. 35 | 36 | M(:,1) = vi ./ norm(vi); 37 | 38 | for i=2:n 39 | nrm = 0; 40 | while nrm= 2) 22 | type = 'subtensor'; 23 | return; 24 | end 25 | 26 | type = 'subscripts'; 27 | 28 | 29 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/tt_ccong.m: -------------------------------------------------------------------------------- 1 | function X = tt_ccong(m,n,gamma) 2 | %TT_CCONG Create a random matrix with a fixed congruence 3 | % 4 | % X = TT_CCONG(M,N,GAMMA) creates a matrix X of size M x N such 5 | % that each column of X has norm 1 and any two columns of X have an inner 6 | % product equal to GAMMA. 7 | % 8 | % Based on code from Evrim Acar and the paper G. Tomasi and R. Bro, A 9 | % comparison of algorithms for fitting the PARAFAC model, Computational 10 | % Statistics & Data Analysis, 50: 1700-1734, 2006. 11 | % 12 | %MATLAB Tensor Toolbox. 13 | %Copyright 2012, Sandia Corporation. 14 | 15 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 16 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 17 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 18 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 19 | % work by or on behalf of the U.S. Government. Export of this data may 20 | % require a license from the United States Government. 21 | % The full license terms can be found in the file LICENSE.txt 22 | 23 | CG = gamma * ones(n,n) + (1-gamma) * eye(n); 24 | CGR = chol(CG); 25 | X = randn(m,n); 26 | [Q,~] = qr(X,0); 27 | X = Q * CGR; -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/tt_cp_fun.m: -------------------------------------------------------------------------------- 1 | function [f,g] = tt_cp_fun(x,Z,Znormsqr) 2 | %TT_CP_FUN Calculate function and gradient for CP fit function. 3 | % 4 | % [F,G] = TT_CP_FUN(X,Z) where X is a vector containing the entries of the 5 | % components of the model and Z is the tensor to be fit. 6 | % 7 | % See also TT_CP_VEC_TO_FAC, TT_FAC_TO_VEC, TT_CP_FG, CP_OPT 8 | % 9 | %MATLAB Tensor Toolbox. 10 | %Copyright 2012, Sandia Corporation. 11 | 12 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 13 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 14 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 15 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 16 | % work by or on behalf of the U.S. Government. Export of this data may 17 | % require a license from the United States Government. 18 | % The full license terms can be found in the file LICENSE.txt 19 | 20 | 21 | %% Convert x to a cell array of matrices 22 | A = tt_cp_vec_to_fac(x,Z); 23 | 24 | %% Call cp_fit and cp_gradient using cp_fg 25 | [f,G] = tt_cp_fg(Z,A,Znormsqr); 26 | 27 | %% Convert a cell array to a vector 28 | g = tt_fac_to_vec(G); 29 | 30 | 31 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/tt_cp_vec_to_fac.m: -------------------------------------------------------------------------------- 1 | function A = cp_vec_to_fac(x,Z) 2 | %CP_VEC_TO_FAC Converts a vector to a cell array of factor matrices. 3 | % 4 | % A = CP_VEC_TO_FAC(X,Z) converts the vector X into a cell array 5 | % of factor matrices consistent with the size of the tensor Z. 6 | % 7 | % See also FAC_TO_VEC, CP_FUN, CP_OPT. 8 | % 9 | %MATLAB Tensor Toolbox. 10 | %Copyright 2012, Sandia Corporation. 11 | 12 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 13 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 14 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 15 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 16 | % work by or on behalf of the U.S. Government. Export of this data may 17 | % require a license from the United States Government. 18 | % The full license terms can be found in the file LICENSE.txt 19 | 20 | 21 | %% Set-up 22 | P = length(x); 23 | N = ndims(Z); 24 | sz = size(Z); 25 | 26 | %% Determine R 27 | R = P / sum(sz); 28 | 29 | %% Create A 30 | A = cell(N,1); 31 | for n = 1:N 32 | idx1 = sum(sz(1:n-1))*R + 1; 33 | idx2 = sum(sz(1:n))*R; 34 | A{n} = reshape(x(idx1:idx2),sz(n),R); 35 | end -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/tt_cp_wfg_sparse_setup.m: -------------------------------------------------------------------------------- 1 | function Zvals = cp_wfg_sparse_setup(Z,W) 2 | %CP_WFG_SPARSE_SETUP Creates a special array. 3 | % 4 | % ZVALS = CP_WFG_SPARSE_SETUP(Z,W) creates an array ZVALS that 5 | % contains the values of Z corresponding to the indices specified 6 | % by W.subs. 7 | % 8 | % See also CP_WFG_SPARSE. 9 | % 10 | %MATLAB Tensor Toolbox. 11 | %Copyright 2012, Sandia Corporation. 12 | 13 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 14 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 15 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 16 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 17 | % work by or on behalf of the U.S. Government. Export of this data may 18 | % require a license from the United States Government. 19 | % The full license terms can be found in the file LICENSE.txt 20 | 21 | 22 | Zsubs = Z.subs; 23 | Wsubs = W.subs; 24 | Zvals = zeros(size(W.vals)); 25 | [junk,loc] = ismember(Zsubs,Wsubs,'rows'); 26 | Zvals(loc) = Z.vals; 27 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/tt_fac_to_vec.m: -------------------------------------------------------------------------------- 1 | function x = fac_to_vec(A) 2 | %FAC_TO_VEC Converts a set of factor matrices to a vector. 3 | % 4 | % X = FAC_TO_VEC(A) converts a cell array of factor matrices A to a 5 | % vector by vectorizing each matrix and stacking them. 6 | % 7 | % See also CP_VEC_TO_FAC, CP_FUN, CP_OPT. 8 | % 9 | %MATLAB Tensor Toolbox. 10 | %Copyright 2012, Sandia Corporation. 11 | 12 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 13 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 14 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 15 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 16 | % work by or on behalf of the U.S. Government. Export of this data may 17 | % require a license from the United States Government. 18 | % The full license terms can be found in the file LICENSE.txt 19 | 20 | 21 | %% Set-up 22 | N = length(A); 23 | 24 | %% Get sizes 25 | sz = zeros(N,1); 26 | for n = 1:N 27 | sz(n) = size(A{n},1); 28 | end 29 | R = size(A{1},2); 30 | P = sum(sz)*R; 31 | 32 | %% Create x 33 | x = zeros(P,1); 34 | for n = 1:N 35 | idx1 = sum(sz(1:n-1))*R + 1; 36 | idx2 = sum(sz(1:n))*R; 37 | x(idx1:idx2) = reshape(A{n},sz(n)*R,1); 38 | end -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/tt_ind2sub.m: -------------------------------------------------------------------------------- 1 | function subs = tt_ind2sub(siz,idx) 2 | %TT_IND2SUB Multiple subscripts from linear indices. 3 | % 4 | % SUBS = TT_IND2SUB(SIZ,INDS) returns that subscripts equivalent 5 | % to the linear indices in INDS for a tensor of size SIZ. 6 | % 7 | % See also TT_SUB2IND, IND2SUB. 8 | % 9 | %MATLAB Tensor Toolbox. 10 | %Copyright 2012, Sandia Corporation. 11 | 12 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 13 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 14 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 15 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 16 | % work by or on behalf of the U.S. Government. Export of this data may 17 | % require a license from the United States Government. 18 | % The full license terms can be found in the file LICENSE.txt 19 | 20 | 21 | if isempty(idx) 22 | subs = []; 23 | return; 24 | end 25 | 26 | k = [1 cumprod(siz(1:end-1))]; 27 | n = length(siz); 28 | idx = idx - 1; 29 | for i = n : -1 : 1 30 | subs(:,i) = floor(idx / k(i)) + 1; 31 | idx = rem(idx,k(i)); 32 | end 33 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/tt_intvec2str.m: -------------------------------------------------------------------------------- 1 | function s = tt_intvec2str(v) 2 | %TT_VEC2STR Print integer vector to a string with brackets. 3 | % 4 | %MATLAB Tensor Toolbox. 5 | %Copyright 2012, Sandia Corporation. 6 | 7 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 8 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 9 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 10 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 11 | % work by or on behalf of the U.S. Government. Export of this data may 12 | % require a license from the United States Government. 13 | % The full license terms can be found in the file LICENSE.txt 14 | 15 | 16 | if isempty(v) 17 | s = sprintf('[]'); 18 | return; 19 | end 20 | 21 | s = ['[ ' sprintf('%d ',v(1:end)) ']']; 22 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/tt_loglikelihood.m: -------------------------------------------------------------------------------- 1 | function f = tt_loglikelihood(X,M) 2 | %TT_LOGLIKELIHOOD Compute log-likelihood of data X with model M. 3 | % 4 | % F = TT_LOGLIKELIHOOD(X,M) computes the log-likelihood of model M given 5 | % data X, where M is a ktensor and X is a tensor or sptensor. 6 | % Specifically, F = - (sum_i m_i - x_i * log_i) where i is a multiindex 7 | % across all tensor dimensions. 8 | % 9 | % See also cp_apr, tensor, sptensor, ktensor. 10 | % 11 | %MATLAB Tensor Toolbox. 12 | %Copyright 2012, Sandia Corporation. 13 | 14 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 15 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 16 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 17 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 18 | % work by or on behalf of the U.S. Government. Export of this data may 19 | % require a license from the United States Government. 20 | % The full license terms can be found in the file LICENSE.txt 21 | 22 | N = ndims(X); 23 | 24 | if ~isa(M, 'ktensor') 25 | error('M must be a ktensor'); 26 | end 27 | 28 | M = normalize(M,1,1); 29 | 30 | if isa(X, 'sptensor') 31 | xsubs = X.subs; 32 | A = M.U{1}(xsubs(:,1),:); 33 | for n = 2:N 34 | A = A .* M.U{n}(xsubs(:,n),:); 35 | end 36 | f = sum(X.vals .* log(sum(A,2))) - sum(sum(M.U{1})); 37 | else 38 | f = sum(sum(double(tenmat(X,1)) .* log(double(tenmat(M,1))))) - sum(sum(M.U{1})); 39 | end 40 | 41 | 42 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/tt_matrix2cellstr.m: -------------------------------------------------------------------------------- 1 | function S = tt_matrix2cellstr(M) 2 | %TT_MATRIX2CELLSTR Convert a matrix to a cell array of strings. 3 | % 4 | %MATLAB Tensor Toolbox. 5 | %Copyright 2012, Sandia Corporation. 6 | 7 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 8 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 9 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 10 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 11 | % work by or on behalf of the U.S. Government. Export of this data may 12 | % require a license from the United States Government. 13 | % The full license terms can be found in the file LICENSE.txt 14 | 15 | 16 | fmt = get(0,'FormatSpacing'); 17 | format compact 18 | S = evalc('disp(M)'); 19 | set(0,'FormatSpacing',fmt) 20 | S = textscan(S,'%s','delimiter','\n','whitespace',''); 21 | S = S{1}; 22 | end 23 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/tt_size2str.m: -------------------------------------------------------------------------------- 1 | function s = tt_size2str(sz) 2 | %TT_SIZE2STR Convert size to a string that can be printed. 3 | % 4 | %MATLAB Tensor Toolbox. 5 | %Copyright 2012, Sandia Corporation. 6 | 7 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 8 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 9 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 10 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 11 | % work by or on behalf of the U.S. Government. Export of this data may 12 | % require a license from the United States Government. 13 | % The full license terms can be found in the file LICENSE.txt 14 | 15 | 16 | if isempty(sz) 17 | s = sprintf('[empty tensor]'); 18 | return; 19 | end 20 | 21 | if numel(sz) == 1 22 | s = sprintf('%d',sz); 23 | else 24 | s = [sprintf('%d x ',sz(1:end-1)) sprintf('%d', sz(end)) ]; 25 | end 26 | 27 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/tt_sizecheck.m: -------------------------------------------------------------------------------- 1 | function ok = tt_sizecheck(siz) 2 | %TT_SIZECHECK Checks that the size is valid. 3 | % 4 | % TT_SIZECHECK(S) throws an error if S is not a valid size array, 5 | % which means that it is a row vector with strictly postitive, 6 | % real-valued, finite integer values. 7 | % 8 | % X = TT_SIZECHECK(S) returns true if S is a valid and false otherwise. 9 | % 10 | % See also TT_SUBSCHECK. 11 | % 12 | %MATLAB Tensor Toolbox. 13 | %Copyright 2012, Sandia Corporation. 14 | 15 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 16 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 17 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 18 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 19 | % work by or on behalf of the U.S. Government. Export of this data may 20 | % require a license from the United States Government. 21 | % The full license terms can be found in the file LICENSE.txt 22 | 23 | 24 | if ndims(siz) == 2 && size(siz,1) == 1 ... 25 | && isreal(siz) ... 26 | && ~any(isnan(siz(:))) && ~any(isinf(siz(:))) ... 27 | && isequal(siz,round(siz)) && all(siz(:) > 0) 28 | ok = true; 29 | else 30 | ok = false; 31 | end 32 | 33 | if ~ok && nargout == 0 34 | error('Size must be a row vector of real positive integers'); 35 | end 36 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/tt_sub2ind.m: -------------------------------------------------------------------------------- 1 | function idx = tt_sub2ind(siz,subs) 2 | %TT_SUB2IND Converts multidimensional subscripts to linear indices. 3 | % 4 | % INDS = TT_SUB2IND(SIZ,SUBS) returns the linear indices 5 | % equivalent to the subscripts in the array SUBS for a tensor of 6 | % size SIZ. 7 | % 8 | % See also TT_IND2SUB, SUB2IND. 9 | % 10 | %MATLAB Tensor Toolbox. 11 | %Copyright 2012, Sandia Corporation. 12 | 13 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 14 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 15 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 16 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 17 | % work by or on behalf of the U.S. Government. Export of this data may 18 | % require a license from the United States Government. 19 | % The full license terms can be found in the file LICENSE.txt 20 | 21 | 22 | if isempty(subs) 23 | idx = []; 24 | return; 25 | end 26 | 27 | mult = [1 cumprod(siz(1:end-1))]; 28 | idx = (subs - 1) * mult' + 1; 29 | 30 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/tt_subscheck.m: -------------------------------------------------------------------------------- 1 | function ok = tt_subscheck(subs) 2 | %TT_SUBSCHECK Checks for valid subscripts. 3 | % 4 | % TT_SUBSCHECK(S) throws an error if S is not a valid subscript 5 | % array, which means that S is a matrix of real-valued, finite, 6 | % positive, integer subscripts. 7 | % 8 | % X = TT_SUBSCHECK(S) returns true if S is a valid and false 9 | % otherwise. 10 | % 11 | % See also TT_SIZECHECK, TT_VALSCHECK. 12 | % 13 | %MATLAB Tensor Toolbox. 14 | %Copyright 2012, Sandia Corporation. 15 | 16 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 17 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 18 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 19 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 20 | % work by or on behalf of the U.S. Government. Export of this data may 21 | % require a license from the United States Government. 22 | % The full license terms can be found in the file LICENSE.txt 23 | 24 | % 25 | % Includes improvements offered by Marcus Brubaker. 26 | 27 | if isempty(subs) 28 | ok = true; 29 | elseif ndims(subs) == 2 && isreal(subs) ... 30 | && all(isfinite(subs(:)) & subs(:) > 0) ... 31 | && isequal(subs,round(subs)) 32 | ok = true; 33 | else 34 | ok = false; 35 | end 36 | 37 | if ~ok && nargout == 0 38 | error('Subscripts must be a matrix of real positive integers'); 39 | end 40 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/tt_subsubsref.m: -------------------------------------------------------------------------------- 1 | function a = tt_subsubsref(obj,s) 2 | %TT_SUBSUBSREF Helper function for tensor toolbox subsref. 3 | % 4 | %MATLAB Tensor Toolbox. 5 | %Copyright 2012, Sandia Corporation. 6 | 7 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 8 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 9 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 10 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 11 | % work by or on behalf of the U.S. Government. Export of this data may 12 | % require a license from the United States Government. 13 | % The full license terms can be found in the file LICENSE.txt 14 | 15 | 16 | if length(s) == 1 17 | a = obj; 18 | else 19 | a = subsref(obj, s(2:end)); 20 | end 21 | 22 | -------------------------------------------------------------------------------- /BRTF/tensor_toolbox_2.5/tt_valscheck.m: -------------------------------------------------------------------------------- 1 | function ok = tt_valscheck(vals) 2 | %TT_VALSCHECK Checks for valid values. 3 | % 4 | % TT_VALSCHECK(S) throws an error if S is not a valid values 5 | % array, which means that S is a column array. 6 | % 7 | % X = TT_VALSCHECK(S) returns true if S is a valid and false otherwise. 8 | % 9 | %MATLAB Tensor Toolbox. 10 | %Copyright 2012, Sandia Corporation. 11 | 12 | % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. 13 | % http://www.sandia.gov/~tgkolda/TensorToolbox. 14 | % Copyright (2012) Sandia Corporation. Under the terms of Contract 15 | % DE-AC04-94AL85000, there is a non-exclusive license for use of this 16 | % work by or on behalf of the U.S. Government. Export of this data may 17 | % require a license from the United States Government. 18 | % The full license terms can be found in the file LICENSE.txt 19 | 20 | 21 | if isempty(vals) 22 | ok = true; 23 | elseif ndims(vals) == 2 && size(vals,2) == 1 24 | ok = true; 25 | else 26 | ok = false; 27 | end 28 | 29 | if ~ok && nargout == 0 30 | error('Values must be a column array'); 31 | end 32 | -------------------------------------------------------------------------------- /DemoVBM.m: -------------------------------------------------------------------------------- 1 | 2 | % A demo for video background modeling 3 | % Author: Qibin Zhao 2014 4 | 5 | 6 | %% load video data 7 | fpath = strcat('.', filesep, 'videos', filesep); 8 | fname = 'hall'; 9 | % fname = 'WaterSurface'; 10 | % fname = 'ShoppingMall'; 11 | % fname = 'Lobby'; 12 | 13 | load(strcat(fpath,fname)); 14 | 15 | 16 | %% BRCPF for video background and foreground modeling 17 | Y = double(reshape(vid1, [imHeight*imWidth, 3, nFrames])); 18 | Y = Y./255; 19 | timecost =[]; 20 | IV =10; 21 | if isequal(fname,'ShoppingMall') || isequal(fname,'Lobby') 22 | IV = 1; 23 | end 24 | 25 | tic 26 | [model] = BayesRCP(Y, 'init', 'rand', 'maxRank', 10, 'maxiters', 20, 'initVar', IV, 'updateHyper', 'off',... 27 | 'tol', 1e-3, 'dimRed', 1, 'verbose', 1); 28 | timecost(1) = toc; 29 | X = double(ktensor(model.Z)) * 255; 30 | S = model.E * 255; 31 | 32 | 33 | %% Visualization for results 34 | X_BRCPF = reshape(X, [imHeight, imWidth, 3, nFrames]); 35 | S_BRCPF = reshape(S, [imHeight, imWidth, 3, nFrames]); 36 | showbgfg(vid1, X_BRCPF, S_BRCPF); 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /Readme.txt: -------------------------------------------------------------------------------- 1 | Matlab Code of Bayesian Robust Tensor Factorization 2 | 3 | 4 | We provide three demo codes: 5 | I. DemoBayesRCP.m Demonstration on synthesic data. 6 | II. DemoBayesRCP_TC.m Demonstration on synthetic data for the case of incomplete tensor 7 | III. DemoVBM.m Demonstration for video background modeling. 8 | 9 | Reference: 10 | Q. Zhao, G. Zhou, L. Zhang, A. Cichocki, and S. Amari. Bayesian robust tensor factorization for incomplete multiway data. IEEE Transactions on Neural Networks and Learning Systems, 27(4):736–748, 2016. 11 | 12 | % < Bayesian Robust CP Factorization > 13 | % Copyright (C) 2013 Qibin Zhao 14 | -------------------------------------------------------------------------------- /loadpath.m: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | addpath(genpath(pwd)); -------------------------------------------------------------------------------- /videos/Lobby.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qbzhao/BRTF/7704a1d7651f61af8c7eec93e116bfcc0d27fcf1/videos/Lobby.mat -------------------------------------------------------------------------------- /videos/ShoppingMall.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qbzhao/BRTF/7704a1d7651f61af8c7eec93e116bfcc0d27fcf1/videos/ShoppingMall.mat -------------------------------------------------------------------------------- /videos/WaterSurface.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qbzhao/BRTF/7704a1d7651f61af8c7eec93e116bfcc0d27fcf1/videos/WaterSurface.mat -------------------------------------------------------------------------------- /videos/hall.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qbzhao/BRTF/7704a1d7651f61af8c7eec93e116bfcc0d27fcf1/videos/hall.mat --------------------------------------------------------------------------------