├── *A Block Coordinate Descent Method for Regularized Multiconvex Optimization with Applications to Nonnegative Tensor Factorization and Completion.pdf ├── *Tensor Decompositions and Applications.pdf ├── *张量分解.pdf ├── README.md ├── algorithms ├── lrr │ ├── ADM │ │ ├── Atxz.m │ │ ├── Axz.m │ │ ├── adm_lrr.m │ │ ├── ladmp_lrr.m │ │ ├── ladmp_lrr_fast.m │ │ ├── lrr.m │ │ ├── lrra.m │ │ └── lrraffine.m │ ├── ALM │ │ ├── demo.m │ │ ├── exact_alm_lrr_l1v2.m │ │ ├── exact_alm_lrr_l21v2.m │ │ ├── inexact_alm_lrr_l1.m │ │ ├── inexact_alm_lrr_l21.m │ │ ├── solve_l1l2.m │ │ └── solve_lrr.m │ └── ROSL │ │ ├── LowRankDictionaryShrinkage_m.m │ │ ├── LowRankDictionarySparsify_m.m │ │ ├── LowRankDictionaryUpdate_m.m │ │ ├── inexact_alm_rlr.m │ │ ├── inexact_alm_rosl.m │ │ ├── inexact_alm_rosl_subsampling.m │ │ └── test.m ├── mc │ ├── FPC │ │ ├── FPC.m │ │ └── run_FPC.m │ ├── GROUSE │ │ ├── demo.m │ │ ├── grouse.m │ │ └── run_GROUSE.m │ ├── LMaFit-SMS │ │ ├── README │ │ ├── demo_all.m │ │ ├── demo_chkb.m │ │ ├── demo_rand.m │ │ ├── demo_spim.m │ │ └── lmafit_sms_v1.m │ ├── LRGeomCG │ │ ├── cost.m │ │ ├── egrad.m │ │ ├── euclidean_hessian.m │ │ ├── linesearch_helper.m │ │ └── low_rank_matrix_completion.m │ ├── OptSpace │ │ ├── OptSpace.m │ │ ├── run_OptSpace.m │ │ └── testing.m │ └── SVT │ │ ├── SVT.m │ │ ├── Test_SVT.m │ │ └── run_SVT.m ├── nmf │ ├── DRMF │ │ ├── DRMF.m │ │ ├── EffRank.m │ │ ├── GetOptions.m │ │ ├── README.txt │ │ ├── RMSE.m │ │ ├── ShowImages.m │ │ ├── choosvd.m │ │ ├── demo_fgbg.m │ │ ├── exact_alm_rpca.m │ │ ├── inexact_alm_rpca.m │ │ ├── sos.m │ │ ├── svdex.m │ │ └── test_svd.m │ ├── Deep-Semi-NMF │ │ ├── NNDSVD.m │ │ ├── deep_seminmf.m │ │ ├── seminmf.m │ │ └── seminmf_new.m │ ├── ENMF │ │ ├── ExactNMF.m │ │ ├── HALS.m │ │ └── RunMe.m │ ├── LNMF │ │ ├── BuildPatch.m │ │ ├── DEMO.m │ │ ├── DLA.m │ │ ├── DNMF.m │ │ ├── EuDist2.m │ │ ├── FGD.m │ │ ├── FGD_H.m │ │ ├── GetLabel.m │ │ ├── KLC.cpp │ │ ├── KLC.mexw32 │ │ ├── KLC.mexw64 │ │ ├── LDA.m │ │ ├── LNMF.m │ │ ├── LPP.m │ │ ├── MFGD.m │ │ ├── MFGD_H.m │ │ ├── NDLA.m │ │ ├── NMF.m │ │ ├── NPAF.m │ │ ├── PCA.m │ │ ├── RandPartDB.m │ │ ├── RandRandOcc.m │ │ ├── SumC.cpp │ │ ├── SumC.mexw32 │ │ ├── SumC.mexw64 │ │ ├── SumC1.cpp │ │ ├── SumC1.mexw32 │ │ └── constructW.m │ ├── ManhNMF │ │ ├── ApproxFunC.m │ │ ├── Demo.m │ │ ├── GetStopCriterion.m │ │ ├── ManhNMF.m │ │ ├── RandPartDB.m │ │ ├── ShowImage.m │ │ ├── wmedianf.mexw32 │ │ └── wmedianf.mexw64 │ ├── NMF-DTU-Toolbox │ │ ├── compare.m │ │ ├── nmf.m │ │ ├── nmf_als.m │ │ ├── nmf_alsobs.m │ │ ├── nmf_cjlin.m │ │ ├── nmf_euclidean_dist.m │ │ ├── nmf_mm.m │ │ ├── nmf_prob.m │ │ ├── order_comp.m │ │ └── test_toolbox.m │ ├── NeNMF │ │ ├── Demo.m │ │ ├── EuDist2.m │ │ ├── EucliDist2.m │ │ ├── GetStopCriterion.m │ │ ├── NeNMF.m │ │ └── constructW.m │ ├── Semi-NMF │ │ ├── NNDSVD.m │ │ └── seminmf.m │ ├── iNMF │ │ ├── README.txt │ │ ├── example.m │ │ ├── inmf.m │ │ ├── nmf.m │ │ └── ssbinitial.m │ └── nmfLS2 │ │ ├── README.md │ │ ├── computeWeight.m │ │ ├── nmfLS2.m │ │ └── nndSVD.m ├── ntf │ ├── bcuNCP │ │ ├── example_ncp.html │ │ └── ncp.m │ ├── bcuNTD │ │ ├── example_ntd.html │ │ └── ntd.m │ ├── betaNTF │ │ ├── betaNTF.m │ │ └── license.txt │ └── lraNTD │ │ ├── call_tucker_als.m │ │ ├── call_tucker_als_opts.mat │ │ ├── demo_ntd.m │ │ ├── fitness.m │ │ ├── lraNTD_ANLS.m │ │ ├── lraNTD_ANLS.p │ │ ├── readme.m │ │ └── scanparam.m ├── rpca │ ├── ADM │ │ ├── ADM.m │ │ └── run_ADM.m │ ├── ALM │ │ ├── alm.m │ │ └── choosvd.m │ ├── APG │ │ ├── choosvd.m │ │ ├── pos.m │ │ └── proximal_gradient_rpca.m │ ├── APG_PARTIAL │ │ ├── choosvd.m │ │ ├── partial_proximal_gradient_rpca.m │ │ └── pos.m │ ├── AS-RPCA │ │ ├── as_rpca.m │ │ └── test.m │ ├── BRPCA-MD-NSS │ │ ├── Bayesian_RPCAmcmc_MarkovDep_NN.m │ │ └── InitialPara_random_MarkovDep_NN.m │ ├── BRPCA-MD │ │ ├── Bayesian_RPCAmcmc_MarkovDep.m │ │ └── InitialPara_random_MarkovDep.m │ ├── DECOLOR │ │ ├── DECOLOR.m │ │ ├── gco-v3.0 │ │ │ ├── GCO_README.TXT │ │ │ ├── GCoptimization.cpp │ │ │ ├── GCoptimization.h │ │ │ ├── LinkedBlockList.cpp │ │ │ ├── LinkedBlockList.h │ │ │ ├── block.h │ │ │ ├── compile.m │ │ │ ├── energy.h │ │ │ ├── example.cpp │ │ │ ├── graph.cpp │ │ │ ├── graph.h │ │ │ ├── matlab │ │ │ │ ├── GCO_BuildLib.m │ │ │ │ ├── GCO_ComputeEnergy.m │ │ │ │ ├── GCO_Create.m │ │ │ │ ├── GCO_Delete.m │ │ │ │ ├── GCO_ExpandOnAlpha.m │ │ │ │ ├── GCO_Expansion.m │ │ │ │ ├── GCO_GetLabeling.m │ │ │ │ ├── GCO_ListHandles.m │ │ │ │ ├── GCO_LoadLib.m │ │ │ │ ├── GCO_SetDataCost.m │ │ │ │ ├── GCO_SetLabelCost.m │ │ │ │ ├── GCO_SetLabelOrder.m │ │ │ │ ├── GCO_SetLabeling.m │ │ │ │ ├── GCO_SetNeighbors.m │ │ │ │ ├── GCO_SetSmoothCost.m │ │ │ │ ├── GCO_SetVerbosity.m │ │ │ │ ├── GCO_Swap.m │ │ │ │ ├── GCO_UnitTest.m │ │ │ │ ├── README.TXT │ │ │ │ ├── bin │ │ │ │ │ ├── gco_matlab.exp │ │ │ │ │ ├── gco_matlab.lib │ │ │ │ │ ├── gco_matlab.mexw32 │ │ │ │ │ └── gco_matlab.mexw64 │ │ │ │ └── gco_matlab.cpp │ │ │ └── maxflow.cpp │ │ └── internal │ │ │ ├── getGradient.m │ │ │ ├── preAlign.m │ │ │ ├── regImg.m │ │ │ ├── regMGNC.m │ │ │ └── warpImg.m │ ├── DUAL │ │ ├── choosvd.m │ │ ├── dual_rpca.m │ │ ├── dual_rpca_2.m │ │ └── lansvd_d1.m │ ├── EALM │ │ └── exact_alm_rpca.m │ ├── FPCP │ │ └── fastpcp.m │ ├── FW-T │ │ ├── FW_T.m │ │ ├── ProjectOntoL1Ball.m │ │ ├── __README FIRST__ │ │ ├── choosvd.m │ │ ├── demo_FWT.m │ │ ├── fista.m │ │ ├── ista.m │ │ ├── power_method.m │ │ └── startup.m │ ├── GA │ │ ├── LICENSE.txt │ │ ├── README.txt │ │ ├── em_pca.m │ │ ├── grassmann_average.m │ │ ├── grassmann_median.m │ │ ├── private │ │ │ ├── reorth.c │ │ │ ├── reorth.m │ │ │ ├── reorth.mexa64 │ │ │ ├── reorth.mexglx │ │ │ ├── reorth.mexmaci64 │ │ │ ├── reorth.mexw32 │ │ │ └── reorth.mexw64 │ │ ├── test.m │ │ └── trimmed_grassmann_average.m │ ├── GoDec │ │ └── GoDec.m │ ├── GreGoDec │ │ ├── GreBackground.m │ │ ├── GreGoDec.m │ │ └── TestGreGoDec.m │ ├── IALM │ │ └── inexact_alm_rpca.m │ ├── IALM_BLWS │ │ └── inexact_alm_rpca_with_blws.m │ ├── IALM_LMSVDS │ │ └── inexact_alm_rpca_with_lmsvds.m │ ├── L1F │ │ ├── gene_seed.m │ │ ├── ialm_rpca.m │ │ ├── inexact_alm_rpca.m │ │ ├── l1_filter.m │ │ ├── rpca_l1f.m │ │ ├── solve_ml1.m │ │ └── test.m │ ├── LSADM │ │ ├── ALM_SADAL_smoothed.m │ │ ├── Onerun.m │ │ ├── choosvd.m │ │ ├── getdata.m │ │ └── run_LSADM.m │ ├── MBRMF │ │ ├── BRMF.m │ │ ├── MBRMF.m │ │ ├── Utilities │ │ │ ├── countPR.m │ │ │ ├── drawFromIG.m │ │ │ ├── evaluateIGPDF.m │ │ │ ├── filterBlock.m │ │ │ ├── findFMeasure.m │ │ │ └── sampleHyper.m │ │ ├── demo.m │ │ ├── make.m │ │ ├── mex │ │ │ ├── mexutils.c │ │ │ ├── mexutils.h │ │ │ ├── sampleTau.cpp │ │ │ ├── sampleTau.mexw32 │ │ │ └── sampleTau.mexw64 │ │ ├── normalize.m │ │ └── readme.txt │ ├── MoG-RPCA │ │ ├── example.m │ │ ├── logsumexp.m │ │ ├── mog_rpca.m │ │ └── run_MoG_RPCA.m │ ├── NSA1 │ │ ├── README.txt │ │ ├── Subroutines │ │ │ ├── choosvd.m │ │ │ ├── l1proj.m │ │ │ ├── plot_data.m │ │ │ ├── post_noise_removal.m │ │ │ └── theta_search.m │ │ ├── create_data_noisy_L2.m │ │ ├── demo_1.m │ │ ├── demo_2.m │ │ ├── nsa_v1.m │ │ └── nsa_v1_original.m │ ├── NSA2 │ │ ├── choosvd.m │ │ ├── create_data_noisy_L2.m │ │ ├── demo_1.m │ │ ├── demo_2.m │ │ ├── lambda_search.m │ │ ├── nsa_v2.m │ │ ├── nsa_v2_original.m │ │ └── plot_data.m │ ├── OP-RPCA │ │ ├── mr_pca_part.m │ │ └── run_OP_RPCA.m │ ├── OPRMF │ │ ├── normalize.m │ │ ├── onlineRPMF.m │ │ ├── runOnline.m │ │ └── show.m │ ├── PCP │ │ └── PCP.m │ ├── PRMF │ │ ├── README.txt │ │ ├── RPMF.m │ │ ├── normalize.m │ │ ├── runBatch.m │ │ └── show.m │ ├── PSPG │ │ ├── README.txt │ │ ├── Subroutines │ │ │ ├── l1proj.m │ │ │ ├── lambda_search.m │ │ │ └── treshold.m │ │ ├── demo.m │ │ └── pspg.m │ ├── R2PCP │ │ ├── README.txt │ │ ├── data_formation.m │ │ ├── demo_airport_video.m │ │ ├── demo_lobby_video.m │ │ ├── demo_synthetic_data.m │ │ ├── imnorm.m │ │ ├── initialization.m │ │ ├── make_movie.m │ │ ├── model_formation.m │ │ ├── plot_stat.m │ │ ├── proj_fr.m │ │ ├── proj_l0.m │ │ ├── riem_hess.m │ │ ├── riem_optim.m │ │ ├── rtr_fr.m │ │ ├── rtr_l0.m │ │ ├── run_R2PCP.m │ │ ├── slv_lrs_ams.m │ │ └── trimming.m │ ├── RPCA │ │ ├── readme.m │ │ ├── rob_pca.m │ │ ├── rpca_demo.m │ │ ├── run_RPCA.m │ │ └── weighted_pca.m │ ├── RegL1-ALM │ │ ├── RobustApproximation_M_UV_TraceNormReg.m │ │ ├── demo_photometricstereo.m │ │ ├── demo_random.m │ │ └── readme.txt │ ├── SPCP │ │ ├── fista.m │ │ └── ista.m │ ├── SPGL1 │ │ ├── demo_elevatorVideo.m │ │ ├── downloadEscalatorData.m │ │ ├── downloadReferenceSolutions.m │ │ ├── errorFunction.m │ │ ├── loadSyntheticProblem.m │ │ ├── randomizedSVD.m │ │ ├── recreatePaperExperiment.m │ │ ├── solver_RPCA_Lagrangian.m │ │ ├── solver_RPCA_SPGL1.m │ │ ├── solver_RPCA_constrained.m │ │ └── vec.m │ ├── SSGoDec │ │ └── SSGoDec.m │ ├── STOC-RPCA │ │ ├── solve_proj2.m │ │ └── stoc_rpca.m │ ├── SVT │ │ ├── pos.m │ │ ├── singular_value_rpca.m │ │ └── vec.m │ ├── TFOCS │ │ ├── SIAM_demo.m │ │ └── tfocs_interface.m │ └── VBRPCA │ │ ├── Readme.txt │ │ ├── RunVBMC.m │ │ ├── RunVBRPCA.m │ │ ├── VBMC.m │ │ └── VBRPCA.m ├── st │ ├── GOSUS │ │ ├── ReadMe.txt │ │ ├── demo1.m │ │ ├── demo2.m │ │ ├── getGroupNonOverlap.m │ │ ├── getGroupNonOverlapColor.m │ │ ├── getGroupNonOverlapColor27.m │ │ ├── getGroupOverlap.m │ │ ├── getGroupOverlapColor.m │ │ ├── getGroupOverlapColor27.m │ │ ├── getGroupSingle.m │ │ ├── getGroupSuper.m │ │ ├── getGroupSuperColor.m │ │ ├── getGroupSuperColor27.m │ │ ├── getGroupSuperNonOverlap.m │ │ ├── getGroupSuperNonOverlapColor.m │ │ ├── getGroupSuperNonOverlapColor27.m │ │ ├── gosus.bkp.m │ │ ├── gosus.m │ │ ├── initializeSubspace.m │ │ ├── make.m │ │ ├── segImage.m │ │ ├── segImageRegion.m │ │ ├── shrinkageMex.cpp │ │ ├── shrinkageMex.mexmaci64 │ │ ├── shrinkageMex.mexw32 │ │ ├── shrinkageMex.mexw64 │ │ ├── solveWXADMM.m │ │ ├── test.m │ │ ├── testMex.m │ │ ├── testSuperPixel.m │ │ ├── testSuperPixelTime.m │ │ └── updateSubspace.m │ ├── GRASTA │ │ ├── GPL.txt │ │ ├── LGPL.txt │ │ ├── LICENSE.txt │ │ ├── admm_srp.m │ │ ├── bgfg_seperation_grasta.m │ │ ├── bgtraining.m │ │ ├── column.pdf │ │ ├── grasta_RobustMC_demo.m │ │ ├── grasta_mc.m │ │ ├── grasta_path.m │ │ ├── grasta_stream.m │ │ ├── outliers.pdf │ │ ├── run_GRASTA.m │ │ └── video_demo.m │ └── pROST │ │ ├── robustpca_batch.m │ │ ├── robustpca_demo_batch.m │ │ ├── robustpca_demo_incomplete.m │ │ └── testdata.m ├── td │ ├── CP2 │ │ ├── license.txt │ │ └── parafac2.m │ ├── itl │ │ ├── DTA.m │ │ ├── STA.m │ │ ├── WTA.m │ │ ├── grams.m │ │ └── updateW.m │ ├── rlrt │ │ ├── rpca │ │ │ ├── RemoveWhiteSpace.m │ │ │ ├── add_batch_noise_obs.m │ │ │ ├── add_sparse_gross_noise.m │ │ │ ├── check_sep_acc.m │ │ │ ├── choosvd.m │ │ │ ├── compute_tranks.m │ │ │ ├── gen_lowrank_tensor.m │ │ │ ├── gen_syn_data.m │ │ │ ├── get_algs.m │ │ │ ├── horpca_lambda_search.m │ │ │ ├── inexact_alm_rpca.m │ │ │ ├── lowrank_sparse_fista.m │ │ │ ├── matrix_rpca.m │ │ │ ├── plot_batch_tensor_exp_ncx.m │ │ │ ├── plot_noisy_missing.m │ │ │ ├── plot_obs_spa_for_ranks.m │ │ │ ├── plot_obs_spa_rank_analysis.m │ │ │ ├── plot_ranks_obs_for_spa.m │ │ │ ├── plot_ranks_spa_for_obs.m │ │ │ ├── prep_trpca_data.m │ │ │ ├── rpca_cs.m │ │ │ ├── rpca_for_tensor.m │ │ │ ├── run_batch_tensor_exp.m │ │ │ ├── run_batch_tensor_exp_ncx.m │ │ │ ├── shrinkage.m │ │ │ ├── tenInd2matInd.m │ │ │ ├── tenInd2matInd_core.m │ │ │ ├── tensor_rpca_adal.m │ │ │ ├── tensor_rpca_adal2.m │ │ │ ├── tensor_rpca_adal_ncx.m │ │ │ ├── tensor_rpca_tc_adal.m │ │ │ ├── tensor_rpca_tc_adal2.m │ │ │ ├── tensor_rpca_tc_adal_ncx.m │ │ │ ├── tensor_tucker_adal_ncx.m │ │ │ └── test_trpca.m │ │ ├── tc │ │ │ ├── TC_ADAL.m │ │ │ ├── mc_ls_grad.m │ │ │ ├── optimal_mc_ls_Y.m │ │ │ ├── optimal_nuclear_X.m │ │ │ ├── prep_tensor.m │ │ │ ├── ten_sum_all.m │ │ │ └── test_tc.m │ │ └── utils │ │ │ ├── choosvd.m │ │ │ ├── copyright.m │ │ │ ├── get_SNR.m │ │ │ ├── get_markers.m │ │ │ ├── img_matrix2tensor.m │ │ │ ├── matrix_shrinkage.m │ │ │ ├── mysign.m │ │ │ ├── numarray2strarray.m │ │ │ ├── plot_parafac_factors.m │ │ │ ├── plot_tenmat_sv.m │ │ │ ├── qmult.m │ │ │ ├── sample_indices.m │ │ │ ├── scale_matrix.m │ │ │ ├── shrinkage_t.m │ │ │ ├── shrinkage_v.m │ │ │ ├── ten_sum_all.m │ │ │ ├── tensor_1norm.m │ │ │ ├── tensor_array_add.m │ │ │ ├── tensor_array_diff.m │ │ │ ├── tensor_array_innerprod.m │ │ │ ├── tensor_array_norm.m │ │ │ ├── tensor_array_scale.m │ │ │ ├── tensor_hard_thresh.m │ │ │ ├── tensor_shrinkage.m │ │ │ ├── tq_dwt.m │ │ │ └── tq_idwt.m │ └── rstd │ │ ├── RSTD.m │ │ └── utils │ │ ├── HOSVD.m │ │ ├── epp1.c │ │ ├── epp1.m │ │ ├── epp1.mexw32 │ │ ├── epp1.mexw64 │ │ ├── folding.m │ │ ├── iHOSVD.m │ │ ├── smartSVD.m │ │ └── unfolding.m └── ttd │ ├── 3WD │ ├── Run3WD.m │ ├── ThreeWayDec.m │ ├── get_training_images.m │ ├── list_image_files.m │ ├── pos.m │ ├── prepare3WD.m │ ├── run_3WD.m │ └── saveResults.m │ ├── ADMM │ ├── ADMM.m │ ├── avg.m │ ├── matrix_decomp.m │ ├── objective.m │ ├── prox_l1.m │ └── prox_matrix.m │ └── MAMR_RMAMR │ ├── MtOmega.m │ ├── core_MAMR.m │ ├── core_RMAMR.m │ ├── run_MAMR_RMAMR.m │ ├── shrink.m │ └── test_MAMR.m ├── mytensor ├── .gitignore ├── cat.m ├── sktensor │ ├── __init__.py │ ├── core.py │ ├── dtensor.py │ ├── pyutils.py │ └── tucker.py └── tdg.py ├── scikit-tensor ├── .gitignore ├── LICENSE ├── MANIFEST.in ├── README.md ├── data │ └── sensory-bread │ │ ├── bread.txt │ │ └── brod.mat ├── examples │ └── cp_sensory_bread_data.py ├── setup.cfg ├── setup.py └── sktensor │ ├── __init__.py │ ├── core.py │ ├── cp.py │ ├── dedicom.py │ ├── dtensor.py │ ├── indscal.py │ ├── ktensor.py │ ├── pyutils.py │ ├── rescal.py │ ├── setup.py │ ├── sptensor.py │ ├── tests │ ├── __init__.py │ ├── fixtures.py │ ├── test_base.py │ ├── test_dtensor.py │ ├── test_ktensor.py │ ├── test_pyutils.py │ ├── test_sptensor.py │ ├── test_tucker_hooi.py │ └── test_utils.py │ ├── tucker.py │ ├── utils.py │ └── version.py └── tensor_toolbox ├── @ktensor ├── arrange.m ├── datadisp.m ├── disp.m ├── display.m ├── double.m ├── end.m ├── extract.m ├── fixsigns.m ├── full.m ├── innerprod.m ├── isequal.m ├── issymmetric.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 ├── symmetrize.m ├── times.m ├── tocell.m ├── ttm.m ├── ttv.m ├── uminus.m └── uplus.m ├── @sptenmat ├── 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 ├── 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 ├── 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 ├── 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 ├── 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_eq05572125758666918607.png │ ├── D_ktensor_doc.html │ ├── D_ktensor_doc_eq03981049146616847228.png │ ├── D_ktensor_doc_eq06950581413034201722.png │ ├── D_ktensor_doc_eq11724614562625913327.png │ ├── D_ktensor_doc_eq15815821552081582258.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 └── images │ ├── Workspace.png │ ├── banner-background.jpg │ └── logo.gif ├── eig_geap.m ├── eig_sshopm.m ├── eig_sshopmc.m ├── export_data.m ├── helpindex.xml ├── helptoc.xml ├── import_data.m ├── info.xml ├── khatrirao.m ├── matrandcong.m ├── matrandnorm.m ├── matrandorth.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 ├── tendiag.m ├── teneye.m ├── tenones.m ├── tenrand.m ├── tensor_toolbox_product_page.html ├── tenzeros.m ├── tt_cp_fg.m ├── tt_cp_fun.m ├── tt_cp_vec_to_fac.m ├── tt_dimscheck.m ├── tt_fac_to_vec.m ├── tt_ind2sub.m ├── tt_intvec2str.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 └── tucker_sym.m /*A Block Coordinate Descent Method for Regularized Multiconvex Optimization with Applications to Nonnegative Tensor Factorization and Completion.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiangsiwei/tensor_tools/141d0a92d3e01626ca5a709a5a46e6dc57f42032/*A Block Coordinate Descent Method for Regularized Multiconvex Optimization with Applications to Nonnegative Tensor Factorization and Completion.pdf -------------------------------------------------------------------------------- /*Tensor Decompositions and Applications.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiangsiwei/tensor_tools/141d0a92d3e01626ca5a709a5a46e6dc57f42032/*Tensor Decompositions and Applications.pdf -------------------------------------------------------------------------------- /*张量分解.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiangsiwei/tensor_tools/141d0a92d3e01626ca5a709a5a46e6dc57f42032/*张量分解.pdf -------------------------------------------------------------------------------- /algorithms/lrr/ADM/Atxz.m: -------------------------------------------------------------------------------- 1 | function Atz = Atxz(z); 2 | 3 | global A Xg eta M;%A is the skinny SVD of Z_k, Xg is a copy of X, and M=X-E_{k+1}+Y/mu_k. 4 | 5 | %compute Z'*z 6 | temp1 = (A.U)'*z; 7 | temp1 = (A.s).*temp1; 8 | temp1 = (A.V)*temp1; 9 | 10 | %compute X*z 11 | Xz = Xg*z; 12 | 13 | %compute X'*X*z = X'*(X*z)=X'*Xz 14 | temp2 = Xg'*Xz; 15 | 16 | %compute Z'*X'*X*z = Z'*(X'*X*z) = Z'*temp2 17 | temp3 = (A.U)'*temp2; 18 | temp3 = (A.s).*temp3; 19 | temp3 = (A.V)*temp3; 20 | 21 | %compute (X'*(X - X*Z - E - Y/mu))'*z = (M' - Z'*X')*(X*z) 22 | % = M'*Xz - Z'*(X'*Xz) = M'*Xz - temp3 23 | temp4 = M'*Xz - temp3; 24 | 25 | Atz = temp1 + temp4/eta; 26 | 27 | -------------------------------------------------------------------------------- /algorithms/lrr/ADM/Axz.m: -------------------------------------------------------------------------------- 1 | function Az = Axz(z); 2 | 3 | global A Xg eta M;%A is the skinny SVD of Z_k, Xg is a copy of X, and M=X-E_{k+1}+Y/mu_k. 4 | 5 | %compute Z*z 6 | temp1 = (A.V)'*z; 7 | temp1 = (A.s).*temp1; 8 | temp1 = A.U*temp1; 9 | 10 | %compute (X - X*Z - E - Y/mu)*z = (M - X*Z)z = M*z - X*(Z*z) 11 | temp2 = M*z - Xg*temp1; 12 | 13 | %compute X'*(X - X*Z - E - Y/mu)*z 14 | temp3 = Xg'*temp2; 15 | 16 | Az = temp1 + temp3/eta; 17 | 18 | -------------------------------------------------------------------------------- /algorithms/lrr/ALM/solve_l1l2.m: -------------------------------------------------------------------------------- 1 | function [E] = solve_l1l2(W,lambda) 2 | n = size(W,2); 3 | E = W; 4 | for i=1:n 5 | E(:,i) = solve_l2(W(:,i),lambda); 6 | end 7 | end 8 | 9 | function [x] = solve_l2(w,lambda) 10 | % min lambda |x|_2 + |x-w|_2^2 11 | nw = norm(w); 12 | if nw>lambda 13 | x = (nw-lambda)*w/nw; 14 | else 15 | x = zeros(length(w),1); 16 | end 17 | end -------------------------------------------------------------------------------- /algorithms/lrr/ROSL/LowRankDictionaryUpdate_m.m: -------------------------------------------------------------------------------- 1 | function [A, D, alpha] = LowRankDictionaryUpdate_m(A_prev, D_prev, alpha_prev, lambda) 2 | 3 | % min \|E\|_1+ \lambda*(\|D\|_f^2+\|\alpha\|_f^2) s.t. D*\lambda+E=X 4 | 5 | % this function is to update the bases D and coefficients \alpha, over 6 | % the constraint D*\alpha = A_prev, by one iteration of ADM 7 | 8 | % Xianbiao Shu (xshu2@illinois.edu) 9 | % Updated on Aug-10-2011 10 | % Copyright: Mitsubishi Electric Research Lab 11 | 12 | D = A_prev*alpha_prev'*inv(alpha_prev*alpha_prev'+lambda); 13 | alpha = inv(D'*D+ lambda)*D'*A_prev; 14 | 15 | 16 | A = D*alpha; 17 | 18 | end 19 | -------------------------------------------------------------------------------- /algorithms/mc/GROUSE/run_GROUSE.m: -------------------------------------------------------------------------------- 1 | 2 | [numr,numc] = size(M); 3 | I = randi([0 1],numr,numc); % ones(size(M)); 4 | maxrank = 1; 5 | maxCycles = 100; 6 | step_size = 0.1; 7 | 8 | [Usg, Vsg, err_reg] = grouse(M,I,numr,numc,maxrank,step_size,maxCycles); 9 | L = Usg*Vsg'; 10 | S = M - L; 11 | 12 | % show_2dvideo(M,m,n); 13 | % show_2dvideo(M.*I,m,n); 14 | % show_2dvideo(L,m,n); 15 | % show_2dvideo(S,m,n); 16 | -------------------------------------------------------------------------------- /algorithms/mc/LMaFit-SMS/demo_all.m: -------------------------------------------------------------------------------- 1 | % This script runs all 3 demos which can each be run 2 | % individually with different inputs after editing. 3 | 4 | clear; close all; 5 | 6 | RandStream.setDefaultStream(RandStream('mt19937ar','seed',31415)); 7 | 8 | disp('Solver: 1 = LMaFit, 2 = IALM, 1:2 both') 9 | %Solver = input(' Solvers = '); 10 | % Solver = 1:2; 11 | Solver = 1; 12 | 13 | t0 = cputime; 14 | 15 | disp('+++ Results from demo_chkb.m +++') 16 | m = 256; impulse = .75; 17 | demo_chkb(Solver,m,impulse); 18 | set(gcf,'Position',[0 400 1200 400]); drawnow 19 | 20 | disp('+++ Results from demo_spim.m +++') 21 | rankD = 8; impulse = .08; 22 | demo_spim(Solver,rankD,impulse); 23 | 24 | disp('+++ Results from demo_rand.m +++') 25 | m = 400; n = m; rankD = 60; impulse = 0.15; tol = 1e-6; 26 | demo_rand(Solver,m,n,rankD,impulse,tol); 27 | 28 | fprintf('Total CPU: %g seconds\n\n\n',cputime-t0) -------------------------------------------------------------------------------- /algorithms/mc/LRGeomCG/cost.m: -------------------------------------------------------------------------------- 1 | function f = cost(X) 2 | global P; 3 | global PA; 4 | % Note that it is very much inefficient to explicitly construct the 5 | % matrix X in this way. Seen as we only need to know the entries 6 | % of Xmat corresponding to the mask P, it would be far more 7 | % efficient to compute those only. 8 | Xmat = X.U*X.S*X.V'; 9 | f = .5*norm( P.*Xmat - PA , 'fro')^2; 10 | end -------------------------------------------------------------------------------- /algorithms/mc/LRGeomCG/egrad.m: -------------------------------------------------------------------------------- 1 | function G = egrad(X) 2 | global P; 3 | global PA; 4 | % Same comment here about Xmat. 5 | Xmat = X.U*X.S*X.V'; 6 | G = P.*Xmat - PA; 7 | end -------------------------------------------------------------------------------- /algorithms/mc/LRGeomCG/euclidean_hessian.m: -------------------------------------------------------------------------------- 1 | function ehess = euclidean_hessian(X, H) 2 | global P; 3 | global problem; 4 | % The function tangent2ambient transforms H (a tangent vector) into 5 | % its equivalent ambient vector representation. The output is a 6 | % structure with fields U, S, V such that U*S*V' is an mxn matrix 7 | % corresponding to the tangent vector H. Note that there are no 8 | % additional guarantees about U, S and V. In particular, U and V 9 | % are not orthonormal. 10 | ambient_H = problem.M.tangent2ambient(X, H); 11 | Xdot = ambient_H.U*ambient_H.S*ambient_H.V'; 12 | % Same comment here about explicitly constructing the ambient 13 | % vector as an mxn matrix Xdot: we only need its entries 14 | % corresponding to the mask P, and this could be computed 15 | % efficiently. 16 | ehess = P.*Xdot; 17 | end -------------------------------------------------------------------------------- /algorithms/mc/LRGeomCG/linesearch_helper.m: -------------------------------------------------------------------------------- 1 | function t = linesearch_helper(X, H) 2 | % Note that you would not usually need the Hessian for this. 3 | residual_omega = nonzeros(problem.egrad(X)); 4 | dir_omega = nonzeros(problem.ehess(X, H)); 5 | t = - dir_omega \ residual_omega ; 6 | end -------------------------------------------------------------------------------- /algorithms/mc/OptSpace/run_OptSpace.m: -------------------------------------------------------------------------------- 1 | 2 | numr = size(M,1); 3 | numc = size(M,2); 4 | I = randi([0 1],numr,numc); 5 | MI = M.*I; % show_2dvideo(MI,m,n); 6 | tol = 1e-8; 7 | [X,S,Y,dist] = OptSpace(sparse(MI),[],20,tol); 8 | L = X*S*Y'; % show_2dvideo(L,m,n); 9 | S = M - L; 10 | -------------------------------------------------------------------------------- /algorithms/nmf/DRMF/EffRank.m: -------------------------------------------------------------------------------- 1 | function [ r ] = EffRank(s, thresh) 2 | %[ r ] = EffRank(s, thresh) 3 | % get the effective rank of an singular value array 4 | % s: the singular values in descending order 5 | % thresh: the total variance to preserve 6 | % author: Liang Xiong (lxiong@cs.cmu.edu) 7 | 8 | if nargin < 2; thresh = 0.99; end 9 | assert(all(s > 0), 'not a proper singular value array'); 10 | 11 | s = sort(s.^2,'descend'); 12 | cs = cumsum(s); 13 | if cs(end) < 1e-10 14 | error('EffRank has encounted a zero matrix'); 15 | else 16 | r = sum(cs./cs(end) <= thresh) + 1; 17 | r = min(length(s), r); 18 | end 19 | -------------------------------------------------------------------------------- /algorithms/nmf/DRMF/README.txt: -------------------------------------------------------------------------------- 1 | Direct Robust Matrix Factorization (DRMF) Matlab package 2 | 3 | This package contains the code of DRMF, and a demo showing how to do video background extraction using DRMF. 4 | 5 | Developed under Matlab 7.11.0. 6 | 7 | To see how this package works, just run "demo_fgbg.m" directly. 8 | 9 | Acknowledgement: 10 | We thank Yi Ma et al (http://perception.csl.uiuc.edu/matrix-rank/sample_code.html) and Emmanuel Candes et al (http://www-stat.stanford.edu/~candes/svt/code.html) for generously publishing their code. 11 | 12 | Contact: Liang Xiong (lxiong@cs.cmu.edu) 13 | -------------------------------------------------------------------------------- /algorithms/nmf/DRMF/RMSE.m: -------------------------------------------------------------------------------- 1 | function [r]=RMSE(err) 2 | % r = RMSE(err) 3 | % author: Liang Xiong (lxiong@cs.cmu.edu) 4 | 5 | r = sqrt(mean(err(:).^2)); 6 | -------------------------------------------------------------------------------- /algorithms/nmf/DRMF/ShowImages.m: -------------------------------------------------------------------------------- 1 | function [ ims ] = ShowImages( x, sz, cols ) 2 | %[ ims ] = showimages( x,sz,cols ) 3 | %SHOWIMAGES show images 4 | % x: images, each column as an image 5 | % sz: [height weight] 6 | % cols: nubmer of images in a row 7 | % author: Liang Xiong (lxiong@cs.cmu.edu) 8 | 9 | cla; 10 | if isempty(x) 11 | return; 12 | end 13 | 14 | height = sz(1); 15 | width = sz(2); 16 | 17 | x = full(x); 18 | 19 | if nargin < 3 20 | cols = min(size(x,2),floor(800/width)); 21 | end 22 | rows = ceil(size(x,2)/cols); 23 | 24 | ims = zeros(height*rows,width*cols); 25 | for ind = 1:size(x,2) 26 | yy = ceil(ind/cols); 27 | xx = ind - cols*(yy - 1); 28 | ims(((yy-1)*height+1):(yy*height),((xx-1)*width+1):(xx*width)) = ... 29 | reshape(x(:,ind),height,width); 30 | end 31 | 32 | mi = min(x(:)); 33 | ma = max(x(:)) + 1e-2; 34 | if nargout == 0 35 | imshow(ims,[mi ma]); 36 | end 37 | -------------------------------------------------------------------------------- /algorithms/nmf/DRMF/choosvd.m: -------------------------------------------------------------------------------- 1 | function y = choosvd( n, d) 2 | 3 | if n <= 100 4 | if d / n <= 0.02 5 | y = 1; 6 | else 7 | y = 0; 8 | end 9 | elseif n <= 200 10 | if d / n <= 0.06 11 | y = 1; 12 | else 13 | y = 0; 14 | end 15 | elseif n <= 300 16 | if d / n <= 0.26 17 | y = 1; 18 | else 19 | y = 0; 20 | end 21 | elseif n <= 400 22 | if d / n <= 0.28 23 | y = 1; 24 | else 25 | y = 0; 26 | end 27 | elseif n <= 500 28 | if d / n <= 0.34 29 | y = 1; 30 | else 31 | y = 0; 32 | end 33 | else 34 | if d / n <= 0.38 35 | y = 1; 36 | else 37 | y = 0; 38 | end 39 | end -------------------------------------------------------------------------------- /algorithms/nmf/DRMF/sos.m: -------------------------------------------------------------------------------- 1 | function [result]=sos(A, dim) 2 | %[result] = sos(A, dim) 3 | % return the sum of squares 4 | % if dim = 0, then return the total sos 5 | % otherwise, as in sum or mean 6 | % author: Liang Xiong (lxiong@cs.cmu.edu) 7 | 8 | if nargin < 2 9 | dim=0; 10 | end 11 | 12 | if dim == 0 13 | result = sum(A(:).^2); 14 | else 15 | result = sum(A.^2, dim); 16 | end 17 | -------------------------------------------------------------------------------- /algorithms/nmf/DRMF/test_svd.m: -------------------------------------------------------------------------------- 1 | addpath ./propack 2 | addpath ./yima_rpca 3 | addpath ./lib 4 | 5 | X = rand(1000, 1000); 6 | k = 20; 7 | 8 | tic;[U1 s1 V1] = svdex(X, k, struct('svd_solver', 'svd'));t1 = toc; 9 | tic;[U2 s2 V2] = svdex(X, k, struct('svd_solver', 'svds'));t2 = toc; 10 | tic;[U3 s3 V3] = svdex(X, k, struct('svd_solver', 'lansvd', 'init', randn(size(X,1),1)));t3 = toc; 11 | figure; plot(1:k,s1,'r', 1:k,s2,'g^', 1:k,s3,'bv'); 12 | fprintf('Time:\n svd=%fs\n svds=%fs\n lansvd=%fs\n',t1,t2,t3); 13 | 14 | Y1 = bsxfun(@times, U1, s1')*V1'; 15 | err1 = max(abs(X(:) - Y1(:))); 16 | Y2 = bsxfun(@times, U2, s2')*V2'; 17 | err2 = max(abs(X(:) - Y2(:))); 18 | Y3 = bsxfun(@times, U3, s3')*V3'; 19 | err3 = max(abs(X(:) - Y3(:))); 20 | fprintf('Error:\n svd=%f\n svds=%f\n lansvd=%f\n',err1,err2,err3); 21 | -------------------------------------------------------------------------------- /algorithms/nmf/ENMF/RunMe.m: -------------------------------------------------------------------------------- 1 | % Example of using ExactNMF on the slack matrix of the regular 9-gon with 2 | % 1000 attemps 3 | 4 | load SlackMatrices; 5 | [V,W]=ExactNMF(S9gon, 7, 1000); -------------------------------------------------------------------------------- /algorithms/nmf/LNMF/DLA.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiangsiwei/tensor_tools/141d0a92d3e01626ca5a709a5a46e6dc57f42032/algorithms/nmf/LNMF/DLA.m -------------------------------------------------------------------------------- /algorithms/nmf/LNMF/DNMF.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiangsiwei/tensor_tools/141d0a92d3e01626ca5a709a5a46e6dc57f42032/algorithms/nmf/LNMF/DNMF.m -------------------------------------------------------------------------------- /algorithms/nmf/LNMF/FGD.m: -------------------------------------------------------------------------------- 1 | function [H2,Z2,sLen2,iter]=FGD(V,W,H,Z,tol) 2 | 3 | % Fast gradient descent (FGD) with Newton method for NNLS 4 | % Copyright 2010-2012 by Naiyang Guan and Dacheng Tao 5 | % Arguments: 6 | % sLen: step length 7 | 8 | % Calculate scaled negative gradient at W 9 | n=size(V,2); 10 | G=H.*(W'*(V./Z))./(sum(W)'*ones(1,n))-H; 11 | Z1=W*G; 12 | d=sum(sum(Z1)); 13 | C=Z./Z1; 14 | 15 | % Newton method 16 | sLen=1; 17 | for iter=1:20 18 | [sum1,sum2]=SumC1(V,C,sLen); 19 | sLen1=sLen-(d-sum1)/sum2; 20 | if abs(sLen1-sLen)=0 29 | sLen3=Inf; 30 | else 31 | C=H./G; 32 | sLen3=min(-C(C<0)); 33 | end 34 | 35 | % Best step length 36 | sLen2=max(min(sLen1,0.99*sLen3),1); 37 | H2=H+sLen2*G; 38 | Z2=Z+sLen2*Z1; 39 | 40 | return; -------------------------------------------------------------------------------- /algorithms/nmf/LNMF/FGD_H.m: -------------------------------------------------------------------------------- 1 | function [H2,Z2,sLen2,iter]=FGD_H(V,W,H,Z,Lpos,Lneg,tol) 2 | 3 | % Fast gradient descent (FGD) with Newton method for NPAF 4 | % Copyright@Naiyang Guan and Dacheng Tao 5 | % Arguments: 6 | % sLen: step length 7 | 8 | % Calculate scaled negative gradient at H 9 | n=size(H,2); 10 | G=H.*(W'*(V./Z)+H*Lneg)./(sum(W)'*ones(1,n)+H*Lpos)-H; 11 | L=Lpos-Lneg; 12 | Z1=W*G; 13 | a=sum(sum(L.*(G'*G))); 14 | d=sum(sum(L.*(G'*H)))+sum(sum(Z1)); 15 | C=Z./Z1; 16 | 17 | % Newton method 18 | sLen=1; 19 | for iter=1:20, 20 | [sum1,sum2]=SumC1(V,C,sLen); 21 | sLen1=sLen-(a*sLen-sum1+d)/(a+sum2); 22 | if abs(sLen1-sLen)=0 31 | sLen3=Inf; 32 | else 33 | C=H./G; 34 | sLen3=min(-C(C<0)); 35 | end 36 | 37 | % Best step length 38 | sLen2=max(min(sLen1,0.99*sLen3),1); 39 | H2=H+sLen2*G; 40 | Z2=Z+sLen2*Z1; 41 | 42 | return; -------------------------------------------------------------------------------- /algorithms/nmf/LNMF/GetLabel.m: -------------------------------------------------------------------------------- 1 | function newLabel=GetLabel(trnData,tstData,trnLabel) 2 | 3 | % Shared by algorithms. 4 | % copyright @ guan naiyang 5 | 6 | dist=EuDist2(tstData',trnData',0); 7 | [junk, sortedIdx]=sort(dist,2); 8 | newLabel=trnLabel(sortedIdx); 9 | clear dist; 10 | 11 | return; -------------------------------------------------------------------------------- /algorithms/nmf/LNMF/KLC.mexw32: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiangsiwei/tensor_tools/141d0a92d3e01626ca5a709a5a46e6dc57f42032/algorithms/nmf/LNMF/KLC.mexw32 -------------------------------------------------------------------------------- /algorithms/nmf/LNMF/KLC.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiangsiwei/tensor_tools/141d0a92d3e01626ca5a709a5a46e6dc57f42032/algorithms/nmf/LNMF/KLC.mexw64 -------------------------------------------------------------------------------- /algorithms/nmf/LNMF/LDA.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiangsiwei/tensor_tools/141d0a92d3e01626ca5a709a5a46e6dc57f42032/algorithms/nmf/LNMF/LDA.m -------------------------------------------------------------------------------- /algorithms/nmf/LNMF/LNMF.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiangsiwei/tensor_tools/141d0a92d3e01626ca5a709a5a46e6dc57f42032/algorithms/nmf/LNMF/LNMF.m -------------------------------------------------------------------------------- /algorithms/nmf/LNMF/NDLA.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiangsiwei/tensor_tools/141d0a92d3e01626ca5a709a5a46e6dc57f42032/algorithms/nmf/LNMF/NDLA.m -------------------------------------------------------------------------------- /algorithms/nmf/LNMF/NPAF.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiangsiwei/tensor_tools/141d0a92d3e01626ca5a709a5a46e6dc57f42032/algorithms/nmf/LNMF/NPAF.m -------------------------------------------------------------------------------- /algorithms/nmf/LNMF/RandPartDB.m: -------------------------------------------------------------------------------- 1 | function [tr,vd,ts]=RandPartDB(gnd,trNum) 2 | % partition dataset in three subsets 3 | % gnd, class labels 4 | % trNum, feature number selected individually 5 | % copyright @ Guan Naiyang 6 | % modified time: 7 | % 18/4/2010 8 | 9 | lb = unique(gnd); 10 | n = length(gnd); 11 | nn = length(lb); 12 | tr = []; 13 | ts = []; 14 | for j = 1:nn 15 | p_index = find(gnd==lb(j)); 16 | index = randperm(length(p_index)); 17 | tr = [tr, p_index(index(1:trNum))']; 18 | ts = [ts, p_index(index(trNum+1:(2*trNum)))']; 19 | end 20 | vd = 1:n; 21 | vd([tr,ts]) = []; 22 | 23 | return; -------------------------------------------------------------------------------- /algorithms/nmf/LNMF/RandRandOcc.m: -------------------------------------------------------------------------------- 1 | function [fea_o] = RandRandOcc(fea, h_img, w_img, ocld) 2 | 3 | % random position occluding 4 | % author@Guan Naiyang 5 | 6 | n = size(fea,1); 7 | for i = 1:n 8 | a = ceil(rand*(h_img+1-ocld)); 9 | b = ceil(rand*(w_img+1-ocld)); 10 | index = repmat(1:ocld, ocld, 1)'+repmat(0:h_img:(ocld-1)*h_img, ocld, 1); 11 | index = (b-1)*h_img+a-1+reshape(index, 1, ocld*ocld); 12 | fea(i, index) = 0; 13 | end 14 | fea_o = fea; 15 | 16 | return; -------------------------------------------------------------------------------- /algorithms/nmf/LNMF/SumC.mexw32: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiangsiwei/tensor_tools/141d0a92d3e01626ca5a709a5a46e6dc57f42032/algorithms/nmf/LNMF/SumC.mexw32 -------------------------------------------------------------------------------- /algorithms/nmf/LNMF/SumC.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiangsiwei/tensor_tools/141d0a92d3e01626ca5a709a5a46e6dc57f42032/algorithms/nmf/LNMF/SumC.mexw64 -------------------------------------------------------------------------------- /algorithms/nmf/LNMF/SumC1.mexw32: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiangsiwei/tensor_tools/141d0a92d3e01626ca5a709a5a46e6dc57f42032/algorithms/nmf/LNMF/SumC1.mexw32 -------------------------------------------------------------------------------- /algorithms/nmf/ManhNMF/ApproxFunC.m: -------------------------------------------------------------------------------- 1 | function y = ApproxFunC(E,D,lambda) 2 | 3 | % Closed-form Approximated Smoothing Function 4 | % Written by Naiyang Guan (ny.guan@gmail.com) 5 | 6 | X = abs(E)./D; 7 | Y = X-lambda/2; 8 | index = (X <= lambda); 9 | Y(index) = X(index).^2/(lambda*2); 10 | y = sum(sum(Y.*D)); 11 | 12 | return; -------------------------------------------------------------------------------- /algorithms/nmf/ManhNMF/GetStopCriterion.m: -------------------------------------------------------------------------------- 1 | function retVal=GetStopCriterion(stop_rule,X,gradX) 2 | % Stopping Criterions 3 | % Written by Naiyang (ny.guan@gmail.com) 4 | 5 | switch stop_rule 6 | case 1 7 | pGrad=gradX(gradX<0|X>0); 8 | retVal=norm(pGrad); 9 | case 2 10 | pGrad=gradX(gradX<0|X>0); 11 | pGradNorm=norm(pGrad); 12 | retVal=pGradNorm/length(pGrad); 13 | case 3 14 | resmat=min(X,gradX); resvec=resmat(:); 15 | deltao=norm(resvec,1); %L1-norm 16 | num_notconv=length(find(abs(resvec)>0)); 17 | retVal=deltao/num_notconv; 18 | end -------------------------------------------------------------------------------- /algorithms/nmf/ManhNMF/RandPartDB.m: -------------------------------------------------------------------------------- 1 | function [tr,vd,ts]=RandPartDB(gnd,trNum) 2 | % partition dataset in three subsets 3 | % gnd, class labels 4 | % trNum, feature number selected individually 5 | % copyright @ Guan Naiyang 6 | % modified time: 7 | % 18/4/2010 8 | 9 | lb = unique(gnd); 10 | n = length(gnd); 11 | nn = length(lb); 12 | tr = []; 13 | ts = []; 14 | for j = 1:nn 15 | p_index = find(gnd==lb(j)); 16 | index = randperm(length(p_index)); 17 | tr = [tr, p_index(index(1:trNum))']; 18 | ts = [ts, p_index(index(trNum+1:(2*trNum)))']; 19 | end 20 | vd = 1:n; 21 | vd([tr,ts]) = []; 22 | 23 | return; -------------------------------------------------------------------------------- /algorithms/nmf/ManhNMF/wmedianf.mexw32: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiangsiwei/tensor_tools/141d0a92d3e01626ca5a709a5a46e6dc57f42032/algorithms/nmf/ManhNMF/wmedianf.mexw32 -------------------------------------------------------------------------------- /algorithms/nmf/ManhNMF/wmedianf.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiangsiwei/tensor_tools/141d0a92d3e01626ca5a709a5a46e6dc57f42032/algorithms/nmf/ManhNMF/wmedianf.mexw64 -------------------------------------------------------------------------------- /algorithms/nmf/NMF-DTU-Toolbox/compare.m: -------------------------------------------------------------------------------- 1 | function [in_perm,error]=compare(W1,W2) 2 | % 3 | % This functions compares two W'matrices from NMF 4 | % by estimating the permutation and computing the 5 | % normalized LS of the permuted matrix 6 | % 7 | % in_perm is the permutation of W2 to similar it with W1 8 | % error is 1-mean(correff); 9 | [D,K]=size(W1); 10 | covar=zeros(K); 11 | xW1=W1-repmat(mean(W1,1),D,1); 12 | xW2=W2-repmat(mean(W2,1),D,1); 13 | % 14 | stds1=std(W1,[],1); 15 | stds2=std(W2,[],1); 16 | % 17 | for k1=1:K, 18 | % 19 | for k2=1:K, 20 | covar(k1,k2)=abs(sum((xW1(:,k1).*xW2(:,k2)))/D)/(stds1(k1)*stds2(k2)); 21 | end, 22 | end, 23 | % 24 | error=0; 25 | inlist=logical(ones(K,1)); 26 | arrayx=1:K; 27 | for k=1:K, 28 | [dummy,in]=max(covar(k,inlist)); 29 | xarrayx=arrayx(inlist); 30 | in_perm(k)=xarrayx(in); 31 | inlist(xarrayx(in))=0; 32 | error=error+dummy; 33 | end 34 | error=1-(error/K); 35 | -------------------------------------------------------------------------------- /algorithms/nmf/NMF-DTU-Toolbox/nmf_euclidean_dist.m: -------------------------------------------------------------------------------- 1 | function err = nmf_eucl_dist(X,Y) 2 | 3 | err = sum(sum((X-Y).^2)); -------------------------------------------------------------------------------- /algorithms/nmf/NMF-DTU-Toolbox/order_comp.m: -------------------------------------------------------------------------------- 1 | function [W,H,nrgy]=order_comp(W,H) 2 | % 3 | % Order components according to "energy" 4 | % 5 | [D,K]=size(W); 6 | [K,N]=size(H); 7 | % 8 | nrgy=zeros(K,1); 9 | wsum=sum(W,1); 10 | hsum=sum(H,2)'; 11 | nrgy=wsum.*hsum; 12 | [nrgy,index]=sort(-nrgy); 13 | nrgy=-nrgy; 14 | W=W(:,index); 15 | H=H(index,:); -------------------------------------------------------------------------------- /algorithms/nmf/NMF-DTU-Toolbox/test_toolbox.m: -------------------------------------------------------------------------------- 1 | clear 2 | 3 | % create data 4 | %X = rand(1000, 500); 5 | load text_demo/exp_data_med; 6 | X = sparse(X); 7 | 8 | K = 5; 9 | maxiter = 200; 10 | 11 | % run nmf 12 | alg = {'mm', 'cjlin', 'als', 'alsobs', 'prob'}; 13 | %alg = {'prob'} 14 | for i=1:length(alg) 15 | [W{i} H{i}] = nmf(X, K, alg{i}, maxiter, 1); 16 | end 17 | 18 | % calc error 19 | for i=1:length(alg) 20 | dist(i)=nmf_euclidean_dist(X,W{i}*H{i}); 21 | end 22 | [y index] = sort(dist); 23 | 24 | % display error 25 | for i=index 26 | disp(['Euclidean distance ' num2str(dist(i),'%0.2f') ' for algorithm ', alg{i}]); 27 | end 28 | -------------------------------------------------------------------------------- /algorithms/nmf/NeNMF/EucliDist2.m: -------------------------------------------------------------------------------- 1 | %******************************************************************* 2 | % Euclidean distance between two matrixs' column vector 3 | %******************************************************************* 4 | function [D] = EucliDist2(A, B) 5 | 6 | if size(A, 1) == size(B, 1) 7 | D = A'.^2*ones(size(B))+ones(size(A'))*(B).^2-2*A'*B; 8 | else 9 | disp('incorrect input matrix, the first dimension not matched'); 10 | D = 0; 11 | end -------------------------------------------------------------------------------- /algorithms/nmf/NeNMF/GetStopCriterion.m: -------------------------------------------------------------------------------- 1 | function retVal=GetStopCriterion(stop_rule,X,gradX) 2 | % Stopping Criterions 3 | % Written by Naiyang (ny.guan@gmail.com) 4 | 5 | switch stop_rule 6 | case 1 7 | pGrad=gradX(gradX<0|X>0); 8 | retVal=norm(pGrad); 9 | case 2 10 | pGrad=gradX(gradX<0|X>0); 11 | pGradNorm=norm(pGrad); 12 | retVal=pGradNorm/length(pGrad); 13 | case 3 14 | resmat=min(X,gradX); resvec=resmat(:); 15 | deltao=norm(resvec,1); %L1-norm 16 | num_notconv=length(find(abs(resvec)>0)); 17 | retVal=deltao/num_notconv; 18 | end -------------------------------------------------------------------------------- /algorithms/nmf/iNMF/README.txt: -------------------------------------------------------------------------------- 1 | - See example.m to see how the code works. 2 | - Please report any problems or errors to Serhat Bucak: bucakser@msu.edu 3 | - If you use the code, please cite: 4 | S.S. Bucak, B. Gunsel, "Incremental Subspace Learning via Non-negative Matrix Factorization," Pattern Recognition , vol 42(5), pp. 788-797, May 2009. 5 | 6 | -------------------------------------------------------------------------------- /algorithms/nmf/iNMF/example.m: -------------------------------------------------------------------------------- 1 | % Serhat Selcuk Bucak, bucakser@msu.edu 2 | 3 | % Lets assume that all samples are stored in data matrix V (each column is a sample) 4 | 5 | %Execute NMF for the first n samples 6 | %% These number are selected just for demonstration 7 | V=rand(40,500); 8 | n=100; 9 | rdim=10; 10 | maxiter=150; 11 | [W, H, objhistory] = nmf(V(:,1:n), rdim, 0, maxiter); 12 | % Now we can execute inmf on each new samples 13 | maxiter=50; 14 | A=V(:,1:n)*H'; 15 | B=H*H'; 16 | h=H(:,end); % Warm start for h 17 | for i=n+1:size(V,2) 18 | i 19 | V_new=V(:,i); 20 | [W_new, h, A, B] = inmf( V_new, W, h, A, B, rdim, 0.9, 0.1, maxiter); 21 | H_store(:,i-n)=h; %Just for demonstration 22 | end -------------------------------------------------------------------------------- /algorithms/nmf/iNMF/ssbinitial.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiangsiwei/tensor_tools/141d0a92d3e01626ca5a709a5a46e6dc57f42032/algorithms/nmf/iNMF/ssbinitial.m -------------------------------------------------------------------------------- /algorithms/nmf/nmfLS2/README.md: -------------------------------------------------------------------------------- 1 | tfkld 2 | ===== 3 | 4 | Code for the [EMNLP 2013 paper](http://www.cc.gatech.edu/~jeisenst/papers/ji-emnlp-2013.pdf) 5 | 6 | 7 | - computeWeight.m - read the sparse matrix of the training set and compute the KLD weights 8 | - nmfLS2 - Non-negative matrix factorization with sparse matrix 9 | - nndSVD - NNDSVD algorithm for initializing W and H in NMF 10 | 11 | @inproceedings{Ji:2013:EMNLP, 12 |     title = {Discriminative Improvements to Distributional Sentence Similarity}, 13 |     author = {Yangfeng Ji and Jacob Eisenstein} 14 |     booktitle = {EMNLP}, 15 |     year = {2013}, 16 | } 17 | -------------------------------------------------------------------------------- /algorithms/ntf/lraNTD/call_tucker_als_opts.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiangsiwei/tensor_tools/141d0a92d3e01626ca5a709a5a46e6dc57f42032/algorithms/ntf/lraNTD/call_tucker_als_opts.mat -------------------------------------------------------------------------------- /algorithms/ntf/lraNTD/demo_ntd.m: -------------------------------------------------------------------------------- 1 | % ==== VERY IMPORTANT ==== 2 | % This code needs the support of Tensor Toolbox developed by Tamara Kolda 3 | % which is available at: 4 | % http://www.sandia.gov/~tgkolda/TensorToolbox/index-2.5.html 5 | % 6 | clear; 7 | clc; 8 | I=[50,50,50]; 9 | R=[5,6,7]; 10 | N=numel(I); 11 | 12 | % Generate data; 13 | A=cell(N,1); 14 | for n=1:N 15 | A{n}=rand(I(n),R(n)); 16 | end 17 | Y=ttensor(tensor(rand(R)),A); 18 | Y=tensor(Y); 19 | 20 | 21 | opts=struct('NumOfComp',R,'nlssolver','hals','maxiter',100,'maxiniter',20,'tdalgFile','call_tucker_als_opts.mat'); 22 | tic; 23 | [Ydec]=lraNTD_ANLS(Y,opts); 24 | toc; 25 | fprintf('Complete. Fit=%f\n',fitness(Y,Ydec)); 26 | -------------------------------------------------------------------------------- /algorithms/ntf/lraNTD/fitness.m: -------------------------------------------------------------------------------- 1 | function [fit res]=fitness(Y,Ycap,flag) 2 | %% function [fit res]=fitness(Y,Ycap) 3 | 4 | if strcmp(class(Y),'double') 5 | Y=tensor(Y); 6 | end 7 | 8 | 9 | normY=norm(Y); 10 | normYcap=norm(Ycap); 11 | res = abs(sqrt( normY^2 + normYcap^2 - 2 * innerprod(Y,Ycap) )); 12 | fit=1-res/normY; 13 | 14 | if nargin==3 && flag==2 15 | fit(2)=1-(res/normY).^2; 16 | end -------------------------------------------------------------------------------- /algorithms/ntf/lraNTD/lraNTD_ANLS.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiangsiwei/tensor_tools/141d0a92d3e01626ca5a709a5a46e6dc57f42032/algorithms/ntf/lraNTD/lraNTD_ANLS.p -------------------------------------------------------------------------------- /algorithms/ntf/lraNTD/scanparam.m: -------------------------------------------------------------------------------- 1 | function varargout = scanparam(defoptions,options) 2 | % Only proper fileds will be transferred. 3 | % Warnings occur when options contains unexpected filed names or data type. 4 | allfields = fieldnames(options); 5 | opts = defoptions; 6 | for k = 1:numel(allfields) 7 | if isfield(defoptions,allfields{k})&&... 8 | strcmp(class(options.(allfields{k})),class(defoptions.(allfields{k}))) 9 | if ~isempty(options.(allfields{k})) 10 | opts.(allfields{k}) = options.(allfields{k}); 11 | end 12 | else 13 | fprintf(strcat('Warning! Unexpected field name or data type: [',' ',inputname(2),'.',allfields{k},'].\n')); 14 | fprintf('Warning! The corresponding value is not transfered.\n'); 15 | end 16 | end 17 | if nargout > 1 18 | varargout = struct2cell(opts); 19 | else 20 | varargout{1} = opts; 21 | end 22 | end -------------------------------------------------------------------------------- /algorithms/rpca/ADM/run_ADM.m: -------------------------------------------------------------------------------- 1 | t = 0.01; 2 | opts = []; 3 | opts.beta = .25/mean(abs(M(:))); % 0.10; 4 | opts.tol = 1e-6; 5 | opts.maxit = 100; %1000 6 | opts.print = 1; 7 | out = ADM(M, t/(1-t), opts); 8 | L = out.LowRank; 9 | S = out.Sparse; -------------------------------------------------------------------------------- /algorithms/rpca/ALM/choosvd.m: -------------------------------------------------------------------------------- 1 | function y = choosvd(n, d) 2 | 3 | if n <= 100 4 | if d / n <= 0.02 5 | y = 1; 6 | else 7 | y = 0; 8 | end 9 | elseif n <= 200 10 | if d / n <= 0.06 11 | y = 1; 12 | else 13 | y = 0; 14 | end 15 | elseif n <= 300 16 | if d / n <= 0.26 17 | y = 1; 18 | else 19 | y = 0; 20 | end 21 | elseif n <= 400 22 | if d / n <= 0.28 23 | y = 1; 24 | else 25 | y = 0; 26 | end 27 | elseif n <= 500 28 | if d / n <= 0.34 29 | y = 1; 30 | else 31 | y = 0; 32 | end 33 | else 34 | if d / n <= 0.38 35 | y = 1; 36 | else 37 | y = 0; 38 | end 39 | end -------------------------------------------------------------------------------- /algorithms/rpca/APG/choosvd.m: -------------------------------------------------------------------------------- 1 | function y = choosvd( n, d) 2 | 3 | if n <= 100 4 | if d / n <= 0.02 5 | y = 1; 6 | else 7 | y = 0; 8 | end 9 | elseif n <= 200 10 | if d / n <= 0.06 11 | y = 1; 12 | else 13 | y = 0; 14 | end 15 | elseif n <= 300 16 | if d / n <= 0.26 17 | y = 1; 18 | else 19 | y = 0; 20 | end 21 | elseif n <= 400 22 | if d / n <= 0.28 23 | y = 1; 24 | else 25 | y = 0; 26 | end 27 | elseif n <= 500 28 | if d / n <= 0.34 29 | y = 1; 30 | else 31 | y = 0; 32 | end 33 | else 34 | if d / n <= 0.38 35 | y = 1; 36 | else 37 | y = 0; 38 | end 39 | end -------------------------------------------------------------------------------- /algorithms/rpca/APG/pos.m: -------------------------------------------------------------------------------- 1 | function P = pos(A) 2 | 3 | P = A .* double( A > 0 ); -------------------------------------------------------------------------------- /algorithms/rpca/APG_PARTIAL/choosvd.m: -------------------------------------------------------------------------------- 1 | function y = choosvd( n, d) 2 | 3 | if n <= 100 4 | if d / n <= 0.02 5 | y = 1; 6 | else 7 | y = 0; 8 | end 9 | elseif n <= 200 10 | if d / n <= 0.06 11 | y = 1; 12 | else 13 | y = 0; 14 | end 15 | elseif n <= 300 16 | if d / n <= 0.26 17 | y = 1; 18 | else 19 | y = 0; 20 | end 21 | elseif n <= 400 22 | if d / n <= 0.28 23 | y = 1; 24 | else 25 | y = 0; 26 | end 27 | elseif n <= 500 28 | if d / n <= 0.34 29 | y = 1; 30 | else 31 | y = 0; 32 | end 33 | else 34 | if d / n <= 0.38 35 | y = 1; 36 | else 37 | y = 0; 38 | end 39 | end -------------------------------------------------------------------------------- /algorithms/rpca/APG_PARTIAL/pos.m: -------------------------------------------------------------------------------- 1 | function P = pos(A) 2 | 3 | P = A .* double( A > 0 ); -------------------------------------------------------------------------------- /algorithms/rpca/AS-RPCA/test.m: -------------------------------------------------------------------------------- 1 | function [] = test() 2 | %UNTITLED Summary of this function goes here 3 | % Detailed explanation goes here 4 | randn('state',1212412414424234324); 5 | rand('state',1212412414424234324); 6 | dim_ambient = 1000; 7 | dim_r = 10; 8 | M = randn(dim_ambient,dim_r); 9 | N = randn(dim_r,dim_ambient); 10 | D0 = M*N/dim_r; 11 | 12 | E0 = sign(randn(dim_ambient,dim_ambient)); 13 | inds = rand(dim_ambient)<0.7; 14 | E0(inds) = 0; 15 | 16 | D = D0 + E0; 17 | 18 | D_hat = as_rpca(D,0.05,5,1.3); 19 | 20 | error = max(max(abs(D0 - D_hat)))./max(max(abs(D0))); 21 | disp(['recover error=' num2str(error)]); 22 | 23 | D_hat = as_rpca(D,0.05,10,1.3); 24 | 25 | error = max(max(abs(D0 - D_hat)))./max(max(abs(D0))); 26 | disp(['recover error=' num2str(error)]); 27 | 28 | D_hat = as_rpca(D,0.05,15,1.3); 29 | 30 | error = max(max(abs(D0 - D_hat)))./max(max(abs(D0))); 31 | disp(['recover error=' num2str(error)]); 32 | end 33 | 34 | -------------------------------------------------------------------------------- /algorithms/rpca/BRPCA-MD-NSS/InitialPara_random_MarkovDep_NN.m: -------------------------------------------------------------------------------- 1 | function Theta0 = InitialPara_random_MarkovDep_NN(X,K) 2 | if nargin<2 3 | K=150; 4 | end 5 | [P,N]=size(X); 6 | 7 | %--------Initialize Parameter D,S,Z,Pi,gamma_epsi,gamma_s----------------- 8 | D=zeros(P,K); 9 | for k=1:K 10 | D(:,k)=randn(P,1)*sqrt(1/P); 11 | end 12 | 13 | 14 | S=zeros(K,N); 15 | for n=1:N 16 | S(:,n)=randn(K,1); 17 | end 18 | 19 | 20 | Z = zeros(K,1); 21 | %Z = ones(K,1); 22 | Delta = ones(K,1); 23 | Tao = ones(K,1); 24 | Pi = 0.5*ones(K,1); 25 | gamma_epsi = 1e3*ones(1,N); 26 | 27 | %sampe sparse component 28 | gamma_s = 1; 29 | S2 = randn(P,N); 30 | Z2 = zeros(P,N); 31 | Pi2 = 0.5*ones(P,N); 32 | 33 | 34 | 35 | 36 | Theta0.D = D; 37 | Theta0.S = S; 38 | Theta0.Z = Z; 39 | Theta0.Delta = Delta; 40 | Theta0.Tao = Tao; 41 | Theta0.Pi = Pi; 42 | Theta0.gamma_epsi = gamma_epsi; 43 | Theta0.S2 = S2; 44 | Theta0.Z2 = Z2; 45 | Theta0.gamma_s = gamma_s; 46 | Theta0.Pi2 = Pi2; 47 | end -------------------------------------------------------------------------------- /algorithms/rpca/BRPCA-MD/InitialPara_random_MarkovDep.m: -------------------------------------------------------------------------------- 1 | function Theta0 = InitialPara_random_MarkovDep(X,K) 2 | if nargin<2 3 | K=150; 4 | end 5 | [P,N]=size(X); 6 | 7 | %--------Initialize Parameter D,S,Z,Pi,gamma_epsi,gamma_s----------------- 8 | D=zeros(P,K); 9 | for k=1:K 10 | D(:,k)=randn(P,1)*sqrt(1/P); 11 | end 12 | 13 | 14 | S=zeros(K,N); 15 | for n=1:N 16 | S(:,n)=randn(K,1); 17 | end 18 | 19 | 20 | Z = zeros(K,1); 21 | Delta = ones(K,1); 22 | Tao = ones(K,1); 23 | Pi = 0.5*ones(K,1); 24 | gamma_epsi = 100; 25 | %sampe sparse component 26 | %gamma_s = 1e-3; % It's used for simulation 27 | gamma_s = 1; 28 | S2 = randn(P,N); 29 | Z2 = zeros(P,N); 30 | Pi2 = 0.5*ones(P,N); 31 | 32 | 33 | 34 | Theta0.D = D; 35 | Theta0.S = S; 36 | Theta0.Z = Z; 37 | Theta0.Delta = Delta; 38 | Theta0.Tao = Tao; 39 | Theta0.Pi = Pi; 40 | Theta0.gamma_epsi = gamma_epsi; 41 | Theta0.S2 = S2; 42 | Theta0.Z2 = Z2; 43 | Theta0.gamma_s = gamma_s; 44 | Theta0.Pi2 = Pi2; 45 | end -------------------------------------------------------------------------------- /algorithms/rpca/DECOLOR/gco-v3.0/compile.m: -------------------------------------------------------------------------------- 1 | addpath(genpath('C:\abslibrary2\algorithms\rpca\DECOLOR\gco-v3.0')); 2 | GCO_BuildLib -------------------------------------------------------------------------------- /algorithms/rpca/DECOLOR/gco-v3.0/matlab/GCO_ComputeEnergy.m: -------------------------------------------------------------------------------- 1 | function [Energy D S L] = GCO_ComputeEnergy(Handle) 2 | % GCO_ComputeEnergy Run alpha-expansion algorithm. 3 | % E = GCO_ComputeEnergy(Handle) returns energy of current labeling. 4 | % [E D S L] = GCO_ComputeEnergy(Handle) also provides a breakdown of 5 | % the energy into Data, Smooth, and Label costs. 6 | 7 | GCO_LoadLib(); 8 | [Energy D S L] = gco_matlab('gco_computeenergy',Handle); 9 | end 10 | -------------------------------------------------------------------------------- /algorithms/rpca/DECOLOR/gco-v3.0/matlab/GCO_Create.m: -------------------------------------------------------------------------------- 1 | function Handle = GCO_Create(NumSites,NumLabels) 2 | % GCO_Create Create a GCoptimization object. 3 | % Handle = GCO_Create(NumSites,NumLabels) creates a new GCoptimization 4 | % object and returns a 'handle' to uniquely identify it. 5 | % Call GCO_Delete(Handle) to delete the object and free its memory. 6 | % Call GCO_Delete(GCO_ListHandles) to delete all GCO objects. 7 | 8 | GCO_LoadLib(); 9 | if (nargin < 2), error('Expected 2 arguments'); end 10 | Handle = gco_matlab('gco_create_general',int32(NumSites),int32(NumLabels)); 11 | end 12 | -------------------------------------------------------------------------------- /algorithms/rpca/DECOLOR/gco-v3.0/matlab/GCO_Delete.m: -------------------------------------------------------------------------------- 1 | function GCO_Delete(Handle) 2 | % GCO_Delete Delete a GCoptimization object. 3 | % GCO_Delete(Handle) deletes the object corresponding to Handle 4 | % and frees its memory. 5 | 6 | gco_matlab('gco_delete',int32(Handle)); 7 | end 8 | -------------------------------------------------------------------------------- /algorithms/rpca/DECOLOR/gco-v3.0/matlab/GCO_ExpandOnAlpha.m: -------------------------------------------------------------------------------- 1 | function GCO_ExpandOnAlpha(Handle,Alpha) 2 | % GCO_ExpandOnAlpha Perform a single alpha-expansion step. 3 | % GCO_Expansion(Handle,Alpha) takes the current labeling and performs 4 | % a single expansion step on label Alpha. 5 | 6 | GCO_LoadLib(); 7 | gco_matlab('gco_alphaexpansion',Handle,int32(Alpha)); 8 | end 9 | -------------------------------------------------------------------------------- /algorithms/rpca/DECOLOR/gco-v3.0/matlab/GCO_GetLabeling.m: -------------------------------------------------------------------------------- 1 | function Labeling = GCO_GetLabeling(Handle,varargin) 2 | % GCO_GetLabeling Retrieve the current labeling 3 | % GCO_GetLabeling(Handle) returns a column vector of all labels. 4 | % GCO_GetLabeling(Handle,i) returns the label of site i. 5 | % GCO_GetLabeling(Handle,i,count) returns labels i..i+count-1 6 | 7 | GCO_LoadLib(); 8 | Start = int32(1); 9 | Count = gco_matlab('gco_getnumsites',Handle); 10 | if (length(varargin) > 2) 11 | error('Too many input arguments.'); 12 | end 13 | if (length(varargin) >= 1), Start = int32(varargin{1}); Count = int32(1); end 14 | if (length(varargin) == 2), Count = int32(varargin{2}); end 15 | Labeling = gco_matlab('gco_getlabeling',Handle,Start,Count); 16 | end 17 | -------------------------------------------------------------------------------- /algorithms/rpca/DECOLOR/gco-v3.0/matlab/GCO_ListHandles.m: -------------------------------------------------------------------------------- 1 | function Handles = GCO_ListHandles() 2 | % GCO_ListHandles Retrieve handles to all current GCO instances 3 | % Useful for cleaning up GCO instances that are using memory, 4 | % particularly when a script was interrupted. 5 | % Example: 6 | % GCO_Delete(GCO_ListHandles); % delete all GCO instances 7 | 8 | GCO_LoadLib(); 9 | Handles = gco_matlab('gco_listhandles'); 10 | end 11 | -------------------------------------------------------------------------------- /algorithms/rpca/DECOLOR/gco-v3.0/matlab/GCO_LoadLib.m: -------------------------------------------------------------------------------- 1 | function GCO_LoadLib() 2 | % GCO_LoadLib Attempt to load the GCO_MATLAB library. 3 | % GCO_LoadLib is used internally by all other GCO_MATLAB commands 4 | % to compile (if necessary), load, and bind the wrapper library. 5 | 6 | GCO_BuildLib(struct('Force',false)); 7 | if (exist('gco_matlab') ~= 3) 8 | error('Failed to load gco_matlab library'); 9 | end 10 | warning on GCO:int32; 11 | 12 | end 13 | -------------------------------------------------------------------------------- /algorithms/rpca/DECOLOR/gco-v3.0/matlab/GCO_SetLabelOrder.m: -------------------------------------------------------------------------------- 1 | function GCO_SetLabelOrder(Handle,Order) 2 | % GCO_SetLabelOrder Set label order for Expansion/Swap moves. 3 | % GCO_SetLabelOrder(Handle,Order) tells Expansion/Swap to select labels 4 | % in a specific order when Order contains integers from 1..NumLabels. 5 | % By default, Expansion/Swap use a consistent, prescribed order of labels 6 | % in until convergence. 7 | % Example: 8 | % GCO_SetLabelOrder(Handle,5:10); % only operate on labels 5..10 9 | % GCO_SetLabelOrder(Handle,randperm(NumLabels)); % random label order 10 | % 11 | 12 | GCO_LoadLib(); 13 | gco_matlab('gco_setlabelorder',Handle,int32(Order)); 14 | end 15 | -------------------------------------------------------------------------------- /algorithms/rpca/DECOLOR/gco-v3.0/matlab/GCO_SetLabeling.m: -------------------------------------------------------------------------------- 1 | function GCO_SetLabeling(Handle,Labeling) 2 | % GCO_SetLabeling Sets the current labeling 3 | % GCO_SetLabeling(Handle,Labeling) sets the entire labeling. 4 | 5 | GCO_LoadLib(); 6 | if (isnumeric(Labeling)) 7 | NumSites = gco_matlab('gco_getnumsites',Handle); 8 | NumLabels = gco_matlab('gco_getnumlabels',Handle); 9 | if (length(Labeling) ~= NumSites) 10 | error('Labeling must be of length NumSites'); 11 | end 12 | if (~isa(Labeling,'int32')) 13 | if (any(floor(Labeling) ~= Labeling)) 14 | error('Labeling was not integer valued'); 15 | end 16 | Labeling = int32(Labeling); 17 | end 18 | if (min(Labeling) < 1 || max(Labeling) > NumLabels) 19 | error('Label must be in range 1..NumLabels'); 20 | end 21 | gco_matlab('gco_setlabeling',Handle,Labeling); 22 | end 23 | -------------------------------------------------------------------------------- /algorithms/rpca/DECOLOR/gco-v3.0/matlab/GCO_Swap.m: -------------------------------------------------------------------------------- 1 | function Energy = GCO_Swap(Handle,MaxIter) 2 | % GCO_Swap Run alpha-beta-swap algorithm. 3 | % GCO_Swap(Handle) runs alpha-beta-swap until convergence. 4 | % GCO_Swap(Handle,MaxIter) runs at most MaxIter swap cycles. 5 | % Returns the energy of the computed labeling. 6 | % The labeling itself can be retrieved via GCO_GetLabeling. 7 | % The order of expansion can be influenced by GCO_SetLabelOrder. 8 | % 9 | % Note that neither label costs nor sparse data costs are currently 10 | % implement for alpha-beta-swap. 11 | 12 | GCO_LoadLib(); 13 | if (nargin < 1), error('Swap requires handle to GCO instance'); end 14 | if (nargin < 2), MaxIter = 1000000; end 15 | Energy = gco_matlab('gco_swap',Handle,int32(MaxIter)); 16 | end 17 | -------------------------------------------------------------------------------- /algorithms/rpca/DECOLOR/gco-v3.0/matlab/bin/gco_matlab.exp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiangsiwei/tensor_tools/141d0a92d3e01626ca5a709a5a46e6dc57f42032/algorithms/rpca/DECOLOR/gco-v3.0/matlab/bin/gco_matlab.exp -------------------------------------------------------------------------------- /algorithms/rpca/DECOLOR/gco-v3.0/matlab/bin/gco_matlab.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiangsiwei/tensor_tools/141d0a92d3e01626ca5a709a5a46e6dc57f42032/algorithms/rpca/DECOLOR/gco-v3.0/matlab/bin/gco_matlab.lib -------------------------------------------------------------------------------- /algorithms/rpca/DECOLOR/gco-v3.0/matlab/bin/gco_matlab.mexw32: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiangsiwei/tensor_tools/141d0a92d3e01626ca5a709a5a46e6dc57f42032/algorithms/rpca/DECOLOR/gco-v3.0/matlab/bin/gco_matlab.mexw32 -------------------------------------------------------------------------------- /algorithms/rpca/DECOLOR/gco-v3.0/matlab/bin/gco_matlab.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiangsiwei/tensor_tools/141d0a92d3e01626ca5a709a5a46e6dc57f42032/algorithms/rpca/DECOLOR/gco-v3.0/matlab/bin/gco_matlab.mexw64 -------------------------------------------------------------------------------- /algorithms/rpca/DECOLOR/internal/preAlign.m: -------------------------------------------------------------------------------- 1 | function [ImTrans,tau] = preAlign(ImData) 2 | % for pre-alignment 3 | numFrame = size(ImData,3); 4 | ImTrans = ImData; 5 | IDcenter = round(numFrame/2); 6 | tau = zeros(6,numFrame); 7 | numLevel = ceil(log2(max([size(ImData,1),size(ImData,2)])/50))+1; 8 | for i = IDcenter-1:-1:1 9 | disp(['frame: ',num2str(i)]); 10 | [ImTrans(:,:,i),tau(:,i)] = regMGNC(ImTrans(:,:,i+1),ImData(:,:,i),tau(:,i+1),numLevel); 11 | end 12 | for i = IDcenter+1:+1:numFrame 13 | disp(['frame: ',num2str(i)]); 14 | [ImTrans(:,:,i),tau(:,i)] = regMGNC(ImTrans(:,:,i-1),ImData(:,:,i),tau(:,i-1),numLevel); 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /algorithms/rpca/DUAL/choosvd.m: -------------------------------------------------------------------------------- 1 | function y = choosvd( n, d) 2 | 3 | if n <= 100 4 | if d / n <= 0.02 5 | y = 1; 6 | else 7 | y = 0; 8 | end 9 | elseif n <= 200 10 | if d / n <= 0.10 11 | y = 1; 12 | else 13 | y = 0; 14 | end 15 | elseif n <= 300 16 | if d / n <= 0.13 17 | y = 1; 18 | else 19 | y = 0; 20 | end 21 | elseif n <= 400 22 | if d / n <= 0.14 23 | y = 1; 24 | else 25 | y = 0; 26 | end 27 | elseif n <= 500 28 | if d / n <= 0.17 29 | y = 1; 30 | else 31 | y = 0; 32 | end 33 | else 34 | if d / n <= 0.19 35 | y = 1; 36 | else 37 | y = 0; 38 | end 39 | end -------------------------------------------------------------------------------- /algorithms/rpca/FW-T/ProjectOntoL1Ball.m: -------------------------------------------------------------------------------- 1 | function w = ProjectOntoL1Ball(v, b) 2 | % PROJECTONTOL1BALL Projects point onto L1 ball of specified radius. 3 | % 4 | % w = ProjectOntoL1Ball(v, b) returns the vector w which is the solution 5 | % to the following constrained minimization problem: 6 | % 7 | % min ||w - v||_2 8 | % s.t. ||w||_1 <= b. 9 | % 10 | % That is, performs Euclidean projection of v to the 1-norm ball of radius 11 | % b. 12 | % 13 | % Author: John Duchi (jduchi@cs.berkeley.edu) 14 | 15 | if (b < 0) 16 | error('Radius of L1 ball is negative: %2.3f\n', b); 17 | end 18 | u = sort(abs(v),'descend'); 19 | sv = cumsum(u); 20 | rho = find(u > (sv - b) ./ (1:length(u))', 1, 'last'); 21 | theta = max(0, (sv(rho) - b) / rho); 22 | w = sign(v) .* max(abs(v) - theta, 0); 23 | -------------------------------------------------------------------------------- /algorithms/rpca/FW-T/__README FIRST__: -------------------------------------------------------------------------------- 1 | First download: 2 | 3 | CVX: Matlab Software for Disciplined Convex Programming 4 | http://cvxr.com/cvx/download/ 5 | 6 | and install it in: 7 | lrslibrary/libs/cvx 8 | 9 | enjoy! -------------------------------------------------------------------------------- /algorithms/rpca/FW-T/choosvd.m: -------------------------------------------------------------------------------- 1 | function y = choosvd( n, d) 2 | 3 | if n <= 100 4 | if d / n <= 0.02 5 | y = 1; 6 | else 7 | y = 0; 8 | end 9 | elseif n <= 200 10 | if d / n <= 0.06 11 | y = 1; 12 | else 13 | y = 0; 14 | end 15 | elseif n <= 300 16 | if d / n <= 0.26 17 | y = 1; 18 | else 19 | y = 0; 20 | end 21 | elseif n <= 400 22 | if d / n <= 0.28 23 | y = 1; 24 | else 25 | y = 0; 26 | end 27 | elseif n <= 500 28 | if d / n <= 0.34 29 | y = 1; 30 | else 31 | y = 0; 32 | end 33 | else 34 | if d / n <= 0.38 35 | y = 1; 36 | else 37 | y = 0; 38 | end 39 | end -------------------------------------------------------------------------------- /algorithms/rpca/FW-T/startup.m: -------------------------------------------------------------------------------- 1 | addpath('..\FW_SPCP\func'); 2 | addpath('D:\solvers\PROPACK'); 3 | addpath('D:\solvers\cvx'); 4 | cvx_setup; warning off; 5 | -------------------------------------------------------------------------------- /algorithms/rpca/GA/private/reorth.mexa64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiangsiwei/tensor_tools/141d0a92d3e01626ca5a709a5a46e6dc57f42032/algorithms/rpca/GA/private/reorth.mexa64 -------------------------------------------------------------------------------- /algorithms/rpca/GA/private/reorth.mexglx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiangsiwei/tensor_tools/141d0a92d3e01626ca5a709a5a46e6dc57f42032/algorithms/rpca/GA/private/reorth.mexglx -------------------------------------------------------------------------------- /algorithms/rpca/GA/private/reorth.mexmaci64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiangsiwei/tensor_tools/141d0a92d3e01626ca5a709a5a46e6dc57f42032/algorithms/rpca/GA/private/reorth.mexmaci64 -------------------------------------------------------------------------------- /algorithms/rpca/GA/private/reorth.mexw32: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiangsiwei/tensor_tools/141d0a92d3e01626ca5a709a5a46e6dc57f42032/algorithms/rpca/GA/private/reorth.mexw32 -------------------------------------------------------------------------------- /algorithms/rpca/GA/private/reorth.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiangsiwei/tensor_tools/141d0a92d3e01626ca5a709a5a46e6dc57f42032/algorithms/rpca/GA/private/reorth.mexw64 -------------------------------------------------------------------------------- /algorithms/rpca/GA/test.m: -------------------------------------------------------------------------------- 1 | D = 2; % we consider a two-dimensional problem 2 | N = 100; % we will generate 100 observations 3 | 4 | %% Generate a random Covariance matrix 5 | tmp = randn(D); 6 | Sigma = tmp.' * tmp; 7 | 8 | %% Sample from the corresponding Gaussian 9 | X = mvnrnd(zeros(D, 1), Sigma, N); 10 | 11 | %% Estimate the leading component 12 | comp = grassmann_average(M, 1); % the second input is the number of component to estimate 13 | comp = trimmed_grassmann_average(M', 50, 1); 14 | show_2dvideo(comp,m,n); 15 | show_2dvideo(comp(:,1),m,n); 16 | show_2dvideo(comp(:,2),m,n); 17 | show_2dvideo(comp(:,3),m,n); 18 | show_2dvideo(comp(:,4),m,n); 19 | show_2dvideo(comp(:,5),m,n); 20 | 21 | %% Plot the results 22 | plot(X(:, 1), X(:, 2), 'ko', 'markerfacecolor', [255,153,51]./255); 23 | axis equal 24 | hold on 25 | plot(3*[-comp(1), comp(1)], 3*[-comp(2), comp(2)], 'k', 'linewidth', 2) 26 | hold off 27 | axis off -------------------------------------------------------------------------------- /algorithms/rpca/GreGoDec/TestGreGoDec.m: -------------------------------------------------------------------------------- 1 | %load hall1-200; 2 | %[L,S,G,error,time]=GreBackground(XO,2,8,3,[144,176],1e-3,1); 3 | 4 | % load shoppingmall1-200; 5 | % [L,S,G,error,time]=GreBackground(XO,3,6,3,[256,320],1e-3,1); 6 | % 7 | load bootstrap1-200; 8 | [L,S,G,error,time]=GreBackground(XO,3,7,5,[120,160],1e-3,1); 9 | % 10 | % load lobby1-200; 11 | % [L,S,G,error,time]=GreBackground(XO,2,6,3,[128,160],1e-3,1); -------------------------------------------------------------------------------- /algorithms/rpca/L1F/rpca_l1f.m: -------------------------------------------------------------------------------- 1 | function [A_full, E_full, t_seed, t_l1f] = rpca_l1f(D) 2 | %sr = 10; 3 | sr = 1; 4 | sc = sr; 5 | % seed recovery 6 | [A_seed, column_seed, row_seed t_seed] = gene_seed(D, sr, sc); 7 | % l1 filtering 8 | [A_full, E_full, t_l1f] = l1_filter(D, column_seed, row_seed, A_seed); 9 | 10 | -------------------------------------------------------------------------------- /algorithms/rpca/LSADM/choosvd.m: -------------------------------------------------------------------------------- 1 | function y = choosvd( n, d) 2 | 3 | if n <= 100 4 | if d / n <= 0.02 5 | y = 1; 6 | else 7 | y = 0; 8 | end 9 | elseif n <= 200 10 | if d / n <= 0.06 11 | y = 1; 12 | else 13 | y = 0; 14 | end 15 | elseif n <= 300 16 | if d / n <= 0.26 17 | y = 1; 18 | else 19 | y = 0; 20 | end 21 | elseif n <= 400 22 | if d / n <= 0.28 23 | y = 1; 24 | else 25 | y = 0; 26 | end 27 | elseif n <= 500 28 | if d / n <= 0.34 29 | y = 1; 30 | else 31 | y = 0; 32 | end 33 | else 34 | if d / n <= 0.38 35 | y = 1; 36 | else 37 | y = 0; 38 | end 39 | end -------------------------------------------------------------------------------- /algorithms/rpca/LSADM/run_LSADM.m: -------------------------------------------------------------------------------- 1 | opts.D = M; 2 | opts.mu = norm(M)/1.25; 3 | [n1,n2] = size(M); 4 | opts.Xs = M; 5 | opts.Ys = M; 6 | opts.n1 = n1; 7 | opts.n2 = n2; 8 | opts.sigma = 1e-6; 9 | opts.maxitr = 500; 10 | opts.rho = 1/sqrt(n1); 11 | opts.eta_mu = 2/3; 12 | opts.eta_sigma = 2/3; 13 | opts.muf = 1e-6; 14 | opts.sigmaf = 1e-6; 15 | opts.epsilon = 1e-7; 16 | opts.sv = 100; 17 | out_ALM = ALM_SADAL_smoothed(opts.D,opts); 18 | L = out_ALM.X; 19 | S = out_ALM.Y; -------------------------------------------------------------------------------- /algorithms/rpca/MBRMF/Utilities/countPR.m: -------------------------------------------------------------------------------- 1 | function [p r] = countPR(truth, est) 2 | correct = sum(sum(double(truth) + double(est) == 2)); 3 | p = correct / sum(sum(truth)); 4 | r = correct / sum(sum(est)); 5 | end -------------------------------------------------------------------------------- /algorithms/rpca/MBRMF/Utilities/drawFromIG.m: -------------------------------------------------------------------------------- 1 | function out = drawFromIG(theta, chi) 2 | [m, n] = size(theta); 3 | chisq1 = randn(m, n).^2; 4 | out = theta + 0.5*theta./chi .* (theta.*chisq1 - sqrt(4*theta.*chi.*chisq1 + theta.^2.*chisq1.^2) ); 5 | l = (rand(m, n) >= theta./(theta+out)); 6 | out(l) = theta(l).^2 ./ out(l); 7 | end -------------------------------------------------------------------------------- /algorithms/rpca/MBRMF/Utilities/evaluateIGPDF.m: -------------------------------------------------------------------------------- 1 | function res = evaluateIGPDF(mu, lambda, x) 2 | res = 0.5 * log(lambda ./ (2 * pi * x .^ 3)) + (-lambda .* (x - mu) .^ 2 ./ (2 * (mu .^ 2) .* x)); 3 | end -------------------------------------------------------------------------------- /algorithms/rpca/MBRMF/Utilities/filterBlock.m: -------------------------------------------------------------------------------- 1 | function ret = filterBlock(in) 2 | in = in + 1e-8; 3 | % idx = [2 4 5 6 8]; 4 | % in = in(idx, :); 5 | mid = in(5, :); 6 | % ret = sum(abs(bsxfun(@minus, log(mid), log(in)))) / 8; 7 | temp = abs(bsxfun(@minus, log(mid), log(in))); 8 | ret = sum((temp)) / 8; 9 | end -------------------------------------------------------------------------------- /algorithms/rpca/MBRMF/Utilities/findFMeasure.m: -------------------------------------------------------------------------------- 1 | function [fmax S bestTH] = findFMeasure(E, S0) 2 | fmax = 0; 3 | Vth = linspace(min(E(:)), max(E(:)), 10000); 4 | for idx = 1:length(Vth) 5 | th = Vth(idx); 6 | Stmp = abs(E) > th; 7 | [pre rec] = countPR(S0, Stmp); 8 | ftmp = 2*rec*pre/(pre+rec); 9 | if ~isnan(ftmp) && ftmp > fmax 10 | fmax = ftmp; 11 | S = Stmp; 12 | bestTH = th; 13 | end 14 | end 15 | end -------------------------------------------------------------------------------- /algorithms/rpca/MBRMF/Utilities/sampleHyper.m: -------------------------------------------------------------------------------- 1 | function [mu, Lambda] = sampleHyper(U, m, invW_0, beta_0, nu_0, r) 2 | U_bar = mean(U)'; 3 | Sigma_bar = cov(U); 4 | % Sample Lambda_u, W is simplified due to hyperparameter settings 5 | W = inv(invW_0 + m * Sigma_bar + beta_0 * m / (beta_0 + m) * (U_bar * U_bar')); 6 | W = (W + W')/ 2; 7 | Lambda = (wishrnd(W, nu_0 + m)); 8 | % Sample mu_u 9 | tempmu = (m * U_bar) / (beta_0 + m); 10 | lam = chol(inv((beta_0 + m) * Lambda)); 11 | lam = lam'; 12 | mu = lam * randn(r, 1) + tempmu; 13 | end -------------------------------------------------------------------------------- /algorithms/rpca/MBRMF/make.m: -------------------------------------------------------------------------------- 1 | function make 2 | % detect platform 3 | 4 | compstr = computer; 5 | is64bit = strcmp(compstr(end-1:end),'64'); 6 | 7 | 8 | % compilation parameters 9 | 10 | compile_params = cell(0); 11 | if (is64bit) 12 | compile_params{1} = '-largeArrayDims'; 13 | end 14 | 15 | 16 | % Compile files % 17 | 18 | sources = {'mexutils.c'}; 19 | 20 | cd mex 21 | disp('Compiling sampleTau...'); 22 | mex('sampleTau.cpp', sources{:},compile_params{:}); 23 | cd .. -------------------------------------------------------------------------------- /algorithms/rpca/MBRMF/mex/sampleTau.mexw32: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiangsiwei/tensor_tools/141d0a92d3e01626ca5a709a5a46e6dc57f42032/algorithms/rpca/MBRMF/mex/sampleTau.mexw32 -------------------------------------------------------------------------------- /algorithms/rpca/MBRMF/mex/sampleTau.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiangsiwei/tensor_tools/141d0a92d3e01626ca5a709a5a46e6dc57f42032/algorithms/rpca/MBRMF/mex/sampleTau.mexw64 -------------------------------------------------------------------------------- /algorithms/rpca/MBRMF/normalize.m: -------------------------------------------------------------------------------- 1 | function X = normalize(X) 2 | [sizeD1, sizeD2] = size(X); 3 | X = X - ones(sizeD1, 1) * mean(X); 4 | DTD = X' * X; 5 | invTrX = ones(sizeD2, 1) ./ sqrt(diag(DTD)); 6 | mul = ones(sizeD1, 1) * invTrX'; 7 | X =X .* mul; 8 | end -------------------------------------------------------------------------------- /algorithms/rpca/MBRMF/readme.txt: -------------------------------------------------------------------------------- 1 | This is the demo code for: 2 | Naiyan Wang, Dit-Yan Yeung. "Bayesian Robust Matrix Factorization for Image and Video Processing." ICCV2013 3 | Project page: http://winsty.net/brmf.html 4 | 5 | Usage: 6 | 0. Please run make.m the compile the necessary mex file. 7 | 1. Run the demo.m to reproduce the results in section 7.2 of original paper. 8 | 2. You can see three figures which correspond to PCP, BRMF, MBRMF 9 | 10 | If you have any questions, please contact winsty@gmail.com -------------------------------------------------------------------------------- /algorithms/rpca/MoG-RPCA/logsumexp.m: -------------------------------------------------------------------------------- 1 | function s = logsumexp(x, dim) 2 | % Compute log(sum(exp(x),dim)) while avoiding numerical underflow. 3 | % By default dim = 1 (columns). 4 | % Written by Michael Chen (sth4nth@gmail.com). 5 | if nargin == 1, 6 | % Determine which dimension sum will use 7 | dim = find(size(x)~=1,1); 8 | if isempty(dim), dim = 1; end 9 | end 10 | 11 | % subtract the largest in each column 12 | y = max(x,[],dim); 13 | x = bsxfun(@minus,x,y); 14 | s = y + log(sum(exp(x),dim)); 15 | i = find(~isfinite(y)); 16 | if ~isempty(i) 17 | s(i) = y(i); 18 | end 19 | -------------------------------------------------------------------------------- /algorithms/rpca/MoG-RPCA/run_MoG_RPCA.m: -------------------------------------------------------------------------------- 1 | %{ 2 | clear, clc; 3 | load('dataset/trafficdb/traffic_patches.mat'); 4 | V = im2double(imgdb{100}); 5 | [M,m,n,p] = convert_video3d_to_2d(V); 6 | %} 7 | 8 | r = 1; 9 | param.mog_k = 3; 10 | param.lr_init = 'SVD'; 11 | param.maxiter = 100; 12 | param.initial_rank = 2*r; 13 | param.tol = 1e-3; 14 | 15 | lr_prior.a0 = 1e-6; 16 | lr_prior.b0 = 1e-6; 17 | 18 | mog_prior.mu0 = 0; 19 | mog_prior.c0 = 1e-3; 20 | mog_prior.d0 = 1e-3; 21 | mog_prior.alpha0 = 1e-3; 22 | mog_prior.beta0 = 1e-3; 23 | 24 | [lr_model, mog_model, r] = mog_rpca(M, param, lr_prior, mog_prior); 25 | 26 | L = lr_model.U*lr_model.V'; 27 | S = M - L; 28 | 29 | %{ 30 | show_2dvideo(M,m,n); 31 | show_2dvideo(L,m,n); 32 | show_2dvideo(S,m,n); 33 | show_2dvideo(hard_threshold(S),m,n); 34 | %} -------------------------------------------------------------------------------- /algorithms/rpca/NSA1/README.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiangsiwei/tensor_tools/141d0a92d3e01626ca5a709a5a46e6dc57f42032/algorithms/rpca/NSA1/README.txt -------------------------------------------------------------------------------- /algorithms/rpca/NSA1/Subroutines/choosvd.m: -------------------------------------------------------------------------------- 1 | function y = choosvd( n, d) 2 | 3 | if n <= 100 4 | if d / n <= 0.02 5 | y = 1; 6 | else 7 | y = 0; 8 | end 9 | elseif n <= 200 10 | if d / n <= 0.06 11 | y = 1; 12 | else 13 | y = 0; 14 | end 15 | elseif n <= 300 16 | if d / n <= 0.26 17 | y = 1; 18 | else 19 | y = 0; 20 | end 21 | elseif n <= 400 22 | if d / n <= 0.28 23 | y = 1; 24 | else 25 | y = 0; 26 | end 27 | elseif n <= 500 28 | if d / n <= 0.34 29 | y = 1; 30 | else 31 | y = 0; 32 | end 33 | else 34 | if d / n <= 0.38 35 | y = 1; 36 | else 37 | y = 0; 38 | end 39 | end -------------------------------------------------------------------------------- /algorithms/rpca/NSA1/Subroutines/l1proj.m: -------------------------------------------------------------------------------- 1 | function out = l1proj(Sbar,delta) 2 | sbar=Sbar(:); 3 | n=length(sbar); 4 | norm_sbar=norm(sbar); 5 | 6 | if norm_sbar<=delta 7 | out=0; 8 | else 9 | flag = 0; 10 | ssbar = sort(sbar,'descend'); 11 | partialsum=norm_sbar^2; 12 | for i=1:n-1 13 | partialsum=partialsum-ssbar(i)^2; 14 | if i*ssbar(i+1)^2+partialsum1, S=diag(S); sig=1; end 14 | 15 | eps=1e-3; 16 | 17 | % Pu=U*U'; Pv=V*V'; 18 | 19 | M=U'*d*V; 20 | % U_p=d*V-Pu*d*V; V_p=d'*U-Pv*d'*U; 21 | U_p=d*V-U*M; V_p=d'*U-V*M'; 22 | 23 | [Q_u,R_u]=qr(U_p,0); 24 | [Q_v,R_v]=qr(V_p,0); 25 | M1=[diag(S)+M, R_v'; R_u, zeros(n3)]; 26 | [U1,S1,V1]=svd(M1); 27 | S1=diag(S1); S1=S1(1:n3); 28 | U1=[U,Q_u]*U1(:,1:n3); 29 | V1=[V,Q_v]*V1(:,1:n3); 30 | 31 | S1=max(S1,eps); 32 | 33 | if sig==1, S1=diag(S1); end 34 | -------------------------------------------------------------------------------- /algorithms/rpca/R2PCP/rtr_l0.m: -------------------------------------------------------------------------------- 1 | function Y=rtr_l0(X,s) 2 | 3 | [n1,n2]=size(X); 4 | X=X(:); 5 | i1=find(X~=0); 6 | Y=X(i1); 7 | [~,i2]=sort(abs(Y(:)),'descend'); 8 | X(i1(i2(s+1:end)))=0; 9 | Y=reshape(X,n1,n2); 10 | 11 | 12 | %%%% old version %%% 13 | % [n1,n2]=size(X); 14 | % 15 | % Y=X(:); 16 | % [~,ii]=sort(abs(Y(:))); 17 | % Y(ii(1:end-s))=0; 18 | % Y=reshape(Y,n1,n2); 19 | 20 | -------------------------------------------------------------------------------- /algorithms/rpca/RegL1-ALM/readme.txt: -------------------------------------------------------------------------------- 1 | Please run 'demo_random' for an example with randomly generated data, and run 'demo_photometricstereo' for the 2 | (product D or M) nonnegative rank-3 factorization of a human-face sequence. The usage of the main functionality 3 | 'RobustApproximation_M_UV_TraceNormReg' should be quite straightforward. 4 | -------------------------------------------------------------------------------- /algorithms/rpca/SPGL1/downloadEscalatorData.m: -------------------------------------------------------------------------------- 1 | function downloadEscalatorData 2 | if ~exist('escalator_data.mat','file') 3 | % This downloads a 3.7 MB demo 4 | disp('About to download the 3.7 MB video...'); 5 | 6 | baseDirectory = fileparts(mfilename('fullpath')); 7 | disp(baseDirectory) 8 | 9 | urlwrite('http://cvxr.com/tfocs/demos/rpca/escalator_data.mat',... 10 | fullfile(baseDirectory,'escalator_data.mat')); 11 | else 12 | disp('You already have the data file; everything is good'); 13 | end -------------------------------------------------------------------------------- /algorithms/rpca/SPGL1/downloadReferenceSolutions.m: -------------------------------------------------------------------------------- 1 | % Run this script to download the reference files 2 | % (117 MB) 3 | 4 | disp('Downloading 117 MB file of reference solutions'); 5 | unzip(... 6 | 'http://amath.colorado.edu/faculty/becker/code/referenceSolutions_v1.0.zip'); 7 | 8 | -------------------------------------------------------------------------------- /algorithms/rpca/SVT/pos.m: -------------------------------------------------------------------------------- 1 | function P = pos(A) 2 | 3 | P = A .* double( A > 0 ); -------------------------------------------------------------------------------- /algorithms/rpca/SVT/vec.m: -------------------------------------------------------------------------------- 1 | function vecA = vec(A) 2 | 3 | vecA = A(:); -------------------------------------------------------------------------------- /algorithms/st/GOSUS/ReadMe.txt: -------------------------------------------------------------------------------- 1 | This is a preliminary version of the implementation of 2 | 3 | Jia Xu, Vamsi K. Ithapu, Lopamudra Mukherjee, James M. Rehg, Vikas Singh. 4 | GOSUS: Grassmannian Online Subspace Updates with Structured-sparsity. 5 | In Proceedings of International Conference on Computer Vision (ICCV) , December 2013. 6 | 7 | 8 | To run this code, you will need VLFEAT installed. 9 | 10 | Please download the data from and change the data path accordingly. demo1.m and demo2.m shows two settings. 11 | 12 | [1] L. Li, W. Huang, I. Y. H. Gu, and Q. Tian. Statistical modeling of complex backgrounds for foreground object detection. TIP, 13(11):1459?1472, 2004. 13 | [2] K. Toyama, J. Krumm, B. Brumitt, and B. Meyers. Wallflower: Principles and practice of background maintenance. In ICCV, 1999. 14 | 15 | For questions and bug report, please contact jiaxu@cs.wisc.edu. 16 | -------------------------------------------------------------------------------- /algorithms/st/GOSUS/getGroupNonOverlap.m: -------------------------------------------------------------------------------- 1 | function g = getGroupNonOverlap(row, col) 2 | 3 | 4 | % N = (row-2)*(col-2); 5 | N = row * col ; 6 | g = sparse(zeros(N,1)); 7 | g = diag(g); 8 | groupCount = 0; 9 | 10 | 11 | %% build non-overlapping group 12 | for i=2:3:col-1 13 | for j=2:3:row-1 14 | groupCount = groupCount+1; 15 | 16 | g(groupCount, (i-2)*row+j-1 ) = 1; 17 | g(groupCount, (i-2)*row+j ) = 1; 18 | g(groupCount, (i-2)*row+j+1 ) = 1; 19 | g(groupCount, (i-1)*row+j-1 ) = 1; 20 | g(groupCount, (i-1)*row+j ) = 1; 21 | g(groupCount, (i-1)*row+j+1 ) = 1; 22 | g(groupCount, i*row+j-1 ) = 1; 23 | g(groupCount, i*row+j ) = 1; 24 | g(groupCount, i*row+j+1 ) = 1; 25 | 26 | end 27 | end 28 | 29 | g= g'; 30 | 31 | % croping g 32 | g =g(:, 1:groupCount); 33 | end 34 | -------------------------------------------------------------------------------- /algorithms/st/GOSUS/getGroupNonOverlapColor27.m: -------------------------------------------------------------------------------- 1 | function G = getGroupNonOverlapColor27(row, col) 2 | 3 | N = row * col ; 4 | g = sparse(N,N); 5 | 6 | groupCount = 0; 7 | 8 | 9 | %% build non-overlapping group 10 | for i=2:3:col-1 11 | for j=2:3:row-1 12 | groupCount = groupCount+1; 13 | 14 | g(groupCount, (i-2)*row+j-1 ) = 1; 15 | g(groupCount, (i-2)*row+j ) = 1; 16 | g(groupCount, (i-2)*row+j+1 ) = 1; 17 | g(groupCount, (i-1)*row+j-1 ) = 1; 18 | g(groupCount, (i-1)*row+j ) = 1; 19 | g(groupCount, (i-1)*row+j+1 ) = 1; 20 | g(groupCount, i*row+j-1 ) = 1; 21 | g(groupCount, i*row+j ) = 1; 22 | g(groupCount, i*row+j+1 ) = 1; 23 | 24 | end 25 | end 26 | 27 | g= g'; 28 | 29 | 30 | g =g(:, 1:groupCount); 31 | 32 | G = [g;g;g]; 33 | 34 | end 35 | -------------------------------------------------------------------------------- /algorithms/st/GOSUS/getGroupSingle.m: -------------------------------------------------------------------------------- 1 | function g = getGroupSingle(row, col) 2 | 3 | %% each pixel is consist of a single pixel 4 | 5 | N = row*col; 6 | 7 | 8 | g = speye(N); 9 | 10 | end -------------------------------------------------------------------------------- /algorithms/st/GOSUS/getGroupSuper.m: -------------------------------------------------------------------------------- 1 | function G = getGroupSuper(I, param) 2 | 3 | 4 | N = size(I,1) * size(I, 2); 5 | 6 | G = sparse(N,N); 7 | 8 | imlab = vl_xyz2lab(vl_rgb2xyz(I)) ; 9 | imlab = single(imlab); 10 | slicParam = param.superpixel.slicParam; 11 | 12 | groupCount = 0; 13 | for i=1:size(slicParam,1) 14 | 15 | segments = vl_slic(imlab, slicParam(i,1), slicParam(i,2)) ; 16 | segments = segments(:); 17 | 18 | maxLabel = max(segments); 19 | for j = 0:maxLabel 20 | G(:, groupCount+j+1) = segments==j; 21 | end 22 | groupCount = groupCount+ maxLabel+1; 23 | 24 | 25 | end 26 | 27 | % croping G 28 | G =G(:, 1:groupCount); 29 | 30 | % G = G'; 31 | end -------------------------------------------------------------------------------- /algorithms/st/GOSUS/getGroupSuperColor.m: -------------------------------------------------------------------------------- 1 | function G = getGroupSuperColor(I, param) 2 | 3 | 4 | N = size(I,1) * size(I, 2); 5 | 6 | g = sparse(N, N); 7 | 8 | imlab = vl_xyz2lab(vl_rgb2xyz(I)) ; 9 | imlab = single(imlab); 10 | slicParam = param.superpixel.slicParam; 11 | 12 | groupCount = 0; 13 | for i=1:size(slicParam,1) 14 | 15 | segments = vl_slic(imlab, slicParam(i,1), slicParam(i,2)) ; 16 | segments = segments(:); 17 | 18 | maxLabel = max(segments); 19 | for j = 0:maxLabel 20 | g(:, groupCount+j+1) = segments==j; 21 | end 22 | groupCount = groupCount+ maxLabel+1; 23 | 24 | 25 | end 26 | 27 | % croping G 28 | g =g(:, 1:groupCount); 29 | 30 | G = sparse(3*N, 3*groupCount); 31 | G(1:N, 1:groupCount) = g; 32 | G(N+1:2*N, groupCount+1:2*groupCount) = g; 33 | G(2*N+1:3*N, 2*groupCount+1:3*groupCount) = g; 34 | 35 | end -------------------------------------------------------------------------------- /algorithms/st/GOSUS/getGroupSuperColor27.m: -------------------------------------------------------------------------------- 1 | function G = getGroupSuperColor27(I, param) 2 | 3 | 4 | N = size(I,1) * size(I, 2); 5 | 6 | g = sparse(N, N); 7 | 8 | imlab = vl_xyz2lab(vl_rgb2xyz(I)) ; 9 | imlab = single(imlab); 10 | slicParam = param.superpixel.slicParam; 11 | 12 | groupCount = 0; 13 | for i=1:size(slicParam,1) 14 | 15 | segments = vl_slic(imlab, slicParam(i,1), slicParam(i,2)) ; 16 | segments = segments(:); 17 | 18 | maxLabel = max(segments); 19 | for j = 0:maxLabel 20 | g(:, groupCount+j+1) = segments==j; 21 | end 22 | groupCount = groupCount+ maxLabel+1; 23 | 24 | 25 | end 26 | 27 | % croping G 28 | g =g(:, 1:groupCount); 29 | 30 | G = [g;g;g]; 31 | 32 | end -------------------------------------------------------------------------------- /algorithms/st/GOSUS/getGroupSuperNonOverlap.m: -------------------------------------------------------------------------------- 1 | function g = getGroupSuperNonOverlap(I, param) 2 | 3 | 4 | N = size(I,1) * size(I, 2); 5 | 6 | g = sparse(zeros(N,1)); 7 | g = diag(g); 8 | 9 | imlab = vl_xyz2lab(vl_rgb2xyz(I)) ; 10 | imlab = single(imlab); 11 | slicParam = param.superpixel.slicParam; 12 | 13 | groupCount = 0; 14 | 15 | segments = vl_slic(imlab, slicParam(1,1), slicParam(1,2)) ; 16 | segments = segments(:); 17 | 18 | for j = 0:segments(N) 19 | g(:, groupCount+j+1) = segments==j; 20 | end 21 | groupCount = groupCount+ segments(N)+1; 22 | 23 | % croping G 24 | g =g(:, 1:groupCount); 25 | 26 | 27 | 28 | 29 | end -------------------------------------------------------------------------------- /algorithms/st/GOSUS/getGroupSuperNonOverlapColor.m: -------------------------------------------------------------------------------- 1 | function G = getGroupSuperNonOverlapColor(I, param) 2 | 3 | 4 | N = size(I,1) * size(I, 2); 5 | 6 | g = sparse(N,N); 7 | 8 | 9 | imlab = vl_xyz2lab(vl_rgb2xyz(I)) ; 10 | imlab = single(imlab); 11 | slicParam = param.superpixel.slicParam; 12 | 13 | groupCount = 0; 14 | 15 | segments = vl_slic(imlab, slicParam(1,1), slicParam(1,2)) ; 16 | segments = segments(:); 17 | 18 | for j = 0:segments(N) 19 | g(:, groupCount+j+1) = segments==j; 20 | end 21 | groupCount = groupCount+ segments(N)+1; 22 | 23 | % croping G 24 | g =g(:, 1:groupCount); 25 | 26 | % G = [g;g;g]; 27 | 28 | groupCount = size(g,2); 29 | 30 | G = sparse( 3*N, 3*groupCount); 31 | 32 | 33 | G(1:N, 1:groupCount) = g; 34 | G(N+1:2*N, groupCount+1:2*groupCount) =g; 35 | G(2*N+1:3*N, 2*groupCount+1:3*groupCount) =g; 36 | end -------------------------------------------------------------------------------- /algorithms/st/GOSUS/getGroupSuperNonOverlapColor27.m: -------------------------------------------------------------------------------- 1 | function G = getGroupSuperNonOverlapColor27(I, param) 2 | 3 | 4 | N = size(I,1) * size(I, 2); 5 | 6 | g = sparse(zeros(N,1)); 7 | g = diag(g); 8 | 9 | imlab = vl_xyz2lab(vl_rgb2xyz(I)) ; 10 | imlab = single(imlab); 11 | slicParam = param.superpixel.slicParam; 12 | 13 | groupCount = 0; 14 | 15 | segments = vl_slic(imlab, slicParam(1,1), slicParam(1,2)) ; 16 | segments = segments(:); 17 | 18 | for j = 0:segments(N) 19 | g(:, groupCount+j+1) = segments==j; 20 | end 21 | groupCount = groupCount+ segments(N)+1; 22 | 23 | % croping G 24 | g =g(:, 1:groupCount); 25 | 26 | G = [g;g;g]; 27 | 28 | 29 | end -------------------------------------------------------------------------------- /algorithms/st/GOSUS/initializeSubspace.m: -------------------------------------------------------------------------------- 1 | function U = initializeSubspace(inputFolder, imgDir, param) 2 | % initial lize the subspace by svd 3 | 4 | trainSize = min(length(imgDir), param.trainSize); 5 | sampleSize = min(param.sampleSize, trainSize); 6 | 7 | randIndex = randperm(trainSize); 8 | 9 | imageIndex = randIndex(1:sampleSize); 10 | 11 | %imageIndex = randperm(trainSize, sampleSize); 12 | 13 | U0=[]; 14 | for i=1:sampleSize 15 | index = imageIndex(i); 16 | imgPath = [inputFolder, imgDir(index).name]; 17 | im = imread(imgPath); 18 | im = im(:); 19 | U0 = [U0 im]; 20 | end 21 | 22 | [U, D] = svds(double(U0), param.rank); 23 | end -------------------------------------------------------------------------------- /algorithms/st/GOSUS/make.m: -------------------------------------------------------------------------------- 1 | 2 | mex -O -largeArrayDims shrinkageMex.cpp 3 | 4 | 5 | -------------------------------------------------------------------------------- /algorithms/st/GOSUS/segImage.m: -------------------------------------------------------------------------------- 1 | function I_s = segImage(I,S) 2 | 3 | S = single(S); 4 | [cx,cy] = gradient(S); 5 | ccc = (abs(cx)+abs(cy))~=0; 6 | ccc = uint8(ccc)*255; 7 | I_s = I; 8 | I_s(:,:,1) = max(I_s(:,:,1),ccc); 9 | I_s(:,:,2) = min(I_s(:,:,2),255-ccc); 10 | I_s(:,:,3) = min(I_s(:,:,3),255-ccc); 11 | -------------------------------------------------------------------------------- /algorithms/st/GOSUS/segImageRegion.m: -------------------------------------------------------------------------------- 1 | function I_s = segImageRegion(I,S) 2 | 3 | I_s = I; 4 | I_s1 = I(:,:,1); 5 | I_s2 = I(:,:,2); 6 | I_s3 = I(:,:,3); 7 | 8 | for i=1:max(S(:)) 9 | 10 | mask = S==i; 11 | 12 | % I_s(mask) = mean(I(mask)); 13 | I_s1(mask) = mean(I_s1(mask)); 14 | I_s2(mask) = mean(I_s2(mask)); 15 | I_s3(mask) = mean(I_s3(mask)); 16 | 17 | I_s(:,:,1) = I_s1; 18 | I_s(:,:,2) = I_s2; 19 | I_s(:,:,3) = I_s3; 20 | end 21 | 22 | end 23 | -------------------------------------------------------------------------------- /algorithms/st/GOSUS/shrinkageMex.mexmaci64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiangsiwei/tensor_tools/141d0a92d3e01626ca5a709a5a46e6dc57f42032/algorithms/st/GOSUS/shrinkageMex.mexmaci64 -------------------------------------------------------------------------------- /algorithms/st/GOSUS/shrinkageMex.mexw32: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiangsiwei/tensor_tools/141d0a92d3e01626ca5a709a5a46e6dc57f42032/algorithms/st/GOSUS/shrinkageMex.mexw32 -------------------------------------------------------------------------------- /algorithms/st/GOSUS/shrinkageMex.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiangsiwei/tensor_tools/141d0a92d3e01626ca5a709a5a46e6dc57f42032/algorithms/st/GOSUS/shrinkageMex.mexw64 -------------------------------------------------------------------------------- /algorithms/st/GOSUS/testSuperPixelTime.m: -------------------------------------------------------------------------------- 1 | clc 2 | clear 3 | close all 4 | 5 | % I = imread('~/research/dataset/stat-background-substraction/WaterSurface/WaterSurface1632.bmp'); 6 | 7 | % I = imread('~/research/dataset/stat-background-substraction/Campus/trees1792.bmp'); 8 | 9 | 10 | I = imread('/home/jxu/research/dataset/wallflower-background-substraction/WavingTrees/b00247.bmp'); 11 | 12 | 13 | 14 | % I = imread('./41006.jpg'); 15 | % I = imread('./b00247.bmp'); 16 | 17 | 18 | 19 | % segment = vl_slic(I,10,2); 20 | imlab = vl_xyz2lab(vl_rgb2xyz(single(I))) ; 21 | imlab = single(imlab); 22 | tic 23 | segments = vl_slic(imlab, 5, 0.1) ; 24 | toc 25 | 26 | 27 | 28 | 29 | 30 | tic 31 | segments = vl_slic(imlab, 20, 0.1) ; 32 | toc 33 | 34 | 35 | tic 36 | segments = vl_slic(imlab, 20, 0.01) ; 37 | 38 | toc -------------------------------------------------------------------------------- /algorithms/st/GOSUS/updateSubspace.m: -------------------------------------------------------------------------------- 1 | function U_out = updateSubspace(U_in, residual, w, param) 2 | % update U 3 | 4 | eta = param.eta; 5 | residualNorm = norm(residual); 6 | wNorm = norm(w); 7 | 8 | sigma = param.lambda * residualNorm * wNorm; 9 | 10 | p = residual / residualNorm; 11 | 12 | q = w / wNorm; 13 | 14 | % t = eta * sigma; % dynamic size 15 | 16 | t =eta; 17 | 18 | U_out = U_in + (cos(t)-1) * U_in * (q * q') - sin(t) * p * q'; 19 | 20 | % normU = norm(U_out) 21 | % diffI = norm(U_out'*U_out - eye(size(U_out,2))) 22 | end 23 | 24 | 25 | -------------------------------------------------------------------------------- /algorithms/st/GRASTA/LICENSE.txt: -------------------------------------------------------------------------------- 1 | The GRASTA Matlab / C++ library is provided without any warranty 2 | of fitness for any purpose. You can redistribute the library 3 | and/or modify it under the terms of the GNU Lesser General 4 | Public License (LGPL) as published by the Free Software 5 | Foundation, either version 3 of the License or (at your option) 6 | any later version. 7 | 8 | Note that the LGPL v3 is formulated as an extension/modification 9 | of the GPL v3 license, providing additional permissions. 10 | For example, programs that use GRASTA can be distributed under 11 | a different license, provided some conditions are met. 12 | 13 | A copy of the LGPL and GPL licenses is provided in this package. 14 | 15 | More info: http://www.opensource.org/licenses 16 | -------------------------------------------------------------------------------- /algorithms/st/GRASTA/column.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiangsiwei/tensor_tools/141d0a92d3e01626ca5a709a5a46e6dc57f42032/algorithms/st/GRASTA/column.pdf -------------------------------------------------------------------------------- /algorithms/st/GRASTA/grasta_path.m: -------------------------------------------------------------------------------- 1 | function grasta_path(BaseDirectory) 2 | fprintf('Setting necessary paths ... \n'); 3 | 4 | if nargin==0 5 | Prefix = [pwd filesep]; 6 | else 7 | Prefix = [BaseDirectory filesep]; 8 | end 9 | appendpath(Prefix); 10 | appendpath([Prefix 'Mex']); 11 | appendpath([Prefix 'util']); 12 | appendpath([Prefix 'make_video']); 13 | 14 | fprintf('Disabling case sensitivity warning ... \n'); 15 | warning('off','MATLAB:dispatcher:InexactMatch'); 16 | end 17 | 18 | function appendpath(string) 19 | fprintf('\t%s \n', string); 20 | addpath(genpath(string)); 21 | end 22 | 23 | 24 | -------------------------------------------------------------------------------- /algorithms/st/GRASTA/outliers.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiangsiwei/tensor_tools/141d0a92d3e01626ca5a709a5a46e6dc57f42032/algorithms/st/GRASTA/outliers.pdf -------------------------------------------------------------------------------- /algorithms/st/GRASTA/video_demo.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiangsiwei/tensor_tools/141d0a92d3e01626ca5a709a5a46e6dc57f42032/algorithms/st/GRASTA/video_demo.m -------------------------------------------------------------------------------- /algorithms/td/itl/grams.m: -------------------------------------------------------------------------------- 1 | function [Q, R] = grams(A) 2 | 3 | % grams Gram-Schmidt orthogonalization of the columns of A. 4 | % The columns of A are assumed to be linearly independent. 5 | % 6 | % Q = grams(A) returns an m by n matrix Q whose columns are 7 | % an orthonormal basis for the column space of A. 8 | % 9 | % [Q, R] = grams(A) returns a matrix Q with orthonormal columns 10 | % and an invertible upper triangular matrix R so that A = Q*R. 11 | % 12 | % Warning: For a more stable algorithm, use [Q, R] = qr(A, 0) . 13 | 14 | [m, n] = size(A); 15 | Asave = A; 16 | for j = 1:n 17 | for k = 1:j-1 18 | mult = (A(:, j)'*A(:, k)) / (A(:, k)'*A(:, k)); 19 | A(:, j) = A(:, j) - mult*A(:, k); 20 | end 21 | end 22 | for j = 1:n 23 | if norm(A(:, j)) < sqrt(eps) 24 | error('Columns of A are linearly dependent.') 25 | end 26 | Q(:, j) = A(:, j) / norm(A(:, j)); 27 | end 28 | R = Q'*Asave; 29 | -------------------------------------------------------------------------------- /algorithms/td/itl/updateW.m: -------------------------------------------------------------------------------- 1 | %update w(t) to w(t+1) 2 | %para: 3 | %j: index of output y 4 | %old_w: W matrix 5 | %X: the input vector X(t) 6 | %lambda: forgetting factor between [0,1] 7 | %---------------------------------------------------------------- 8 | % Copyright: 2005, 9 | % Spiros Papadimitriou, Jimeng Sun, Christos Faloutsos. 10 | % All rights reserved. 11 | % Please address questions or comments to: jimeng@cs.cmu.edu 12 | %---------------------------------------------------------------- 13 | function [w,d,x]=updateW(old_x, old_w,old_d, lambda) 14 | y=old_w'*old_x; 15 | d=lambda*old_d+y^2; 16 | e=old_x-old_w*y; 17 | w=old_w+e*y/d; 18 | x=old_x-w*y; 19 | w=w/norm(w); -------------------------------------------------------------------------------- /algorithms/td/rlrt/rpca/add_sparse_gross_noise.m: -------------------------------------------------------------------------------- 1 | function data = add_sparse_gross_noise( data_name, spa, mag, frac, doSave ) 2 | % add sparse impulsive noise 3 | % sample frac portion of data 4 | 5 | if isstruct( data_name ) 6 | data = data_name; 7 | doSave = false; 8 | else 9 | load( ['..\..\data\',data_name] ); 10 | end 11 | N = length( size(data.X) ); 12 | x = tenmat( data.X, [1:N] ); 13 | m = size( x, 1 ); 14 | I = randperm( m )'; 15 | Nnoise = ceil(m*spa); 16 | noiseI = I( 1:Nnoise ); 17 | x( noiseI ) = x( noiseI ) + random( 'unif', -mag, mag, Nnoise, 1 ); 18 | data.T = tensor( x ); 19 | data.noiseI = noiseI; 20 | data.noise = mag; 21 | 22 | Nobs = ceil(m*frac); 23 | linInd = I( 1:Nobs ); 24 | data.b = data.T(linInd); 25 | data.linInd = linInd; 26 | data.frac = frac; 27 | 28 | if ~exist( 'doSave', 'var' ) || doSave 29 | save( ['..\..\data\',data_name,'-n'], 'data' ); 30 | end 31 | end -------------------------------------------------------------------------------- /algorithms/td/rlrt/rpca/check_sep_acc.m: -------------------------------------------------------------------------------- 1 | function [ acc, acc1 ] = check_sep_acc( E, truth ) 2 | 3 | img = double( E( :, :, 100 ) ); 4 | img( img > 0.1 ) = 1; 5 | img( img <= 0.1 ) = 0; 6 | acc1 = sum( img(:) == truth(:) ) / (size(img,1) * size(img,2)); 7 | 8 | % base acc (when img is completely black) 9 | img = zeros( size(img) ); 10 | acc0 = sum( img(:) == truth(:) ) / (size(img,1) * size(img,2)); 11 | 12 | acc = (acc1 - acc0) / (1-acc0); 13 | 14 | end -------------------------------------------------------------------------------- /algorithms/td/rlrt/rpca/choosvd.m: -------------------------------------------------------------------------------- 1 | function y = choosvd( n, d) 2 | 3 | if n <= 100 4 | if d / n <= 0.02 5 | y = 1; 6 | else 7 | y = 0; 8 | end 9 | elseif n <= 200 10 | if d / n <= 0.06 11 | y = 1; 12 | else 13 | y = 0; 14 | end 15 | elseif n <= 300 16 | if d / n <= 0.26 17 | y = 1; 18 | else 19 | y = 0; 20 | end 21 | elseif n <= 400 22 | if d / n <= 0.28 23 | y = 1; 24 | else 25 | y = 0; 26 | end 27 | elseif n <= 500 28 | if d / n <= 0.34 29 | y = 1; 30 | else 31 | y = 0; 32 | end 33 | else 34 | if d / n <= 0.38 35 | y = 1; 36 | else 37 | y = 0; 38 | end 39 | end -------------------------------------------------------------------------------- /algorithms/td/rlrt/rpca/compute_tranks.m: -------------------------------------------------------------------------------- 1 | function [ rankSum, normRank ] = compute_tranks( Rs, rs ) 2 | 3 | N = length(rs); 4 | temp = zeros( 1, N ); 5 | for i = 1:N 6 | temp(i) = min( rs(i), prod(rs)/rs(i) ); 7 | end 8 | rankSum = sum( temp ); 9 | normRank = halfNorm( 1./Rs ) * halfNorm( rs ); 10 | 11 | end 12 | 13 | function val = halfNorm( x ) 14 | 15 | val = mean( sqrt(x) )^2; 16 | 17 | end -------------------------------------------------------------------------------- /algorithms/td/rlrt/rpca/gen_lowrank_tensor.m: -------------------------------------------------------------------------------- 1 | function data = gen_lowrank_tensor( Rs, rs ) 2 | % Rs and rs are vectors of ranks 3 | 4 | % generate the core 5 | N = length(Rs); 6 | G = tensor( randn( rs ) ); 7 | U = cell( 1, N ); 8 | 9 | % generate orthonormal factors 10 | for i = 1:N 11 | Ui = qmult( Rs(i) ); 12 | U{i} = Ui(:,1:rs(i)); % Ri x ri 13 | end 14 | 15 | % multiply the factors to the core 16 | data.X = ttm( G, U, 1:N ); 17 | data.rank = rs; 18 | 19 | end -------------------------------------------------------------------------------- /algorithms/td/rlrt/rpca/gen_syn_data.m: -------------------------------------------------------------------------------- 1 | function data = gen_syn_data( dataname, Iobs, Inoise, Imag, Irep ) 2 | 3 | if isstruct( dataname ) 4 | data = dataname; 5 | else 6 | load( ['..\..\data\', dataname] ); 7 | end 8 | 9 | dtemp.X = data.X; 10 | dtemp.noise = data.mag(Imag); 11 | dtemp.linInd = data.obs{Iobs}(:,Irep); 12 | dtemp.noiseI = data.noise{Inoise}(Irep).ind; 13 | dtemp.T = data.X; 14 | dtemp.T(dtemp.noiseI) = dtemp.T(dtemp.noiseI) + data.noise{Inoise}(Irep).val(Imag); 15 | dtemp.b = dtemp.T( dtemp.linInd ); 16 | 17 | data = dtemp; 18 | end -------------------------------------------------------------------------------- /algorithms/td/rlrt/rpca/get_algs.m: -------------------------------------------------------------------------------- 1 | function algs = get_algs 2 | 3 | % algs = { 'HORPCA-ADAL', 'HORPCA-TC-ADAL', 'RPCA', 'HORPCA-MIX-ADAL', ... 4 | % 'HORPCA-MIX-TC-ADAL', 'HORPCA-TRMALM', 'HORPCA-MIX-FISTA', ... 5 | % 'HORPCA-FISTA', 'HORPCA-TC-ADAL-ADP', 'RPCA-CS' }; 6 | 7 | algs = { 'HORPCA-S', 'HORPCA-S', 'RPCA', 'HORPCA-M', ... 8 | 'HORPCA-M', 'TR-MALM', 'HORPCA-MP', ... 9 | 'HORPCA-SP', 'HORPCA-S-ADP', 'HORPCA-S-NCX', 'HORPCA-S-NCX', ... 10 | 'TUCKER-ADAL' }; 11 | 12 | end -------------------------------------------------------------------------------- /algorithms/td/rlrt/rpca/matrix_rpca.m: -------------------------------------------------------------------------------- 1 | function results = matrix_rpca( data, params ) 2 | 3 | 4 | end -------------------------------------------------------------------------------- /algorithms/td/rlrt/rpca/plot_noisy_missing.m: -------------------------------------------------------------------------------- 1 | function plot_noisy_missing( dataname ) 2 | 3 | load( ['..\..\',dataname] ); 4 | 5 | 6 | end -------------------------------------------------------------------------------- /algorithms/td/rlrt/rpca/plot_obs_spa_rank_analysis.m: -------------------------------------------------------------------------------- 1 | 2 | gen_many_lr_tensors( 20 ); 3 | 4 | stats1 = plot_obs_spa_for_ranks( 1, false ); 5 | 6 | stats2 = plot_ranks_spa_for_obs( 3, false ); 7 | 8 | stats3 = plot_ranks_obs_for_spa( 7, false ); -------------------------------------------------------------------------------- /algorithms/td/rlrt/rpca/prep_trpca_data.m: -------------------------------------------------------------------------------- 1 | function T = prep_trpca_data( impath, dataname, scale ) 2 | 3 | % impath = the root dir of the images 4 | 5 | if ~exist( 'scale', 'var' ) || isempty( scale ) 6 | scale = 1.0; 7 | end 8 | 9 | files = dir( [impath, '\*.bmp'] ); 10 | N = length( files ); 11 | % N = N - 1; 12 | img = imresize( imread( [impath, '\', files(1).name], 'bmp' ), scale ); 13 | img = rgb2gray( img ); 14 | sz = size( img ); lsz = length(sz); 15 | sz(lsz+1) = N; 16 | X = zeros( sz ); 17 | 18 | for i = 1:N 19 | img = imresize( imread( [impath, '\', files(i).name], 'bmp' ), scale ); 20 | img = rgb2gray( img ); 21 | if lsz == 2 22 | X( :, :, i ) = double(img) / 255; 23 | else 24 | X( :, :, :, i ) = double(img) / 255; 25 | end 26 | end 27 | 28 | % img = imresize( imread( [impath, '\', files(N+1).name], 'bmp' ), scale ); 29 | % img = rgb2gray( img ); 30 | % data.truth = double(img) / 255; 31 | 32 | T = tensor( X ); 33 | 34 | data.X = T; 35 | 36 | save( ['..\..\data\',dataname], 'data' ); 37 | end -------------------------------------------------------------------------------- /algorithms/td/rlrt/rpca/shrinkage.m: -------------------------------------------------------------------------------- 1 | function sol = shrinkage( p, alpha ) 2 | % For L1 regularization 3 | % solves min_x 0.5*|x-p|^2 + alpha*|x| 4 | % p is a tenmat 5 | 6 | pv = double( p ); 7 | temp = abs(pv) - alpha; 8 | temp( temp < 0 ) = 0; 9 | solv = temp .* sign(pv); 10 | sol = tenmat( solv, p.rdims, p.cdims, p.tsize ); 11 | 12 | end -------------------------------------------------------------------------------- /algorithms/td/rlrt/rpca/tenInd2matInd.m: -------------------------------------------------------------------------------- 1 | function data = tenInd2matInd( dataname, mode ) 2 | % convert the indices in Omega w.r.t. the data tensor to indices w.r.t. the 3 | % mode-i unfolding of the tensor 4 | 5 | datapath = ['..\..\data\',dataname]; 6 | load( datapath ); 7 | data = tenInd2matInd_core( data, mode ); 8 | 9 | save( datapath, 'data' ); 10 | end -------------------------------------------------------------------------------- /algorithms/td/rlrt/rpca/tenInd2matInd_core.m: -------------------------------------------------------------------------------- 1 | function data = tenInd2matInd_core( data, mode ) 2 | 3 | tcube = tenzeros( size(data.T) ); 4 | tcube( data.linInd ) = 1; 5 | tmat = tenmat( tcube, mode ); 6 | data.matInd = find( double(tmat) ); 7 | data.rpca_mode = mode; 8 | 9 | end -------------------------------------------------------------------------------- /algorithms/td/rlrt/tc/mc_ls_grad.m: -------------------------------------------------------------------------------- 1 | function grad = mc_ls_grad( X, b, Omega, lambda, opt ) 2 | % grad = lambda*( A'A(X)+A'*b) 3 | % X = a tensor or matrix 4 | % b = a vector of known entries 5 | % Omega = set of matching indices: 6 | % for 'tensor': a matrix of indices (each row is an index) 7 | % for 'matrix': a vector of linear indices 8 | % opt = 'tensor', 'matrix' 9 | 10 | 11 | if exist( 'opt', 'var' ) && strcmp( opt, 'tensor' ) 12 | grad = tenzeros( size( X ) ); 13 | 14 | else 15 | grad = zeros( size( X ) ); 16 | end 17 | 18 | grad( Omega ) = lambda *( X( Omega ) - b ); 19 | 20 | 21 | end -------------------------------------------------------------------------------- /algorithms/td/rlrt/tc/optimal_mc_ls_Y.m: -------------------------------------------------------------------------------- 1 | function Y = optimal_mc_ls_Y( W, b, Omega, Zs, N, grad_sum, mu, lambda ) 2 | 3 | R = tenzeros( size(W) ); 4 | R(Omega) = lambda*b; 5 | R = R - (grad_sum - Zs{N+1}) + (N/mu)*W; 6 | Y = R * mu/N; 7 | Y(Omega) = R(Omega) / (lambda+N/mu); 8 | 9 | end -------------------------------------------------------------------------------- /algorithms/td/rlrt/tc/optimal_nuclear_X.m: -------------------------------------------------------------------------------- 1 | function [ X, U, gammax, V ] = optimal_nuclear_X( W, grad_sum, Zs, i, N, mu, sig ) 2 | 3 | temptenmat = tenmat( N*W - mu*(grad_sum-Zs{i}), i ); 4 | [ U, S, V ] = svd( double( temptenmat ), 'econ' ); 5 | eta = diag(S); 6 | gammax = zeros( size(eta) ); 7 | ind1 = eta <= sig*N + mu; %sum(ind1==1) 8 | gammax(ind1) = sig*eta(ind1) / (sig*N+mu); 9 | gammax(~ind1) = (eta(~ind1)-mu) / N; 10 | X_i = scale_matrix( U, gammax, 1 ) * V'; 11 | X = tensor( tenmat(X_i, temptenmat.rdims, temptenmat.cdims, temptenmat.tsize) ); 12 | 13 | end -------------------------------------------------------------------------------- /algorithms/td/rlrt/tc/prep_tensor.m: -------------------------------------------------------------------------------- 1 | function data = prep_tensor( impath, dataname, frac, scale ) 2 | 3 | % impath = the root dir of the images 4 | 5 | if ~exist( 'scale', 'var' ) || isempty( scale ) 6 | scale = 1.0; 7 | end 8 | 9 | files = dir( [impath, '\*.bmp'] ); 10 | N = length( files ); 11 | img = imresize( imread( [impath, '\', files(1).name], 'bmp' ), scale ); 12 | [ n, m ] = size( img ); 13 | X = zeros( n, m, N ); 14 | 15 | for i = 1:N 16 | img = imresize( imread( [impath, '\', files(i).name], 'bmp' ), scale ); 17 | X( :, :, i ) = double(img) / 255; 18 | end 19 | 20 | X = tensor( X ); 21 | [ b, Omega, linInd ] = sample_indices( X, frac ); 22 | 23 | data.X = X; 24 | data.b = b; 25 | data.Omega = Omega; 26 | data.linInd = linInd; 27 | 28 | save( ['..\..\data\',dataname], 'data' ); 29 | end -------------------------------------------------------------------------------- /algorithms/td/rlrt/tc/ten_sum_all.m: -------------------------------------------------------------------------------- 1 | function result = ten_sum_all( Xs ) 2 | % sums up a cell array of tensors 3 | 4 | result = tenzeros( size(Xs{1}) ); 5 | for i = 1:length(Xs) 6 | result = result + Xs{i}; 7 | end 8 | 9 | end -------------------------------------------------------------------------------- /algorithms/td/rlrt/tc/test_tc.m: -------------------------------------------------------------------------------- 1 | function results = test_tc( dataname ) 2 | 3 | load( ['..\..\data\', dataname] ); 4 | addpath( '..\utils' ); 5 | 6 | % data.W = tenzeros( size(data.X) ); 7 | % data.W(data.Omega) = data.b; 8 | data.W = tenzeros( size(data.X) ); 9 | N = length( size(data.W) ); 10 | data.Lamb = cell(1,N); 11 | for i = 1:N 12 | data.Lamb{i} = tenzeros( size(data.X) ); 13 | end 14 | data.Lambda = tenzeros( size(data.X) ); 15 | 16 | params.mu0 = 1e1; 17 | params.sigma = 1e-3; 18 | params.lambda = 1; 19 | params.max_iter = 100; 20 | params.opt_tol = 1e-3; 21 | params.R = 50; 22 | 23 | while params.lambda < 100 24 | results = TC_ADAL_Nuc( data, params ); 25 | % results = TC_MSA( data, params ); 26 | data.W = results.X; 27 | params.lambda = params.lambda * 5; 28 | end 29 | 30 | end -------------------------------------------------------------------------------- /algorithms/td/rlrt/utils/choosvd.m: -------------------------------------------------------------------------------- 1 | function y = choosvd( n, d) 2 | 3 | if n <= 100 4 | if d / n <= 0.02 5 | y = 1; 6 | else 7 | y = 0; 8 | end 9 | elseif n <= 200 10 | if d / n <= 0.06 11 | y = 1; 12 | else 13 | y = 0; 14 | end 15 | elseif n <= 300 16 | if d / n <= 0.26 17 | y = 1; 18 | else 19 | y = 0; 20 | end 21 | elseif n <= 400 22 | if d / n <= 0.28 23 | y = 1; 24 | else 25 | y = 0; 26 | end 27 | elseif n <= 500 28 | if d / n <= 0.34 29 | y = 1; 30 | else 31 | y = 0; 32 | end 33 | else 34 | if d / n <= 0.38 35 | y = 1; 36 | else 37 | y = 0; 38 | end 39 | end -------------------------------------------------------------------------------- /algorithms/td/rlrt/utils/copyright.m: -------------------------------------------------------------------------------- 1 | % Author: Zhiwei (Tony) Qin (zq2107@columbia.edu) 2 | % Date: April, 2012 3 | % Affiliation: IEOR, Columbia University, New York -------------------------------------------------------------------------------- /algorithms/td/rlrt/utils/get_SNR.m: -------------------------------------------------------------------------------- 1 | function [ rel_err, snr ] = get_SNR( X, X0 ) 2 | 3 | noise = X - X0; 4 | trueNorm = norm(X0); 5 | rel_err = norm( noise ) / trueNorm; 6 | snr = -20*log10( rel_err ); 7 | 8 | end -------------------------------------------------------------------------------- /algorithms/td/rlrt/utils/get_markers.m: -------------------------------------------------------------------------------- 1 | function marker = get_markers 2 | 3 | marker = { '-*k', '-or', '-*b', '-ob', '-og', '-+m', '-*r', '-+g', '', '', '-*k', '-or', '-+b' }; 4 | 5 | end -------------------------------------------------------------------------------- /algorithms/td/rlrt/utils/img_matrix2tensor.m: -------------------------------------------------------------------------------- 1 | function T = img_matrix2tensor( M, n1, n2, maxPix ) 2 | 3 | N = size( M, 2 ); 4 | T = zeros( n1, n2, N ); 5 | 6 | for i = 1:N 7 | T(:,:,i ) = reshape( M(:,i), [ n1, n2 ] ) / maxPix; 8 | end 9 | 10 | T = tensor( T ); 11 | 12 | end -------------------------------------------------------------------------------- /algorithms/td/rlrt/utils/mysign.m: -------------------------------------------------------------------------------- 1 | function S = mysign(A) 2 | %MYSIGN True sign function with MYSIGN(0) = 1. 3 | 4 | % Called by various matrices in elmat/private. 5 | % 6 | % Nicholas J. Higham 7 | % Copyright 1984-2005 The MathWorks, Inc. 8 | % $Revision: 1.4.4.1 $ $Date: 2005/11/18 14:15:15 $ 9 | 10 | S = sign(A); 11 | S(find(S==0)) = 1; 12 | -------------------------------------------------------------------------------- /algorithms/td/rlrt/utils/numarray2strarray.m: -------------------------------------------------------------------------------- 1 | function strcell = numarray2strarray( vec ) 2 | 3 | N = length(vec); 4 | strcell = cell( 1, N ); 5 | for i = 1:N 6 | strcell{i} = num2str( vec(i) ); 7 | end 8 | 9 | end -------------------------------------------------------------------------------- /algorithms/td/rlrt/utils/plot_parafac_factors.m: -------------------------------------------------------------------------------- 1 | function [P_orig, P] = plot_parafac_factors( results, K, Ko, isSing, fig_ind ) 2 | 3 | P_orig = parafac_als( results.X0, Ko, struct('maxiters',100) ); 4 | P = horpca_parafac( results, K, isSing ); 5 | N = length(size(results.X)); 6 | 7 | if ~exist('fig_ind', 'var') || isempty(fig_ind) 8 | fig_ind = 10; 9 | end 10 | figure(fig_ind); 11 | scrsz = get(0,'ScreenSize'); 12 | set(fig_ind,'Position',[10 scrsz(4)*0.05 scrsz(3)*0.7 0.8*scrsz(4)]); 13 | 14 | for i = 1:N 15 | subplot( N, 2, 1+(i-1)*2 ); 16 | plot( P_orig.U{i}, 'LineWidth', 2 ); 17 | title( ['Original loading factors for mode ', num2str(i)] ); 18 | 19 | subplot( N, 2, 2+(i-1)*2 ); 20 | plot( P.U{i}, 'LineWidth', 2 ); 21 | title( ['Reconstructed loading factors for mode ', num2str(i)] ); 22 | end 23 | 24 | end -------------------------------------------------------------------------------- /algorithms/td/rlrt/utils/plot_tenmat_sv.m: -------------------------------------------------------------------------------- 1 | function Nsv = plot_tenmat_sv( T, fig_ind ) 2 | % T is a tensor 3 | % plots the SV's of unfoldings in each mode 4 | % return Nsv = no. of SV's larger than 0.01 * max SV 5 | 6 | 7 | if ~exist('fig_ind', 'var') || isempty(fig_ind) 8 | fig_ind = 10; 9 | end 10 | 11 | N = length(size(T)); 12 | figure(fig_ind); 13 | scrsz = get(0,'ScreenSize'); 14 | set(fig_ind,'Position',[10 scrsz(4)*0.05 scrsz(3)*0.4 0.8*scrsz(4)]); 15 | Nsv = zeros( 1, N ); 16 | 17 | for mode = 1:N 18 | s = svd( double(tenmat(T,mode)) ); 19 | sMax = max(s); 20 | Isv = s > 0.01*sMax; % before: 0.01!!! 21 | Nsv(mode) = sum( Isv ); 22 | 23 | subplot( N, 1, mode ); 24 | plot( s, 'LineWidth', 2 ); 25 | title( ['Singular values for mode ', num2str(mode)] ); 26 | % subplot( 2, N, mode+N ); 27 | % s(~Isv) = 0; 28 | % plot( s, 'LineWidth', 2 ); 29 | end 30 | 31 | end -------------------------------------------------------------------------------- /algorithms/td/rlrt/utils/sample_indices.m: -------------------------------------------------------------------------------- 1 | function [ b, Omega, linInd ] = sample_indices( X, frac ) 2 | 3 | dims = size( X ); 4 | Ndims = length(dims); 5 | N = 1; 6 | for i = 1:Ndims 7 | N = N * dims(i); 8 | end 9 | 10 | Nfrac = ceil( N * frac ); 11 | Irand = randperm( N )'; 12 | linInd = Irand( 1:Nfrac ); 13 | 14 | if Ndims == 3 15 | [I,J,K] = ind2sub( dims, linInd ); 16 | Omega = [ I J K ]; 17 | else if Ndims == 2 18 | [I,J] = ind2sub( dims, linInd ); 19 | Omega = [ I J ]; 20 | end 21 | end 22 | b = X( Omega ); 23 | 24 | end -------------------------------------------------------------------------------- /algorithms/td/rlrt/utils/scale_matrix.m: -------------------------------------------------------------------------------- 1 | function X = scale_matrix( X, s, mode ) 2 | % X = rectangular matrix whose rows or cols are to be scaled 3 | % s = diag of the scaling diag matrix 4 | % mode = 0 row scaling 5 | % = 1 col scaling 6 | 7 | % prod = sparse( size(X,1), size(X,2) ); 8 | if mode 9 | % for j = 1:size(X,2) 10 | % X( :, j ) = X(:,j) * s(j); 11 | % end 12 | X = scale_cols( X, s ); 13 | else 14 | % for i = 1:size(X,1) 15 | % X( i, : ) = X(i,:) * s(i); 16 | % end 17 | X = scale_rows( X, s ); 18 | end 19 | end -------------------------------------------------------------------------------- /algorithms/td/rlrt/utils/shrinkage_t.m: -------------------------------------------------------------------------------- 1 | function T = shrinkage_t( X, alpha ) 2 | % soft-thresholding on tensor X 3 | 4 | Xv = double( X ); 5 | Tv = shrinkage_v( Xv, alpha ); 6 | T = tensor( Tv ); 7 | end -------------------------------------------------------------------------------- /algorithms/td/rlrt/utils/shrinkage_v.m: -------------------------------------------------------------------------------- 1 | function Tv = shrinkage_v( Xv, alpha ) 2 | % Xv is a vector 3 | % Tv is a vector 4 | 5 | temp = abs(Xv) - alpha; 6 | temp( temp < 0 ) = 0; 7 | Tv = temp .* sign(Xv); 8 | 9 | end -------------------------------------------------------------------------------- /algorithms/td/rlrt/utils/ten_sum_all.m: -------------------------------------------------------------------------------- 1 | function result = ten_sum_all( Xs ) 2 | % sums up a cell array of tensors 3 | 4 | result = tenzeros( size(Xs{1}) ); 5 | for i = 1:length(Xs) 6 | result = result + Xs{i}; 7 | end 8 | 9 | end -------------------------------------------------------------------------------- /algorithms/td/rlrt/utils/tensor_1norm.m: -------------------------------------------------------------------------------- 1 | function val = tensor_1norm( X ) 2 | 3 | X = double(X); 4 | val = sum( abs(X(:)) ); 5 | 6 | end -------------------------------------------------------------------------------- /algorithms/td/rlrt/utils/tensor_array_add.m: -------------------------------------------------------------------------------- 1 | function X = tensor_array_add( X1, X2 ) 2 | N = length(X1); 3 | X = cell(1,N); 4 | for i = 1:N 5 | X{i} = X1{i} + X2{i}; 6 | end 7 | end -------------------------------------------------------------------------------- /algorithms/td/rlrt/utils/tensor_array_diff.m: -------------------------------------------------------------------------------- 1 | function D = tensor_array_diff( X1, X2 ) 2 | 3 | D = cell( 1, length(X1) ); 4 | for i = 1:length(X1) 5 | D{i} = X1{i} - X2{i}; 6 | end 7 | end -------------------------------------------------------------------------------- /algorithms/td/rlrt/utils/tensor_array_innerprod.m: -------------------------------------------------------------------------------- 1 | function prod = tensor_array_innerprod( X1, X2 ) 2 | 3 | prod = 0; 4 | N = length(X1); 5 | for i = 1:N 6 | prod = prod + innerprod(X1{i},X2{i}); 7 | end 8 | 9 | end -------------------------------------------------------------------------------- /algorithms/td/rlrt/utils/tensor_array_norm.m: -------------------------------------------------------------------------------- 1 | function tnorm = tensor_array_norm( X ) 2 | % X is a cell array of tensors 3 | 4 | tnorm = 0; 5 | for i = 1:length(X) 6 | tnorm = tnorm + norm(X{i})^2; 7 | end 8 | tnorm = sqrt(tnorm); 9 | 10 | end -------------------------------------------------------------------------------- /algorithms/td/rlrt/utils/tensor_array_scale.m: -------------------------------------------------------------------------------- 1 | function X = tensor_array_scale( X, a ) 2 | 3 | for i = 1:length(X) 4 | X{i} = X{i}*a; 5 | end 6 | 7 | end -------------------------------------------------------------------------------- /algorithms/td/rlrt/utils/tensor_hard_thresh.m: -------------------------------------------------------------------------------- 1 | function [ T, trnorm, U ] = tensor_hard_thresh( X, k, mode ) 2 | % X is a tensor 3 | % Computes the k largest singular values and assoc. singular vectors for 4 | % mode (mode) 5 | 6 | % global sv; 7 | % global tmode; 8 | global use_propack; 9 | 10 | Xmat = tenmat(X,mode); 11 | dXmat = double( Xmat ); 12 | 13 | n = min(size(dXmat,1),size(dXmat,2)); 14 | % i = tmode; 15 | % sv_local = sv(i); 16 | 17 | if choosvd( n, k) && use_propack 18 | opt.delta = eps; 19 | opt.eta = eps; 20 | [ U, S, V ] = lansvd( dXmat, k, 'L', opt); 21 | else 22 | [ U, S, V ] = svds( dXmat, k ); %fprintf( 'sv(%d) = %d \n', i, sv_local ); 23 | end 24 | s = diag(S); 25 | trnorm = sum(s); 26 | Tmat = scale_matrix( U, s, 1 ) * V'; 27 | 28 | T = tensor( tenmat( Tmat, Xmat.rdims, Xmat.cdims, Xmat.tsize ) ); 29 | end -------------------------------------------------------------------------------- /algorithms/td/rlrt/utils/tensor_shrinkage.m: -------------------------------------------------------------------------------- 1 | function [ T, trnorm, U ] = tensor_shrinkage( X, tau, mode ) 2 | % X and T are tensors 3 | global tmode; 4 | tmode = mode; 5 | 6 | Xmat = tenmat(X,mode); 7 | [Tmat, trnorm, U] = matrix_shrinkage( double(Xmat), tau ); 8 | % [ U, S, V ] = svd( double(Xmat), 'econ' ); 9 | % s = diag(S); 10 | % s = s - tau; 11 | % s( s < 0 ) = 0; 12 | % Tmat = scale_matrix( U, s, 1 ) * V'; 13 | T = tensor( tenmat( Tmat, Xmat.rdims, Xmat.cdims, Xmat.tsize ) ); 14 | 15 | end -------------------------------------------------------------------------------- /algorithms/td/rlrt/utils/tq_dwt.m: -------------------------------------------------------------------------------- 1 | function WX = tq_dwt( X, wname ) 2 | % The dimensions of X have to be even!! 3 | 4 | ndim = length(size(X)); 5 | 6 | switch ndim 7 | case 2 8 | [ cA, cH, cV, cD ] = dwt2( X, wname ); 9 | WX = [ cA, cH; cV, cD ]; 10 | 11 | case 3 12 | WX = zeros( size(X) ); 13 | midk = size(X,3) / 2; 14 | wt = dwt3( X, wname ); 15 | WX(:,:,1:midk) = [ wt.dec{1,1,1}, wt.dec{1,2,1}; wt.dec{2,1,1}, wt.dec{2,2,1} ]; 16 | WX(:,:,midk+1:end) = [ wt.dec{1,1,2}, wt.dec{1,2,2}; wt.dec{2,1,2}, wt.dec{2,2,2} ]; 17 | end 18 | 19 | if sum( size(X) ~= size(WX) ) 20 | disp( 'Dimensions of X have to be even!' ); 21 | end 22 | 23 | end -------------------------------------------------------------------------------- /algorithms/td/rlrt/utils/tq_idwt.m: -------------------------------------------------------------------------------- 1 | function X = tq_idwt( WX, wname ) 2 | 3 | global WT; 4 | ndim = length(size(WX)); 5 | 6 | switch ndim 7 | case 2 8 | midr = size(WX,1)/2; midc = size(WX,2)/2; 9 | cA = WX( 1:midr, 1:midc ); 10 | cH = WX( 1:midr, midc+1:end ); 11 | cV = WX( midr+1:end, 1:midc ); 12 | cD = WX( midr+1:end, midc+1:end ); 13 | X = idwt2( cA, cH, cV, cD, wname ); 14 | 15 | case 3 16 | wt = WT; 17 | midr = size(WX,1)/2; midc = size(WX,2)/2; midk = size(WX,3)/2; 18 | for i = 1:2 19 | for j = 1:2 20 | for k = 1:2 21 | wt.dec{i,j,k} = WX( (i-1)*midr+1 : i*midr, (j-1)*midc+1 : j*midc, (k-1)*midk+1 : k*midk ); 22 | end 23 | end 24 | end 25 | X = idwt3( wt ); 26 | end 27 | end -------------------------------------------------------------------------------- /algorithms/td/rstd/utils/HOSVD.m: -------------------------------------------------------------------------------- 1 | function [core] = HOSVD(data, U) 2 | 3 | site = size(data); 4 | core = data; 5 | 6 | for i=1:ndims(data) 7 | [m n] = size(U{i}); 8 | site(i) = n; 9 | core = folding(U{i}'*unfolding(core,i), i, site); 10 | end 11 | -------------------------------------------------------------------------------- /algorithms/td/rstd/utils/epp1.m: -------------------------------------------------------------------------------- 1 | function [x] = epp1(v, rho) 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 3 | % 4 | % Element-wise Soft Thesholding 5 | % 6 | % x= sign(v) max( |v|- rho, 0) 7 | % 8 | % Authors: Yin Li @ PAMI Lab SJTU 9 | % 10 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -------------------------------------------------------------------------------- /algorithms/td/rstd/utils/epp1.mexw32: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiangsiwei/tensor_tools/141d0a92d3e01626ca5a709a5a46e6dc57f42032/algorithms/td/rstd/utils/epp1.mexw32 -------------------------------------------------------------------------------- /algorithms/td/rstd/utils/epp1.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiangsiwei/tensor_tools/141d0a92d3e01626ca5a709a5a46e6dc57f42032/algorithms/td/rstd/utils/epp1.mexw64 -------------------------------------------------------------------------------- /algorithms/td/rstd/utils/folding.m: -------------------------------------------------------------------------------- 1 | % folding the matrix into a tensor along the kth dimension 2 | % use permute for efficiency, this is much faster than circshift 3 | 4 | function [tensor] = folding(matrix, k, site) 5 | 6 | dim = 1:length(site); 7 | dim = dim'; 8 | 9 | dim = circshift(dim, k-1); 10 | site = (circshift(site', 1-k))'; 11 | 12 | tensor = permute(reshape(matrix, site), dim); -------------------------------------------------------------------------------- /algorithms/td/rstd/utils/iHOSVD.m: -------------------------------------------------------------------------------- 1 | function [data] = iHOSVD(core, U) 2 | 3 | site = size(core); 4 | data = core; 5 | 6 | for i=1:ndims(core) 7 | [m n] = size(U{i}); 8 | site(i) = m; 9 | data = folding(U{i}*unfolding(data,i), i, site); 10 | end -------------------------------------------------------------------------------- /algorithms/td/rstd/utils/unfolding.m: -------------------------------------------------------------------------------- 1 | % unfolding the tensor along the kth dimension 2 | % use permute for efficiency, this is much faster than circshift 3 | function [matrix] = unfolding(tensor, k) 4 | 5 | site = size(tensor); 6 | 7 | if k==1 8 | matrix = reshape(tensor, site(1), []); 9 | return; 10 | end 11 | 12 | dim = 1:ndims(tensor); 13 | dim = dim'; 14 | 15 | dim = circshift(dim, 1-k); 16 | matrix = reshape(permute(tensor, dim), site(k), []); 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /algorithms/ttd/3WD/get_training_images.m: -------------------------------------------------------------------------------- 1 | function [fileNames, numImages] = get_training_images(imagePath) 2 | fileNames = {}; 3 | imageIndex = 0; 4 | userDirectoryContents = list_image_files(imagePath); 5 | if isempty(userDirectoryContents) 6 | error(['No image files were found! Check your paths; there should be images in ' fullfile(rootPath, trainingDatabaseName)]); 7 | end 8 | for fileIndex = 1:length(userDirectoryContents), 9 | imageName = userDirectoryContents{fileIndex}; 10 | disp(['Using image file ' imageName '...']); 11 | 12 | imageIndex = imageIndex+1; 13 | 14 | imageFileName = fullfile(imagePath, imageName); 15 | fileNames{imageIndex} = imageFileName; 16 | end 17 | numImages = length(userDirectoryContents); 18 | -------------------------------------------------------------------------------- /algorithms/ttd/3WD/pos.m: -------------------------------------------------------------------------------- 1 | function P = pos(A) 2 | 3 | P = A .* double( A > 0 ); -------------------------------------------------------------------------------- /algorithms/ttd/3WD/saveResults.m: -------------------------------------------------------------------------------- 1 | function saveResults(destDir, canonicalImageSize) 2 | % alignment results 3 | load(fullfile(destDir, 'final.mat'),'A','E','O','M') ; 4 | 5 | %% display 6 | mkdir([destDir '\Err']); 7 | mkdir([destDir '\Res']); 8 | mkdir([destDir '\O']); 9 | FACT = 255; 10 | for i=1:size(A,2) 11 | im = reshape(A(:,i), canonicalImageSize); 12 | imMin = min(im(:)); 13 | imMax = max(im(:)); 14 | im = (im - imMin)./(imMax - imMin); 15 | im = uint8(255*im); 16 | imwrite(im,[destDir '\Res\' sprintf('Image_%.4d.bmp',i)],'bmp'); 17 | 18 | % E 19 | im = reshape(E(:,i), canonicalImageSize); 20 | im = abs(im) ./ max(max(abs(im))); 21 | im = uint8(FACT.*abs(im)); 22 | imwrite(im,[destDir '\Err\' sprintf('Er_%.4d.bmp',i)],'bmp'); 23 | 24 | % O 25 | im = reshape(O(:,i), canonicalImageSize); 26 | im = abs(im) ./ max(max(abs(im))); 27 | im = uint8(FACT.*abs(im)); 28 | imwrite(im,[destDir '\O\' sprintf('O_%.4d.bmp',i)],'bmp'); 29 | end; 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /algorithms/ttd/ADMM/avg.m: -------------------------------------------------------------------------------- 1 | function x = avg(varargin) 2 | N = length(varargin); 3 | x = 0; 4 | for k = 1:N 5 | x = x + varargin{k}; 6 | end 7 | x = x/N; 8 | end -------------------------------------------------------------------------------- /algorithms/ttd/ADMM/objective.m: -------------------------------------------------------------------------------- 1 | function p = objective(X_1, g_2, X_2, g_3, X_3) 2 | p = norm(X_1,'fro').^2 + g_2*norm(X_2(:),1) + g_3*norm(svd(X_3),1); 3 | end -------------------------------------------------------------------------------- /algorithms/ttd/ADMM/prox_l1.m: -------------------------------------------------------------------------------- 1 | function x = prox_l1(v, lambda) 2 | % PROX_L1 The proximal operator of the l1 norm. 3 | % 4 | % prox_l1(v,lambda) is the proximal operator of the l1 norm 5 | % with parameter lambda. 6 | 7 | x = max(0, v - lambda) - max(0, -v - lambda); 8 | end 9 | -------------------------------------------------------------------------------- /algorithms/ttd/ADMM/prox_matrix.m: -------------------------------------------------------------------------------- 1 | function x = prox_matrix(v, lambda, prox_f) 2 | % PROX_MATRIX The proximal operator of a matrix function. 3 | % 4 | % Suppose F is a orthogonally invariant matrix function such that 5 | % F(X) = f(s(X)), where s is the singular value map and f is some 6 | % absolutely symmetric function. Then 7 | % 8 | % X = prox_matrix(V,lambda,prox_f) 9 | % 10 | % evaluates the proximal operator of F via the proximal operator 11 | % of f. Here, it must be possible to evaluate prox_f as prox_f(v,lambda). 12 | % 13 | % For example, 14 | % 15 | % prox_matrix(V,lambda,prox_l1) 16 | % 17 | % evaluates the proximal operator of the nuclear norm at V 18 | % (i.e., the singular value thresholding operator). 19 | 20 | %[U,S,V] = svd(v,'econ'); 21 | [U,S,V] = svdecon(v); % fastest 22 | x = U*diag(prox_f(diag(S), lambda))*V'; 23 | end 24 | -------------------------------------------------------------------------------- /algorithms/ttd/MAMR_RMAMR/MtOmega.m: -------------------------------------------------------------------------------- 1 | function Y=MtOmega(X,I,J,mm,nn) 2 | % Copyright:Xinchen YE, Tianjin University, 2014 3 | SIZ=[mm nn]; 4 | tmpX = X(:); 5 | idx = sub2ind(SIZ,I,J); 6 | tmpY = tmpX(idx);%%%%%%%%%%%%%%%%%%%%%%%% 7 | %Y=spconvert([I J tmpY;m n 0]); 8 | Y = sparse(I,J,tmpY,mm,nn); 9 | -------------------------------------------------------------------------------- /algorithms/ttd/MAMR_RMAMR/shrink.m: -------------------------------------------------------------------------------- 1 | function Y = shrink(X,a) 2 | % Copyright:Xinchen YE, Tianjin University, 2014 3 | tmpY = max(X-a,0); 4 | Y = tmpY + min(X+a,0); 5 | end -------------------------------------------------------------------------------- /algorithms/ttd/MAMR_RMAMR/test_MAMR.m: -------------------------------------------------------------------------------- 1 | %test_MAMR.m tests the condition of binary mask in Omega. 2 | %input: car_data.mat(frames) car_mask.mat(obtained from optical flow(binary)) 3 | % Copyright: Xinchen YE, Tianjin University, 2014 4 | clear;clc;addpath('PROPACK'); 5 | load car_data.mat 6 | load car_mask.mat 7 | % show_2dvideo(D,240,320) 8 | % show_2dvideo(confidence_mask,240,320) 9 | noise_v = 10; %noise variance added on frames in D 10 | lambda = 1; 11 | [m, n]=size(D); 12 | D1 = D + noise_v * randn(size(D)); % show_2dvideo(D1,240,320) 13 | D2 = D1 .* confidence_mask; % show_2dvideo(D2,240,320) 14 | Omega = find(D2 ~= 0); 15 | [I, J] = ind2sub([m n],Omega); 16 | %% 17 | tic 18 | %[L,S,iter1]=core_MAMR(D, lambda, I, J); 19 | [L,S,Z,iter1] = core_RMAMR(D,10, I, J); 20 | toc 21 | % psnr = calcpsnr(reshape(F(:,12),288,352), double(monitor_back_gray)) 22 | %% 23 | % show_2dvideo(L,240,320) show_2dvideo(S,240,320) show_2dvideo(Z,240,320) 24 | for i = 1:24 25 | figure(101);imshow([reshape(D(:,i),240,320) reshape(L(:,i),240,320)],[]); pause(0.1); 26 | end -------------------------------------------------------------------------------- /mytensor/.gitignore: -------------------------------------------------------------------------------- 1 | syntax: glob 2 | *.pyc 3 | build 4 | dist 5 | scikit_tensor.egg-info 6 | docs/build 7 | docs/source/api 8 | -------------------------------------------------------------------------------- /mytensor/sktensor/__init__.py: -------------------------------------------------------------------------------- 1 | from .core import * 2 | 3 | from .dtensor import dtensor 4 | 5 | from .tucker import hooi as tucker_hooi 6 | from .tucker import hooi as tucker_hosvd 7 | -------------------------------------------------------------------------------- /scikit-tensor/.gitignore: -------------------------------------------------------------------------------- 1 | syntax: glob 2 | *.pyc 3 | build 4 | dist 5 | scikit_tensor.egg-info 6 | docs/build 7 | docs/source/api 8 | -------------------------------------------------------------------------------- /scikit-tensor/MANIFEST.in: -------------------------------------------------------------------------------- 1 | include *.rst 2 | recursive-include docs * 3 | recursive-include examples * 4 | recursive-include sktensor *.c *.h *.pyx *.pxd 5 | recursive-include sktensor/datasets *.csv *.csv.gz *.rst *.jpg *.txt 6 | include LICENSE 7 | -------------------------------------------------------------------------------- /scikit-tensor/data/sensory-bread/bread.txt: -------------------------------------------------------------------------------- 1 | Sensory profiling bread data from Prof. Magni Martens. 2 | 3 | Earlier described in 4 | Bro, R, Multi-way Analysis in the Food Industry. Models, Algorithms, and Applications. 5 | 1998. PhD thesis, University of Amsterdam (NL) & Royal Veterinary and Agricultural University (DK). 6 | 7 | For further info see above reference or http://www.models.kvl.dk/users/rasmus/ -------------------------------------------------------------------------------- /scikit-tensor/data/sensory-bread/brod.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiangsiwei/tensor_tools/141d0a92d3e01626ca5a709a5a46e6dc57f42032/scikit-tensor/data/sensory-bread/brod.mat -------------------------------------------------------------------------------- /scikit-tensor/examples/cp_sensory_bread_data.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import logging 4 | from scipy.io.matlab import loadmat 5 | 6 | import sys 7 | sys.path.append('..') 8 | from sktensor import dtensor, cp_als, tucker_hooi 9 | 10 | # Set logging to DEBUG to see CP-ALS information 11 | logging.basicConfig(level=logging.DEBUG) 12 | 13 | # Load Matlab data and convert it to dense tensor format 14 | mat = loadmat('../data/sensory-bread/brod.mat') 15 | T = dtensor(mat['X']) 16 | 17 | # Decompose tensor using CP-ALS 18 | # P, fit, itr, exectimes = cp_als(T, 3, init='random') 19 | core, U = tucker_hooi(T, 3, init='random') 20 | print U -------------------------------------------------------------------------------- /scikit-tensor/setup.cfg: -------------------------------------------------------------------------------- 1 | [metadata] 2 | description-file = README.md 3 | -------------------------------------------------------------------------------- /scikit-tensor/sktensor/__init__.py: -------------------------------------------------------------------------------- 1 | from .version import __version__ 2 | 3 | from .utils import * 4 | from .core import * 5 | 6 | # data types 7 | from .sptensor import sptensor, unfolded_sptensor 8 | from .dtensor import dtensor, unfolded_dtensor 9 | from .ktensor import ktensor 10 | 11 | # import algorithms 12 | from .cp import als as cp_als 13 | from .tucker import hooi as tucker_hooi 14 | from .tucker import hooi as tucker_hosvd 15 | -------------------------------------------------------------------------------- /scikit-tensor/sktensor/setup.py: -------------------------------------------------------------------------------- 1 | def configuration(parent_package='', top_path=None): 2 | from numpy.distutils.misc_util import Configuration 3 | config = Configuration('sktensor', parent_package, top_path) 4 | 5 | config.add_subpackage('tests') 6 | 7 | return config 8 | -------------------------------------------------------------------------------- /scikit-tensor/sktensor/tests/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiangsiwei/tensor_tools/141d0a92d3e01626ca5a709a5a46e6dc57f42032/scikit-tensor/sktensor/tests/__init__.py -------------------------------------------------------------------------------- /scikit-tensor/sktensor/tests/test_ktensor.py: -------------------------------------------------------------------------------- 1 | from numpy.random import randn 2 | from sktensor import ktensor 3 | 4 | from nose.tools import assert_equal 5 | 6 | def test_vectorization(): 7 | rank = 5 8 | shape = (5, 27, 3, 13) 9 | U = [randn(s, rank) for s in shape] 10 | K = ktensor(U) 11 | v = K.tovec() 12 | K2 = v.toktensor() 13 | 14 | assert_equal(sum([s * rank for s in shape]), len(v.v)) 15 | assert_equal(K, K2) 16 | -------------------------------------------------------------------------------- /scikit-tensor/sktensor/tests/test_pyutils.py: -------------------------------------------------------------------------------- 1 | from sktensor.pyutils import * 2 | from nose.tools import assert_equal, assert_true, raises 3 | 4 | def test_from_to_without(): 5 | frm, to, without = 2, 88, 47 6 | lst = list(range(frm, without)) + list(range(without + 1, to)) 7 | assert_equal(lst, from_to_without(frm, to, without)) 8 | 9 | rlst = list(range(to - 1, without, -1)) + list(range(without - 1, frm - 1,-1)) 10 | assert_equal(rlst, from_to_without(frm, to, without, reverse=True)) 11 | assert_equal(lst[::-1], from_to_without(frm, to, without, reverse=True)) 12 | -------------------------------------------------------------------------------- /scikit-tensor/sktensor/tests/test_utils.py: -------------------------------------------------------------------------------- 1 | from ..utils import accum 2 | from nose.tools import assert_true 3 | from numpy import array, allclose 4 | 5 | 6 | def test_accum(): 7 | subs1 = array([0, 1, 1, 2, 2, 2]) 8 | subs2 = array([0, 1, 1, 1, 2, 2]) 9 | vals = array([1, 2, 3, 4, 5, 6]) 10 | nvals, nsubs = accum((subs1, subs2), vals, with_subs=True) 11 | assert_true(allclose(nvals, array([1, 5, 4, 11]))) 12 | assert_true(allclose(nsubs[0], array([0, 1, 2, 2]))) 13 | assert_true(allclose(nsubs[1], array([0, 1, 1, 2]))) 14 | 15 | subs1 = array([0, 0, 1]) 16 | subs2 = array([0, 0, 1]) 17 | vals = array([1, 2, 3]) 18 | nvals, nsubs = accum((subs1, subs2), vals, with_subs=True) 19 | assert_true(allclose(nvals, array([3, 3]))) 20 | assert_true(allclose(nsubs[0], array([0, 1]))) 21 | assert_true(allclose(nsubs[1], array([0, 1]))) 22 | -------------------------------------------------------------------------------- /scikit-tensor/sktensor/version.py: -------------------------------------------------------------------------------- 1 | __version__ = '0.1' 2 | -------------------------------------------------------------------------------- /tensor_toolbox/@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 2015, 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 (2015) 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 | -------------------------------------------------------------------------------- /tensor_toolbox/@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, KTENSOR/FULL. 7 | % 8 | %MATLAB Tensor Toolbox. 9 | %Copyright 2015, 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 (2015) 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 | -------------------------------------------------------------------------------- /tensor_toolbox/@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, KTENSOR/DOUBLE. 11 | % 12 | %MATLAB Tensor Toolbox. 13 | %Copyright 2015, 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 (2015) 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 | -------------------------------------------------------------------------------- /tensor_toolbox/@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 2015, 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 (2015) 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 | -------------------------------------------------------------------------------- /tensor_toolbox/@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 2015, 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 (2015) 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 | -------------------------------------------------------------------------------- /tensor_toolbox/@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 2015, 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 (2015) 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 | -------------------------------------------------------------------------------- /tensor_toolbox/@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 2015, 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 (2015) 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 | -------------------------------------------------------------------------------- /tensor_toolbox/@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 2015, 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 (2015) 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 | -------------------------------------------------------------------------------- /tensor_toolbox/@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 2015, 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 (2015) 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 | -------------------------------------------------------------------------------- /tensor_toolbox/@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 2015, 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 (2015) 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 | -------------------------------------------------------------------------------- /tensor_toolbox/@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 2015, 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 (2015) 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 | -------------------------------------------------------------------------------- /tensor_toolbox/@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 2015, 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 (2015) 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 | -------------------------------------------------------------------------------- /tensor_toolbox/@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 2015, 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 (2015) 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 | -------------------------------------------------------------------------------- /tensor_toolbox/@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 2015, 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 (2015) 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 | -------------------------------------------------------------------------------- /tensor_toolbox/@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 2015, 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 (2015) 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 | -------------------------------------------------------------------------------- /tensor_toolbox/@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 2015, 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 (2015) 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 | -------------------------------------------------------------------------------- /tensor_toolbox/@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 2015, 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 (2015) 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 | -------------------------------------------------------------------------------- /tensor_toolbox/@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 2015, 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 (2015) 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 | -------------------------------------------------------------------------------- /tensor_toolbox/@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 2015, 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 (2015) 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 | -------------------------------------------------------------------------------- /tensor_toolbox/@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 2015, 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 (2015) 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 | -------------------------------------------------------------------------------- /tensor_toolbox/@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 2015, 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 (2015) 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 | -------------------------------------------------------------------------------- /tensor_toolbox/@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 2015, 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 (2015) 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 | -------------------------------------------------------------------------------- /tensor_toolbox/@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 2015, 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 (2015) 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 | -------------------------------------------------------------------------------- /tensor_toolbox/@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 2015, 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 (2015) 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 | -------------------------------------------------------------------------------- /tensor_toolbox/@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 2015, 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 (2015) 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 | -------------------------------------------------------------------------------- /tensor_toolbox/@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 2015, 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 (2015) 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 | -------------------------------------------------------------------------------- /tensor_toolbox/@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 2015, 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 (2015) 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 | -------------------------------------------------------------------------------- /tensor_toolbox/@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 2015, 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 (2015) 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 | -------------------------------------------------------------------------------- /tensor_toolbox/@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 2015, 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 (2015) 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 | -------------------------------------------------------------------------------- /tensor_toolbox/@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 2015, 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 (2015) 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 | -------------------------------------------------------------------------------- /tensor_toolbox/@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 2015, 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 (2015) 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 | -------------------------------------------------------------------------------- /tensor_toolbox/@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 2015, 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 (2015) 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 | -------------------------------------------------------------------------------- /tensor_toolbox/@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 2015, 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 (2015) 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 | -------------------------------------------------------------------------------- /tensor_toolbox/@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 2015, 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 (2015) 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 | -------------------------------------------------------------------------------- /tensor_toolbox/@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 2015, 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 (2015) 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 | -------------------------------------------------------------------------------- /tensor_toolbox/@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 2015, 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 (2015) 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 | -------------------------------------------------------------------------------- /tensor_toolbox/@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 2015, 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 (2015) 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 | -------------------------------------------------------------------------------- /tensor_toolbox/@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 2015, 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 (2015) 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 | -------------------------------------------------------------------------------- /tensor_toolbox/@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 2015, 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 (2015) 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 | -------------------------------------------------------------------------------- /tensor_toolbox/@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 2015, 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 (2015) 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 | -------------------------------------------------------------------------------- /tensor_toolbox/@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 2015, 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 (2015) 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 | -------------------------------------------------------------------------------- /tensor_toolbox/@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 2015, 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 (2015) 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 | -------------------------------------------------------------------------------- /tensor_toolbox/@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 TENSOR, SPTENSOR/FULL, KTENSOR/FULL, TTENSOR/FULL. 7 | % 8 | %MATLAB Tensor Toolbox. 9 | %Copyright 2015, 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 (2015) 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 | -------------------------------------------------------------------------------- /tensor_toolbox/@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 2015, 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 (2015) 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 | -------------------------------------------------------------------------------- /tensor_toolbox/@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 2015, 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 (2015) 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 | -------------------------------------------------------------------------------- /tensor_toolbox/@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 2015, 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 (2015) 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 | -------------------------------------------------------------------------------- /tensor_toolbox/@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 2015, 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 (2015) 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 | -------------------------------------------------------------------------------- /tensor_toolbox/@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 2015, 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 (2015) 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 | -------------------------------------------------------------------------------- /tensor_toolbox/@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 2015, 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 (2015) 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 | -------------------------------------------------------------------------------- /tensor_toolbox/@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 2015, 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 (2015) 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 | -------------------------------------------------------------------------------- /tensor_toolbox/@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 2015, 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 (2015) 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 | -------------------------------------------------------------------------------- /tensor_toolbox/@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 2015, 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 (2015) 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 | -------------------------------------------------------------------------------- /tensor_toolbox/@tensor/mttkrp.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiangsiwei/tensor_tools/141d0a92d3e01626ca5a709a5a46e6dc57f42032/tensor_toolbox/@tensor/mttkrp.m -------------------------------------------------------------------------------- /tensor_toolbox/@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 2015, 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 (2015) 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 | -------------------------------------------------------------------------------- /tensor_toolbox/@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 2015, 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 (2015) 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 | -------------------------------------------------------------------------------- /tensor_toolbox/@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 2015, 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 (2015) 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 | -------------------------------------------------------------------------------- /tensor_toolbox/@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 2015, 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 (2015) 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 | -------------------------------------------------------------------------------- /tensor_toolbox/@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 2015, 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 (2015) 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 | -------------------------------------------------------------------------------- /tensor_toolbox/@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 2015, 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 (2015) 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 | -------------------------------------------------------------------------------- /tensor_toolbox/@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 2015, 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 (2015) 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 | -------------------------------------------------------------------------------- /tensor_toolbox/@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 2015, 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 (2015) 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 | -------------------------------------------------------------------------------- /tensor_toolbox/@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 2015, 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 (2015) 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 | -------------------------------------------------------------------------------- /tensor_toolbox/@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 TENSOR, TENSOR/SQUEEZE, TENSOR/PERMUTE. 7 | % 8 | %MATLAB Tensor Toolbox. 9 | %Copyright 2015, 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 (2015) 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 | -------------------------------------------------------------------------------- /tensor_toolbox/@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 2015, 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 (2015) 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 | -------------------------------------------------------------------------------- /tensor_toolbox/@tensor/transpose.m: -------------------------------------------------------------------------------- 1 | function transpose(x) 2 | %TRANSPOSE is not defined on tensors. 3 | % 4 | % See also TENSOR, TENSOR/PERMUTE. 5 | % 6 | %MATLAB Tensor Toolbox. 7 | %Copyright 2015, 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 (2015) 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 | -------------------------------------------------------------------------------- /tensor_toolbox/@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 2015, 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 (2015) 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 | -------------------------------------------------------------------------------- /tensor_toolbox/@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 2015, 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 (2015) 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 | -------------------------------------------------------------------------------- /tensor_toolbox/@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 2015, 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 (2015) 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 | -------------------------------------------------------------------------------- /tensor_toolbox/@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 2015, 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 (2015) 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 | disp(t,inputname(1)); 18 | -------------------------------------------------------------------------------- /tensor_toolbox/@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 2015, 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 (2015) 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 | A = double(full(T)); 20 | -------------------------------------------------------------------------------- /tensor_toolbox/@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 2015, 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 (2015) 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 | % Note that this only works with {} because () is not supported by 21 | % subsref. 22 | e = ndims(X); 23 | -------------------------------------------------------------------------------- /tensor_toolbox/@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 2015, 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 (2015) 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 | % Preallocate to ensure there is enough space 20 | X = tenzeros(size(T)); 21 | 22 | % Now do the calculation 23 | X = ttm(T.core,T.u); 24 | 25 | % Make sure that X is a dense tensor (small chance it could be a sparse 26 | % tensor). 27 | X = tensor(X); 28 | 29 | return; 30 | -------------------------------------------------------------------------------- /tensor_toolbox/@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 2015, 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 (2015) 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 | if ~isa(B,'ttensor') && numel(B) == 1 18 | C = ttensor(B * A.core, A.u); 19 | elseif ~isa(A,'ttensor') && numel(A) == 1 20 | C = ttensor(A * B.core, B.u); 21 | else 22 | error('Use mtimes(full(A),full(B)).'); 23 | end 24 | -------------------------------------------------------------------------------- /tensor_toolbox/@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 2015, 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 (2015) 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 | n = numel(t.u); 20 | -------------------------------------------------------------------------------- /tensor_toolbox/@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 2015, 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 (2015) 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 prod(size(X)) > prod(size(X.core)) 19 | V = cell(ndims(X),1); 20 | for n = 1:ndims(X) 21 | V{n} = X.u{n}'*X.u{n}; 22 | end 23 | Y = ttm(X.core,V); 24 | tmp = innerprod(Y, X.core); 25 | nrm = sqrt(tmp); 26 | else 27 | nrm = norm(full(X)); 28 | end 29 | -------------------------------------------------------------------------------- /tensor_toolbox/@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 2015, 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 (2015) 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 | if ndims(t) == 0 23 | m = []; 24 | end 25 | 26 | if exist('idx','var') 27 | m = size(t.u{idx}, 1); 28 | else 29 | for i = 1 : ndims(t) 30 | m(i) = size(t.u{i}, 1); 31 | end 32 | end 33 | -------------------------------------------------------------------------------- /tensor_toolbox/@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 2015, 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 (2015) 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 | t.core = -t.core; 18 | -------------------------------------------------------------------------------- /tensor_toolbox/@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 2015, 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 (2015) 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 | % This function does nothing! 18 | -------------------------------------------------------------------------------- /tensor_toolbox/cp_als.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiangsiwei/tensor_tools/141d0a92d3e01626ca5a709a5a46e6dc57f42032/tensor_toolbox/cp_als.m -------------------------------------------------------------------------------- /tensor_toolbox/cp_wopt.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiangsiwei/tensor_tools/141d0a92d3e01626ca5a709a5a46e6dc57f42032/tensor_toolbox/cp_wopt.m -------------------------------------------------------------------------------- /tensor_toolbox/doc/V_SSHOPM_doc.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiangsiwei/tensor_tools/141d0a92d3e01626ca5a709a5a46e6dc57f42032/tensor_toolbox/doc/V_SSHOPM_doc.m -------------------------------------------------------------------------------- /tensor_toolbox/doc/html/C_ttensor_doc_eq05572125758666918607.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiangsiwei/tensor_tools/141d0a92d3e01626ca5a709a5a46e6dc57f42032/tensor_toolbox/doc/html/C_ttensor_doc_eq05572125758666918607.png -------------------------------------------------------------------------------- /tensor_toolbox/doc/html/D_ktensor_doc_eq03981049146616847228.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiangsiwei/tensor_tools/141d0a92d3e01626ca5a709a5a46e6dc57f42032/tensor_toolbox/doc/html/D_ktensor_doc_eq03981049146616847228.png -------------------------------------------------------------------------------- /tensor_toolbox/doc/html/D_ktensor_doc_eq06950581413034201722.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiangsiwei/tensor_tools/141d0a92d3e01626ca5a709a5a46e6dc57f42032/tensor_toolbox/doc/html/D_ktensor_doc_eq06950581413034201722.png -------------------------------------------------------------------------------- /tensor_toolbox/doc/html/D_ktensor_doc_eq11724614562625913327.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiangsiwei/tensor_tools/141d0a92d3e01626ca5a709a5a46e6dc57f42032/tensor_toolbox/doc/html/D_ktensor_doc_eq11724614562625913327.png -------------------------------------------------------------------------------- /tensor_toolbox/doc/html/D_ktensor_doc_eq15815821552081582258.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiangsiwei/tensor_tools/141d0a92d3e01626ca5a709a5a46e6dc57f42032/tensor_toolbox/doc/html/D_ktensor_doc_eq15815821552081582258.png -------------------------------------------------------------------------------- /tensor_toolbox/doc/images/Workspace.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiangsiwei/tensor_tools/141d0a92d3e01626ca5a709a5a46e6dc57f42032/tensor_toolbox/doc/images/Workspace.png -------------------------------------------------------------------------------- /tensor_toolbox/doc/images/banner-background.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiangsiwei/tensor_tools/141d0a92d3e01626ca5a709a5a46e6dc57f42032/tensor_toolbox/doc/images/banner-background.jpg -------------------------------------------------------------------------------- /tensor_toolbox/doc/images/logo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiangsiwei/tensor_tools/141d0a92d3e01626ca5a709a5a46e6dc57f42032/tensor_toolbox/doc/images/logo.gif -------------------------------------------------------------------------------- /tensor_toolbox/helpindex.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Tensor Toolbox 6 | -------------------------------------------------------------------------------- /tensor_toolbox/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 | -------------------------------------------------------------------------------- /tensor_toolbox/khatrirao.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qiangsiwei/tensor_tools/141d0a92d3e01626ca5a709a5a46e6dc57f42032/tensor_toolbox/khatrirao.m -------------------------------------------------------------------------------- /tensor_toolbox/met/Contents.m: -------------------------------------------------------------------------------- 1 | % ttm_me - Memory-efficient sptensor times matrix. 2 | % ttm_me_mem - Estimates intermediate memory comsumption for ttm_me. 3 | % ttm_me_partition - Finds best order for ttm_me. 4 | % tucker_me - Memory-efficient Tucker higher-order orthogonal iteration. 5 | % tucker_me_test - Very simple tests of tucker_me. 6 | -------------------------------------------------------------------------------- /tensor_toolbox/tt_intvec2str.m: -------------------------------------------------------------------------------- 1 | function s = tt_intvec2str(v) 2 | %TT_INTVEC2STR Print integer vector to a string with brackets. 3 | % 4 | %MATLAB Tensor Toolbox. 5 | %Copyright 2015, 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 (2015) 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 | -------------------------------------------------------------------------------- /tensor_toolbox/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 2015, 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 (2015) 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 | if isempty(S) 20 | S = {''}; 21 | return; 22 | end 23 | set(0,'FormatSpacing',fmt) 24 | S = textscan(S,'%s','delimiter','\n','whitespace',''); 25 | S = S{1}; 26 | end 27 | -------------------------------------------------------------------------------- /tensor_toolbox/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 2015, 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 (2015) 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 | -------------------------------------------------------------------------------- /tensor_toolbox/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 2015, 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 (2015) 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 | -------------------------------------------------------------------------------- /tensor_toolbox/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 2015, 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 (2015) 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 | --------------------------------------------------------------------------------