├── results ├── 0_0_147.png ├── 0_0_155.png ├── 0_0_431.png ├── 0_0_818.png ├── Christ_1.png ├── Christ_2.png ├── Christ_3.png ├── Christ_4.png ├── Christ_5.png ├── Christ_6.png ├── Christ_7.png ├── Christ_8.png ├── Christ_9.png ├── banana1.png ├── banana2.png ├── Christ_10.png ├── Christ_11.png ├── Christ_12.png └── Christ_13.png ├── External ├── pdeal.mexglx ├── pdeal.mexw32 ├── SLIC_mex │ ├── SLIC_mex.mexa64 │ ├── SLIC_mex.mexw64 │ ├── SLIC_mex.mexmaci64 │ ├── test.m │ ├── SLIC_mex.cpp │ └── SLIC.h ├── RPCA │ └── exact_alm_rpca │ │ └── exact_alm_rpca │ │ ├── PROPACK │ │ ├── helio.mat │ │ ├── tqlb.mexsg │ │ ├── bdsqr.mexglx │ │ ├── bdsqr.mexsg │ │ ├── bdsqr.mexsg64 │ │ ├── bdsqr.mexsol │ │ ├── bdsqr.mexw32 │ │ ├── reorth.mexglx │ │ ├── reorth.mexsg │ │ ├── reorth.mexsol │ │ ├── tqlb.mexglx │ │ ├── tqlb.mexsg64 │ │ ├── tqlb.mexsol │ │ ├── reorth.mexsg64 │ │ ├── Afunc.m │ │ ├── AtAfunc.m │ │ ├── Atransfunc.m │ │ ├── Cfunc.m │ │ ├── dbdqr.f │ │ ├── pythag.m │ │ ├── tqlb.m │ │ ├── bdsqr.m │ │ ├── refinebounds.m │ │ ├── tqlb_mex.c │ │ ├── compute_int.m │ │ ├── testtqlb.m │ │ ├── bdsqr_mex.c │ │ ├── lansvd.doc │ │ ├── lansvd.txt │ │ ├── laneig.doc │ │ ├── laneig.txt │ │ ├── update_gbound.m │ │ ├── reorth_mex.c │ │ ├── reorth.m │ │ ├── lanpro.doc │ │ ├── lanpro.txt │ │ ├── mminfo.m │ │ ├── lanbpro.doc │ │ ├── lanbpro.txt │ │ ├── reorth.f │ │ ├── tqlb.f │ │ ├── mmwrite.m │ │ ├── mmread.m │ │ ├── test.m │ │ ├── lansvd.m │ │ ├── laneig.m │ │ └── lanpro.m │ │ ├── choosvd.m │ │ └── exact_alm_rpca.m ├── reassign.m ├── posdeal2.m └── pdeal.c ├── images ├── pair │ ├── banana1.bmp │ └── banana2.bmp ├── single │ ├── 0_0_147.bmp │ ├── 0_0_155.bmp │ ├── 0_0_431.bmp │ └── 0_0_818.bmp └── multiple │ ├── Christ_1.bmp │ ├── Christ_10.bmp │ ├── Christ_11.bmp │ ├── Christ_12.bmp │ ├── Christ_13.bmp │ ├── Christ_2.bmp │ ├── Christ_3.bmp │ ├── Christ_4.bmp │ ├── Christ_5.bmp │ ├── Christ_6.bmp │ ├── Christ_7.bmp │ ├── Christ_8.bmp │ └── Christ_9.bmp ├── submaps ├── pair │ ├── banana1_CC.png │ ├── banana1_CP.png │ ├── banana1_HC.png │ ├── banana1_RC.png │ ├── banana1_SP.png │ ├── banana2_CC.png │ ├── banana2_CP.png │ ├── banana2_HC.png │ ├── banana2_RC.png │ ├── banana2_SP.png │ ├── banana1_res.png │ ├── banana2_res.png │ ├── banana1_stage2.png │ └── banana2_stage2.png ├── single │ ├── 0_0_147_GB.png │ ├── 0_0_147_HC.png │ ├── 0_0_147_LR.png │ ├── 0_0_147_RC.png │ ├── 0_0_147_res.png │ ├── 0_0_155_GB.png │ ├── 0_0_155_HC.png │ ├── 0_0_155_LR.png │ ├── 0_0_155_RC.png │ ├── 0_0_155_res.png │ ├── 0_0_431_GB.png │ ├── 0_0_431_HC.png │ ├── 0_0_431_LR.png │ ├── 0_0_431_RC.png │ ├── 0_0_431_res.png │ ├── 0_0_818_GB.png │ ├── 0_0_818_HC.png │ ├── 0_0_818_LR.png │ ├── 0_0_818_RC.png │ ├── 0_0_818_res.png │ ├── 0_0_147_stage2.png │ ├── 0_0_155_stage2.png │ ├── 0_0_431_stage2.png │ └── 0_0_818_stage2.png └── multiple │ ├── Christ_1_CO.png │ ├── Christ_1_RC.png │ ├── Christ_1_SP.png │ ├── Christ_2_CO.png │ ├── Christ_2_RC.png │ ├── Christ_2_SP.png │ ├── Christ_3_CO.png │ ├── Christ_3_RC.png │ ├── Christ_3_SP.png │ ├── Christ_4_CO.png │ ├── Christ_4_RC.png │ ├── Christ_4_SP.png │ ├── Christ_5_CO.png │ ├── Christ_5_RC.png │ ├── Christ_5_SP.png │ ├── Christ_6_CO.png │ ├── Christ_6_RC.png │ ├── Christ_6_SP.png │ ├── Christ_7_CO.png │ ├── Christ_7_RC.png │ ├── Christ_7_SP.png │ ├── Christ_8_CO.png │ ├── Christ_8_RC.png │ ├── Christ_8_SP.png │ ├── Christ_9_CO.png │ ├── Christ_9_RC.png │ ├── Christ_9_SP.png │ ├── Christ_10_CO.png │ ├── Christ_10_RC.png │ ├── Christ_10_SP.png │ ├── Christ_10_res.png │ ├── Christ_11_CO.png │ ├── Christ_11_RC.png │ ├── Christ_11_SP.png │ ├── Christ_11_res.png │ ├── Christ_12_CO.png │ ├── Christ_12_RC.png │ ├── Christ_12_SP.png │ ├── Christ_12_res.png │ ├── Christ_13_CO.png │ ├── Christ_13_RC.png │ ├── Christ_13_SP.png │ ├── Christ_13_res.png │ ├── Christ_1_res.png │ ├── Christ_2_res.png │ ├── Christ_3_res.png │ ├── Christ_4_res.png │ ├── Christ_5_res.png │ ├── Christ_6_res.png │ ├── Christ_7_res.png │ ├── Christ_8_res.png │ ├── Christ_9_res.png │ ├── Christ_10_stage2.png │ ├── Christ_11_stage2.png │ ├── Christ_12_stage2.png │ ├── Christ_13_stage2.png │ ├── Christ_1_stage2.png │ ├── Christ_2_stage2.png │ ├── Christ_3_stage2.png │ ├── Christ_4_stage2.png │ ├── Christ_5_stage2.png │ ├── Christ_6_stage2.png │ ├── Christ_7_stage2.png │ ├── Christ_8_stage2.png │ └── Christ_9_stage2.png ├── SACS_code ├── normalize.m ├── ReadDAT.m └── sacs_calWeight.m ├── .gitattributes ├── .gitignore ├── demo_single.m ├── demo_pair.m ├── demo_mul.m └── Readme.txt /results/0_0_147.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/results/0_0_147.png -------------------------------------------------------------------------------- /results/0_0_155.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/results/0_0_155.png -------------------------------------------------------------------------------- /results/0_0_431.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/results/0_0_431.png -------------------------------------------------------------------------------- /results/0_0_818.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/results/0_0_818.png -------------------------------------------------------------------------------- /results/Christ_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/results/Christ_1.png -------------------------------------------------------------------------------- /results/Christ_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/results/Christ_2.png -------------------------------------------------------------------------------- /results/Christ_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/results/Christ_3.png -------------------------------------------------------------------------------- /results/Christ_4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/results/Christ_4.png -------------------------------------------------------------------------------- /results/Christ_5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/results/Christ_5.png -------------------------------------------------------------------------------- /results/Christ_6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/results/Christ_6.png -------------------------------------------------------------------------------- /results/Christ_7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/results/Christ_7.png -------------------------------------------------------------------------------- /results/Christ_8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/results/Christ_8.png -------------------------------------------------------------------------------- /results/Christ_9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/results/Christ_9.png -------------------------------------------------------------------------------- /results/banana1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/results/banana1.png -------------------------------------------------------------------------------- /results/banana2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/results/banana2.png -------------------------------------------------------------------------------- /External/pdeal.mexglx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/External/pdeal.mexglx -------------------------------------------------------------------------------- /External/pdeal.mexw32: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/External/pdeal.mexw32 -------------------------------------------------------------------------------- /results/Christ_10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/results/Christ_10.png -------------------------------------------------------------------------------- /results/Christ_11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/results/Christ_11.png -------------------------------------------------------------------------------- /results/Christ_12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/results/Christ_12.png -------------------------------------------------------------------------------- /results/Christ_13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/results/Christ_13.png -------------------------------------------------------------------------------- /images/pair/banana1.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/images/pair/banana1.bmp -------------------------------------------------------------------------------- /images/pair/banana2.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/images/pair/banana2.bmp -------------------------------------------------------------------------------- /images/single/0_0_147.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/images/single/0_0_147.bmp -------------------------------------------------------------------------------- /images/single/0_0_155.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/images/single/0_0_155.bmp -------------------------------------------------------------------------------- /images/single/0_0_431.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/images/single/0_0_431.bmp -------------------------------------------------------------------------------- /images/single/0_0_818.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/images/single/0_0_818.bmp -------------------------------------------------------------------------------- /submaps/pair/banana1_CC.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/pair/banana1_CC.png -------------------------------------------------------------------------------- /submaps/pair/banana1_CP.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/pair/banana1_CP.png -------------------------------------------------------------------------------- /submaps/pair/banana1_HC.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/pair/banana1_HC.png -------------------------------------------------------------------------------- /submaps/pair/banana1_RC.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/pair/banana1_RC.png -------------------------------------------------------------------------------- /submaps/pair/banana1_SP.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/pair/banana1_SP.png -------------------------------------------------------------------------------- /submaps/pair/banana2_CC.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/pair/banana2_CC.png -------------------------------------------------------------------------------- /submaps/pair/banana2_CP.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/pair/banana2_CP.png -------------------------------------------------------------------------------- /submaps/pair/banana2_HC.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/pair/banana2_HC.png -------------------------------------------------------------------------------- /submaps/pair/banana2_RC.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/pair/banana2_RC.png -------------------------------------------------------------------------------- /submaps/pair/banana2_SP.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/pair/banana2_SP.png -------------------------------------------------------------------------------- /images/multiple/Christ_1.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/images/multiple/Christ_1.bmp -------------------------------------------------------------------------------- /images/multiple/Christ_10.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/images/multiple/Christ_10.bmp -------------------------------------------------------------------------------- /images/multiple/Christ_11.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/images/multiple/Christ_11.bmp -------------------------------------------------------------------------------- /images/multiple/Christ_12.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/images/multiple/Christ_12.bmp -------------------------------------------------------------------------------- /images/multiple/Christ_13.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/images/multiple/Christ_13.bmp -------------------------------------------------------------------------------- /images/multiple/Christ_2.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/images/multiple/Christ_2.bmp -------------------------------------------------------------------------------- /images/multiple/Christ_3.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/images/multiple/Christ_3.bmp -------------------------------------------------------------------------------- /images/multiple/Christ_4.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/images/multiple/Christ_4.bmp -------------------------------------------------------------------------------- /images/multiple/Christ_5.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/images/multiple/Christ_5.bmp -------------------------------------------------------------------------------- /images/multiple/Christ_6.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/images/multiple/Christ_6.bmp -------------------------------------------------------------------------------- /images/multiple/Christ_7.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/images/multiple/Christ_7.bmp -------------------------------------------------------------------------------- /images/multiple/Christ_8.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/images/multiple/Christ_8.bmp -------------------------------------------------------------------------------- /images/multiple/Christ_9.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/images/multiple/Christ_9.bmp -------------------------------------------------------------------------------- /submaps/pair/banana1_res.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/pair/banana1_res.png -------------------------------------------------------------------------------- /submaps/pair/banana2_res.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/pair/banana2_res.png -------------------------------------------------------------------------------- /submaps/single/0_0_147_GB.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/single/0_0_147_GB.png -------------------------------------------------------------------------------- /submaps/single/0_0_147_HC.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/single/0_0_147_HC.png -------------------------------------------------------------------------------- /submaps/single/0_0_147_LR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/single/0_0_147_LR.png -------------------------------------------------------------------------------- /submaps/single/0_0_147_RC.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/single/0_0_147_RC.png -------------------------------------------------------------------------------- /submaps/single/0_0_147_res.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/single/0_0_147_res.png -------------------------------------------------------------------------------- /submaps/single/0_0_155_GB.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/single/0_0_155_GB.png -------------------------------------------------------------------------------- /submaps/single/0_0_155_HC.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/single/0_0_155_HC.png -------------------------------------------------------------------------------- /submaps/single/0_0_155_LR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/single/0_0_155_LR.png -------------------------------------------------------------------------------- /submaps/single/0_0_155_RC.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/single/0_0_155_RC.png -------------------------------------------------------------------------------- /submaps/single/0_0_155_res.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/single/0_0_155_res.png -------------------------------------------------------------------------------- /submaps/single/0_0_431_GB.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/single/0_0_431_GB.png -------------------------------------------------------------------------------- /submaps/single/0_0_431_HC.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/single/0_0_431_HC.png -------------------------------------------------------------------------------- /submaps/single/0_0_431_LR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/single/0_0_431_LR.png -------------------------------------------------------------------------------- /submaps/single/0_0_431_RC.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/single/0_0_431_RC.png -------------------------------------------------------------------------------- /submaps/single/0_0_431_res.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/single/0_0_431_res.png -------------------------------------------------------------------------------- /submaps/single/0_0_818_GB.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/single/0_0_818_GB.png -------------------------------------------------------------------------------- /submaps/single/0_0_818_HC.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/single/0_0_818_HC.png -------------------------------------------------------------------------------- /submaps/single/0_0_818_LR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/single/0_0_818_LR.png -------------------------------------------------------------------------------- /submaps/single/0_0_818_RC.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/single/0_0_818_RC.png -------------------------------------------------------------------------------- /submaps/single/0_0_818_res.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/single/0_0_818_res.png -------------------------------------------------------------------------------- /submaps/multiple/Christ_1_CO.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/multiple/Christ_1_CO.png -------------------------------------------------------------------------------- /submaps/multiple/Christ_1_RC.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/multiple/Christ_1_RC.png -------------------------------------------------------------------------------- /submaps/multiple/Christ_1_SP.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/multiple/Christ_1_SP.png -------------------------------------------------------------------------------- /submaps/multiple/Christ_2_CO.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/multiple/Christ_2_CO.png -------------------------------------------------------------------------------- /submaps/multiple/Christ_2_RC.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/multiple/Christ_2_RC.png -------------------------------------------------------------------------------- /submaps/multiple/Christ_2_SP.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/multiple/Christ_2_SP.png -------------------------------------------------------------------------------- /submaps/multiple/Christ_3_CO.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/multiple/Christ_3_CO.png -------------------------------------------------------------------------------- /submaps/multiple/Christ_3_RC.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/multiple/Christ_3_RC.png -------------------------------------------------------------------------------- /submaps/multiple/Christ_3_SP.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/multiple/Christ_3_SP.png -------------------------------------------------------------------------------- /submaps/multiple/Christ_4_CO.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/multiple/Christ_4_CO.png -------------------------------------------------------------------------------- /submaps/multiple/Christ_4_RC.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/multiple/Christ_4_RC.png -------------------------------------------------------------------------------- /submaps/multiple/Christ_4_SP.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/multiple/Christ_4_SP.png -------------------------------------------------------------------------------- /submaps/multiple/Christ_5_CO.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/multiple/Christ_5_CO.png -------------------------------------------------------------------------------- /submaps/multiple/Christ_5_RC.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/multiple/Christ_5_RC.png -------------------------------------------------------------------------------- /submaps/multiple/Christ_5_SP.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/multiple/Christ_5_SP.png -------------------------------------------------------------------------------- /submaps/multiple/Christ_6_CO.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/multiple/Christ_6_CO.png -------------------------------------------------------------------------------- /submaps/multiple/Christ_6_RC.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/multiple/Christ_6_RC.png -------------------------------------------------------------------------------- /submaps/multiple/Christ_6_SP.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/multiple/Christ_6_SP.png -------------------------------------------------------------------------------- /submaps/multiple/Christ_7_CO.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/multiple/Christ_7_CO.png -------------------------------------------------------------------------------- /submaps/multiple/Christ_7_RC.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/multiple/Christ_7_RC.png -------------------------------------------------------------------------------- /submaps/multiple/Christ_7_SP.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/multiple/Christ_7_SP.png -------------------------------------------------------------------------------- /submaps/multiple/Christ_8_CO.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/multiple/Christ_8_CO.png -------------------------------------------------------------------------------- /submaps/multiple/Christ_8_RC.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/multiple/Christ_8_RC.png -------------------------------------------------------------------------------- /submaps/multiple/Christ_8_SP.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/multiple/Christ_8_SP.png -------------------------------------------------------------------------------- /submaps/multiple/Christ_9_CO.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/multiple/Christ_9_CO.png -------------------------------------------------------------------------------- /submaps/multiple/Christ_9_RC.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/multiple/Christ_9_RC.png -------------------------------------------------------------------------------- /submaps/multiple/Christ_9_SP.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/multiple/Christ_9_SP.png -------------------------------------------------------------------------------- /submaps/pair/banana1_stage2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/pair/banana1_stage2.png -------------------------------------------------------------------------------- /submaps/pair/banana2_stage2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/pair/banana2_stage2.png -------------------------------------------------------------------------------- /External/SLIC_mex/SLIC_mex.mexa64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/External/SLIC_mex/SLIC_mex.mexa64 -------------------------------------------------------------------------------- /External/SLIC_mex/SLIC_mex.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/External/SLIC_mex/SLIC_mex.mexw64 -------------------------------------------------------------------------------- /submaps/multiple/Christ_10_CO.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/multiple/Christ_10_CO.png -------------------------------------------------------------------------------- /submaps/multiple/Christ_10_RC.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/multiple/Christ_10_RC.png -------------------------------------------------------------------------------- /submaps/multiple/Christ_10_SP.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/multiple/Christ_10_SP.png -------------------------------------------------------------------------------- /submaps/multiple/Christ_10_res.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/multiple/Christ_10_res.png -------------------------------------------------------------------------------- /submaps/multiple/Christ_11_CO.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/multiple/Christ_11_CO.png -------------------------------------------------------------------------------- /submaps/multiple/Christ_11_RC.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/multiple/Christ_11_RC.png -------------------------------------------------------------------------------- /submaps/multiple/Christ_11_SP.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/multiple/Christ_11_SP.png -------------------------------------------------------------------------------- /submaps/multiple/Christ_11_res.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/multiple/Christ_11_res.png -------------------------------------------------------------------------------- /submaps/multiple/Christ_12_CO.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/multiple/Christ_12_CO.png -------------------------------------------------------------------------------- /submaps/multiple/Christ_12_RC.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/multiple/Christ_12_RC.png -------------------------------------------------------------------------------- /submaps/multiple/Christ_12_SP.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/multiple/Christ_12_SP.png -------------------------------------------------------------------------------- /submaps/multiple/Christ_12_res.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/multiple/Christ_12_res.png -------------------------------------------------------------------------------- /submaps/multiple/Christ_13_CO.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/multiple/Christ_13_CO.png -------------------------------------------------------------------------------- /submaps/multiple/Christ_13_RC.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/multiple/Christ_13_RC.png -------------------------------------------------------------------------------- /submaps/multiple/Christ_13_SP.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/multiple/Christ_13_SP.png -------------------------------------------------------------------------------- /submaps/multiple/Christ_13_res.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/multiple/Christ_13_res.png -------------------------------------------------------------------------------- /submaps/multiple/Christ_1_res.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/multiple/Christ_1_res.png -------------------------------------------------------------------------------- /submaps/multiple/Christ_2_res.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/multiple/Christ_2_res.png -------------------------------------------------------------------------------- /submaps/multiple/Christ_3_res.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/multiple/Christ_3_res.png -------------------------------------------------------------------------------- /submaps/multiple/Christ_4_res.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/multiple/Christ_4_res.png -------------------------------------------------------------------------------- /submaps/multiple/Christ_5_res.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/multiple/Christ_5_res.png -------------------------------------------------------------------------------- /submaps/multiple/Christ_6_res.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/multiple/Christ_6_res.png -------------------------------------------------------------------------------- /submaps/multiple/Christ_7_res.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/multiple/Christ_7_res.png -------------------------------------------------------------------------------- /submaps/multiple/Christ_8_res.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/multiple/Christ_8_res.png -------------------------------------------------------------------------------- /submaps/multiple/Christ_9_res.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/multiple/Christ_9_res.png -------------------------------------------------------------------------------- /submaps/single/0_0_147_stage2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/single/0_0_147_stage2.png -------------------------------------------------------------------------------- /submaps/single/0_0_155_stage2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/single/0_0_155_stage2.png -------------------------------------------------------------------------------- /submaps/single/0_0_431_stage2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/single/0_0_431_stage2.png -------------------------------------------------------------------------------- /submaps/single/0_0_818_stage2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/single/0_0_818_stage2.png -------------------------------------------------------------------------------- /External/SLIC_mex/SLIC_mex.mexmaci64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/External/SLIC_mex/SLIC_mex.mexmaci64 -------------------------------------------------------------------------------- /External/SLIC_mex/test.m: -------------------------------------------------------------------------------- 1 | % 2 | img = imread('test.jpg'); 3 | superpixels= SLIC_mex( img, 200, 20 ); 4 | imshow(superpixels,[]); -------------------------------------------------------------------------------- /submaps/multiple/Christ_10_stage2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/multiple/Christ_10_stage2.png -------------------------------------------------------------------------------- /submaps/multiple/Christ_11_stage2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/multiple/Christ_11_stage2.png -------------------------------------------------------------------------------- /submaps/multiple/Christ_12_stage2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/multiple/Christ_12_stage2.png -------------------------------------------------------------------------------- /submaps/multiple/Christ_13_stage2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/multiple/Christ_13_stage2.png -------------------------------------------------------------------------------- /submaps/multiple/Christ_1_stage2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/multiple/Christ_1_stage2.png -------------------------------------------------------------------------------- /submaps/multiple/Christ_2_stage2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/multiple/Christ_2_stage2.png -------------------------------------------------------------------------------- /submaps/multiple/Christ_3_stage2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/multiple/Christ_3_stage2.png -------------------------------------------------------------------------------- /submaps/multiple/Christ_4_stage2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/multiple/Christ_4_stage2.png -------------------------------------------------------------------------------- /submaps/multiple/Christ_5_stage2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/multiple/Christ_5_stage2.png -------------------------------------------------------------------------------- /submaps/multiple/Christ_6_stage2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/multiple/Christ_6_stage2.png -------------------------------------------------------------------------------- /submaps/multiple/Christ_7_stage2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/multiple/Christ_7_stage2.png -------------------------------------------------------------------------------- /submaps/multiple/Christ_8_stage2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/multiple/Christ_8_stage2.png -------------------------------------------------------------------------------- /submaps/multiple/Christ_9_stage2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/submaps/multiple/Christ_9_stage2.png -------------------------------------------------------------------------------- /External/RPCA/exact_alm_rpca/exact_alm_rpca/PROPACK/helio.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/External/RPCA/exact_alm_rpca/exact_alm_rpca/PROPACK/helio.mat -------------------------------------------------------------------------------- /External/RPCA/exact_alm_rpca/exact_alm_rpca/PROPACK/tqlb.mexsg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/External/RPCA/exact_alm_rpca/exact_alm_rpca/PROPACK/tqlb.mexsg -------------------------------------------------------------------------------- /External/RPCA/exact_alm_rpca/exact_alm_rpca/PROPACK/bdsqr.mexglx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/External/RPCA/exact_alm_rpca/exact_alm_rpca/PROPACK/bdsqr.mexglx -------------------------------------------------------------------------------- /External/RPCA/exact_alm_rpca/exact_alm_rpca/PROPACK/bdsqr.mexsg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/External/RPCA/exact_alm_rpca/exact_alm_rpca/PROPACK/bdsqr.mexsg -------------------------------------------------------------------------------- /External/RPCA/exact_alm_rpca/exact_alm_rpca/PROPACK/bdsqr.mexsg64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/External/RPCA/exact_alm_rpca/exact_alm_rpca/PROPACK/bdsqr.mexsg64 -------------------------------------------------------------------------------- /External/RPCA/exact_alm_rpca/exact_alm_rpca/PROPACK/bdsqr.mexsol: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/External/RPCA/exact_alm_rpca/exact_alm_rpca/PROPACK/bdsqr.mexsol -------------------------------------------------------------------------------- /External/RPCA/exact_alm_rpca/exact_alm_rpca/PROPACK/bdsqr.mexw32: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/External/RPCA/exact_alm_rpca/exact_alm_rpca/PROPACK/bdsqr.mexw32 -------------------------------------------------------------------------------- /External/RPCA/exact_alm_rpca/exact_alm_rpca/PROPACK/reorth.mexglx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/External/RPCA/exact_alm_rpca/exact_alm_rpca/PROPACK/reorth.mexglx -------------------------------------------------------------------------------- /External/RPCA/exact_alm_rpca/exact_alm_rpca/PROPACK/reorth.mexsg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/External/RPCA/exact_alm_rpca/exact_alm_rpca/PROPACK/reorth.mexsg -------------------------------------------------------------------------------- /External/RPCA/exact_alm_rpca/exact_alm_rpca/PROPACK/reorth.mexsol: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/External/RPCA/exact_alm_rpca/exact_alm_rpca/PROPACK/reorth.mexsol -------------------------------------------------------------------------------- /External/RPCA/exact_alm_rpca/exact_alm_rpca/PROPACK/tqlb.mexglx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/External/RPCA/exact_alm_rpca/exact_alm_rpca/PROPACK/tqlb.mexglx -------------------------------------------------------------------------------- /External/RPCA/exact_alm_rpca/exact_alm_rpca/PROPACK/tqlb.mexsg64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/External/RPCA/exact_alm_rpca/exact_alm_rpca/PROPACK/tqlb.mexsg64 -------------------------------------------------------------------------------- /External/RPCA/exact_alm_rpca/exact_alm_rpca/PROPACK/tqlb.mexsol: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/External/RPCA/exact_alm_rpca/exact_alm_rpca/PROPACK/tqlb.mexsol -------------------------------------------------------------------------------- /External/RPCA/exact_alm_rpca/exact_alm_rpca/PROPACK/reorth.mexsg64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HzFu/SACS_TIP2014/HEAD/External/RPCA/exact_alm_rpca/exact_alm_rpca/PROPACK/reorth.mexsg64 -------------------------------------------------------------------------------- /SACS_code/normalize.m: -------------------------------------------------------------------------------- 1 | function nmap = normalize( map ) 2 | % normallize 3 | nmap = double(map); 4 | nmap = (nmap-min(nmap(:)))*255/(max(nmap(:))-min(nmap(:))); 5 | nmap = nmap*255/max(nmap(:)); 6 | nmap = uint8(floor(nmap)); 7 | end 8 | 9 | -------------------------------------------------------------------------------- /External/RPCA/exact_alm_rpca/exact_alm_rpca/PROPACK/Afunc.m: -------------------------------------------------------------------------------- 1 | function y=Afunc(x) 2 | % y=Afunc(x) 3 | % Testfunction returning a linear operator applied to x. 4 | % Used for testing lansvd. 5 | % 6 | % y = A'*x 7 | 8 | % Rasmus Munk Larsen, DAIMI, 1998 9 | 10 | global A MxV 11 | y = A*x; 12 | MxV = MxV + 1; -------------------------------------------------------------------------------- /External/RPCA/exact_alm_rpca/exact_alm_rpca/PROPACK/AtAfunc.m: -------------------------------------------------------------------------------- 1 | function y=AtAfunc(x) 2 | % y=AtAfunc(x) 3 | % Testfunction defining a linear operator applied to x. 4 | % Used for testing laneig. 5 | % 6 | % y = A'*(A*x) 7 | 8 | % Rasmus Munk Larsen, DAIMI, 1998 9 | 10 | 11 | global A MxV 12 | y = A'*(A*x); 13 | MxV = MxV + 2; 14 | -------------------------------------------------------------------------------- /External/RPCA/exact_alm_rpca/exact_alm_rpca/PROPACK/Atransfunc.m: -------------------------------------------------------------------------------- 1 | function y=Atransfunc(x) 2 | % y=Atransfunc(x) 3 | % Testfunction returning the transpose of a linear operator applied to x. 4 | % Used for testing lansvd. 5 | % 6 | % y = A'*x 7 | 8 | % Rasmus Munk Larsen, DAIMI, 1998 9 | 10 | global A MxV 11 | y = A'*x; 12 | MxV = MxV + 1; 13 | -------------------------------------------------------------------------------- /External/RPCA/exact_alm_rpca/exact_alm_rpca/PROPACK/Cfunc.m: -------------------------------------------------------------------------------- 1 | function y = Cfunc(x) 2 | % y=Cfunc(x) 3 | % Testfunction defining a linear operator applied to x. 4 | % Used for testing laneig. 5 | % 6 | % y = [ 0 A ] * x 7 | % [ A' 0 ] 8 | 9 | % Rasmus Munk Larsen, DAIMI, 1998 10 | 11 | 12 | global A MxV 13 | [m n] = size(A); 14 | y = [A*x(m+1:end,:); A'*x(1:m,:)]; 15 | MxV = MxV + 2; -------------------------------------------------------------------------------- /External/reassign.m: -------------------------------------------------------------------------------- 1 | clear; 2 | 3 | dirname = 'rawresult'; 4 | maplist = dir([dirname '/*.png']); 5 | 6 | for i=1:length(maplist), 7 | map = imread([dirname '/' maplist(i).name]); 8 | map = posdeal2(map,0.3,6);%0.3 is used to control the threshold in equation 13 9 | % Note that, we use 0.4 for image pair saliency detection, and 0.3 for others. 10 | map = normalize(map); 11 | imwrite(map, ['result/' maplist(i).name] , 'png'); 12 | disp([maplist(i).name 'is done']); 13 | end; -------------------------------------------------------------------------------- /SACS_code/ReadDAT.m: -------------------------------------------------------------------------------- 1 | function B = ReadDAT(image_size,data_path) 2 | % $Description: 3 | % -read the superpixel labels from .dat file 4 | % $Agruments 5 | % Input; 6 | % -image_size: [width height] 7 | % -data_path: the path of the .dat file 8 | % Output: 9 | % -label matrix width*height 10 | 11 | row = image_size(1); 12 | colomn = image_size(2); 13 | fid = fopen(data_path,'r'); 14 | A = fread(fid, row * colomn, 'uint32')'; 15 | A = A + 1; 16 | B = reshape(A,[colomn, row]); 17 | B = B'; 18 | fclose(fid); -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | *.sln merge=union 7 | *.csproj merge=union 8 | *.vbproj merge=union 9 | *.fsproj merge=union 10 | *.dbproj merge=union 11 | 12 | # Standard to msysgit 13 | *.doc diff=astextplain 14 | *.DOC diff=astextplain 15 | *.docx diff=astextplain 16 | *.DOCX diff=astextplain 17 | *.dot diff=astextplain 18 | *.DOT diff=astextplain 19 | *.pdf diff=astextplain 20 | *.PDF diff=astextplain 21 | *.rtf diff=astextplain 22 | *.RTF diff=astextplain 23 | -------------------------------------------------------------------------------- /External/RPCA/exact_alm_rpca/exact_alm_rpca/PROPACK/dbdqr.f: -------------------------------------------------------------------------------- 1 | 2 | subroutine dbdqr(n, D, E, c1, c2) 3 | implicit none 4 | integer n 5 | double precision D(*),E(*),c1,c2 6 | 7 | integer i 8 | double precision cs,sn,r 9 | 10 | if (n.lt.2) return 11 | do i=1,n-1 12 | call dlartg(d(i),e(i),cs,sn,r) 13 | d(i) = r 14 | e(i) = sn*d(i+1) 15 | d(i+1) = cs*d(i+1) 16 | enddo 17 | call dlartg(d(n),e(n),cs,sn,r) 18 | d(n) = r 19 | e(n) = 0.0 20 | c1 = sn 21 | c2 = cs 22 | end 23 | 24 | -------------------------------------------------------------------------------- /External/posdeal2.m: -------------------------------------------------------------------------------- 1 | function [ saliency ] = posdeal2( saliency, thes,k) 2 | saliency = double(saliency); 3 | 4 | t1 = thes * max(saliency(:)); 5 | 6 | [row , col] = find(saliency >= t1 ); 7 | foci = [row , col]; 8 | 9 | t2 = thes * max(saliency(:)); 10 | 11 | [row , col] = find(saliency < t2 ); 12 | it = find(saliency < t2 ); 13 | index = [row , col]; 14 | 15 | %df = zeros(1,length(index)); 16 | 17 | df = pdeal(foci , index); 18 | df = df.^(1/2); 19 | 20 | df = df - min(min(df)); 21 | df = df / max(max(df)); 22 | 23 | df = exp(-k*df); 24 | saliency(it) = saliency(it).*df'; 25 | saliency = uint8(saliency); 26 | end 27 | -------------------------------------------------------------------------------- /External/RPCA/exact_alm_rpca/exact_alm_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 -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | 5 | # Folder config file 6 | Desktop.ini 7 | 8 | # Recycle Bin used on file shares 9 | $RECYCLE.BIN/ 10 | 11 | # Windows Installer files 12 | *.cab 13 | *.msi 14 | *.msm 15 | *.msp 16 | 17 | # ========================= 18 | # Operating System Files 19 | # ========================= 20 | 21 | # OSX 22 | # ========================= 23 | 24 | .DS_Store 25 | .AppleDouble 26 | .LSOverride 27 | 28 | # Icon must end with two \r 29 | Icon 30 | 31 | # Thumbnails 32 | ._* 33 | 34 | # Files that might appear on external disk 35 | .Spotlight-V100 36 | .Trashes 37 | 38 | # Directories potentially created on remote AFP share 39 | .AppleDB 40 | .AppleDesktop 41 | Network Trash Folder 42 | Temporary Items 43 | .apdisk 44 | -------------------------------------------------------------------------------- /External/RPCA/exact_alm_rpca/exact_alm_rpca/PROPACK/pythag.m: -------------------------------------------------------------------------------- 1 | function x = pythag(y,z) 2 | %PYTHAG Computes sqrt( y^2 + z^2 ). 3 | % 4 | % x = pythag(y,z) 5 | % 6 | % Returns sqrt(y^2 + z^2) but is careful to scale to avoid overflow. 7 | 8 | % Christian H. Bischof, Argonne National Laboratory, 03/31/89. 9 | 10 | [m n] = size(y); 11 | if m>1 | n>1 12 | y = y(:); z=z(:); 13 | rmax = max(abs([y';z']))'; 14 | id=find(rmax==0); 15 | if length(id)>0 16 | rmax(id) = 1; 17 | x = rmax.*sqrt((y./rmax).^2 + (z./rmax).^2); 18 | x(id)=0; 19 | else 20 | x = rmax.*sqrt((y./rmax).^2 + (z./rmax).^2); 21 | end 22 | x = reshape(x,m,n); 23 | else 24 | rmax = max(abs([y;z])); 25 | if (rmax==0) 26 | x = 0; 27 | else 28 | x = rmax*sqrt((y/rmax)^2 + (z/rmax)^2); 29 | end 30 | end 31 | -------------------------------------------------------------------------------- /External/pdeal.c: -------------------------------------------------------------------------------- 1 | #include "mex.h" 2 | 3 | void dofor(double *reu, int lf, int li, double *foci, double *index){ 4 | int i, j; 5 | double *ed; 6 | ed = mxCalloc(lf , sizeof(double)); 7 | for(i=0; itol1 & bnd(i+l)>tol1 27 | bnd(i+l) = pythag(bnd(i),bnd(i+l)); 28 | bnd(i) = 0; 29 | end 30 | end 31 | end 32 | end 33 | % Refine error bounds 34 | gap = inf*ones(1,j); 35 | gap(1:j-1) = min([gap(1:j-1);[D(2:j)-bnd(2:j)-D(1:j-1)]']); 36 | gap(2:j) = min([gap(2:j);[D(2:j)-D(1:j-1)-bnd(1:j-1)]']); 37 | gap = gap(:); 38 | I = find(gap>bnd); 39 | bnd(I) = bnd(I).*(bnd(I)./gap(I)); 40 | 41 | bnd(PERM) = bnd; -------------------------------------------------------------------------------- /demo_single.m: -------------------------------------------------------------------------------- 1 | close all; 2 | clear; 3 | %% parameter settings 4 | addpath(genpath('./External')); 5 | addpath(genpath('./SACS_code')); 6 | 7 | imgpath = './images/single';%put any single images in this foledr 8 | mappath = './submaps/single'; 9 | 10 | imglist = dir([imgpath '/*.bmp']); %bmp imgs only 11 | maplist = dir([mappath '/*.png']); 12 | 13 | %the map names used in this demo, correspoding to MR, HS, LR, RC, HC and GB 14 | map_names = {'_stage2.png','_res.png','_LR.png','_RC.png','_HC.png','_GB.png'}; 15 | map_num = length(map_names); 16 | 17 | for i=1:length(imglist), 18 | %% self-adaptively weight fusion 19 | img_num = 1; 20 | inames{1} = strrep(imglist(i).name, '.bmp', ''); 21 | Mset = cell(img_num, map_num); 22 | for j=1:map_num, 23 | Mset{1,j} = imread([mappath '/' inames{1} map_names{j}]); 24 | end; 25 | w = sacs_calWeight(map_names, inames, Mset, imgpath); 26 | saliency = zeros(size(Mset{1,1})); 27 | for j=1:map_num, 28 | saliency = saliency + w(1,j)*double(Mset{1,j}); 29 | end; 30 | raws = saliency; 31 | raws = normalize(raws); 32 | imwrite(raws, ['results/' strrep(imglist(i).name, 'bmp' , 'png')] , 'png'); 33 | end; -------------------------------------------------------------------------------- /demo_pair.m: -------------------------------------------------------------------------------- 1 | close all; 2 | clear; 3 | %% parameter settings 4 | addpath(genpath('./External')); 5 | addpath(genpath('./SACS_code')); 6 | 7 | imgpath = './images/pair';%put a pair of images in this foleder 8 | mappath = './submaps/pair'; 9 | 10 | imglist = dir([imgpath '/*.bmp']); %bmp imgs only 11 | maplist = dir([mappath '/*.png']); 12 | 13 | img_num = length(imglist); 14 | %the map names used in this demo, correspoding to MR, HS, RC, HC, CC, CP and CO 15 | map_names = {'_stage2.png','_res.png','_RC.png','_HC.png','_CC.png','_CP.png','_SP.png'}; 16 | map_num = length(map_names); 17 | 18 | %% self-adaptively weight fusion 19 | 20 | inames = cell(1,img_num); 21 | for i=1:img_num, 22 | inames{i} = strrep(imglist(i).name, '.bmp', ''); 23 | end; 24 | Mset = cell(img_num, map_num); 25 | for i=1:img_num, 26 | for j=1:map_num, 27 | Mset{i,j} = imread([mappath '/' inames{i} map_names{j}]); 28 | end; 29 | end; 30 | 31 | w = sacs_calWeight(map_names, inames, Mset, imgpath); 32 | 33 | saliency = cell(1,img_num); 34 | for j=1:img_num, 35 | saliency{j} = zeros(size(Mset{j,1})); 36 | end; 37 | for j = 1:img_num, 38 | for q=1:map_num, 39 | saliency{j} = saliency{j} + w(j,q)*double(Mset{j,q}); 40 | end; 41 | end; 42 | raws = saliency; 43 | for j=1:img_num, 44 | rs = raws{j}; 45 | rs = normalize(rs); 46 | imwrite(rs, ['results/' strrep(imglist(j).name, 'bmp' , 'png')] , 'png'); 47 | end; -------------------------------------------------------------------------------- /demo_mul.m: -------------------------------------------------------------------------------- 1 | close all; 2 | clear; 3 | %% parameter settings 4 | addpath(genpath('./External')); 5 | addpath(genpath('./SACS_code')); 6 | 7 | imgpath = './images/multiple'; %put a group of images in this folder 8 | mappath = './submaps/multiple'; % the sub saliency maps by other methods 9 | 10 | imglist = dir([imgpath '/*.bmp']); % BMP imgs only 11 | maplist = dir([mappath '/*.png']); 12 | 13 | img_num = length(imglist); 14 | %the map names used in this demo, correspoding to MR, HS, RC, SP and CO 15 | map_names = {'_stage2.png','_res.png','_RC.png','_SP.png','_CO.png'}; 16 | map_num = length(map_names); 17 | 18 | %% self-adaptively weight fusion 19 | 20 | inames = cell(1,img_num); 21 | for i=1:img_num, 22 | inames{i} = strrep(imglist(i).name, '.bmp', ''); 23 | end; 24 | Mset = cell(img_num, map_num); 25 | for i=1:img_num, 26 | for j=1:map_num, 27 | Mset{i,j} = imread([mappath '/' inames{i} map_names{j}]); 28 | end; 29 | end; 30 | 31 | w = sacs_calWeight(map_names, inames, Mset, imgpath); 32 | 33 | 34 | saliency = cell(1,img_num); 35 | for j=1:img_num, 36 | saliency{j} = zeros(size(Mset{j,1})); 37 | end; 38 | for j = 1:img_num, 39 | for q=1:map_num, 40 | saliency{j} = saliency{j} + w(j,q)*double(Mset{j,q}); 41 | end; 42 | end; 43 | raws = saliency; 44 | for j=1:img_num, 45 | rs = raws{j}; 46 | rs = normalize(rs); 47 | imwrite(rs, ['results/' strrep(imglist(j).name, 'bmp' , 'png')] , 'png'); 48 | end; -------------------------------------------------------------------------------- /External/RPCA/exact_alm_rpca/exact_alm_rpca/PROPACK/tqlb_mex.c: -------------------------------------------------------------------------------- 1 | /* 2 | MEX interface for TQLB. Matlab calling sequence: 3 | [lambda,top,bot,err] = tqlb(alpha,beta) 4 | */ 5 | 6 | 7 | #include 8 | #include "mex.h" 9 | 10 | /* Template for tqlb: */ 11 | void tqlb_(int *n, double *d__, double *e, double *bnd, 12 | double *bnd2, int *ierr); 13 | 14 | /* Here comes the gateway function to be called by Matlab: */ 15 | void mexFunction(int nlhs, mxArray *plhs[], 16 | int nrhs, const mxArray *prhs[]) 17 | { 18 | int m, n,i, ierr; 19 | double x, *tmp; 20 | 21 | if (nrhs != 2) 22 | mexErrMsgTxt("tqlb requires two input arguments"); 23 | else if (nlhs != 4) 24 | mexErrMsgTxt("tqlb requires four output arguments"); 25 | 26 | for (i=0; i<2; i++) { 27 | m = mxGetM(prhs[i]); /* get the dimensions of the input */ 28 | n = mxGetN(prhs[i]); 29 | 30 | /* make sure input is m x 1 */ 31 | if (n != 1) 32 | mexErrMsgTxt("Input must be a m x 1 vectors"); 33 | } 34 | 35 | /* Create/allocate return argument, a 1x1 real-valued Matrix */ 36 | for (i=0; i<3; i++) { 37 | plhs[i]=mxCreateDoubleMatrix(m,1,mxREAL); 38 | } 39 | plhs[3] = mxCreateDoubleMatrix(1,1,mxREAL); 40 | tmp = mxCalloc(m,sizeof(double)); 41 | 42 | memcpy(mxGetPr(plhs[0]), mxGetPr(prhs[0]),m*sizeof(double)); 43 | memcpy(tmp,mxGetPr(prhs[1]), m*sizeof(double)); 44 | tqlb_(&m,mxGetPr(plhs[0]),tmp,mxGetPr(plhs[1]), 45 | mxGetPr(plhs[2]),&ierr); 46 | 47 | *(mxGetPr(plhs[3])) = (double) ierr; 48 | mxFree(tmp); 49 | } 50 | -------------------------------------------------------------------------------- /External/RPCA/exact_alm_rpca/exact_alm_rpca/PROPACK/compute_int.m: -------------------------------------------------------------------------------- 1 | function int = compute_int(mu,j,delta,eta,LL,strategy,extra) 2 | %COMPUTE_INT: Determine which Lanczos vectors to reorthogonalize against. 3 | % 4 | % int = compute_int(mu,eta,LL,strategy,extra)) 5 | % 6 | % Strategy 0: Orthogonalize vectors v_{i-r-extra},...,v_{i},...v_{i+s+extra} 7 | % with nu>eta, where v_{i} are the vectors with mu>delta. 8 | % Strategy 1: Orthogonalize all vectors v_{r-extra},...,v_{s+extra} where 9 | % v_{r} is the first and v_{s} the last Lanczos vector with 10 | % mu > eta. 11 | % Strategy 2: Orthogonalize all vectors with mu > eta. 12 | % 13 | % Notice: The first LL vectors are excluded since the new Lanczos 14 | % vector is already orthogonalized against them in the main iteration. 15 | 16 | % Rasmus Munk Larsen, DAIMI, 1998. 17 | 18 | if (delta= ETA.') 20 | end 21 | switch strategy 22 | case 0 23 | I0 = find(abs(mu(1:j))>=delta); 24 | if length(I0)==0 25 | [mm,I0] = max(abs(mu(1:j))); 26 | end 27 | int = zeros(j,1); 28 | for i = 1:length(I0) 29 | for r=I0(i):-1:1 30 | if abs(mu(r))0 47 | int(1:LL) = 0; 48 | end 49 | int = find(int); 50 | case 1 51 | int=find(abs(mu(1:j))>eta); 52 | int = max(LL+1,min(int)-extra):min(max(int)+extra,j); 53 | case 2 54 | int=find(abs(mu(1:j))>=eta); 55 | end 56 | int = int(:); -------------------------------------------------------------------------------- /External/RPCA/exact_alm_rpca/exact_alm_rpca/PROPACK/testtqlb.m: -------------------------------------------------------------------------------- 1 | % Script for comparing speed an accuracy of original TQLB, optimized TQLB 2 | % and builtin EIG command. 3 | 4 | % Rasmus Munk Larsen, DAIMI, 1998. 5 | 6 | n=1000; 7 | 8 | % Use 2. order difference matrix as testproblem. 9 | e = ones(n,1); 10 | T = spdiags([-e 2*e -e], -1:1, n, n); 11 | true = 4*cos(pi/2*[n:-1:1]'./(n+1)).^2; 12 | alpha = 2*ones(n,1); 13 | beta = -ones(n,1); 14 | 15 | fprintf('-----------------------------------------------------------------\n') 16 | disp('Modified tqlb:') 17 | fprintf('\n') 18 | tic, flops(0) 19 | [lambda,top,bot,err] = tqlb(alpha,beta); 20 | fprintf('Elapsed time = %f\n',toc); 21 | fprintf('Number of flops = %f\n',flops); 22 | fprintf('Max rel. error = %e\n',max(abs((lambda-true)./true))) 23 | 24 | 25 | fprintf('-----------------------------------------------------------------\n') 26 | disp('Original tqlb:') 27 | fprintf('\n') 28 | tic, flops(0); 29 | [lambda2,top,bot,err2] = tqlb_orig(alpha,beta); 30 | fprintf('Elapsed time = %f\n',toc); 31 | fprintf('Number of flops = %f\n',flops); 32 | fprintf('Max rel. error = %e\n',max(abs((lambda2-true)./true))) 33 | 34 | 35 | fprintf('-----------------------------------------------------------------\n') 36 | disp('eig:') 37 | fprintf('\n') 38 | tic, flops(0); 39 | lambda1 = eig(T); 40 | lambda1 =sort(lambda1); 41 | fprintf('Elapsed time = %f\n',toc); 42 | fprintf('Number of flops = %f\n',flops); 43 | fprintf('Max rel. error = %e\n',max(abs((lambda1-true)./true))) 44 | 45 | fprintf('-----------------------------------------------------------------\n') 46 | disp('eig:') 47 | fprintf('\n') 48 | tic, flops(0); 49 | lambda1 = eig(full(T)); 50 | lambda1 =sort(lambda1); 51 | fprintf('Elapsed time = %f\n',toc); 52 | fprintf('Number of flops = %f\n',flops); 53 | fprintf('Max rel. error = %e\n',max(abs((lambda1-true)./true))) 54 | 55 | 56 | -------------------------------------------------------------------------------- /External/RPCA/exact_alm_rpca/exact_alm_rpca/PROPACK/bdsqr_mex.c: -------------------------------------------------------------------------------- 1 | /* 2 | MEX interface for LAPACK routine bdsqr. 3 | Matlab calling sequence: 4 | [sigma,bnd] = bdsqr(alpha,beta) 5 | */ 6 | 7 | #include 8 | #include 9 | #include "mex.h" 10 | 11 | /* Templates for FORTRAN routines: */ 12 | void dbdqr_(int *n, double *d, double *e, double *c1, double *c2); 13 | void dbdsqr_(char *uplo, int *n, int *ncvt, int *nru, int *ncc, 14 | double *d, double *e, double *vt, int *ldt, double *u, 15 | int *ldu, double *c, int *ldc, double *work, int *info); 16 | 17 | /* Here comes the gateway function to be called by Matlab: */ 18 | void mexFunction(int nlhs, mxArray *plhs[], 19 | int nrhs, const mxArray *prhs[]) 20 | { 21 | int m, n, i, info, zero=0, one=1; 22 | double *d,*e,dummy, *wrk, *bnd; 23 | 24 | if (nrhs != 2) 25 | mexErrMsgTxt("bdsqr requires two input arguments"); 26 | else if (nlhs != 2) 27 | mexErrMsgTxt("bdsqr requires two output arguments"); 28 | 29 | m = mxGetM(prhs[0]); /* get the dimensions of the input */ 30 | n = mxGetN(prhs[0]); 31 | /* make sure input input vectors are same length */ 32 | if (m != mxGetM(prhs[1]) ) 33 | mexErrMsgTxt("alpha and beta must have the same size"); 34 | /* make sure input is m x 1 */ 35 | if ( n != 1 || mxGetN(prhs[1]) != 1 || n != mxGetN(prhs[1])) 36 | mexErrMsgTxt("alpha and beta must be a m x 1 vectors"); 37 | 38 | /* Create/allocate return arguments */ 39 | for (i=0; i<2; i++) { 40 | plhs[i]=mxCreateDoubleMatrix(m,1,mxREAL); 41 | } 42 | 43 | e = mxCalloc(m,sizeof(double)); 44 | wrk = mxCalloc(4*m-4,sizeof(double)); 45 | d = mxGetPr(plhs[0]); 46 | memcpy(d,mxGetPr(prhs[0]), m*sizeof(double)); 47 | memcpy(e,mxGetPr(prhs[1]), m*sizeof(double)); 48 | bnd = mxGetPr(plhs[1]); 49 | for (i=0; i 0) 63 | mexWarnMsgTxt("DBDSQR: singular values did not converge"); 64 | 65 | /* Free work arrays */ 66 | mxFree(e); 67 | mxFree(wrk); 68 | } 69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /SACS_code/sacs_calWeight.m: -------------------------------------------------------------------------------- 1 | function w = sacs_calWeight(map_names, img_names, Mset, imgpath) 2 | img_num = length(img_names); 3 | map_num = length(map_names); 4 | 5 | w = zeros([img_num map_num]); 6 | bins = 1000; 7 | supdir='./superpixels/'; %the superpixel label file path 8 | 9 | F = zeros( [img_num*map_num, bins] );%the feature matrix 10 | 11 | for i = 1:img_num, 12 | imname = [imgpath '/' [img_names{i},'.bmp'] ]; 13 | img = imread(imname); 14 | [m,n,~] = size(img); 15 | img_R = double(img(:,:,1)); 16 | img_G = double(img(:,:,2)); 17 | img_B = double(img(:,:,3)); 18 | 19 | %------------generate the superpixels-------------------% 20 | superpixels= SLIC_mex( img, 200, 20 ); 21 | spnum = max(superpixels(:)); % the actual numbler of the superpixels 22 | 23 | avg = zeros(1,spnum); 24 | for p=1:map_num, 25 | mest = Mset{i,p}; 26 | mest = double(mest); 27 | for j=1:spnum, 28 | h = superpixels == j; 29 | %calculate the average saliency score for each superpixel 30 | avg(j) = mean(mest(h)); 31 | end; 32 | thes = 0.3; 33 | sign = avg >= thes * max(avg);%sailency thresholding 34 | slabels = find(sign); % record the superpixel label over the theshold 35 | %compute the color histogram for the p^th map of the i^th img 36 | fhis = []; 37 | for j=1:length(slabels), 38 | h = superpixels == slabels(j); 39 | H = floor(img_R(h)/25.6)*100+floor(img_G(h)/25.6)*10+floor(img_B(h)/25.6); 40 | his = hist( H(:) , 0:1:bins-1 ); 41 | fhis = [fhis;his]; 42 | end; 43 | F( (i-1)*map_num + p , : ) = sum(fhis); 44 | end; 45 | end; 46 | 47 | F = F / 10000; % to reduce the scale of each bin, for accelerating the speed. 48 | %---------------------RPCA---------------------------% 49 | %lamda is used to control the weight of the saprsity of E 50 | lamda = 0.05; 51 | [~ ,E] = exact_alm_rpca(F',lamda); 52 | S = double(E'); 53 | %equation 10 54 | for i=1:img_num, 55 | for j=1:map_num, 56 | w(i,j) = norm( S((i-1)*map_num+j,:) ); 57 | end; 58 | end; 59 | w = w / (max(w(:))-min(w(:))); %normalization 60 | w = exp(-w); 61 | sum_w = sum(w , 2); 62 | sum_w = repmat(sum_w , 1, map_num); 63 | w = w ./ sum_w; 64 | end -------------------------------------------------------------------------------- /External/RPCA/exact_alm_rpca/exact_alm_rpca/PROPACK/lansvd.doc: -------------------------------------------------------------------------------- 1 | LANSVD Compute a few singular values and singular vectors. 2 | LANSVD computes singular triplets (u,v,sigma) such that 3 | A*u = sigma*v and A'*v = sigma*u. Only a few singular values 4 | and singular vectors are computed using the Lanczos 5 | bidiagonalization algorithm with partial reorthogonalization (BPRO). 6 | 7 | S = LANSVD(A) 8 | S = LANSVD('Afun','Atransfun',M,N) 9 | 10 | The first input argument is either a matrix or a 11 | string containing the name of an M-file which applies a linear 12 | operator to the columns of a given matrix. In the latter case, 13 | the second input must be the name of an M-file which applies the 14 | transpose of the same operator to the columns of a given matrix, 15 | and the third and fourth arguments must be M and N, the dimensions 16 | of the problem. 17 | 18 | [U,S,V] = LANSVD(A,K,'L',...) computes the K largest singular values. 19 | 20 | [U,S,V] = LANSVD(A,K,'S',...) computes the K smallest singular values. 21 | 22 | The full calling sequence is 23 | 24 | [U,S,V] = LANSVD(A,K,SIGMA,OPTIONS) 25 | [U,S,V] = LANSVD('Afun','Atransfun',M,N,K,SIGMA,OPTIONS) 26 | 27 | where K is the number of singular values desired and 28 | SIGMA is 'L' or 'S'. 29 | 30 | The OPTIONS structure specifies certain parameters in the algorithm. 31 | Field name Parameter Default 32 | 33 | OPTIONS.tol Convergence tolerance 16*eps 34 | OPTIONS.lanmax Dimension of the Lanczos basis. 35 | OPTIONS.p0 Starting vector for the Lanczos rand(n,1)-0.5 36 | iteration. 37 | OPTIONS.delta Level of orthogonality among the sqrt(eps/K) 38 | Lanczos vectors. 39 | OPTIONS.eta Level of orthogonality after 10*eps^(3/4) 40 | reorthogonalization. 41 | OPTIONS.cgs reorthogonalization method used 0 42 | '0' : iterated modified Gram-Schmidt 43 | '1' : iterated classical Gram-Schmidt 44 | OPTIONS.elr If equal to 1 then extended local 1 45 | reorthogonalization is enforced. 46 | 47 | See also LANBPRO, SVDS, SVD 48 | 49 | References: 50 | R.M. Larsen, Ph.D. Thesis, Aarhus University, 1998. 51 | 52 | B. N. Parlett, ``The Symmetric Eigenvalue Problem'', 53 | Prentice-Hall, Englewood Cliffs, NJ, 1980. 54 | 55 | H. D. Simon, ``The Lanczos algorithm with partial reorthogonalization'', 56 | Math. Comp. 42 (1984), no. 165, 115--142. 57 | 58 | Rasmus Munk Larsen, DAIMI, 1998 59 | -------------------------------------------------------------------------------- /External/RPCA/exact_alm_rpca/exact_alm_rpca/PROPACK/lansvd.txt: -------------------------------------------------------------------------------- 1 | LANSVD Compute a few singular values and singular vectors. 2 | LANSVD computes singular triplets (u,v,sigma) such that 3 | A*u = sigma*v and A'*v = sigma*u. Only a few singular values 4 | and singular vectors are computed using the Lanczos 5 | bidiagonalization algorithm with partial reorthogonalization (BPRO). 6 | 7 | S = LANSVD(A) 8 | S = LANSVD('Afun','Atransfun',M,N) 9 | 10 | The first input argument is either a matrix or a 11 | string containing the name of an M-file which applies a linear 12 | operator to the columns of a given matrix. In the latter case, 13 | the second input must be the name of an M-file which applies the 14 | transpose of the same operator to the columns of a given matrix, 15 | and the third and fourth arguments must be M and N, the dimensions 16 | of the problem. 17 | 18 | [U,S,V] = LANSVD(A,K,'L',...) computes the K largest singular values. 19 | 20 | [U,S,V] = LANSVD(A,K,'S',...) computes the K smallest singular values. 21 | 22 | The full calling sequence is 23 | 24 | [U,S,V] = LANSVD(A,K,SIGMA,OPTIONS) 25 | [U,S,V] = LANSVD('Afun','Atransfun',M,N,K,SIGMA,OPTIONS) 26 | 27 | where K is the number of singular values desired and 28 | SIGMA is 'L' or 'S'. 29 | 30 | The OPTIONS structure specifies certain parameters in the algorithm. 31 | Field name Parameter Default 32 | 33 | OPTIONS.tol Convergence tolerance 16*eps 34 | OPTIONS.lanmax Dimension of the Lanczos basis. 35 | OPTIONS.p0 Starting vector for the Lanczos rand(n,1)-0.5 36 | iteration. 37 | OPTIONS.delta Level of orthogonality among the sqrt(eps/K) 38 | Lanczos vectors. 39 | OPTIONS.eta Level of orthogonality after 10*eps^(3/4) 40 | reorthogonalization. 41 | OPTIONS.cgs reorthogonalization method used 0 42 | '0' : iterated modified Gram-Schmidt 43 | '1' : iterated classical Gram-Schmidt 44 | OPTIONS.elr If equal to 1 then extended local 1 45 | reorthogonalization is enforced. 46 | 47 | See also LANBPRO, SVDS, SVD 48 | 49 | References: 50 | R.M. Larsen, Ph.D. Thesis, Aarhus University, 1998. 51 | 52 | B. N. Parlett, ``The Symmetric Eigenvalue Problem'', 53 | Prentice-Hall, Englewood Cliffs, NJ, 1980. 54 | 55 | H. D. Simon, ``The Lanczos algorithm with partial reorthogonalization'', 56 | Math. Comp. 42 (1984), no. 165, 115--142. 57 | 58 | Rasmus Munk Larsen, DAIMI, 1998 59 | -------------------------------------------------------------------------------- /External/RPCA/exact_alm_rpca/exact_alm_rpca/PROPACK/laneig.doc: -------------------------------------------------------------------------------- 1 | LANEIG Compute a few eigenvalues and eigenvectors. 2 | LANEIG solves the eigenvalue problem A*v=lambda*v, when A is 3 | real and symmetric using the Lanczos algorithm with partial 4 | reorthogonalization (PRO). 5 | 6 | [V,D] = LANEIG(A) 7 | [V,D] = LANEIG('Afun',N) 8 | 9 | The first input argument is either a real symmetric matrix, or a 10 | string containing the name of an M-file which applies a linear 11 | operator to the columns of a given matrix. In the latter case, 12 | the second input argument must be N, the order of the problem. 13 | 14 | The full calling sequence is 15 | 16 | [V,D,ERR] = LANEIG(A,K,SIGMA,OPTIONS) 17 | [V,D,ERR] = LANEIG('Afun',N,K,SIGMA,OPTIONS) 18 | 19 | On exit ERR contains the computed error bounds. K is the number of 20 | eigenvalues desired and SIGMA is numerical shift or a two letter string 21 | which specifies which part of the spectrum should be computed: 22 | 23 | SIGMA Specified eigenvalues 24 | 25 | 'AL' Algebraically Largest 26 | 'AS' Algebraically Smallest 27 | 'LM' Largest Magnitude (default) 28 | 'SM' Smallest Magnitude (does not work when A is an m-file) 29 | 'BE' Both Ends. Computes k/2 eigenvalues 30 | from each end of the spectrum (one more 31 | from the high end if k is odd.) 32 | 33 | The OPTIONS structure specifies certain parameters in the algorithm. 34 | 35 | Field name Parameter Default 36 | 37 | OPTIONS.tol Convergence tolerance 16*eps 38 | OPTIONS.lanmax Dimension of the Lanczos basis. 39 | OPTIONS.v0 Starting vector for the Lanczos rand(n,1)-0.5 40 | iteration. 41 | OPTIONS.delta Level of orthogonality among the sqrt(eps/K) 42 | Lanczos vectors. 43 | OPTIONS.eta Level of orthogonality after 10*eps^(3/4) 44 | reorthogonalization. 45 | OPTIONS.cgs reorthogonalization method used 0 46 | '0' : iterated modified Gram-Schmidt 47 | '1' : iterated classical Gram-Schmidt 48 | OPTIONS.elr If equal to 1 then extended local 1 49 | reorthogonalization is enforced. 50 | 51 | See also LANPRO, EIGS, EIG. 52 | 53 | References: 54 | R.M. Larsen, Ph.D. Thesis, Aarhus University, 1998. 55 | 56 | B. N. Parlett, ``The Symmetric Eigenvalue Problem'', 57 | Prentice-Hall, Englewood Cliffs, NJ, 1980. 58 | 59 | H. D. Simon, ``The Lanczos algorithm with partial reorthogonalization'', 60 | Math. Comp. 42 (1984), no. 165, 115--142. 61 | 62 | Rasmus Munk Larsen, DAIMI, 1998 63 | -------------------------------------------------------------------------------- /External/RPCA/exact_alm_rpca/exact_alm_rpca/PROPACK/laneig.txt: -------------------------------------------------------------------------------- 1 | LANEIG Compute a few eigenvalues and eigenvectors. 2 | LANEIG solves the eigenvalue problem A*v=lambda*v, when A is 3 | real and symmetric using the Lanczos algorithm with partial 4 | reorthogonalization (PRO). 5 | 6 | [V,D] = LANEIG(A) 7 | [V,D] = LANEIG('Afun',N) 8 | 9 | The first input argument is either a real symmetric matrix, or a 10 | string containing the name of an M-file which applies a linear 11 | operator to the columns of a given matrix. In the latter case, 12 | the second input argument must be N, the order of the problem. 13 | 14 | The full calling sequence is 15 | 16 | [V,D,ERR] = LANEIG(A,K,SIGMA,OPTIONS) 17 | [V,D,ERR] = LANEIG('Afun',N,K,SIGMA,OPTIONS) 18 | 19 | On exit ERR contains the computed error bounds. K is the number of 20 | eigenvalues desired and SIGMA is numerical shift or a two letter string 21 | which specifies which part of the spectrum should be computed: 22 | 23 | SIGMA Specified eigenvalues 24 | 25 | 'AL' Algebraically Largest 26 | 'AS' Algebraically Smallest 27 | 'LM' Largest Magnitude (default) 28 | 'SM' Smallest Magnitude (does not work when A is an m-file) 29 | 'BE' Both Ends. Computes k/2 eigenvalues 30 | from each end of the spectrum (one more 31 | from the high end if k is odd.) 32 | 33 | The OPTIONS structure specifies certain parameters in the algorithm. 34 | 35 | Field name Parameter Default 36 | 37 | OPTIONS.tol Convergence tolerance 16*eps 38 | OPTIONS.lanmax Dimension of the Lanczos basis. 39 | OPTIONS.v0 Starting vector for the Lanczos rand(n,1)-0.5 40 | iteration. 41 | OPTIONS.delta Level of orthogonality among the sqrt(eps/K) 42 | Lanczos vectors. 43 | OPTIONS.eta Level of orthogonality after 10*eps^(3/4) 44 | reorthogonalization. 45 | OPTIONS.cgs reorthogonalization method used 0 46 | '0' : iterated modified Gram-Schmidt 47 | '1' : iterated classical Gram-Schmidt 48 | OPTIONS.elr If equal to 1 then extended local 1 49 | reorthogonalization is enforced. 50 | 51 | See also LANPRO, EIGS, EIG. 52 | 53 | References: 54 | R.M. Larsen, Ph.D. Thesis, Aarhus University, 1998. 55 | 56 | B. N. Parlett, ``The Symmetric Eigenvalue Problem'', 57 | Prentice-Hall, Englewood Cliffs, NJ, 1980. 58 | 59 | H. D. Simon, ``The Lanczos algorithm with partial reorthogonalization'', 60 | Math. Comp. 42 (1984), no. 165, 115--142. 61 | 62 | Rasmus Munk Larsen, DAIMI, 1998 63 | -------------------------------------------------------------------------------- /External/RPCA/exact_alm_rpca/exact_alm_rpca/PROPACK/update_gbound.m: -------------------------------------------------------------------------------- 1 | function anorm = update_gbound(anorm,alpha,beta,j) 2 | %UPDATE_GBOUND Update Gerscgorin estimate of 2-norm 3 | % ANORM = UPDATE_GBOUND(ANORM,ALPHA,BETA,J) updates the Gersgorin bound 4 | % for the tridiagonal in the Lanczos process after the J'th step. 5 | % Applies Gerscgorins circles to T_K'*T_k instead of T_k itself 6 | % since this gives a tighter bound. 7 | 8 | if j==1 % Apply Gerscgorin circles to T_k'*T_k to estimate || A ||_2 9 | i=j; 10 | % scale to avoid overflow 11 | scale = max(abs(alpha(i)),abs(beta(i+1))); 12 | alpha(i) = alpha(i)/scale; 13 | beta(i) = beta(i)/scale; 14 | anorm = 1.01*scale*sqrt(alpha(i)^2+beta(i+1)^2 + abs(alpha(i)*beta(i+1))); 15 | elseif j==2 16 | i=1; 17 | % scale to avoid overflow 18 | scale = max(max(abs(alpha(1:2)),max(abs(beta(2:3))))); 19 | alpha(1:2) = alpha(1:2)/scale; 20 | beta(2:3) = beta(2:3)/scale; 21 | 22 | anorm = max(anorm, scale*sqrt(alpha(i)^2+beta(i+1)^2 + ... 23 | abs(alpha(i)*beta(i+1) + alpha(i+1)*beta(i+1)) + ... 24 | abs(beta(i+1)*beta(i+2)))); 25 | i=2; 26 | anorm = max(anorm,scale*sqrt(abs(beta(i)*alpha(i-1) + alpha(i)*beta(i)) + ... 27 | beta(i)^2+alpha(i)^2+beta(i+1)^2 + ... 28 | abs(alpha(i)*beta(i+1))) ); 29 | elseif j==3 30 | % scale to avoid overflow 31 | scale = max(max(abs(alpha(1:3)),max(abs(beta(2:4))))); 32 | alpha(1:3) = alpha(1:3)/scale; 33 | beta(2:4) = beta(2:4)/scale; 34 | i=2; 35 | anorm = max(anorm,scale*sqrt(abs(beta(i)*alpha(i-1) + alpha(i)*beta(i)) + ... 36 | beta(i)^2+alpha(i)^2+beta(i+1)^2 + ... 37 | abs(alpha(i)*beta(i+1) + alpha(i+1)*beta(i+1)) + ... 38 | abs(beta(i+1)*beta(i+2))) ); 39 | i=3; 40 | anorm = max(anorm,scale*sqrt(abs(beta(i)*beta(i-1)) + ... 41 | abs(beta(i)*alpha(i-1) + alpha(i)*beta(i)) + ... 42 | beta(i)^2+alpha(i)^2+beta(i+1)^2 + ... 43 | abs(alpha(i)*beta(i+1))) ); 44 | else 45 | % scale to avoid overflow 46 | % scale = max(max(abs(alpha(j-2:j)),max(abs(beta(j-2:j+1))))); 47 | % alpha(j-2:j) = alpha(j-2:j)/scale; 48 | % beta(j-2:j+1) = beta(j-2:j+1)/scale; 49 | 50 | % Avoid scaling, which is slow. At j>3 the estimate is usually quite good 51 | % so just make sure that anorm is not made infinite by overflow. 52 | i = j-1; 53 | anorm1 = sqrt(abs(beta(i)*beta(i-1)) + ... 54 | abs(beta(i)*alpha(i-1) + alpha(i)*beta(i)) + ... 55 | beta(i)^2+alpha(i)^2+beta(i+1)^2 + ... 56 | abs(alpha(i)*beta(i+1) + alpha(i+1)*beta(i+1)) + ... 57 | abs(beta(i+1)*beta(i+2))); 58 | if isfinite(anorm1) 59 | anorm = max(anorm,anorm1); 60 | end 61 | i = j; 62 | anorm1 = sqrt(abs(beta(i)*beta(i-1)) + ... 63 | abs(beta(i)*alpha(i-1) + alpha(i)*beta(i)) + ... 64 | beta(i)^2+alpha(i)^2+beta(i+1)^2 + ... 65 | abs(alpha(i)*beta(i+1))); 66 | if isfinite(anorm1) 67 | anorm = max(anorm,anorm1); 68 | end 69 | end 70 | -------------------------------------------------------------------------------- /External/RPCA/exact_alm_rpca/exact_alm_rpca/PROPACK/reorth_mex.c: -------------------------------------------------------------------------------- 1 | /* 2 | ------------------------------------------------------------------------- 3 | GATEWAY ROUTINE FOR CALLING REORTH FROM MATLAB. 4 | 5 | REORTH Reorthogonalize a vector using iterated Gram-Schmidt 6 | 7 | [R_NEW,NORMR_NEW,NRE] = reorth(Q,R,NORMR,INDEX,ALPHA,METHOD) 8 | reorthogonalizes R against the subset of columns of Q given by INDEX. 9 | If INDEX==[] then R is reorthogonalized all columns of Q. 10 | If the result R_NEW has a small norm, i.e. if norm(R_NEW) < ALPHA*NORMR, 11 | then a second reorthogonalization is performed. If the norm of R_NEW 12 | is once more decreased by more than a factor of ALPHA then R is 13 | numerically in span(Q(:,INDEX)) and a zero-vector is returned for R_NEW. 14 | 15 | If method==0 then iterated modified Gram-Schmidt is used. 16 | If method==1 then iterated classical Gram-Schmidt is used. 17 | 18 | The default value for ALPHA is 0.5. 19 | NRE is the number of reorthogonalizations performed (1 or 2). 20 | 21 | References: 22 | Aake Bjorck, "Numerical Methods for Least Squares Problems", 23 | SIAM, Philadelphia, 1996, pp. 68-69. 24 | 25 | J.~W. Daniel, W.~B. Gragg, L. Kaufman and G.~W. Stewart, 26 | ``Reorthogonalization and Stable Algorithms Updating the 27 | Gram-Schmidt QR Factorization'', Math. Comp., 30 (1976), no. 28 | 136, pp. 772-795. 29 | 30 | B. N. Parlett, ``The Symmetric Eigenvalue Problem'', 31 | Prentice-Hall, Englewood Cliffs, NJ, 1980. pp. 105-109 32 | 33 | Rasmus Munk Larsen, DAIMI, 1998. 34 | ------------------------------------------------------------------------- 35 | */ 36 | 37 | #include 38 | #include "mex.h" 39 | 40 | /* Template for reorth: */ 41 | 42 | void reorth_(int *n, int *k, double *V, int *ldv, double *vnew, 43 | double *normvnew, double *index, double *alpha, double *work, 44 | int *iflag, int *nre); 45 | 46 | /* Here comes the gateway function to be called by Matlab: */ 47 | void mexFunction(int nlhs, mxArray *plhs[], 48 | int nrhs, const mxArray *prhs[]) 49 | { 50 | int n, k1, k, imethod, inre; 51 | double *work; 52 | 53 | if (nrhs != 6) 54 | mexErrMsgTxt("reorth requires 6 input arguments"); 55 | else if (nlhs < 2) 56 | mexErrMsgTxt("reorth requires at least 2 output arguments"); 57 | 58 | n = mxGetM(prhs[0]); /* get the dimensions of the input */ 59 | k1 = mxGetN(prhs[0]); 60 | k = mxGetM(prhs[3]) * mxGetN(prhs[3]); 61 | 62 | /* Create/allocate return argument, a 1x1 real-valued Matrix */ 63 | plhs[0]=mxCreateDoubleMatrix(n,1,mxREAL); 64 | plhs[1]=mxCreateDoubleMatrix(1,1,mxREAL); 65 | if (nlhs>2) 66 | plhs[2]=mxCreateDoubleMatrix(1,1,mxREAL); 67 | 68 | work = mxCalloc(k,sizeof(double)); 69 | 70 | memcpy(mxGetPr(plhs[0]),mxGetPr(prhs[1]), n*sizeof(double)); 71 | memcpy(mxGetPr(plhs[1]),mxGetPr(prhs[2]), sizeof(double)); 72 | imethod = (int) mxGetScalar(prhs[5]); 73 | 74 | reorth_(&n, &k, mxGetPr(prhs[0]), &n, mxGetPr(plhs[0]), 75 | mxGetPr(plhs[1]), mxGetPr(prhs[3]), mxGetPr(prhs[4]), 76 | work,&imethod,&inre); 77 | if (nlhs>2) 78 | *(mxGetPr(plhs[2])) = (double) inre*k; 79 | 80 | mxFree(work); 81 | } 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /External/RPCA/exact_alm_rpca/exact_alm_rpca/PROPACK/reorth.m: -------------------------------------------------------------------------------- 1 | function [r,normr,nre,s] = reorth(Q,r,normr,index,alpha,method) 2 | 3 | %REORTH Reorthogonalize a vector using iterated Gram-Schmidt 4 | % 5 | % [R_NEW,NORMR_NEW,NRE] = reorth(Q,R,NORMR,INDEX,ALPHA,METHOD) 6 | % reorthogonalizes R against the subset of columns of Q given by INDEX. 7 | % If INDEX==[] then R is reorthogonalized all columns of Q. 8 | % If the result R_NEW has a small norm, i.e. if norm(R_NEW) < ALPHA*NORMR, 9 | % then a second reorthogonalization is performed. If the norm of R_NEW 10 | % is once more decreased by more than a factor of ALPHA then R is 11 | % numerically in span(Q(:,INDEX)) and a zero-vector is returned for R_NEW. 12 | % 13 | % If method==0 then iterated modified Gram-Schmidt is used. 14 | % If method==1 then iterated classical Gram-Schmidt is used. 15 | % 16 | % The default value for ALPHA is 0.5. 17 | % NRE is the number of reorthogonalizations performed (1 or 2). 18 | 19 | % References: 20 | % Aake Bjorck, "Numerical Methods for Least Squares Problems", 21 | % SIAM, Philadelphia, 1996, pp. 68-69. 22 | % 23 | % J.~W. Daniel, W.~B. Gragg, L. Kaufman and G.~W. Stewart, 24 | % ``Reorthogonalization and Stable Algorithms Updating the 25 | % Gram-Schmidt QR Factorization'', Math. Comp., 30 (1976), no. 26 | % 136, pp. 772-795. 27 | % 28 | % B. N. Parlett, ``The Symmetric Eigenvalue Problem'', 29 | % Prentice-Hall, Englewood Cliffs, NJ, 1980. pp. 105-109 30 | 31 | % Rasmus Munk Larsen, DAIMI, 1998. 32 | 33 | % Check input arguments. 34 | % warning('PROPACK:NotUsingMex','Using slow matlab code for reorth.') 35 | if nargin<2 36 | error('Not enough input arguments.') 37 | end 38 | [n k1] = size(Q); 39 | if nargin<3 | isempty(normr) 40 | % normr = norm(r); 41 | normr = sqrt(r'*r); 42 | end 43 | if nargin<4 | isempty(index) 44 | k=k1; 45 | index = [1:k]'; 46 | simple = 1; 47 | else 48 | k = length(index); 49 | if k==k1 & index(:)==[1:k]' 50 | simple = 1; 51 | else 52 | simple = 0; 53 | end 54 | end 55 | if nargin<5 | isempty(alpha) 56 | alpha=0.5; % This choice garanties that 57 | % || Q^T*r_new - e_{k+1} ||_2 <= 2*eps*||r_new||_2, 58 | % cf. Kahans ``twice is enough'' statement proved in 59 | % Parletts book. 60 | end 61 | if nargin<6 | isempty(method) 62 | method = 0; 63 | end 64 | if k==0 | n==0 65 | return 66 | end 67 | if nargout>3 68 | s = zeros(k,1); 69 | end 70 | 71 | 72 | normr_old = 0; 73 | nre = 0; 74 | while normr < alpha*normr_old | nre==0 75 | if method==1 76 | if simple 77 | t = Q'*r; 78 | r = r - Q*t; 79 | else 80 | t = Q(:,index)'*r; 81 | r = r - Q(:,index)*t; 82 | end 83 | else 84 | for i=index, 85 | t = Q(:,i)'*r; 86 | r = r - Q(:,i)*t; 87 | end 88 | end 89 | if nargout>3 90 | s = s + t; 91 | end 92 | normr_old = normr; 93 | % normr = norm(r); 94 | normr = sqrt(r'*r); 95 | nre = nre + 1; 96 | if nre > 4 97 | % r is in span(Q) to full accuracy => accept r = 0 as the new vector. 98 | r = zeros(n,1); 99 | normr = 0; 100 | return 101 | end 102 | end 103 | -------------------------------------------------------------------------------- /External/RPCA/exact_alm_rpca/exact_alm_rpca/PROPACK/lanpro.doc: -------------------------------------------------------------------------------- 1 | LANPRO Lanczos tridiagonalization with partial reorthogonalization 2 | LANPRO computes the Lanczos tridiagonalization of a real symmetric 3 | matrix using the symmetric Lanczos algorithm with partial 4 | reorthogonalization. 5 | 6 | [Q_K,T_K,R,ANORM,IERR,WORK] = LANPRO(A,K,R0,OPTIONS,Q_old,T_old) 7 | [Q_K,T_K,R,ANORM,IERR,WORK] = LANPRO('Afun',N,K,R0,OPTIONS,Q_old,T_old) 8 | 9 | Computes K steps of the Lanczos algorithm with starting vector R0, 10 | and returns the K x K tridiagonal T_K, the N x K matrix Q_K 11 | with semiorthonormal columns and the residual vector R such that 12 | 13 | A*Q_K = Q_K*T_K + R . 14 | 15 | Partial reorthogonalization is used to keep the columns of Q_K 16 | semiorthogonal: 17 | MAX(DIAG((eye(k) - Q_K'*Q_K))) <= OPTIONS.delta. 18 | 19 | 20 | The first input argument is either a real symmetric matrix, a struct with 21 | components A.L and A.U or a string containing the name of an M-file which 22 | applies a linear operator to the columns of a given matrix. In the latter 23 | case, the second input argument must be N, the order of the problem. 24 | 25 | If A is a struct with components A.L and A.U, such that 26 | L*U = (A - sigma*I), a shift-and-invert Lanczos iteration is performed 27 | 28 | The OPTIONS structure is used to control the reorthogonalization: 29 | OPTIONS.delta: Desired level of orthogonality 30 | (default = sqrt(eps/K)). 31 | OPTIONS.eta : Level of orthogonality after reorthogonalization 32 | (default = eps^(3/4)/sqrt(K)). 33 | OPTIONS.cgs : Flag for switching between different reorthogonalization 34 | algorithms: 35 | 0 = iterated modified Gram-Schmidt (default) 36 | 1 = iterated classical Gram-Schmidt 37 | OPTIONS.elr : If OPTIONS.elr = 1 (default) then extended local 38 | reorthogonalization is enforced. 39 | OPTIONS.Y : The lanczos vectors are reorthogonalized against 40 | the columns of the matrix OPTIONS.Y. 41 | 42 | If both R0, Q_old and T_old are provided, they must contain 43 | a partial Lanczos tridiagonalization of A on the form 44 | 45 | A Q_old = Q_old T_old + R0 . 46 | 47 | In this case the factorization is extended to dimension K x K by 48 | continuing the Lanczos algorithm with R0 as starting vector. 49 | 50 | On exit ANORM contains an approximation to ||A||_2. 51 | IERR = 0 : K steps were performed succesfully. 52 | IERR > 0 : K steps were performed succesfully, but the algorithm 53 | switched to full reorthogonalization after IERR steps. 54 | IERR < 0 : Iteration was terminated after -IERR steps because an 55 | invariant subspace was found, and 3 deflation attempts 56 | were unsuccessful. 57 | On exit WORK(1) contains the number of reorthogonalizations performed, and 58 | WORK(2) contains the number of inner products performed in the 59 | reorthogonalizations. 60 | 61 | See also LANEIG, REORTH, COMPUTE_INT 62 | 63 | References: 64 | R.M. Larsen, Ph.D. Thesis, Aarhus University, 1998. 65 | 66 | G. H. Golub & C. F. Van Loan, "Matrix Computations", 67 | 3. Ed., Johns Hopkins, 1996. Chapter 9. 68 | 69 | B. N. Parlett, ``The Symmetric Eigenvalue Problem'', 70 | Prentice-Hall, Englewood Cliffs, NJ, 1980. 71 | 72 | H. D. Simon, ``The Lanczos algorithm with partial reorthogonalization'', 73 | Math. Comp. 42 (1984), no. 165, 115--142. 74 | 75 | Rasmus Munk Larsen, DAIMI, 1998 76 | -------------------------------------------------------------------------------- /External/RPCA/exact_alm_rpca/exact_alm_rpca/PROPACK/lanpro.txt: -------------------------------------------------------------------------------- 1 | LANPRO Lanczos tridiagonalization with partial reorthogonalization 2 | LANPRO computes the Lanczos tridiagonalization of a real symmetric 3 | matrix using the symmetric Lanczos algorithm with partial 4 | reorthogonalization. 5 | 6 | [Q_K,T_K,R,ANORM,IERR,WORK] = LANPRO(A,K,R0,OPTIONS,Q_old,T_old) 7 | [Q_K,T_K,R,ANORM,IERR,WORK] = LANPRO('Afun',N,K,R0,OPTIONS,Q_old,T_old) 8 | 9 | Computes K steps of the Lanczos algorithm with starting vector R0, 10 | and returns the K x K tridiagonal T_K, the N x K matrix Q_K 11 | with semiorthonormal columns and the residual vector R such that 12 | 13 | A*Q_K = Q_K*T_K + R . 14 | 15 | Partial reorthogonalization is used to keep the columns of Q_K 16 | semiorthogonal: 17 | MAX(DIAG((eye(k) - Q_K'*Q_K))) <= OPTIONS.delta. 18 | 19 | 20 | The first input argument is either a real symmetric matrix, a struct with 21 | components A.L and A.U or a string containing the name of an M-file which 22 | applies a linear operator to the columns of a given matrix. In the latter 23 | case, the second input argument must be N, the order of the problem. 24 | 25 | If A is a struct with components A.L and A.U, such that 26 | L*U = (A - sigma*I), a shift-and-invert Lanczos iteration is performed 27 | 28 | The OPTIONS structure is used to control the reorthogonalization: 29 | OPTIONS.delta: Desired level of orthogonality 30 | (default = sqrt(eps/K)). 31 | OPTIONS.eta : Level of orthogonality after reorthogonalization 32 | (default = eps^(3/4)/sqrt(K)). 33 | OPTIONS.cgs : Flag for switching between different reorthogonalization 34 | algorithms: 35 | 0 = iterated modified Gram-Schmidt (default) 36 | 1 = iterated classical Gram-Schmidt 37 | OPTIONS.elr : If OPTIONS.elr = 1 (default) then extended local 38 | reorthogonalization is enforced. 39 | OPTIONS.Y : The lanczos vectors are reorthogonalized against 40 | the columns of the matrix OPTIONS.Y. 41 | 42 | If both R0, Q_old and T_old are provided, they must contain 43 | a partial Lanczos tridiagonalization of A on the form 44 | 45 | A Q_old = Q_old T_old + R0 . 46 | 47 | In this case the factorization is extended to dimension K x K by 48 | continuing the Lanczos algorithm with R0 as starting vector. 49 | 50 | On exit ANORM contains an approximation to ||A||_2. 51 | IERR = 0 : K steps were performed succesfully. 52 | IERR > 0 : K steps were performed succesfully, but the algorithm 53 | switched to full reorthogonalization after IERR steps. 54 | IERR < 0 : Iteration was terminated after -IERR steps because an 55 | invariant subspace was found, and 3 deflation attempts 56 | were unsuccessful. 57 | On exit WORK(1) contains the number of reorthogonalizations performed, and 58 | WORK(2) contains the number of inner products performed in the 59 | reorthogonalizations. 60 | 61 | See also LANEIG, REORTH, COMPUTE_INT 62 | 63 | References: 64 | R.M. Larsen, Ph.D. Thesis, Aarhus University, 1998. 65 | 66 | G. H. Golub & C. F. Van Loan, "Matrix Computations", 67 | 3. Ed., Johns Hopkins, 1996. Chapter 9. 68 | 69 | B. N. Parlett, ``The Symmetric Eigenvalue Problem'', 70 | Prentice-Hall, Englewood Cliffs, NJ, 1980. 71 | 72 | H. D. Simon, ``The Lanczos algorithm with partial reorthogonalization'', 73 | Math. Comp. 42 (1984), no. 165, 115--142. 74 | 75 | Rasmus Munk Larsen, DAIMI, 1998 76 | -------------------------------------------------------------------------------- /External/RPCA/exact_alm_rpca/exact_alm_rpca/PROPACK/mminfo.m: -------------------------------------------------------------------------------- 1 | function [rows, cols, entries, rep, field, symm] = mminfo(filename) 2 | % 3 | % function [rows, cols, entries, rep, field, symmetry] = mminfo(filename) 4 | % 5 | % Reads the contents of the Matrix Market file 'filename' 6 | % and extracts size and storage information. 7 | % 8 | % In the case of coordinate matrices, entries refers to the 9 | % number of coordinate entries stored in the file. The number 10 | % of non-zero entries in the final matrix cannot be determined 11 | % until the data is read (and symmetrized, if necessary). 12 | % 13 | % In the case of array matrices, entries is the product 14 | % rows*cols, regardless of whether symmetry was used to 15 | % store the matrix efficiently. 16 | % 17 | % 18 | 19 | mmfile = fopen(filename,'r'); 20 | if ( mmfile == -1 ) 21 | disp(filename); 22 | error('File not found'); 23 | end; 24 | 25 | header = fgets(mmfile); 26 | if (header == -1 ) 27 | error('Empty file.') 28 | end 29 | 30 | % NOTE: If using a version of Matlab for which strtok is not 31 | % defined, substitute 'gettok' for 'strtok' in the 32 | % following lines, and download gettok.m from the 33 | % Matrix Market site. 34 | [head0,header] = strtok(header); % see note above 35 | [head1,header] = strtok(header); 36 | [rep,header] = strtok(header); 37 | [field,header] = strtok(header); 38 | [symm,header] = strtok(header); 39 | head1 = lower(head1); 40 | rep = lower(rep); 41 | field = lower(field); 42 | symm = lower(symm); 43 | if ( length(symm) == 0 ) 44 | disp('Not enough words in header line.') 45 | disp('Recognized format: ') 46 | disp('%%MatrixMarket matrix representation field symmetry') 47 | error('Check header line.') 48 | end 49 | if ( ~ strcmp(head0,'%%MatrixMarket') ) 50 | error('Not a valid MatrixMarket header.') 51 | end 52 | if ( ~ strcmp(head1,'matrix') ) 53 | disp(['This seems to be a MatrixMarket ',head1,' file.']); 54 | disp('This function only knows how to read MatrixMarket matrix files.'); 55 | disp(' '); 56 | error(' '); 57 | end 58 | 59 | % Read through comments, ignoring them 60 | 61 | commentline = fgets(mmfile); 62 | while length(commentline) > 0 & commentline(1) == '%', 63 | commentline = fgets(mmfile); 64 | end 65 | 66 | % Read size information, then branch according to 67 | % sparse or dense format 68 | 69 | if ( strcmp(rep,'coordinate')) % read matrix given in sparse 70 | % coordinate matrix format 71 | 72 | [sizeinfo,count] = sscanf(commentline,'%d%d%d'); 73 | while ( count == 0 ) 74 | commentline = fgets(mmfile); 75 | if (commentline == -1 ) 76 | error('End-of-file reached before size information was found.') 77 | end 78 | [sizeinfo,count] = sscanf(commentline,'%d%d%d'); 79 | if ( count > 0 & count ~= 3 ) 80 | error('Invalid size specification line.') 81 | end 82 | end 83 | rows = sizeinfo(1); 84 | cols = sizeinfo(2); 85 | entries = sizeinfo(3); 86 | 87 | elseif ( strcmp(rep,'array') ) % read matrix given in dense 88 | % array (column major) format 89 | 90 | [sizeinfo,count] = sscanf(commentline,'%d%d'); 91 | while ( count == 0 ) 92 | commentline = fgets(mmfile); 93 | if (commentline == -1 ) 94 | error('End-of-file reached before size information was found.') 95 | end 96 | [sizeinfo,count] = sscanf(commentline,'%d%d'); 97 | if ( count > 0 & count ~= 2 ) 98 | error('Invalid size specification line.') 99 | end 100 | end 101 | rows = sizeinfo(1); 102 | cols = sizeinfo(2); 103 | entries = rows*cols; 104 | end 105 | 106 | fclose(mmfile); 107 | % Done. 108 | 109 | -------------------------------------------------------------------------------- /External/RPCA/exact_alm_rpca/exact_alm_rpca/PROPACK/lanbpro.doc: -------------------------------------------------------------------------------- 1 | LANBPRO Lanczos bidiagonalization with partial reorthogonalization. 2 | 3 | LANBPRO computes the Lanczos bidiagonalization of a real 4 | matrix using the with partial reorthogonalization. 5 | 6 | [U_k,B_k,V_k,R,ierr,work] = LANBPRO(A,K,R0,OPTIONS,U_old,B_old,V_old) 7 | [U_k,B_k,V_k,R,ierr,work] = LANBPRO('Afun','Atransfun',M,N,K,R0, ... 8 | OPTIONS,U_old,B_old,V_old) 9 | 10 | Computes K steps of the Lanczos bidiagonalization algorithm with partial 11 | reorthogonalization (BPRO) with M-by-1 starting vector R0, producing a 12 | lower bidiagonal K-by-K matrix B_k, an N-by-K matrix V_k, an M-by-K 13 | matrix U_k and a M-by-1 vector such that 14 | A*V_k = U_k*B_k + R 15 | Partial reorthogonalization is used to keep the columns of V_K and U_k 16 | semiorthogonal: 17 | MAX(DIAG((EYE(K) - V_K'*V_K))) <= OPTIONS.delta 18 | and 19 | MAX(DIAG((EYE(K) - U_K'*U_K))) <= OPTIONS.delta. 20 | 21 | B_k = LANBPRO(...) returns the bidiagonal matrix only. 22 | 23 | The first input argument is either a real matrix, or a string 24 | containing the name of an M-file which applies a linear operator 25 | to the columns of a given matrix. In the latter case, the second 26 | input must be the name of an M-file which applies the transpose of 27 | the same linear operator to the columns of a given matrix, 28 | and the third and fourth arguments must be M and N, the dimensions 29 | of then problem. 30 | 31 | The OPTIONS structure is used to control the reorthogonalization: 32 | OPTIONS.delta: Desired level of orthogonality 33 | (default = sqrt(eps/K)). 34 | OPTIONS.eta : Level of orthogonality after reorthogonalization 35 | (default = eps^(3/4)/sqrt(K)). 36 | OPTIONS.cgs : Flag for switching between different reorthogonalization 37 | algorithms: 38 | 0 = iterated modified Gram-Schmidt (default) 39 | 1 = iterated classical Gram-Schmidt 40 | OPTIONS.elr : If OPTIONS.elr = 1 (default) then extended local 41 | reorthogonalization is enforced. 42 | OPTIONS.onesided 43 | : If OPTIONS.onesided = 0 (default) then both the left 44 | (U) and right (V) Lanczos vectors are kept 45 | semiorthogonal. 46 | OPTIONS.onesided = 1 then only the columns of U are 47 | are reorthogonalized. 48 | OPTIONS.onesided = -1 then only the columns of V are 49 | are reorthogonalized. 50 | OPTIONS.waitbar 51 | : The progress of the algorithm is display graphically. 52 | 53 | If both R0, U_old, B_old, and V_old are provided, they must 54 | contain a partial Lanczos bidiagonalization of A on the form 55 | 56 | A V_old = U_old B_old + R0 . 57 | 58 | In this case the factorization is extended to dimension K x K by 59 | continuing the Lanczos bidiagonalization algorithm with R0 as a 60 | starting vector. 61 | 62 | The output array work contains information about the work used in 63 | reorthogonalizing the u- and v-vectors. 64 | work = [ RU PU ] 65 | [ RV PV ] 66 | where 67 | RU = Number of reorthogonalizations of U. 68 | PU = Number of inner products used in reorthogonalizing U. 69 | RV = Number of reorthogonalizations of V. 70 | PV = Number of inner products used in reorthogonalizing V. 71 | 72 | References: 73 | R.M. Larsen, Ph.D. Thesis, Aarhus University, 1998. 74 | 75 | G. H. Golub & C. F. Van Loan, "Matrix Computations", 76 | 3. Ed., Johns Hopkins, 1996. Section 9.3.4. 77 | 78 | B. N. Parlett, ``The Symmetric Eigenvalue Problem'', 79 | Prentice-Hall, Englewood Cliffs, NJ, 1980. 80 | 81 | H. D. Simon, ``The Lanczos algorithm with partial reorthogonalization'', 82 | Math. Comp. 42 (1984), no. 165, 115--142. 83 | 84 | 85 | Rasmus Munk Larsen, DAIMI, 1998. 86 | -------------------------------------------------------------------------------- /External/RPCA/exact_alm_rpca/exact_alm_rpca/PROPACK/lanbpro.txt: -------------------------------------------------------------------------------- 1 | LANBPRO Lanczos bidiagonalization with partial reorthogonalization. 2 | 3 | LANBPRO computes the Lanczos bidiagonalization of a real 4 | matrix using the with partial reorthogonalization. 5 | 6 | [U_k,B_k,V_k,R,ierr,work] = LANBPRO(A,K,R0,OPTIONS,U_old,B_old,V_old) 7 | [U_k,B_k,V_k,R,ierr,work] = LANBPRO('Afun','Atransfun',M,N,K,R0, ... 8 | OPTIONS,U_old,B_old,V_old) 9 | 10 | Computes K steps of the Lanczos bidiagonalization algorithm with partial 11 | reorthogonalization (BPRO) with M-by-1 starting vector R0, producing a 12 | lower bidiagonal K-by-K matrix B_k, an N-by-K matrix V_k, an M-by-K 13 | matrix U_k and a M-by-1 vector such that 14 | A*V_k = U_k*B_k + R 15 | Partial reorthogonalization is used to keep the columns of V_K and U_k 16 | semiorthogonal: 17 | MAX(DIAG((EYE(K) - V_K'*V_K))) <= OPTIONS.delta 18 | and 19 | MAX(DIAG((EYE(K) - U_K'*U_K))) <= OPTIONS.delta. 20 | 21 | B_k = LANBPRO(...) returns the bidiagonal matrix only. 22 | 23 | The first input argument is either a real matrix, or a string 24 | containing the name of an M-file which applies a linear operator 25 | to the columns of a given matrix. In the latter case, the second 26 | input must be the name of an M-file which applies the transpose of 27 | the same linear operator to the columns of a given matrix, 28 | and the third and fourth arguments must be M and N, the dimensions 29 | of then problem. 30 | 31 | The OPTIONS structure is used to control the reorthogonalization: 32 | OPTIONS.delta: Desired level of orthogonality 33 | (default = sqrt(eps/K)). 34 | OPTIONS.eta : Level of orthogonality after reorthogonalization 35 | (default = eps^(3/4)/sqrt(K)). 36 | OPTIONS.cgs : Flag for switching between different reorthogonalization 37 | algorithms: 38 | 0 = iterated modified Gram-Schmidt (default) 39 | 1 = iterated classical Gram-Schmidt 40 | OPTIONS.elr : If OPTIONS.elr = 1 (default) then extended local 41 | reorthogonalization is enforced. 42 | OPTIONS.onesided 43 | : If OPTIONS.onesided = 0 (default) then both the left 44 | (U) and right (V) Lanczos vectors are kept 45 | semiorthogonal. 46 | OPTIONS.onesided = 1 then only the columns of U are 47 | are reorthogonalized. 48 | OPTIONS.onesided = -1 then only the columns of V are 49 | are reorthogonalized. 50 | OPTIONS.waitbar 51 | : The progress of the algorithm is display graphically. 52 | 53 | If both R0, U_old, B_old, and V_old are provided, they must 54 | contain a partial Lanczos bidiagonalization of A on the form 55 | 56 | A V_old = U_old B_old + R0 . 57 | 58 | In this case the factorization is extended to dimension K x K by 59 | continuing the Lanczos bidiagonalization algorithm with R0 as a 60 | starting vector. 61 | 62 | The output array work contains information about the work used in 63 | reorthogonalizing the u- and v-vectors. 64 | work = [ RU PU ] 65 | [ RV PV ] 66 | where 67 | RU = Number of reorthogonalizations of U. 68 | PU = Number of inner products used in reorthogonalizing U. 69 | RV = Number of reorthogonalizations of V. 70 | PV = Number of inner products used in reorthogonalizing V. 71 | 72 | References: 73 | R.M. Larsen, Ph.D. Thesis, Aarhus University, 1998. 74 | 75 | G. H. Golub & C. F. Van Loan, "Matrix Computations", 76 | 3. Ed., Johns Hopkins, 1996. Section 9.3.4. 77 | 78 | B. N. Parlett, ``The Symmetric Eigenvalue Problem'', 79 | Prentice-Hall, Englewood Cliffs, NJ, 1980. 80 | 81 | H. D. Simon, ``The Lanczos algorithm with partial reorthogonalization'', 82 | Math. Comp. 42 (1984), no. 165, 115--142. 83 | 84 | 85 | Rasmus Munk Larsen, DAIMI, 1998. 86 | -------------------------------------------------------------------------------- /External/RPCA/exact_alm_rpca/exact_alm_rpca/exact_alm_rpca.m: -------------------------------------------------------------------------------- 1 | function [A_hat E_hat iter] = exact_alm_rpca(D, lambda, tol, maxIter) 2 | 3 | % Oct 2009 4 | % This matlab code implements the augmented Lagrange multiplier method for 5 | % Robust PCA. 6 | % 7 | % D - m x n matrix of observations/data (required input) 8 | % 9 | % lambda - weight on sparse error term in the cost function 10 | % 11 | % tol - tolerance for stopping criterion. 12 | % - DEFAULT 1e-7 if omitted or -1. 13 | % 14 | % maxIter - maximum number of iterations 15 | % - DEFAULT 1000, if omitted or -1. 16 | % 17 | % Initialize A,E,Y,u 18 | % while ~converged 19 | % minimize 20 | % L(A,E,Y,u) = |A|_* + lambda * |E|_1 + + mu/2 * |D-A-E|_F^2; 21 | % Y = Y + \mu * (D - A - E); 22 | % \mu = \rho * \mu; 23 | % end 24 | % 25 | % Minming Chen, October 2009. Questions? v-minmch@microsoft.com ; 26 | % Arvind Ganesh (abalasu2@illinois.edu) 27 | % 28 | % Copyright: Perception and Decision Laboratory, University of Illinois, Urbana-Champaign 29 | % Microsoft Research Asia, Beijing 30 | 31 | % addpath PROPACK; 32 | path(path, './RPCA/exact_alm_rpca/exact_alm_rpca/PROPACK'); 33 | 34 | [m n] = size(D); 35 | 36 | if nargin < 2 37 | lambda = 1 / sqrt(m); 38 | end 39 | 40 | if nargin < 3 41 | tol = 1e-7; 42 | elseif tol == -1 43 | tol = 1e-7; 44 | end 45 | 46 | if nargin < 4 47 | maxIter = 1000; 48 | elseif maxIter == -1 49 | maxIter = 1000; 50 | end 51 | 52 | % initialize 53 | Y = sign(D); 54 | norm_two = lansvd(Y, 1, 'L'); 55 | norm_inf = norm( Y(:), inf) / lambda; 56 | dual_norm = max(norm_two, norm_inf); 57 | Y = Y / dual_norm; 58 | 59 | A_hat = zeros( m, n); 60 | E_hat = zeros( m, n); 61 | dnorm = norm(D, 'fro'); 62 | tolProj = 1e-6 * dnorm; 63 | total_svd = 0; 64 | %mu = .5/norm_two % this one can be tuned 65 | mu = .5; 66 | rho = 6; % this one can be tuned 67 | 68 | iter = 0; 69 | converged = false; 70 | stopCriterion = 1; 71 | sv = 5; 72 | svp = sv; 73 | while ~converged 74 | iter = iter + 1; 75 | 76 | % solve the primal problem by alternative projection 77 | primal_converged = false; 78 | primal_iter = 0; 79 | sv = sv + round(n * 0.1); 80 | while primal_converged == false 81 | 82 | temp_T = D - A_hat + (1/mu)*Y; 83 | temp_E = max( temp_T - lambda/mu,0) + min( temp_T + lambda/mu,0); 84 | 85 | if choosvd(n, sv) == 1 86 | [U S V] = lansvd(D - temp_E + (1/mu)*Y, sv, 'L'); 87 | else 88 | [U S V] = svd(D - temp_E + (1/mu)*Y, 'econ'); 89 | end 90 | diagS = diag(S); 91 | svp = length(find(diagS > 1/mu)); 92 | if svp < sv 93 | sv = min(svp + 1, n); 94 | else 95 | sv = min(svp + round(0.05*n), n); 96 | end 97 | temp_A = U(:,1:svp)*diag(diagS(1:svp)-1/mu)*V(:,1:svp)'; 98 | 99 | if norm(A_hat - temp_A, 'fro') < tolProj && norm(E_hat - temp_E, 'fro') < tolProj 100 | primal_converged = true; 101 | end 102 | A_hat = temp_A; 103 | E_hat = temp_E; 104 | primal_iter = primal_iter + 1; 105 | total_svd = total_svd + 1; 106 | 107 | end 108 | 109 | Z = D - A_hat - E_hat; 110 | Y = Y + mu*Z; 111 | mu = rho * mu; 112 | 113 | %% stop Criterion 114 | stopCriterion = norm(Z, 'fro') / dnorm; 115 | if stopCriterion < tol 116 | converged = true; 117 | end 118 | 119 | disp(['Iteration' num2str(iter) ' #svd ' num2str(total_svd) ' r(A) ' num2str(svp)... 120 | ' |E|_0 ' num2str(length(find(abs(E_hat)>0)))... 121 | ' stopCriterion ' num2str(stopCriterion)]); 122 | 123 | if ~converged && iter >= maxIter 124 | disp('Maximum iterations reached') ; 125 | converged = 1 ; 126 | end 127 | end 128 | 129 | if nargin == 5 130 | fclose(fid); 131 | end 132 | 133 | -------------------------------------------------------------------------------- /External/RPCA/exact_alm_rpca/exact_alm_rpca/PROPACK/reorth.f: -------------------------------------------------------------------------------- 1 | subroutine reorth(n,k,V,ldv,vnew,normv,index,alpha,work, 2 | c iflag,nre) 3 | c 4 | c FORTRAN 77 version of MATLAB routine REORTH: 5 | c 6 | c REORTH Reorthogonalize a vector using iterated Gram-Schmidt 7 | c 8 | c [R_NEW,NORMR_NEW,NRE] = reorth(Q,R,NORMR,INDEX,ALPHA,METHOD) 9 | c reorthogonalizes R against the subset of columns of Q given by INDEX. 10 | c If INDEX==[] then R is reorthogonalized all columns of Q. 11 | c If the result R_NEW has a small norm, i.e. if norm(R_NEW) < ALPHA*NORMR, 12 | c then a second reorthogonalization is performed. If the norm of R_NEW 13 | c is once more decreased by more than a factor of ALPHA then R is 14 | c numerically in span(Q(:,INDEX)) and a zero-vector is returned for R_NEW. 15 | c 16 | c If method==0 then iterated modified Gram-Schmidt is used. 17 | c If method==1 then iterated classical Gram-Schmidt is used. 18 | c 19 | c The default value for ALPHA is 0.5. 20 | c NRE is the number of reorthogonalizations performed (1 or 2). 21 | 22 | c References: 23 | c Aake Bjorck, "Numerical Methods for Least Squares Problems", 24 | c SIAM, Philadelphia, 1996, pp. 68-69. 25 | c 26 | c J.~W. Daniel, W.~B. Gragg, L. Kaufman and G.~W. Stewart, 27 | c ``Reorthogonalization and Stable Algorithms Updating the 28 | c Gram-Schmidt QR Factorization'', Math. Comp., 30 (1976), no. 29 | c 136, pp. 772-795. 30 | c 31 | c B. N. Parlett, ``The Symmetric Eigenvalue Problem'', 32 | c Prentice-Hall, Englewood Cliffs, NJ, 1980. pp. 105-109 33 | 34 | c Rasmus Munk Larsen, DAIMI, 1998. 35 | implicit none 36 | integer n,k,ldv,i,iflag,nre 37 | double precision V(ldv,*),vnew(*),normv,index(*),work(*) 38 | double precision alpha,normv_old,dnrm2 39 | integer MAXTRY 40 | parameter (MAXTRY=4) 41 | external dgemv,dnrm2 42 | 43 | c Hack: If index .ne. 1:k we do MGS to avoid reshuffling. 44 | if (iflag.eq.1) then 45 | do i=1,k 46 | if (int(index(i)).ne.i) then 47 | iflag=0 48 | goto 100 49 | endif 50 | enddo 51 | endif 52 | 100 normv_old = 0 53 | nre = 0 54 | normv = dnrm2(n,vnew,1) 55 | do while ((normv.lt.alpha*normv_old .or. nre.eq.0)) 56 | if (iflag.eq.1) then 57 | c CGS: 58 | call dgemv('T',n,k,1D0,V,ldv,vnew,1,0D0,work,1) 59 | call dgemv('N',n,k,-1D0,V,ldv,work,1,1D0,vnew,1) 60 | else 61 | c MGS: 62 | call MGS(n,k,V,ldv,vnew,index) 63 | endif 64 | normv_old = normv 65 | normv = dnrm2(n,vnew,1) 66 | nre = nre + 1 67 | 68 | if ( nre.gt.MAXTRY ) then 69 | c 70 | c vnew is numerically in span(V) => return vnew = (0,0,...,0)^T 71 | normv = 0d0 72 | do i=1,n 73 | vnew(i) = 0d0 74 | enddo 75 | return 76 | endif 77 | enddo 78 | end 79 | c 80 | c**************************************************************************** 81 | c 82 | 83 | subroutine MGS(n,k,V,ldv,vnew,index) 84 | implicit none 85 | integer n,k,ldv 86 | double precision V(ldv,*),vnew(*),index(*) 87 | integer i,j,idx 88 | double precision s 89 | 90 | c 91 | c Modified Gram-Schmidt orthogonalization: 92 | c Orthogalizes vnew against the k vectors in V by the 93 | c iterative process 94 | c 95 | c FOR i=1...k DO 96 | c vnew = vnew - DOT( V(:,i), vnew ) * V(:,i) 97 | c 98 | 99 | c This simple version is faster on Pentium machines. 100 | c Compile with "g77 -O6 -funroll-all-loops -fomit-frame-pointer" 101 | 102 | do i=1,k 103 | idx = int(index(i)) 104 | s = 0 105 | do j=1,n 106 | s = s + V(j,idx)*vnew(j) 107 | enddo 108 | do j=1,n 109 | vnew(j) = vnew(j) - s*V(j,idx) 110 | enddo 111 | enddo 112 | end 113 | c 114 | c**************************************************************************** 115 | c 116 | 117 | -------------------------------------------------------------------------------- /Readme.txt: -------------------------------------------------------------------------------- 1 | The Matlab code for Self-adaptively Weighted Co-saliency (SACS) Detection 2 | 3 | 4 | -------------------------------------------------------------------------------- 5 | 6 | Please cite the following publication if you used or was inspired by this code/work: 7 | 8 | 9 | 1. Xiaochun Cao, Zhiqiang Tao, Bao Zhang, Huazhu Fu, Wei Feng, "Self-adaptively Weighted Co-saliency Detection via Rank Constraint", 10 | IEEE Transactions on Image Processing (T-IP), vol. 23, no. 9, pp. 4175-4186, 2014. 11 | 12 | 2. Xiaochun Cao, Zhiqiang Tao, Bao Zhang, Huazhu Fu, Xuewei Li, "Saliency map fusion based on rank-one constraint", 13 | in IEEE International Conference on Multimedia & Expo (ICME), 2013, pp. 1-6. 14 | 15 | -------------------------------------------------------------------------------- 16 | 17 | This code is a primitive MATLAB code, which is simpler than that we used in the paper. 18 | 19 | If you find any bugs, please contact Zhiqiang Tao (zqtaomail@gmail.com). 20 | 21 | 22 | -------------------------------------------------------------------------------- 23 | 24 | Demo: 25 | 26 | 1.demo_mul.m: In this demo, we fuse five methods, which are MR (_stage2.png), HS (_res.png), 27 | RC (_RC.png), SP (_SP.png) and CO (_CO.png), for detecting co-saliency in a group of 28 | 13 images from iCoseg dataset. 29 | 30 | 2.demo_pair.m: In this demo, we fuse seven methods, which are MR (_stage2.png), HS (_res.png), 31 | RC (_RC.png), HC (_HC.png), CC(_CC.png), CP(_CP.png) and SP (_SP.png), for detecting co-saliency in a 32 | pair of images from ImagePair dataset. 33 | 34 | 3.demo_single.m: In this demo, we provide four single salieny dectetion examples, where each is obtaind by 35 | fusing six methods: MR (_stage2.png), HS (_res.png), RC (_RC.png), HC (_HC.png), LR(_LR.png) and GB(_GB.png). 36 | These four images are from MSRB-B dataset. 37 | -------------------------------------------------------------------------------- 38 | 39 | We examplify demo_mul.m to show how to use this code: 40 | 41 | 1. Put a set of images in the folder 'images/multiple' for co-saliency detection. 42 | 43 | 2. Generate the maps of various methods for the input images, and put the results in the folder 'submaps/multiple'. 44 | Please note that, these results should be named as 'img_name + method_name', e.g., 'Christ_1_CO.png'. 45 | 46 | 3. Run demo_mul.m for raw results. 47 | 48 | 4. Run reassign.m for the refined results. 49 | 50 | 51 | 52 | ---------------------------------------------------------------------------------- 53 | The elementary saliency methods below are uesd in our framework: 54 | 55 | 1. For multipe images co-saliency dection on iCoseg dataset: 56 | MR (_stage2.png), HS (_res.png), RC (_RC.png), SP (_SP.png) and CO (_CO.png). 57 | 2. For image pair co-saliency dection on image pair dataset: 58 | MR (_stage2.png), HS (_res.png), RC (_RC.png), HC (_HC.png), SP (_SP.png), CC (_CC.png), 59 | CP (_CP.png), and SP (_SP.png). 60 | 3. For single image saliency dection on MSRA-B dataset: 61 | MR (_stage2.png), HS (_res.png), LR (_LR.png), RC (_RC.png), HC (_HC.png) and GB (_GB.png). 62 | 63 | More details can be found in our paper, and you can find the codes or the results of the methods above 64 | form the addresses listed below: 65 | 66 | MR: C. Yang, L. Zhang, H. Lu, X. Ruan, and M.-H. Yang, "Saliency detection via graph-based manifold ranking," 67 | in CVPR, 2013, pp. 3166-3173. 68 | 69 | HS: Q. Yan, L. Xu, J. Shi, and J. Jia, "Hierarchical saliency detection," in CVPR, 70 | 2013, pp. 1155-1162. 71 | 72 | RC,HC: M. Cheng, G. Zhang, N. J. Mitra, X. Huang, and S. Hu, "Global contrast based salient region detection," 73 | in CVPR, 2011, pp. 409-416. 74 | 75 | SP,CO: H. Fu, X. Cao, and Z. Tu, "Cluster-based co-saliency detection," IEEE 76 | Trans. Image Process., vol. 22, no. 10, pp. 3766-3778 77 | 78 | CC,CP: H. Li and K. Ngan, "A co-saliency model of image pairs," IEEE Trans.Image Process., 79 | vol. 20, no. 12, pp. 3365-3375, 2011. 80 | 81 | LR: X. Shen and Y. Wu, "A unified approach to salient object detection via 82 | low rank matrix recovery," in CVPR, 2012, pp. 853-860. 83 | 84 | GB: J. Harel, C. Koch, and P. Perona, "Graph-based visual saliency," in NIPS. 85 | MIT Press, 2007, pp. 545-552. 86 | 87 | Please also cited these works if you use their results or codes. 88 | -------------------------------------------------------------------------------- /External/SLIC_mex/SLIC_mex.cpp: -------------------------------------------------------------------------------- 1 | /** A wrapper function for the SLIC superpixel oversegmentation method 2 | % 3 | % Copyright (c) 2013, Anestis Papazoglou 4 | % All rights reserved. 5 | % 6 | % Redistribution and use in source and binary forms, with or without 7 | % modification, are permitted provided that the following conditions are 8 | % met: 9 | % 10 | % 1. Redistributions of source code must retain the above copyright notice, 11 | % this list of conditions and the following disclaimer. 12 | % 2. Redistributions in binary form must reproduce the above copyright 13 | % notice, this list of conditions and the following disclaimer in the 14 | % documentation and/or other materials provided with the distribution. 15 | % 16 | % THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | % "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 18 | % TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 19 | % PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 20 | % OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 21 | % EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 22 | % PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 23 | % PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 24 | % LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 | % NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | % SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 27 | 28 | 29 | #include 30 | #include 31 | #include 32 | 33 | #include 34 | #include 35 | 36 | #include "SLIC.h" 37 | 38 | #define OPAQUE 0xFF0000 39 | #define SQUARE255 65025 40 | 41 | #define USAGE_NOTE "USAGE: \n" 42 | 43 | void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] ) 44 | { 45 | bool isRGB; 46 | unsigned char R, G, B; 47 | unsigned int height, width, pixels, pixelsX2, dimensions; 48 | int superpixelsNumber, labelsNumber; 49 | double compactness; 50 | unsigned char *image; 51 | unsigned short *output; 52 | unsigned int *aRGBimage; 53 | int *superpixels; 54 | 55 | const mxArray *imageMxArray; 56 | const mxArray *superpixelsNumberMxArray; 57 | mxArray *superpixelsMxArray; 58 | 59 | if( nrhs == 2 || nrhs == 3 ) 60 | { 61 | imageMxArray = prhs[ 0 ]; 62 | superpixelsNumberMxArray = prhs[ 1 ]; 63 | 64 | if( mxGetClassID( imageMxArray ) != mxUINT8_CLASS ) 65 | mexErrMsgTxt( USAGE_NOTE ); 66 | 67 | if( mxGetClassID( superpixelsNumberMxArray ) != mxDOUBLE_CLASS ) 68 | mexErrMsgTxt( USAGE_NOTE ); 69 | 70 | dimensions = mxGetNumberOfDimensions( imageMxArray ); 71 | 72 | if( dimensions == 3 ) 73 | { 74 | //TODO: make sure 3rd dimensions contains 3 colours 75 | isRGB = true; 76 | height = mxGetM( imageMxArray ); 77 | width = mxGetN( imageMxArray ) / 3; 78 | } 79 | else if( dimensions == 1 ) 80 | { 81 | isRGB = false; 82 | height = mxGetM( imageMxArray ); 83 | width = mxGetN( imageMxArray ); 84 | } 85 | else 86 | { 87 | mexErrMsgTxt( USAGE_NOTE ); 88 | } 89 | pixels = height * width; 90 | pixelsX2 = 2 * pixels; 91 | 92 | image = ( unsigned char * )mxGetData( imageMxArray ); 93 | superpixelsNumber = ( unsigned int )( ( double * )mxGetData( superpixelsNumberMxArray ) )[ 0 ]; 94 | 95 | if( ( superpixelsNumber < 1 ) || ( superpixelsNumber >= pixels ) ) 96 | mexErrMsgTxt( USAGE_NOTE ); 97 | 98 | if( nrhs == 3 ) 99 | { 100 | if( mxGetClassID( prhs[ 2 ] ) == mxDOUBLE_CLASS ) 101 | compactness = ( ( double * )mxGetData( prhs[ 2 ] ) )[ 0 ]; 102 | else 103 | mexErrMsgTxt( USAGE_NOTE ); 104 | } 105 | else 106 | { 107 | compactness = 20; 108 | } 109 | } 110 | else 111 | { 112 | mexErrMsgTxt( USAGE_NOTE ); 113 | } 114 | 115 | superpixelsMxArray = mxCreateNumericMatrix( height, width, mxUINT16_CLASS, mxREAL ); 116 | //superpixels = ( int * )mxGetData( superpixelsMxArray ); 117 | aRGBimage = new unsigned int[ pixels ]; 118 | 119 | for( unsigned int i = 0; i < pixels; i++ ) 120 | { 121 | R = image[ i ]; 122 | G = image[ i + pixels ]; 123 | B = image[ i + pixelsX2 ]; 124 | 125 | aRGBimage[ i ] = OPAQUE + SQUARE255 * R + 255 * G + B; 126 | } 127 | 128 | SLIC slic; 129 | 130 | slic.DoSuperpixelSegmentation_ForGivenNumberOfSuperpixels( aRGBimage, height, width, superpixels, labelsNumber, superpixelsNumber, compactness ); 131 | //mexEvalString( "pause" ); 132 | //mxSetData( superpixelsMxArray, ( void * )superpixels ); 133 | //mxSetM( superpixelsMxArray, height ); 134 | //mxSetN( superpixelsMxArray, width ); 135 | 136 | output = ( unsigned short * )mxGetData( superpixelsMxArray ); 137 | for( int i = 0; i < pixels; i++ ) 138 | { 139 | output[ i ] = ( unsigned short )( superpixels[ i ] + 1 ); 140 | } 141 | 142 | plhs[ 0 ] = superpixelsMxArray; 143 | 144 | delete [] aRGBimage; 145 | 146 | return; 147 | } 148 | 149 | -------------------------------------------------------------------------------- /External/RPCA/exact_alm_rpca/exact_alm_rpca/PROPACK/tqlb.f: -------------------------------------------------------------------------------- 1 | C 2 | C @(#)TQLB.F 1.1 (BNP) 5/9/89 3 | C 4 | SUBROUTINE TQLB(N,D,E,BND,BND2,IERR) 5 | C 6 | INTEGER I,J,L,M,N,II,L1,L2,MML,IERR 7 | DOUBLE PRECISION D(N),E(N),BND(N),BND2(N) 8 | DOUBLE PRECISION C,C2,C3,DL1,EL1,F,G,H,H1,P,R,S,S2,TST1,TST2 9 | C 10 | C THIS SUBROUTINE IS A MODIFICATION OF THE ALGOL PROCEDURE TQL1, 11 | C NUM. MATH. 11, 293-306(1968) BY BOWDLER, MARTIN, REINSCH, AND 12 | C WILKINSON. 13 | C HANDBOOK FOR AUTO. COMP., VOL.II-LINEAR ALGEBRA, 227-240(1971). 14 | C 15 | C THIS SUBROUTINE FINDS THE EIGENVALUES OF A SYMMETRIC 16 | C TRIDIAGONAL MATRIX BY THE QL METHOD. 17 | C 18 | C ON INPUT 19 | C 20 | C N IS THE ORDER OF THE MATRIX. 21 | C 22 | C D CONTAINS THE DIAGONAL ELEMENTS OF THE INPUT MATRIX. 23 | C 24 | C E CONTAINS THE SUBDIAGONAL ELEMENTS OF THE INPUT MATRIX 25 | C IN ITS LAST N-1 POSITIONS. E(1) IS ARBITRARY. 26 | C 27 | C ON OUTPUT 28 | C 29 | C D CONTAINS THE EIGENVALUES IN ASCENDING ORDER. IF AN 30 | C ERROR EXIT IS MADE, THE EIGENVALUES ARE CORRECT AND 31 | C ORDERED FOR INDICES 1,2,...IERR-1, BUT MAY NOT BE 32 | C THE SMALLEST EIGENVALUES. 33 | C 34 | C E HAS BEEN DESTROYED. 35 | C 36 | C BND WILL HOLD THE TOP ELEMENTS OF THE NORMALIZED EIGENVECTORS. 37 | C 38 | C IERR IS SET TO 39 | C ZERO FOR NORMAL RETURN, 40 | C J IF THE J-TH EIGENVALUE HAS NOT BEEN 41 | C DETERMINED AFTER 30 ITERATIONS. 42 | C 43 | C calls to PYTHAG for SQRT(A*A + B*B) have been replaced by inline code. 44 | C 45 | C QUESTIONS AND COMMENTS SHOULD BE DIRECTED TO BURTON S. GARBOW, 46 | C MATHEMATICS AND COMPUTER SCIENCE DIV, ARGONNE NATIONAL LABORATORY 47 | C 48 | C THIS VERSION DATED AUGUST 1983 (AUGUST 1998). 49 | C 50 | C ------------------------------------------------------------------ 51 | C 52 | IERR = 0 53 | BND(1) = 1.0D0 54 | IF (N .EQ. 1) GO TO 1001 55 | BND2(N) = 1.0D0 56 | C 57 | DO 100 I = 2, N 58 | BND(I) = 0.0D0 59 | BND2(I-1) = 0.0D0 60 | 100 E(I-1) = E(I) 61 | C 62 | F = 0.0D0 63 | TST1 = 0.0D0 64 | E(N) = 0.0D0 65 | C 66 | DO 290 L = 1, N 67 | J = 0 68 | H = ABS(D(L)) + ABS(E(L)) 69 | IF (TST1 .LT. H) TST1 = H 70 | C .......... LOOK FOR SMALL SUB-DIAGONAL ELEMENT .......... 71 | DO 110 M = L, N 72 | TST2 = TST1 + ABS(E(M)) 73 | IF (TST2 .EQ. TST1) GO TO 120 74 | C .......... E(N) IS ALWAYS ZERO, SO THERE IS NO EXIT 75 | C THROUGH THE BOTTOM OF THE LOOP .......... 76 | 110 CONTINUE 77 | C 78 | 120 IF (M .EQ. L) GO TO 210 79 | 130 IF (J .EQ. 30) GO TO 1000 80 | J = J + 1 81 | C .......... FORM SHIFT .......... 82 | L1 = L + 1 83 | L2 = L1 + 1 84 | G = D(L) 85 | P = (D(L1) - G) / (2.0D0 * E(L)) 86 | if (abs(p).le.1.0e0) then 87 | p = p + sign(sqrt(1.0e0 + p*p),p) 88 | else 89 | p = p * (1.0e0 + sqrt(1.0e0 + (1.0e0/p)**2)) 90 | endif 91 | d(l) = e(l) / p 92 | d(l1) = e(l) * p 93 | c********** Original code: ******************** 94 | c R = PYTHAG(P,1.0D0) 95 | c D(L) = E(L) / (P + SIGN(R,P)) 96 | c D(L1) = E(L) * (P + SIGN(R,P)) 97 | c********************************************* 98 | DL1 = D(L1) 99 | H = G - D(L) 100 | IF (L2 .GT. N) GO TO 145 101 | C 102 | DO 140 I = L2, N 103 | 140 D(I) = D(I) - H 104 | C 105 | 145 F = F + H 106 | C .......... QL TRANSFORMATION .......... 107 | P = D(M) 108 | C = 1.0D0 109 | C2 = C 110 | EL1 = E(L1) 111 | S = 0.0D0 112 | MML = M - L 113 | C .......... FOR I=M-1 STEP -1 UNTIL L DO -- .......... 114 | DO 200 II = 1, MML 115 | C3 = C2 116 | C2 = C 117 | S2 = S 118 | I = M - II 119 | G = C * E(I) 120 | H = C * P 121 | c inlined call to PYTHAG. This code corresponds to LAPACK rutine DLAPY2. 122 | c Speeds tqlb up by a factor of 3 on MIPS R10000. 123 | IF(DABS(P).GE.DABS(E(I))) then 124 | S=E(I)/P 125 | R=SQRT(1D0+S*S) 126 | E(I+1)=S2*P*R 127 | C=1D0/R 128 | S=S*C 129 | else 130 | C=P/E(I) 131 | R=SQRT(1D0+C*C) 132 | E(I+1)=S2*E(I)*R 133 | S=1D0/R 134 | C=C*S 135 | endif 136 | P = C * D(I) - S * G 137 | D(I+1) = H + S * (C * G + S * D(I)) 138 | H = BND(I+1) 139 | BND(I+1) = S*BND(I)+C*H 140 | BND(I) = C*BND(I)-S*H 141 | H = BND2(I+1) 142 | BND2(I+1) = S*BND2(I)+C*H 143 | BND2(I) = C*BND2(I)-S*H 144 | 200 CONTINUE 145 | C 146 | P = -S * S2 * C3 * EL1 * E(L) / DL1 147 | E(L) = S * P 148 | D(L) = C * P 149 | TST2 = TST1 + ABS(E(L)) 150 | IF (TST2 .GT. TST1) GO TO 130 151 | 210 P = D(L) + F 152 | H = BND(L) 153 | H1 = BND2(L) 154 | C .......... ORDER EIGENVALUES .......... 155 | IF (L .EQ. 1) GO TO 250 156 | C .......... FOR I=L STEP -1 UNTIL 2 DO -- .......... 157 | DO 230 II = 2, L 158 | I = L + 2 - II 159 | IF (P .GE. D(I-1)) GO TO 270 160 | D(I) = D(I-1) 161 | BND(I) = BND(I-1) 162 | BND2(I) = BND2(I-1) 163 | 230 CONTINUE 164 | C 165 | 250 I = 1 166 | 270 D(I) = P 167 | BND(I) = H 168 | BND2(I)= H1 169 | 290 CONTINUE 170 | C 171 | GO TO 1001 172 | C .......... SET ERROR -- NO CONVERGENCE TO AN 173 | C EIGENVALUE AFTER 30 ITERATIONS .......... 174 | 1000 IERR = L 175 | 1001 RETURN 176 | END 177 | -------------------------------------------------------------------------------- /External/RPCA/exact_alm_rpca/exact_alm_rpca/PROPACK/mmwrite.m: -------------------------------------------------------------------------------- 1 | function [ err ] = mmwrite(filename,A,comment,field,precision) 2 | % 3 | % Function: mmwrite(filename,A,comment,field,precision) 4 | % 5 | % Writes the sparse or dense matrix A to a Matrix Market (MM) 6 | % formatted file. 7 | % 8 | % Required arguments: 9 | % 10 | % filename - destination file 11 | % 12 | % A - sparse or full matrix 13 | % 14 | % Optional arguments: 15 | % 16 | % comment - matrix of comments to prepend to 17 | % the MM file. To build a comment matrix, 18 | % use str2mat. For example: 19 | % 20 | % comment = str2mat(' Comment 1' ,... 21 | % ' Comment 2',... 22 | % ' and so on.',... 23 | % ' to attach a date:',... 24 | % [' ',date]); 25 | % If ommitted, a single line date stamp comment 26 | % will be included. 27 | % 28 | % field - 'real' 29 | % 'complex' 30 | % 'integer' 31 | % 'pattern' 32 | % If ommitted, data will determine type. 33 | % 34 | % precision - number of digits to display for real 35 | % or complex values 36 | % If ommitted, full working precision is used. 37 | % 38 | 39 | if ( nargin == 5) 40 | precision = 16; 41 | elseif ( nargin == 4) 42 | precision = 16; 43 | elseif ( nargin == 3) 44 | mattype = 'real'; % placeholder, will check after FIND-ing A 45 | precision = 16; 46 | elseif ( nargin == 2) 47 | comment = ''; 48 | % Check whether there is an imaginary part: 49 | mattype = 'real'; % placeholder, will check after FIND-ing A 50 | precision = 16; 51 | end 52 | 53 | mmfile = fopen([filename],'w'); 54 | if ( mmfile == -1 ) 55 | error('Cannot open file for output'); 56 | end; 57 | 58 | 59 | [M,N] = size(A); 60 | 61 | %%%%%%%%%%%%% This part for sparse matrices %%%%%%%%%%%%%%%% 62 | if ( issparse(A) ) 63 | 64 | [I,J,V] = find(A); 65 | if ( sum(abs(imag(nonzeros(V)))) > 0 ) 66 | Vreal = 0; 67 | else 68 | Vreal = 1; 69 | end 70 | 71 | if ( ~ strcmp(mattype,'pattern') & Vreal ) 72 | mattype = 'real'; 73 | elseif ( ~ strcmp(mattype,'pattern') ) 74 | mattype = 'complex'; 75 | end 76 | % 77 | % Determine symmetry: 78 | % 79 | if ( M ~= N ) 80 | symm = 'general'; 81 | issymm = 0; 82 | NZ = length(V); 83 | else 84 | issymm = 1; 85 | NZ = length(V); 86 | for i=1:NZ 87 | if ( A(J(i),I(i)) ~= V(i) ) 88 | issymm = 0; 89 | break; 90 | end 91 | end 92 | if ( issymm ) 93 | symm = 'symmetric'; 94 | ATEMP = tril(A); 95 | [I,J,V] = find(ATEMP); 96 | NZ = nnz(ATEMP); 97 | else 98 | isskew = 1; 99 | for i=1:NZ 100 | if ( A(J(i),I(i)) ~= - V(i) ) 101 | isskew = 0; 102 | break; 103 | end 104 | end 105 | if ( isskew ) 106 | symm = 'skew-symmetric'; 107 | ATEMP = tril(A); 108 | [I,J,V] = find(ATEMP); 109 | NZ = nnz(ATEMP); 110 | elseif ( strcmp(mattype,'complex') ) 111 | isherm = 1; 112 | for i=1:NZ 113 | if ( A(J(i),I(i)) ~= conj(V(i)) ) 114 | isherm = 0; 115 | break; 116 | end 117 | end 118 | if ( isherm ) 119 | symm = 'hermitian'; 120 | ATEMP = tril(A); 121 | [I,J,V] = find(ATEMP); 122 | NZ = nnz(ATEMP); 123 | else 124 | symm = 'general'; 125 | NZ = nnz(A); 126 | end 127 | else 128 | symm = 'general'; 129 | NZ = nnz(A); 130 | end 131 | end 132 | end 133 | 134 | % Sparse coordinate format: 135 | 136 | rep = 'coordinate'; 137 | 138 | 139 | fprintf(mmfile,'%%%%MatrixMarket matrix %s %s %s\n',rep,mattype,symm); 140 | [MC,NC] = size(comment); 141 | if ( MC == 0 ) 142 | fprintf(mmfile,'%% Generated %s\n',[date]); 143 | else 144 | for i=1:MC, 145 | fprintf(mmfile,'%%%s\n',comment(i,:)); 146 | end 147 | end 148 | fprintf(mmfile,'%d %d %d\n',M,N,NZ); 149 | cplxformat = sprintf('%%d %%d %% .%dg %% .%dg\n',precision,precision); 150 | realformat = sprintf('%%d %%d %% .%dg\n',precision); 151 | if ( strcmp(mattype,'real') ) 152 | for i=1:NZ 153 | fprintf(mmfile,realformat,I(i),J(i),V(i)); 154 | end; 155 | elseif ( strcmp(mattype,'complex') ) 156 | for i=1:NZ 157 | fprintf(mmfile,cplxformat,I(i),J(i),real(V(i)),imag(V(i))); 158 | end; 159 | elseif ( strcmp(mattype,'pattern') ) 160 | for i=1:NZ 161 | fprintf(mmfile,'%d %d\n',I(i),J(i)); 162 | end; 163 | else 164 | err = -1; 165 | disp('Unsupported mattype:') 166 | mattype 167 | end; 168 | 169 | %%%%%%%%%%%%% This part for dense matrices %%%%%%%%%%%%%%%% 170 | else 171 | if ( sum(abs(imag(nonzeros(A)))) > 0 ) 172 | Areal = 0; 173 | else 174 | Areal = 1; 175 | end 176 | if ( ~strcmp(mattype,'pattern') & Areal ) 177 | mattype = 'real'; 178 | elseif ( ~strcmp(mattype,'pattern') ) 179 | mattype = 'complex'; 180 | end 181 | % 182 | % Determine symmetry: 183 | % 184 | if ( M ~= N ) 185 | issymm = 0; 186 | symm = 'general'; 187 | else 188 | issymm = 1; 189 | for j=1:N 190 | for i=j+1:N 191 | if (A(i,j) ~= A(j,i) ) 192 | issymm = 0; 193 | break; 194 | end 195 | end 196 | if ( ~ issymm ) break; end 197 | 198 | end 199 | if ( issymm ) 200 | symm = 'symmetric'; 201 | else 202 | isskew = 1; 203 | for j=1:N 204 | for i=j+1:N 205 | if (A(i,j) ~= - A(j,i) ) 206 | isskew = 0; 207 | break; 208 | end 209 | end 210 | if ( ~ isskew ) break; end 211 | end 212 | if ( isskew ) 213 | symm = 'skew-symmetric'; 214 | elseif ( strcmp(mattype,'complex') ) 215 | isherm = 1; 216 | for j=1:N 217 | for i=j+1:N 218 | if (A(i,j) ~= conj(A(j,i)) ) 219 | isherm = 0; 220 | break; 221 | end 222 | end 223 | if ( ~ isherm ) break; end 224 | end 225 | if ( isherm ) 226 | symm = 'hermitian'; 227 | else 228 | symm = 'general'; 229 | end 230 | else 231 | symm = 'general'; 232 | end 233 | end 234 | end 235 | 236 | % Dense array format: 237 | 238 | rep = 'array'; 239 | [MC,NC] = size(comment); 240 | fprintf(mmfile,'%%%%MatrixMarket mtx %s %s %s\n',rep,mattype,symm); 241 | for i=1:MC, 242 | fprintf(mmfile,'%%%s\n',comment(i,:)); 243 | end; 244 | fprintf(mmfile,'%d %d\n',M,N); 245 | cplxformat = sprintf('%% .%dg %% .%dg\n', precision,precision); 246 | realformat = sprintf('%% .%dg\n', precision); 247 | if ( ~ strcmp(symm,'general') ) 248 | rowloop = 'j'; 249 | else 250 | rowloop = '1'; 251 | end 252 | if ( strcmp(mattype,'real') ) 253 | for j=1:N 254 | for i=eval(rowloop):M 255 | fprintf(mmfile,realformat,A(i,j)); 256 | end 257 | end 258 | elseif ( strcmp(mattype,'complex') ) 259 | for j=1:N 260 | for i=eval(rowloop):M 261 | fprintf(mmfile,cplxformat,real(A(i,j)),imag(A(i,j))); 262 | end 263 | end 264 | elseif ( strcmp(mattype,'pattern') ) 265 | err = -2 266 | disp('Pattern type inconsistant with dense matrix') 267 | else 268 | err = -2 269 | disp('Unknown matrix type:') 270 | mattype 271 | end 272 | end 273 | 274 | fclose(mmfile); 275 | -------------------------------------------------------------------------------- /External/RPCA/exact_alm_rpca/exact_alm_rpca/PROPACK/mmread.m: -------------------------------------------------------------------------------- 1 | function [A,rows,cols,entries,rep,field,symm] = mmread(filename) 2 | % 3 | % function [A] = mmread(filename) 4 | % 5 | % function [A,rows,cols,entries,rep,field,symm] = mmread(filename) 6 | % 7 | % Reads the contents of the Matrix Market file 'filename' 8 | % into the matrix 'A'. 'A' will be either sparse or full, 9 | % depending on the Matrix Market format indicated by 10 | % 'coordinate' (coordinate sparse storage), or 11 | % 'array' (dense array storage). The data will be duplicated 12 | % as appropriate if symmetry is indicated in the header. 13 | % 14 | % Optionally, size information about the matrix can be 15 | % obtained by using the return values rows, cols, and 16 | % entries, where entries is the number of nonzero entries 17 | % in the final matrix. Type information can also be retrieved 18 | % using the optional return values rep (representation), field, 19 | % and symm (symmetry). 20 | % 21 | 22 | mmfile = fopen(filename,'r'); 23 | if ( mmfile == -1 ) 24 | disp(filename); 25 | error('File not found'); 26 | end; 27 | 28 | header = fgets(mmfile); 29 | if (header == -1 ) 30 | error('Empty file.') 31 | end 32 | 33 | % NOTE: If using a version of Matlab for which strtok is not 34 | % defined, substitute 'gettok' for 'strtok' in the 35 | % following lines, and download gettok.m from the 36 | % Matrix Market site. 37 | [head0,header] = strtok(header); % see note above 38 | [head1,header] = strtok(header); 39 | [rep,header] = strtok(header); 40 | [field,header] = strtok(header); 41 | [symm,header] = strtok(header); 42 | head1 = lower(head1); 43 | rep = lower(rep); 44 | field = lower(field); 45 | symm = lower(symm); 46 | if ( length(symm) == 0 ) 47 | disp(['Not enough words in header line of file ',filename]) 48 | disp('Recognized format: ') 49 | disp('%%MatrixMarket matrix representation field symmetry') 50 | error('Check header line.') 51 | end 52 | if ( ~ strcmp(head0,'%%MatrixMarket') ) 53 | error('Not a valid MatrixMarket header.') 54 | end 55 | if ( ~ strcmp(head1,'matrix') ) 56 | disp(['This seems to be a MatrixMarket ',head1,' file.']); 57 | disp('This function only knows how to read MatrixMarket matrix files.'); 58 | disp(' '); 59 | error(' '); 60 | end 61 | 62 | % Read through comments, ignoring them 63 | 64 | commentline = fgets(mmfile); 65 | while length(commentline) > 0 & commentline(1) == '%', 66 | commentline = fgets(mmfile); 67 | end 68 | 69 | % Read size information, then branch according to 70 | % sparse or dense format 71 | 72 | if ( strcmp(rep,'coordinate')) % read matrix given in sparse 73 | % coordinate matrix format 74 | 75 | [sizeinfo,count] = sscanf(commentline,'%d%d%d'); 76 | while ( count == 0 ) 77 | commentline = fgets(mmfile); 78 | if (commentline == -1 ) 79 | error('End-of-file reached before size information was found.') 80 | end 81 | [sizeinfo,count] = sscanf(commentline,'%d%d%d'); 82 | if ( count > 0 & count ~= 3 ) 83 | error('Invalid size specification line.') 84 | end 85 | end 86 | rows = sizeinfo(1); 87 | cols = sizeinfo(2); 88 | entries = sizeinfo(3); 89 | 90 | if ( strcmp(field,'real') ) % real valued entries: 91 | 92 | [T,count] = fscanf(mmfile,'%f',3); 93 | T = [T; fscanf(mmfile,'%f')]; 94 | if ( size(T) ~= 3*entries ) 95 | message = ... 96 | str2mat('Data file does not contain expected amount of data.',... 97 | 'Check that number of data lines matches nonzero count.'); 98 | disp(message); 99 | error('Invalid data.'); 100 | end 101 | T = reshape(T,3,entries)'; 102 | A = sparse(T(:,1), T(:,2), T(:,3), rows , cols); 103 | 104 | elseif ( strcmp(field,'complex')) % complex valued entries: 105 | 106 | T = fscanf(mmfile,'%f',4); 107 | T = [T; fscanf(mmfile,'%f')]; 108 | if ( size(T) ~= 4*entries ) 109 | message = ... 110 | str2mat('Data file does not contain expected amount of data.',... 111 | 'Check that number of data lines matches nonzero count.'); 112 | disp(message); 113 | error('Invalid data.'); 114 | end 115 | T = reshape(T,4,entries)'; 116 | A = sparse(T(:,1), T(:,2), T(:,3) + T(:,4)*sqrt(-1), rows , cols); 117 | 118 | elseif ( strcmp(field,'pattern')) % pattern matrix (no values given): 119 | 120 | T = fscanf(mmfile,'%f',2); 121 | T = [T; fscanf(mmfile,'%f')]; 122 | if ( size(T) ~= 2*entries ) 123 | message = ... 124 | str2mat('Data file does not contain expected amount of data.',... 125 | 'Check that number of data lines matches nonzero count.'); 126 | disp(message); 127 | error('Invalid data.'); 128 | end 129 | T = reshape(T,2,entries)'; 130 | A = sparse(T(:,1), T(:,2), ones(entries,1) , rows , cols); 131 | 132 | end 133 | 134 | elseif ( strcmp(rep,'array') ) % read matrix given in dense 135 | % array (column major) format 136 | 137 | [sizeinfo,count] = sscanf(commentline,'%d%d'); 138 | while ( count == 0 ) 139 | commentline = fgets(mmfile); 140 | if (commentline == -1 ) 141 | error('End-of-file reached before size information was found.') 142 | end 143 | [sizeinfo,count] = sscanf(commentline,'%d%d'); 144 | if ( count > 0 & count ~= 2 ) 145 | error('Invalid size specification line.') 146 | end 147 | end 148 | rows = sizeinfo(1); 149 | cols = sizeinfo(2); 150 | entries = rows*cols; 151 | if ( strcmp(field,'real') ) % real valued entries: 152 | A = fscanf(mmfile,'%f',1); 153 | A = [A; fscanf(mmfile,'%f')]; 154 | if ( strcmp(symm,'symmetric') | strcmp(symm,'hermitian') | strcmp(symm,'skew-symmetric') ) 155 | for j=1:cols-1, 156 | currenti = j*rows; 157 | A = [A(1:currenti); zeros(j,1);A(currenti+1:length(A))]; 158 | end 159 | elseif ( ~ strcmp(symm,'general') ) 160 | disp('Unrecognized symmetry') 161 | disp(symm) 162 | disp('Recognized choices:') 163 | disp(' symmetric') 164 | disp(' hermitian') 165 | disp(' skew-symmetric') 166 | disp(' general') 167 | error('Check symmetry specification in header.'); 168 | end 169 | A = reshape(A,rows,cols); 170 | elseif ( strcmp(field,'complex')) % complx valued entries: 171 | tmpr = fscanf(mmfile,'%f',1); 172 | tmpi = fscanf(mmfile,'%f',1); 173 | A = tmpr+tmpi*i; 174 | for j=1:entries-1 175 | tmpr = fscanf(mmfile,'%f',1); 176 | tmpi = fscanf(mmfile,'%f',1); 177 | A = [A; tmpr + tmpi*i]; 178 | end 179 | if ( strcmp(symm,'symmetric') | strcmp(symm,'hermitian') | strcmp(symm,'skew-symmetric') ) 180 | for j=1:cols-1, 181 | currenti = j*rows; 182 | A = [A(1:currenti); zeros(j,1);A(currenti+1:length(A))]; 183 | end 184 | elseif ( ~ strcmp(symm,'general') ) 185 | disp('Unrecognized symmetry') 186 | disp(symm) 187 | disp('Recognized choices:') 188 | disp(' symmetric') 189 | disp(' hermitian') 190 | disp(' skew-symmetric') 191 | disp(' general') 192 | error('Check symmetry specification in header.'); 193 | end 194 | A = reshape(A,rows,cols); 195 | elseif ( strcmp(field,'pattern')) % pattern (makes no sense for dense) 196 | disp('Matrix type:',field) 197 | error('Pattern matrix type invalid for array storage format.'); 198 | else % Unknown matrix type 199 | disp('Matrix type:',field) 200 | error('Invalid matrix type specification. Check header against MM documentation.'); 201 | end 202 | end 203 | 204 | % 205 | % If symmetric, skew-symmetric or Hermitian, duplicate lower 206 | % triangular part and modify entries as appropriate: 207 | % 208 | 209 | if ( strcmp(symm,'symmetric') ) 210 | A = A + A.' - diag(diag(A)); 211 | entries = nnz(A); 212 | elseif ( strcmp(symm,'hermitian') ) 213 | A = A + A' - diag(diag(A)); 214 | entries = nnz(A); 215 | elseif ( strcmp(symm,'skew-symmetric') ) 216 | A = A - A'; 217 | entries = nnz(A); 218 | end 219 | 220 | fclose(mmfile); 221 | % Done. 222 | 223 | -------------------------------------------------------------------------------- /External/SLIC_mex/SLIC.h: -------------------------------------------------------------------------------- 1 | // SLIC.h: interface for the SLIC class. 2 | //=========================================================================== 3 | // This code implements the superpixel method described in: 4 | // 5 | // Radhakrishna Achanta, Appu Shaji, Kevin Smith, Aurelien Lucchi, Pascal Fua, and Sabine Susstrunk, 6 | // "SLIC Superpixels", 7 | // EPFL Technical Report no. 149300, June 2010. 8 | //=========================================================================== 9 | // Copyright (c) 2012 Radhakrishna Achanta [EPFL]. All rights reserved. 10 | //=========================================================================== 11 | ////////////////////////////////////////////////////////////////////// 12 | 13 | #if !defined(_SLIC_H_INCLUDED_) 14 | #define _SLIC_H_INCLUDED_ 15 | 16 | 17 | #include 18 | #include 19 | #include 20 | using namespace std; 21 | 22 | 23 | class SLIC 24 | { 25 | public: 26 | SLIC(); 27 | virtual ~SLIC(); 28 | //============================================================================ 29 | // Superpixel segmentation for a given step size (superpixel size ~= step*step) 30 | //============================================================================ 31 | void DoSuperpixelSegmentation_ForGivenSuperpixelSize( 32 | const unsigned int* ubuff,//Each 32 bit unsigned int contains ARGB pixel values. 33 | const int width, 34 | const int height, 35 | int*& klabels, 36 | int& numlabels, 37 | const int& superpixelsize, 38 | const double& compactness); 39 | //============================================================================ 40 | // Superpixel segmentation for a given number of superpixels 41 | //============================================================================ 42 | void DoSuperpixelSegmentation_ForGivenNumberOfSuperpixels( 43 | const unsigned int* ubuff, 44 | const int width, 45 | const int height, 46 | int*& klabels, 47 | int& numlabels, 48 | const int& K,//required number of superpixels 49 | const double& compactness);//10-20 is a good value for CIELAB space 50 | //============================================================================ 51 | // Supervoxel segmentation for a given step size (supervoxel size ~= step*step*step) 52 | //============================================================================ 53 | void DoSupervoxelSegmentation( 54 | unsigned int**& ubuffvec, 55 | const int& width, 56 | const int& height, 57 | const int& depth, 58 | int**& klabels, 59 | int& numlabels, 60 | const int& supervoxelsize, 61 | const double& compactness); 62 | private: 63 | //============================================================================ 64 | // The main SLIC algorithm for generating superpixels 65 | //============================================================================ 66 | void PerformSuperpixelSLIC( 67 | vector& kseedsl, 68 | vector& kseedsa, 69 | vector& kseedsb, 70 | vector& kseedsx, 71 | vector& kseedsy, 72 | int*& klabels, 73 | const int& STEP, 74 | const vector& edgemag, 75 | const double& m = 10.0); 76 | //============================================================================ 77 | // The main SLIC algorithm for generating supervoxels 78 | //============================================================================ 79 | void PerformSupervoxelSLIC( 80 | vector& kseedsl, 81 | vector& kseedsa, 82 | vector& kseedsb, 83 | vector& kseedsx, 84 | vector& kseedsy, 85 | vector& kseedsz, 86 | int**& klabels, 87 | const int& STEP, 88 | const double& compactness); 89 | //============================================================================ 90 | // Pick seeds for superpixels when step size of superpixels is given. 91 | //============================================================================ 92 | void GetLABXYSeeds_ForGivenStepSize( 93 | vector& kseedsl, 94 | vector& kseedsa, 95 | vector& kseedsb, 96 | vector& kseedsx, 97 | vector& kseedsy, 98 | const int& STEP, 99 | const bool& perturbseeds, 100 | const vector& edgemag); 101 | //============================================================================ 102 | // Pick seeds for supervoxels 103 | //============================================================================ 104 | void GetKValues_LABXYZ( 105 | vector& kseedsl, 106 | vector& kseedsa, 107 | vector& kseedsb, 108 | vector& kseedsx, 109 | vector& kseedsy, 110 | vector& kseedsz, 111 | const int& STEP); 112 | //============================================================================ 113 | // Move the superpixel seeds to low gradient positions to avoid putting seeds 114 | // at region boundaries. 115 | //============================================================================ 116 | void PerturbSeeds( 117 | vector& kseedsl, 118 | vector& kseedsa, 119 | vector& kseedsb, 120 | vector& kseedsx, 121 | vector& kseedsy, 122 | const vector& edges); 123 | //============================================================================ 124 | // Detect color edges, to help PerturbSeeds() 125 | //============================================================================ 126 | void DetectLabEdges( 127 | const double* lvec, 128 | const double* avec, 129 | const double* bvec, 130 | const int& width, 131 | const int& height, 132 | vector& edges); 133 | //============================================================================ 134 | // sRGB to XYZ conversion; helper for RGB2LAB() 135 | //============================================================================ 136 | void RGB2XYZ( 137 | const int& sR, 138 | const int& sG, 139 | const int& sB, 140 | double& X, 141 | double& Y, 142 | double& Z); 143 | //============================================================================ 144 | // sRGB to CIELAB conversion (uses RGB2XYZ function) 145 | //============================================================================ 146 | void RGB2LAB( 147 | const int& sR, 148 | const int& sG, 149 | const int& sB, 150 | double& lval, 151 | double& aval, 152 | double& bval); 153 | //============================================================================ 154 | // sRGB to CIELAB conversion for 2-D images 155 | //============================================================================ 156 | void DoRGBtoLABConversion( 157 | const unsigned int*& ubuff, 158 | double*& lvec, 159 | double*& avec, 160 | double*& bvec); 161 | //============================================================================ 162 | // sRGB to CIELAB conversion for 3-D volumes 163 | //============================================================================ 164 | void DoRGBtoLABConversion( 165 | unsigned int**& ubuff, 166 | double**& lvec, 167 | double**& avec, 168 | double**& bvec); 169 | //============================================================================ 170 | // Post-processing of SLIC segmentation, to avoid stray labels. 171 | //============================================================================ 172 | void EnforceLabelConnectivity( 173 | const int* labels, 174 | const int width, 175 | const int height, 176 | int*& nlabels,//input labels that need to be corrected to remove stray labels 177 | int& numlabels,//the number of labels changes in the end if segments are removed 178 | const int& K); //the number of superpixels desired by the user 179 | //============================================================================ 180 | // Post-processing of SLIC supervoxel segmentation, to avoid stray labels. 181 | //============================================================================ 182 | void EnforceSupervoxelLabelConnectivity( 183 | int**& labels,//input - previous labels, output - new labels 184 | const int& width, 185 | const int& height, 186 | const int& depth, 187 | int& numlabels, 188 | const int& STEP); 189 | 190 | private: 191 | int m_width; 192 | int m_height; 193 | int m_depth; 194 | 195 | double* m_lvec; 196 | double* m_avec; 197 | double* m_bvec; 198 | 199 | double** m_lvecvec; 200 | double** m_avecvec; 201 | double** m_bvecvec; 202 | }; 203 | 204 | #endif // !defined(_SLIC_H_INCLUDED_) 205 | -------------------------------------------------------------------------------- /External/RPCA/exact_alm_rpca/exact_alm_rpca/PROPACK/test.m: -------------------------------------------------------------------------------- 1 | % Script for testing singular values computed using LANSVD, LANEIG and 2 | % EIGS. 3 | 4 | % Rasmus Munk Larsen, DAIMI, 1998. 5 | global MxV MU MUTRUE NU NUTRUE 6 | MU=[]; 7 | MUTRUE=[]; 8 | NU=[]; 9 | NUTRUE=[]; 10 | rand('state',0); 11 | setup = 1; % set setup=1 to set up testproblem. 12 | k=10; % Number of singular values to compute 13 | HB_dir = 'Harwell-Boeing'; 14 | 15 | % TESTPROBLEMS. Uncomment the relevant line to select a problem. 16 | %=============================================================== 17 | % NAME DIMENSIONS 18 | %=============================================================== 19 | 20 | % Discrete 1. order derivative matrix: 21 | %problem = 'derivative';% 500 x 501 22 | 23 | % Discrete 2. order derivative matrix. (symmetric) 24 | %problem = 'laplace'; % 500 x 500 25 | 26 | % Test problem from helioseismology. 27 | %problem='helio212a'; % 212 x 100 28 | %problem='helio212b'; % 212 x 100 29 | 30 | % Harwell-Boeing testmatrices: 31 | %problem='abb313'; % 313 x 175 32 | %problem='west0479'; % 479 x 479 33 | %problem='rbs480a'; % 480 x 480 34 | %problem='illc1850'; % 1850 x 712 35 | %problem='qh1484'; % 1484 x 1484 36 | problem='mhd4800a'; % 4800 x 4800 37 | %problem='cry10000'; % 10000 x 10000 38 | %problem='fidap011'; % 16614 x 16614 39 | %problem='af23560'; % 23560 x 23560 40 | %problem='bcsstk32'; % 44609 x 44609 41 | %problem='s3dkt3m2'; % 90449 x 90449 42 | 43 | global A C 44 | format compact 45 | 46 | if setup==1, 47 | A=[]; C=[]; Sigma=[]; 48 | switch problem 49 | case 'derivative' 50 | m = 500; n=m+1; 51 | e = ones(n,1); 52 | A = spdiags([e -e], 0:1, n-1, n); 53 | Sigma = -sort(-2*cos(pi/2*[m:-1:1]'./(m+1))); 54 | Sigma1 = svd(full(A)); 55 | case 'laplace' 56 | m = 100; n=m; 57 | e = ones(n,1); 58 | A = spdiags([-e 2*e -e], -1:1, n, n); 59 | Sigma = -sort(-4*cos(pi/2*[n:-1:1]'./(n+1)).^2); 60 | Sigma1 = svd(full(A)); 61 | case 'helio212a' 62 | load 'helio.mat' 63 | [m n] = size(A); 64 | [U,Sigma,V] = svd(full(A)); 65 | x = rand(m,1); x = x/norm(x); 66 | [dummy,P1] = sort(x); 67 | y = rand(n,1); y = y/norm(y); 68 | [dummy,P2] = sort(y); 69 | A = sparse(Sigma); 70 | A = A(P1,P2); % Permute rows and columns randomly. 71 | Sigma = diag(Sigma); 72 | % shift = eps*min(Sigma); 73 | shift = 0; 74 | % Add a small perturbation to try hide that A is just 75 | % a permuted diagonal and see if we can fool SVD into doing full 76 | % reduction to bidiagonal form. 77 | if shift~=0 78 | A = A + shift*(x*y'); 79 | Sigma = Sigma+shift; 80 | end 81 | Sigma1 = svd(full(A)); 82 | case 'helio212b' 83 | load 'helio.mat' 84 | [U,Sigma,V] = svd(full(A)); 85 | A = U * Sigma *V'; 86 | Sigma = diag(Sigma); 87 | Sigma1 = svd(full(A)); 88 | case 'diag' 89 | m = 200; n=100; 90 | % Sigma = logspace(0,-0.1,n); 91 | Sigma = [n:-1:1]'; 92 | Sigma(1) = 1000; 93 | A = [spdiags(Sigma(:),0,n,n); sparse(m-n,n)]; 94 | otherwise 95 | cur = pwd; 96 | cd(HB_dir) 97 | file = [problem,'.mtx']; 98 | [A,m,n,nz] = mmread(file); 99 | cd(cur) 100 | A = sparse(A); 101 | if min(m,n)^2*max(m,n) < 300^3 102 | Sigma = svd(full(A)); 103 | end 104 | end 105 | [m n] = size(A); 106 | fprintf('nnz(A) = %i\n',nnz(A)); 107 | C = sparse([[sparse(m,m),A];[A',sparse(n,n)]]); 108 | end 109 | 110 | %%% Print information about matrix %%% 111 | clc; 112 | disp('************** PROPACK TEST ****************') 113 | fprintf('The testmatrix %s is %i-by-%i and has %i non-zero elements.\n', ... 114 | problem,m,n,nnz(A)); 115 | if issparse(A) 116 | fprintf('Here is what the sparsity pattern of the matrix looks like... \n(press a key to continue)\n') 117 | spy(A) 118 | title(problem) 119 | pause 120 | hold off 121 | end 122 | fprintf('Calculating %i singular triplets of the matrix.\n',k) 123 | 124 | 125 | if max(m,n) < 300 126 | %%%%%%%%%%%%%%%%%%%% SVD %%%%%%%%%%%%%%%%%%%%%%%%%% 127 | fprintf('-------------------------------------------------------------------\n') 128 | fprintf('\n') 129 | fprintf('METHOD = SVD\n') 130 | fprintf('\n') 131 | 132 | 133 | flops(0);tic; 134 | [U,S,V] = svd(full(A),0); 135 | Sigma=diag(S); 136 | fprintf('Elapsed time = %f\n',toc); 137 | fprintf('Number of flops = %e\n',flops); 138 | fprintf('Residual norm = %e\n',norm(A*V - U*S,'fro')/norm(A,'fro')); 139 | fprintf('Orthogonality U = %e\n',norm(eye(n) - U'*U,'fro')) 140 | fprintf('Orthogonality V = %e\n',norm(eye(n) - V'*V,'fro')) 141 | end 142 | 143 | 144 | %%%%%%%%%%%%%%%%%%%% LANSVD %%%%%%%%%%%%%%%%%%%%%%%%%% 145 | fprintf('-------------------------------------------------------------------\n') 146 | fprintf('\n') 147 | fprintf('METHOD = LANSVD\n') 148 | fprintf('\n') 149 | 150 | options = []; 151 | v0 = rand(m,1)-0.5; 152 | options.p0 = v0; 153 | 154 | MxV = 0;flops(0);tic; 155 | [U1,S1,V1] = lansvd('Afunc','Atransfunc',m,n,k,'L',options); 156 | fprintf('Number MxV = %f\n',MxV); 157 | fprintf('Elapsed time = %f\n',toc); 158 | fprintf('Number of flops = %e\n',flops); 159 | fprintf('Residual norm = %e\n',norm(A*V1 - U1*S1,'fro')/norm(A,'fro')); 160 | fprintf('Orthogonality U = %e\n',norm(eye(k) - U1'*U1,'fro')) 161 | fprintf('Orthogonality V = %e\n',norm(eye(k) - V1'*V1,'fro')) 162 | 163 | if ~isempty(Sigma) 164 | % Compare with "true" singular values 165 | S1 = diag(S1); 166 | l= length(S1); 167 | E1 = abs((S1 - Sigma(1:l))./Sigma(1:l)); 168 | fprintf('Max rel. error = %g\n',max(E1)) 169 | fprintf('Mean rel. error = %g\n',mean(E1)) 170 | if exist('Sigma1') & ~isempty(Sigma1) 171 | semilogy(abs((Sigma1(1:l) - Sigma(1:l))./Sigma(1:l)),'+'); 172 | hold on 173 | end 174 | semilogy(E1,'o'); 175 | hold off 176 | ylabel('Relative error |\theta_i - \sigma_i| / \sigma_i') 177 | xlabel('i') 178 | end 179 | 180 | %%%%%%%%%%%%%%%%%%%% LANEIG(A'*A) %%%%%%%%%%%%%%%%%%%%%%%%%% 181 | fprintf('-------------------------------------------------------------------\n') 182 | fprintf('\n') 183 | fprintf('METHOD = LANEIG(A''*A)\n') 184 | fprintf('\n') 185 | options=[]; 186 | options.v0 = A'*v0; 187 | 188 | 189 | flops(0);MxV=0; tic; 190 | %S = laneig(C,k,'AL',options); 191 | [V3,S3,b3] = laneig('AtAfunc',n,k,'AL',options); 192 | U3 = A*V3; 193 | for i=1:k 194 | U3(:,i) = U3(:,i)/norm(U3(:,i)); 195 | end 196 | 197 | fprintf('Number MxV = %f\n',MxV); 198 | fprintf('Elapsed time = %f\n',toc); 199 | fprintf('Number of flops = %e\n',flops); 200 | fprintf('Residual norm = %e\n',norm(A'*(A*V3) - V3*S3,'fro')/norm(A'*A,'fro')); 201 | fprintf('Orthogonality U = %e\n',norm(eye(k) - U3'*U3,'fro')) 202 | fprintf('Orthogonality V = %e\n',norm(eye(k) - V3'*V3,'fro')) 203 | S3 = diag(sqrt(diag(S3))); 204 | 205 | if ~isempty(Sigma) 206 | S3 = diag(S3); 207 | l= length(S3); 208 | % Compare with "true" singular values 209 | E3 = abs((S3 - Sigma(1:l))./Sigma(1:l)); 210 | fprintf('Max rel. error = %g\n',max(E3)) 211 | fprintf('Mean rel. error = %g\n',mean(E3)) 212 | hold on 213 | semilogy(E3,'d'); 214 | hold off 215 | end 216 | 217 | %%%%%%%%%%%%%%%%%%%% LANEIG(C) %%%%%%%%%%%%%%%%%%%%%%%%%% 218 | fprintf('-------------------------------------------------------------------\n') 219 | fprintf('\n') 220 | fprintf('METHOD = LANEIG(C)\n') 221 | fprintf('\n') 222 | options.v0 = [v0;zeros(n,1)]; 223 | 224 | tic; flops(0);MxV=0; 225 | %S = laneig(C,k,'AL',options); 226 | [V2,S2] = laneig('Cfunc',m+n,k,'AL',options); 227 | U2= sqrt(2)*V2(1:m,:); 228 | V2= sqrt(2)*V2(m+1:end,:); 229 | fprintf('Number MxV = %f\n',MxV); 230 | fprintf('Elapsed time = %f\n',toc); 231 | fprintf('Number of flops = %e\n',flops); 232 | fprintf('Residual norm = %e\n',norm(A*V2 - U2*S2,'fro')/norm(A,'fro')); 233 | fprintf('Orthogonality U = %e\n',norm(eye(k) - U2'*U2,'fro')) 234 | fprintf('Orthogonality V = %e\n',norm(eye(k) - V2'*V2,'fro')) 235 | 236 | 237 | if ~isempty(Sigma) 238 | S2 = diag(S2); 239 | l= length(S2); 240 | % Compare with "true" singular values 241 | E2 = abs((S2 - Sigma(1:l))./Sigma(1:l)); 242 | fprintf('Max rel. error = %g\n',max(E2)) 243 | fprintf('Mean rel. error = %g\n',mean(E2)) 244 | hold on 245 | semilogy(E2,'x'); 246 | hold off 247 | legend('SVD','BPRO','PRO(A''*A)','PRO(C)',2) 248 | end 249 | 250 | 251 | %%%%%%%%%%%%%%%%%%%% EIGS %%%%%%%%%%%%%%%%%%%%%%%% 252 | % Try ARPACK based eigs routine: 253 | fprintf('\n') 254 | fprintf('-------------------------------------------------------------------\n') 255 | fprintf('METHOD = EIGS(C)\n') 256 | fprintf('\n') 257 | 258 | options =[]; 259 | options.disp=0; 260 | options.issym = 1; 261 | options.v0 = [v0;zeros(n,1)]; 262 | 263 | tic; flops(0);MxV=0; 264 | [V4,S4] = eigs('Cfunc',m+n,k,'LR',options); 265 | U4= sqrt(2)*V4(1:m,:); 266 | V4= sqrt(2)*V4(m+1:end,:); 267 | fprintf('Number MxV = %f\n',MxV); 268 | fprintf('Elapsed time = %f\n',toc); 269 | fprintf('Number of flops = %e\n',flops); 270 | fprintf('Residual norm = %e\n',norm(A*V4 - U4*S4,'fro')/norm(A,'fro')); 271 | fprintf('Orthogonality U = %e\n',norm(eye(k) - U4'*U4,'fro')) 272 | fprintf('Orthogonality V = %e\n',norm(eye(k) - V4'*V4,'fro')) 273 | 274 | if ~isempty(Sigma) 275 | % Compare with "true" singular values 276 | S4 = diag(S4); 277 | l= length(S4); 278 | E4 = abs((S4 - Sigma(1:l))./Sigma(1:l)); 279 | fprintf('Max rel. error = %g\n',max(E4)) 280 | fprintf('Mean rel. error = %g\n',mean(E4)) 281 | hold on 282 | semilogy(E4,'*'); 283 | hold off 284 | legend('SVD','BPRO','PRO(A''*A)','PRO(C)','EIGS',2) 285 | end 286 | 287 | 288 | 289 | %%%%%%%%%%%%%%%%%%%% EIGS %%%%%%%%%%%%%%%%%%%%%%%% 290 | % Try ARPACK based eigs routine: 291 | fprintf('-------------------------------------------------------------------\n') 292 | fprintf('\n') 293 | fprintf('METHOD = EIGS(A''*A)\n') 294 | fprintf('\n') 295 | 296 | options =[]; 297 | options.disp=0; 298 | options.issym = 1; 299 | options.v0 = A'*v0; 300 | 301 | tic; flops(0); MxV=0; 302 | [V5,S5] = eigs('AtAfunc',n,k,'LR',options); 303 | U5 = A*V5; 304 | for i=1:k 305 | U5(:,i) = U5(:,i)/norm(U5(:,i)); 306 | end 307 | fprintf('Number MxV = %f\n',MxV); 308 | fprintf('Elapsed time = %f\n',toc); 309 | fprintf('Number of flops = %e\n',flops); 310 | fprintf('Residual norm = %e\n',norm(A'*(A*V5) - V5*S5,'fro')/norm(A'*A,'fro')); 311 | fprintf('Orthogonality U = %e\n',norm(eye(k) - U5'*U5,'fro')) 312 | fprintf('Orthogonality V = %e\n',norm(eye(k) - V5'*V5,'fro')) 313 | S5 = diag(sqrt(diag(S5))); 314 | 315 | if ~isempty(Sigma) 316 | % Compare with "true" singular values 317 | S5 = diag(S5); 318 | l= length(S5); 319 | E5 = abs((S5 - Sigma(1:l))./Sigma(1:l)); 320 | fprintf('Max rel. error = %e\n',max(E5)) 321 | fprintf('Mean rel. error = %e\n',mean(E5)) 322 | hold on 323 | semilogy(E5,'^'); 324 | hold off 325 | title('Accuracy of \sigma_i compared with output from the svd command.') 326 | legend('BPRO','PRO(A''*A)','PRO(C)','EIGS(C)','EIGS(A''*A)',2) 327 | end 328 | -------------------------------------------------------------------------------- /External/RPCA/exact_alm_rpca/exact_alm_rpca/PROPACK/lansvd.m: -------------------------------------------------------------------------------- 1 | function [U,S,V,bnd,j] = lansvd(varargin) 2 | 3 | %LANSVD Compute a few singular values and singular vectors. 4 | % LANSVD computes singular triplets (u,v,sigma) such that 5 | % A*u = sigma*v and A'*v = sigma*u. Only a few singular values 6 | % and singular vectors are computed using the Lanczos 7 | % bidiagonalization algorithm with partial reorthogonalization (BPRO). 8 | % 9 | % S = LANSVD(A) 10 | % S = LANSVD('Afun','Atransfun',M,N) 11 | % 12 | % The first input argument is either a matrix or a 13 | % string containing the name of an M-file which applies a linear 14 | % operator to the columns of a given matrix. In the latter case, 15 | % the second input must be the name of an M-file which applies the 16 | % transpose of the same operator to the columns of a given matrix, 17 | % and the third and fourth arguments must be M and N, the dimensions 18 | % of the problem. 19 | % 20 | % [U,S,V] = LANSVD(A,K,'L',...) computes the K largest singular values. 21 | % 22 | % [U,S,V] = LANSVD(A,K,'S',...) computes the K smallest singular values. 23 | % 24 | % The full calling sequence is 25 | % 26 | % [U,S,V] = LANSVD(A,K,SIGMA,OPTIONS) 27 | % [U,S,V] = LANSVD('Afun','Atransfun',M,N,K,SIGMA,OPTIONS) 28 | % 29 | % where K is the number of singular values desired and 30 | % SIGMA is 'L' or 'S'. 31 | % 32 | % The OPTIONS structure specifies certain parameters in the algorithm. 33 | % Field name Parameter Default 34 | % 35 | % OPTIONS.tol Convergence tolerance 16*eps 36 | % OPTIONS.lanmax Dimension of the Lanczos basis. 37 | % OPTIONS.p0 Starting vector for the Lanczos rand(n,1)-0.5 38 | % iteration. 39 | % OPTIONS.delta Level of orthogonality among the sqrt(eps/K) 40 | % Lanczos vectors. 41 | % OPTIONS.eta Level of orthogonality after 10*eps^(3/4) 42 | % reorthogonalization. 43 | % OPTIONS.cgs reorthogonalization method used 0 44 | % '0' : iterated modified Gram-Schmidt 45 | % '1' : iterated classical Gram-Schmidt 46 | % OPTIONS.elr If equal to 1 then extended local 1 47 | % reorthogonalization is enforced. 48 | % 49 | % See also LANBPRO, SVDS, SVD 50 | 51 | % References: 52 | % R.M. Larsen, Ph.D. Thesis, Aarhus University, 1998. 53 | % 54 | % B. N. Parlett, ``The Symmetric Eigenvalue Problem'', 55 | % Prentice-Hall, Englewood Cliffs, NJ, 1980. 56 | % 57 | % H. D. Simon, ``The Lanczos algorithm with partial reorthogonalization'', 58 | % Math. Comp. 42 (1984), no. 165, 115--142. 59 | 60 | % Rasmus Munk Larsen, DAIMI, 1998 61 | 62 | 63 | %%%%%%%%%%%%%%%%%%%%% Parse and check input arguments. %%%%%%%%%%%%%%%%%%%%%% 64 | 65 | if nargin<1 | length(varargin)<1 66 | error('Not enough input arguments.'); 67 | end 68 | 69 | A = varargin{1}; 70 | if ~isstr(A) 71 | if ~isreal(A) 72 | error('A must be real') 73 | end 74 | [m n] = size(A); 75 | if length(varargin) < 2, k=min(min(m,n),6); else k=varargin{2}; end 76 | if length(varargin) < 3, sigma = 'L'; else sigma=varargin{3}; end 77 | if length(varargin) < 4, options = []; else options=varargin{4}; end 78 | else 79 | if length(varargin)<4 80 | error('Not enough input arguments.'); 81 | end 82 | Atrans = varargin{2}; 83 | if ~isstr(Atrans) 84 | error('Atransfunc must be the name of a function') 85 | end 86 | m = varargin{3}; 87 | n = varargin{4}; 88 | if length(varargin) < 5, k=min(min(m,n),6); else k=varargin{5}; end 89 | if length(varargin) < 6, sigma = 'L'; else sigma=varargin{6}; end 90 | if length(varargin) < 7, options = []; else options=varargin{7}; end 91 | end 92 | 93 | if ~isnumeric(n) | real(abs(fix(n))) ~= n | ~isnumeric(m) | ... 94 | real(abs(fix(m))) ~= m | ~isnumeric(k) | real(abs(fix(k))) ~= k 95 | error('M, N and K must be positive integers.') 96 | end 97 | 98 | 99 | % Quick return for min(m,n) equal to 0 or 1 or for zero A. 100 | if min(n,m) < 1 | k<1 101 | if nargout<3 102 | U = zeros(k,1); 103 | else 104 | U = eye(m,k); S = zeros(k,k); V = eye(n,k); bnd = zeros(k,1); 105 | end 106 | return 107 | elseif min(n,m) == 1 & k>0 108 | if isstr(A) 109 | % Extract the single column or row of A 110 | if n==1 111 | A = feval(A,1); 112 | else 113 | A = feval(Atrans,1)'; 114 | end 115 | end 116 | if nargout==1 117 | U = norm(A); 118 | else 119 | [U,S,V] = svd(full(A)); 120 | bnd = 0; 121 | end 122 | return 123 | end 124 | 125 | % A is the matrix of all zeros (not detectable if A is defined by an m-file) 126 | if isnumeric(A) 127 | if nnz(A)==0 128 | if nargout<3 129 | U = zeros(k,1); 130 | else 131 | U = eye(m,k); S = zeros(k,k); V = eye(n,k); bnd = zeros(k,1); 132 | end 133 | return 134 | end 135 | end 136 | 137 | lanmax = min(m,n); 138 | tol = 16*eps; 139 | p = rand(m,1)-0.5; 140 | % Parse options struct 141 | if isstruct(options) 142 | c = fieldnames(options); 143 | for i=1:length(c) 144 | if any(strcmp(c(i),'p0')), p = getfield(options,'p0'); p=p(:); end 145 | if any(strcmp(c(i),'tol')), tol = getfield(options,'tol'); end 146 | if any(strcmp(c(i),'lanmax')), lanmax = getfield(options,'lanmax'); end 147 | end 148 | end 149 | 150 | % Protect against absurd options. 151 | tol = max(tol,eps); 152 | lanmax = min(lanmax,min(m,n)); 153 | if size(p,1)~=m 154 | error('p0 must be a vector of length m') 155 | end 156 | 157 | lanmax = min(lanmax,min(m,n)); 158 | if k>lanmax 159 | error('K must satisfy K <= LANMAX <= MIN(M,N).'); 160 | end 161 | 162 | 163 | 164 | %%%%%%%%%%%%%%%%%%%%% Here begins the computation %%%%%%%%%%%%%%%%%%%%%% 165 | 166 | if strcmp(sigma,'S') 167 | if isstr(A) 168 | error('Shift-and-invert works only when the matrix A is given explicitly.'); 169 | else 170 | % Prepare for shift-and-invert Lanczos. 171 | if issparse(A) 172 | pmmd = colmmd(A); 173 | A.A = A(:,pmmd); 174 | else 175 | A.A = A; 176 | end 177 | if m>=n 178 | if issparse(A.A) 179 | A.R = qr(A.A,0); 180 | A.Rt = A.R'; 181 | p = A.Rt\(A.A'*p); % project starting vector on span(Q1) 182 | else 183 | [A.Q,A.R] = qr(A.A,0); 184 | A.Rt = A.R'; 185 | p = A.Q'*p; % project starting vector on span(Q1) 186 | end 187 | else 188 | error('Sorry, shift-and-invert for m 1/eps 194 | error(['A is rank deficient or too ill-conditioned to do shift-and-' ... 195 | ' invert.']) 196 | end 197 | end 198 | end 199 | 200 | ksave = k; 201 | neig = 0; nrestart=-1; 202 | j = min(k+max(8,k)+1,lanmax); 203 | U = []; V = []; B = []; anorm = []; work = zeros(2,2); 204 | 205 | while neig < k 206 | 207 | %%%%%%%%%%%%%%%%%%%%% Compute Lanczos bidiagonalization %%%%%%%%%%%%%%%%% 208 | if ~isstr(A) 209 | [U,B,V,p,ierr,w] = lanbpro(A,j,p,options,U,B,V,anorm); 210 | else 211 | [U,B,V,p,ierr,w] = lanbpro(A,Atrans,m,n,j,p,options,U,B,V,anorm); 212 | end 213 | work= work + w; 214 | 215 | if ierr<0 % Invariant subspace of dimension -ierr found. 216 | j = -ierr; 217 | end 218 | 219 | %%%%%%%%%%%%%%%%%%%%%%%%%%%% 220 | if size(B,1) == 1 221 | if nargout<3 222 | U = zeros(k,1); 223 | else 224 | U = eye(m,k); S = zeros(k,k); V = eye(n,k); bnd = zeros(k,1); 225 | end 226 | return 227 | end 228 | %%%%%%%%%%%%%%%%%%%%%%%%%%%% 229 | 230 | %%%%%%%%%%%%%%%%%% Compute singular values and error bounds %%%%%%%%%%%%%%%% 231 | % Analyze B 232 | resnrm = norm(p); 233 | % We might as well use the extra info. in p. 234 | % S = svd(full([B;[zeros(1,j-1),resnrm]]),0); 235 | % [P,S,Q] = svd(full([B;[zeros(1,j-1),resnrm]]),0); 236 | % S = diag(S); 237 | % bot = min(abs([P(end,1:j);Q(end,1:j)]))'; 238 | 239 | [S,bot] = bdsqr(diag(B),[diag(B,-1); resnrm]); 240 | 241 | % Use Largest Ritz value to estimate ||A||_2. This might save some 242 | % reorth. in case of restart. 243 | anorm=S(1); 244 | 245 | % Set simple error bounds 246 | bnd = resnrm*abs(bot); 247 | 248 | % Examine gap structure and refine error bounds 249 | bnd = refinebounds(S.^2,bnd,n*eps*anorm); 250 | 251 | %%%%%%%%%%%%%%%%%%% Check convergence criterion %%%%%%%%%%%%%%%%%%%% 252 | i=1; 253 | neig = 0; 254 | while i<=min(j,k) 255 | if (bnd(i) <= tol*abs(S(i))) 256 | neig = neig + 1; 257 | i = i+1; 258 | else 259 | i = min(j,k)+1; 260 | end 261 | end 262 | 263 | %%%%%%%%%% Check whether to stop or to extend the Krylov basis? %%%%%%%%%% 264 | if ierr<0 % Invariant subspace found 265 | if j=lanmax % Maximal dimension of Krylov subspace reached. Bail out 272 | if j>=min(m,n) 273 | neig = ksave; 274 | break; 275 | end 276 | if neig0 285 | % increase j by approx. half the average number of steps pr. converged 286 | % singular value (j/neig) times the number of remaining ones (k-neig). 287 | j = j + min(100,max(2,0.5*(k-neig)*j/(neig+1))); 288 | else 289 | % As long a very few singular values have converged, increase j rapidly. 290 | % j = j + ceil(min(100,max(8,2^nrestart*k))); 291 | j = max(1.5*j,j+10); 292 | end 293 | j = ceil(min(j+1,lanmax)); 294 | nrestart = nrestart + 1; 295 | end 296 | 297 | 298 | 299 | %%%%%%%%%%%%%%%% Lanczos converged (or failed). Prepare output %%%%%%%%%%%%%%% 300 | k = min(ksave,j); 301 | 302 | if nargout>2 303 | j = size(B,2); 304 | % Compute singular vectors 305 | [P,S,Q] = svd(full([B;[zeros(1,j-1),resnrm]]),0); 306 | S = diag(S); 307 | if size(Q,2)~=k 308 | Q = Q(:,1:k); 309 | P = P(:,1:k); 310 | end 311 | % Compute and normalize Ritz vectors (overwrites U and V to save memory). 312 | if resnrm~=0 313 | U = U*P(1:j,:) + (p/resnrm)*P(j+1,:); 314 | else 315 | U = U*P(1:j,:); 316 | end 317 | V = V*Q; 318 | for i=1:k 319 | nq = norm(V(:,i)); 320 | if isfinite(nq) & nq~=0 & nq~=1 321 | V(:,i) = V(:,i)/nq; 322 | end 323 | nq = norm(U(:,i)); 324 | if isfinite(nq) & nq~=0 & nq~=1 325 | U(:,i) = U(:,i)/nq; 326 | end 327 | end 328 | end 329 | 330 | % Pick out desired part the spectrum 331 | S = S(1:k); 332 | bnd = bnd(1:k); 333 | 334 | if strcmp(sigma,'S') 335 | [S,p] = sort(-1./S); 336 | S = -S; 337 | bnd = bnd(p); 338 | if nargout>2 339 | if issparse(A.A) 340 | U = A.A*(A.R\U(:,p)); 341 | V(pmmd,:) = V(:,p); 342 | else 343 | U = A.Q(:,1:min(m,n))*U(:,p); 344 | V = V(:,p); 345 | end 346 | end 347 | end 348 | 349 | if nargout<3 350 | U = S; 351 | S = B; % Undocumented feature - for checking B. 352 | else 353 | S = diag(S); 354 | end 355 | -------------------------------------------------------------------------------- /External/RPCA/exact_alm_rpca/exact_alm_rpca/PROPACK/laneig.m: -------------------------------------------------------------------------------- 1 | function [V,D,bnd,j,work] = laneig(A,nin,k,sigma,options) 2 | 3 | %LANEIG Compute a few eigenvalues and eigenvectors. 4 | % LANEIG solves the eigenvalue problem A*v=lambda*v, when A is 5 | % real and symmetric using the Lanczos algorithm with partial 6 | % reorthogonalization (PRO). 7 | % 8 | % [V,D] = LANEIG(A) 9 | % [V,D] = LANEIG('Afun',N) 10 | % 11 | % The first input argument is either a real symmetric matrix, or a 12 | % string containing the name of an M-file which applies a linear 13 | % operator to the columns of a given matrix. In the latter case, 14 | % the second input argument must be N, the order of the problem. 15 | % 16 | % The full calling sequence is 17 | % 18 | % [V,D,ERR] = LANEIG(A,K,SIGMA,OPTIONS) 19 | % [V,D,ERR] = LANEIG('Afun',N,K,SIGMA,OPTIONS) 20 | % 21 | % On exit ERR contains the computed error bounds. K is the number of 22 | % eigenvalues desired and SIGMA is numerical shift or a two letter string 23 | % which specifies which part of the spectrum should be computed: 24 | % 25 | % SIGMA Specified eigenvalues 26 | % 27 | % 'AL' Algebraically Largest 28 | % 'AS' Algebraically Smallest 29 | % 'LM' Largest Magnitude (default) 30 | % 'SM' Smallest Magnitude (does not work when A is an m-file) 31 | % 'BE' Both Ends. Computes k/2 eigenvalues 32 | % from each end of the spectrum (one more 33 | % from the high end if k is odd.) 34 | % 35 | % The OPTIONS structure specifies certain parameters in the algorithm. 36 | % 37 | % Field name Parameter Default 38 | % 39 | % OPTIONS.tol Convergence tolerance 16*eps 40 | % OPTIONS.lanmax Dimension of the Lanczos basis. 41 | % OPTIONS.v0 Starting vector for the Lanczos rand(n,1)-0.5 42 | % iteration. 43 | % OPTIONS.delta Level of orthogonality among the sqrt(eps/K) 44 | % Lanczos vectors. 45 | % OPTIONS.eta Level of orthogonality after 10*eps^(3/4) 46 | % reorthogonalization. 47 | % OPTIONS.cgs reorthogonalization method used 0 48 | % '0' : iterated modified Gram-Schmidt 49 | % '1' : iterated classical Gram-Schmidt 50 | % OPTIONS.elr If equal to 1 then extended local 1 51 | % reorthogonalization is enforced. 52 | % 53 | % See also LANPRO, EIGS, EIG. 54 | 55 | % References: 56 | % R.M. Larsen, Ph.D. Thesis, Aarhus University, 1998. 57 | % 58 | % B. N. Parlett, ``The Symmetric Eigenvalue Problem'', 59 | % Prentice-Hall, Englewood Cliffs, NJ, 1980. 60 | % 61 | % H. D. Simon, ``The Lanczos algorithm with partial reorthogonalization'', 62 | % Math. Comp. 42 (1984), no. 165, 115--142. 63 | 64 | % Rasmus Munk Larsen, DAIMI, 1998 65 | 66 | 67 | %%%%%%%%%%%%%%%%%%%%% Parse and check input arguments. %%%%%%%%%%%%%%%%%%%%%% 68 | 69 | if ~isstr(A) 70 | if nargin<1 71 | error('Not enough input arguments.'); 72 | end 73 | [m n] = size(A); 74 | Aisfunc = 0; 75 | if m~=n | ~isequal(A,A') | ~isreal(A) 76 | error('A must be real symmetric') 77 | end 78 | if nargin < 4 | isempty(sigma) 79 | options = []; 80 | else 81 | options = sigma; 82 | end 83 | if nargin < 3 | isempty(k), sigma = 'LM'; else, sigma = k; end 84 | if nargin < 2 | isempty(nin), k = min(n,5); else, k = nin; end 85 | else 86 | if nargin<2 87 | error('Not enough input arguments.'); 88 | end 89 | Aisfunc = 1; 90 | n = nin; 91 | if nargin < 5 | isempty(options) 92 | options.tol = 16*eps; 93 | options.lanmax = n; 94 | options.v0 = rand(n,1)-0.5; 95 | end 96 | if nargin < 4 | isempty(sigma), sigma = 'LM'; end 97 | if nargin < 3 | isempty(k), k = min(n,5); end 98 | end 99 | 100 | if ~isnumeric(k) | real(abs(fix(k)))~=k | ~isnumeric(n) | real(abs(fix(n)))~=n 101 | error('Input arguments N and K must be positive integers.') 102 | end 103 | 104 | % Quick return for n<2 or k<1 105 | if n < 1 | k<1 106 | if nargout < 2 107 | V = zeros(k,1); 108 | else 109 | V = eye(n,k); 110 | D = zeros(k,k); 111 | bnd =zeros(k,1); 112 | end 113 | return 114 | end 115 | if n == 1 116 | if ~Aisfunc 117 | D = A; 118 | V = 1; 119 | bnd = 0; 120 | else 121 | D = feval(A,1); 122 | V = 1; 123 | dnb = 0; 124 | end 125 | if nargout<2 126 | V=D; 127 | end 128 | return 129 | end 130 | 131 | % A is the matrix of all zeros (not detectable if A is a string) 132 | if ~Aisfunc 133 | if nnz(A)==0 134 | if nargout < 2 135 | V = zeros(k,1); 136 | else 137 | V = eye(n,k); 138 | D = zeros(k,k); 139 | bnd =zeros(k,1); 140 | end 141 | return 142 | end 143 | end 144 | 145 | lanmax = n; 146 | tol = 16*eps; 147 | r = rand(n,1)-0.5; 148 | part = sigma; 149 | % Parse options struct 150 | if ~isempty(options) & isstruct(options) 151 | c = fieldnames(options); 152 | for i=1:length(c) 153 | if strmatch(c(i),'v0'), r = getfield(options,'v0'); r=r(:); end 154 | if strmatch(c(i),'tol'), tol = getfield(options,'tol'); end 155 | if strmatch(c(i),'lanmax'), lanmax = getfield(options,'lanmax'); end 156 | end 157 | end 158 | 159 | % Protect against absurd arguments. 160 | tol = max(tol,eps); 161 | lanmax = min(lanmax,n); 162 | if size(r,1)~=n 163 | error('v0 must be a vector of length n') 164 | end 165 | 166 | lanmax = min(lanmax,n); 167 | if k>lanmax 168 | error('K must satisfy K <= LANMAX <= N.'); 169 | end 170 | ksave = k; 171 | 172 | if strcmp(sigma,'SM') & ~isstr(A) 173 | sigma = 0; 174 | end 175 | 176 | 177 | % Prepare for shift-and-invert if sigma is numeric. 178 | if isnumeric(sigma) 179 | part = 'LM'; 180 | if isstr(A) 181 | error('Shift-and-invert works only when the matrix A is given explicitly.'); 182 | else 183 | pmmd = symmmd(A); 184 | A = A(pmmd,pmmd); 185 | [S.L,S.U] = lu(A - sigma*speye(n)); 186 | condU = condest(S.U); 187 | dsigma = n * full(max(max(abs(A)))) * eps; 188 | if sigma < 0 189 | sgnsig = -1; 190 | else 191 | sgnsig = 1; 192 | end 193 | sigitr = 1; 194 | while condU > 1/eps & ((dsigma <= 1 & sigitr <= 10) | ~isfinite(condU)) 195 | disps1 = sprintf(['sigma = %10e is near an exact eigenvalue of A,\n' ... 196 | 'so we cannot use the LU factorization of (A-sigma*I): ' ... 197 | ' condest(U) = %10e.\n'],sigma,condU); 198 | if abs(sigma) < 1 199 | sigma = sigma + sgnsig * dsigma; 200 | disps2 = sprintf('We are trying sigma + %10e = %10e instead.\n', ... 201 | sgnsig*dsigma,sigma); 202 | else 203 | sigma = sigma * (1 + dsigma); 204 | disps2 = sprintf('We are trying sigma * (1 + %10e) = %10e instead.\n', ... 205 | dsigma,sigma); 206 | end 207 | % if nargout < 3 & dispn ~= 0 208 | disp([disps1 disps2]) 209 | % end 210 | [S.L,S.U] = lu(A - sigma*speye(n)); 211 | condU = condest(S.U); 212 | dsigma = 10 * dsigma; 213 | sigitr = sigitr + 1; 214 | end 215 | end 216 | A = S; 217 | end 218 | 219 | 220 | neig = 0; nrestart=-1; 221 | if ~strcmp(part,'BE') 222 | j = min(2*k+2,lanmax); 223 | else 224 | j = min(k+1,lanmax); 225 | end 226 | 227 | 228 | %%%%%%%%%%%%%%%%%%%%% Here begins the computation %%%%%%%%%%%%%%%%%%%%%% 229 | 230 | V = []; T = []; anorm = []; work = zeros(1,2); rnorm=-1; 231 | 232 | 233 | 234 | 235 | while neig < k 236 | %%%%%%%%%%%%%%%%%%%%% Compute Lanczos tridiagonalization %%%%%%%%%%%%%%%%% 237 | j = min(lanmax,j+1-mod(j,2)); 238 | % "Trick" to avoid unwanted zero eigenvalues when laneig is used for 239 | % SVD calculations. (Nothing to if lanmax is odd, though.) 240 | 241 | if ~isstr(A) 242 | [V,T,r,anorm,ierr,w] = lanpro(A,j,r,options,V,T,anorm); 243 | else 244 | [V,T,r,anorm,ierr,w] = lanpro(A,n,j,r,options,V,T,anorm); 245 | end 246 | work= work + w; 247 | 248 | if ierr<0 % Invariant subspace of dimension -ierr found. 249 | j = -ierr; 250 | end 251 | 252 | %%%%%%%%%%%%%%%%%% Compute eigenvalues and error bounds %%%%%%%%%%%%%%%%%% 253 | % Analyze T 254 | [D,top,bot,err] = tqlb([full(diag(T))],full([0;diag(T,1)])); 255 | % if err>0 256 | % printf(['TQLB failed. Eigenvalue no. %i did not converge in 30', ... 257 | % ' iterations'],err); 258 | % end 259 | % full(T) 260 | % [P,D] = eig(full(T)); 261 | % D = diag(D); 262 | % bot = P(end,:)'; 263 | % [P(1,:)' P(end,:)'] 264 | [D,I] = sort(D); 265 | bot = bot(I); 266 | 267 | % Set simple error bounds 268 | rnorm = norm(r); 269 | bnd = rnorm*abs(bot); 270 | 271 | % Use Largest Ritz value to estimate ||A||_2. This might save some 272 | % reorth. in case of restart. 273 | anorm = max(abs(D)); 274 | 275 | % Estimate gap structure and refine error bounds 276 | bnd = refinebounds(D,bnd,n*eps*anorm); 277 | 278 | %%%%%%%%%%%%%%%%%%% Check convergence criterion %%%%%%%%%%%%%%%%%%%% 279 | % Reorder eigenvalues according to SIGMA 280 | switch part 281 | case 'AS' 282 | IPART = 1:j; 283 | case 'AL' 284 | IPART = j:-1:1; 285 | case 'LM' 286 | [dummy,IPART] = sort(-abs(D)); 287 | case 'BE' 288 | if j=lanmax % Maximal dimension of Krylov subspace reached => Bail out! 319 | if neig0 328 | % j = j + ceil(min(20,max(2,((j-1)*(k-neig+1))/(2*(neig+1))))); 329 | j = j + min(100,max(2,0.5*(k-neig)*j/(neig+1))); 330 | elseif neig1 344 | j = size(T,1); 345 | [Q,D] = eig(full(T)); D = diag(D); 346 | [D,I] = sort(D); 347 | % Compute and normalize Ritz vectors (overwrite V to save memory). 348 | V = V*Q(:,I(IPART(1:k))); 349 | for i=1:k 350 | nq = norm(V(:,i)); 351 | if isfinite(nq) & nq~=0 & nq~=1 352 | V(:,i) = V(:,i)/nq; 353 | end 354 | end 355 | [D,I] = sort(D); 356 | D = D(IPART(1:k)); 357 | if isnumeric(sigma) 358 | D = sigma + 1./D; 359 | V(pmmd,:) = V; 360 | end 361 | end 362 | 363 | % Pick out desired part of the spectrum 364 | if length(D)~=k 365 | D = D(1:k); 366 | bnd = bnd(1:k); 367 | end 368 | 369 | if nargout<2 370 | V = D; 371 | else 372 | D = diag(D); 373 | end 374 | 375 | -------------------------------------------------------------------------------- /External/RPCA/exact_alm_rpca/exact_alm_rpca/PROPACK/lanpro.m: -------------------------------------------------------------------------------- 1 | function [Q_k,T_k,r,anorm,ierr,work] = lanpro(A,nin,kmax,r,options,... 2 | Q_k,T_k,anorm) 3 | 4 | %LANPRO Lanczos tridiagonalization with partial reorthogonalization 5 | % LANPRO computes the Lanczos tridiagonalization of a real symmetric 6 | % matrix using the symmetric Lanczos algorithm with partial 7 | % reorthogonalization. 8 | % 9 | % [Q_K,T_K,R,ANORM,IERR,WORK] = LANPRO(A,K,R0,OPTIONS,Q_old,T_old) 10 | % [Q_K,T_K,R,ANORM,IERR,WORK] = LANPRO('Afun',N,K,R0,OPTIONS,Q_old,T_old) 11 | % 12 | % Computes K steps of the Lanczos algorithm with starting vector R0, 13 | % and returns the K x K tridiagonal T_K, the N x K matrix Q_K 14 | % with semiorthonormal columns and the residual vector R such that 15 | % 16 | % A*Q_K = Q_K*T_K + R . 17 | % 18 | % Partial reorthogonalization is used to keep the columns of Q_K 19 | % semiorthogonal: 20 | % MAX(DIAG((eye(k) - Q_K'*Q_K))) <= OPTIONS.delta. 21 | % 22 | % 23 | % The first input argument is either a real symmetric matrix, a struct with 24 | % components A.L and A.U or a string containing the name of an M-file which 25 | % applies a linear operator to the columns of a given matrix. In the latter 26 | % case, the second input argument must be N, the order of the problem. 27 | % 28 | % If A is a struct with components A.L and A.U, such that 29 | % L*U = (A - sigma*I), a shift-and-invert Lanczos iteration is performed 30 | % 31 | % The OPTIONS structure is used to control the reorthogonalization: 32 | % OPTIONS.delta: Desired level of orthogonality 33 | % (default = sqrt(eps/K)). 34 | % OPTIONS.eta : Level of orthogonality after reorthogonalization 35 | % (default = eps^(3/4)/sqrt(K)). 36 | % OPTIONS.cgs : Flag for switching between different reorthogonalization 37 | % algorithms: 38 | % 0 = iterated modified Gram-Schmidt (default) 39 | % 1 = iterated classical Gram-Schmidt 40 | % OPTIONS.elr : If OPTIONS.elr = 1 (default) then extended local 41 | % reorthogonalization is enforced. 42 | % OPTIONS.Y : The lanczos vectors are reorthogonalized against 43 | % the columns of the matrix OPTIONS.Y. 44 | % 45 | % If both R0, Q_old and T_old are provided, they must contain 46 | % a partial Lanczos tridiagonalization of A on the form 47 | % 48 | % A Q_old = Q_old T_old + R0 . 49 | % 50 | % In this case the factorization is extended to dimension K x K by 51 | % continuing the Lanczos algorithm with R0 as starting vector. 52 | % 53 | % On exit ANORM contains an approximation to ||A||_2. 54 | % IERR = 0 : K steps were performed succesfully. 55 | % IERR > 0 : K steps were performed succesfully, but the algorithm 56 | % switched to full reorthogonalization after IERR steps. 57 | % IERR < 0 : Iteration was terminated after -IERR steps because an 58 | % invariant subspace was found, and 3 deflation attempts 59 | % were unsuccessful. 60 | % On exit WORK(1) contains the number of reorthogonalizations performed, and 61 | % WORK(2) contains the number of inner products performed in the 62 | % reorthogonalizations. 63 | % 64 | % See also LANEIG, REORTH, COMPUTE_INT 65 | 66 | % References: 67 | % R.M. Larsen, Ph.D. Thesis, Aarhus University, 1998. 68 | % 69 | % G. H. Golub & C. F. Van Loan, "Matrix Computations", 70 | % 3. Ed., Johns Hopkins, 1996. Chapter 9. 71 | % 72 | % B. N. Parlett, ``The Symmetric Eigenvalue Problem'', 73 | % Prentice-Hall, Englewood Cliffs, NJ, 1980. 74 | % 75 | % H. D. Simon, ``The Lanczos algorithm with partial reorthogonalization'', 76 | % Math. Comp. 42 (1984), no. 165, 115--142. 77 | 78 | % Rasmus Munk Larsen, DAIMI, 1998 79 | 80 | 81 | % Check input arguments. 82 | if nargin<1, error('Not enough input arguments.'); end 83 | if isnumeric(A) | isstruct(A) 84 | if isnumeric(A) 85 | [m n] = size(A); 86 | if m~=n | ~isequal(A,A') | ~isreal(A) 87 | error('A must be real symmetric') 88 | end 89 | elseif isstruct(A) 90 | [m n] = size(A.L); 91 | end 92 | 93 | if nargin<7 | isempty(T_k), 94 | anorm = []; est_anorm=1; 95 | else 96 | anorm = T_k; est_anorm=0; 97 | end 98 | if nargin<6, Q_k=[]; T_k=[]; else, T_k = Q_k; Q_k = options; end 99 | if nargin<4 | isempty(r), options = []; else, options = r; end 100 | if nargin<3 | isempty(kmax), 101 | r = rand(n,1)-0.5; 102 | else 103 | r = kmax; 104 | end 105 | if nargin<2 | isempty(nin); kmax = max(10,n/10); else, kmax = nin; end 106 | else 107 | if nargin<2 108 | error('Not enough input arguments.'); 109 | end 110 | % Check input functions and parse to create an internal object 111 | % if an explicit expression is given. 112 | [A, msg] = fcnchk(A); 113 | if ~isempty(msg) 114 | error(msg); 115 | end 116 | n = nin; 117 | if nargin<8 | isempty(anorm), anorm = []; est_anorm=1; else est_anorm=0; end 118 | if nargin<7, Q_k=[]; T_k=[]; end 119 | if nargin<5 | isempty(options), options = []; end 120 | if nargin<4 | isempty(r), r = rand(n,1)-0.5; end 121 | if nargin<3 | isempty(kmax); kmax = max(10,n/10); end 122 | end 123 | 124 | % Set options. 125 | delta = sqrt(eps/kmax); % Desired level of orthogonality. 126 | eta = eps^(3/4)/sqrt(kmax); % Level of orth. after reorthogonalization. 127 | cgs = 0; % Flag for switching between iterated CGS and MGS. 128 | elr = 1; % Flag for switching extended local 129 | % reorthogonalization on and off. 130 | deflate = 0; % Flag for deflation against OPTIONS.Y 131 | 132 | % Parse options struct 133 | if ~isempty(options) & isstruct(options) 134 | c = fieldnames(options); 135 | for i=1:length(c) 136 | if strmatch(c(i),'delta'), delta = getfield(options,'delta'); end 137 | if strmatch(c(i),'eta'), eta = getfield(options,'eta'); end 138 | if strmatch(c(i),'cgs'), cgs = getfield(options,'cgs'); end 139 | if strmatch(c(i),'elr'), elr = getfield(options,'elr'); end 140 | if strmatch(c(i),'Y'), deflate = ~isempty(options.Y); end 141 | end 142 | end 143 | 144 | np = 0; nr = 0; ierr=0; 145 | 146 | % Rule-of-thumb estimate on the size of round-off terms: 147 | eps1 = sqrt(n)*eps/2; % Notice that {\bf u} == eps/2. 148 | gamma = 1/sqrt(2); 149 | 150 | % Prepare Lanczos iteration 151 | if isempty(Q_k) % New Lanczos tridiagonalization. 152 | % Allocate space 153 | alpha = zeros(kmax+1,1); beta = zeros(kmax+1,1); 154 | Q_k = zeros(n,kmax); 155 | q = zeros(n,1); beta(1)=norm(r); 156 | omega = zeros(kmax,1); omega_max = omega; omega_old = omega; 157 | omega(1) = 0; force_reorth= 0; 158 | j0 = 1; 159 | else % Extending existing Lanczos tridiagonalization. 160 | j = size(Q_k,2); % Size of existing factorization 161 | % Allocate space 162 | Q_k = [Q_k zeros(n,kmax-j)]; 163 | alpha = zeros(kmax+1,1); beta = zeros(kmax+1,1); 164 | alpha(1:j) = diag(T_k); 165 | if j>1 166 | beta(2:j) = diag(T_k,-1); 167 | end 168 | q = Q_k(:,j); 169 | % Reorthogonalize r. 170 | beta(j+1) = norm(r); 171 | if j1 228 | t1 = q_old'*r; 229 | t2 = q'*r; 230 | r = r - (q_old*t1 + q*t2); % Add small terms together first to 231 | if beta(j)~=0 % reduce risk of cancellation. 232 | beta(j) = beta(j) + t1; 233 | end 234 | alpha(j) = alpha(j) + t2; 235 | end 236 | beta(j+1) = sqrt(r'*r); % Quick and dirty estimate. 237 | end 238 | 239 | % Update Gersgorin estimate of ||T_k|| if required 240 | % if est_anorm & beta(j+1)~=0 241 | % T_k = spdiags([[beta(2:j);0] alpha(1:j) beta(1:j)],-1:1,j,j); 242 | % anorm = sqrt(norm(T_k'*T_k,1)) 243 | % end 244 | if est_anorm & beta(j+1)~=0 245 | anorm = update_gbound(anorm,alpha,beta,j); 246 | end 247 | 248 | % Update omega-recurrence 249 | if j>1 & ~fro & beta(j+1)~=0 250 | [omega,omega_old] = update_omega(omega,omega_old,j,alpha,beta,... 251 | eps1,anorm); 252 | omega_max(j) = max(abs(omega)); 253 | end 254 | 255 | % Reorthogonalize if required 256 | if j>1 & (fro | force_reorth | omega_max(j)>delta) & beta(j+1)~=0 257 | if fro 258 | int = 1:j; 259 | else 260 | if force_reorth == 0 261 | force_reorth= 1; % Do forced reorth to avoid spill-over from q_{j-1}. 262 | int = compute_int(omega,j,delta,eta,0,0,0); 263 | else 264 | force_reorth= 0; 265 | end 266 | end 267 | [r,beta(j+1),rr] = reorth(Q_k,r,beta(j+1),int,gamma,cgs); 268 | omega(int) = eps1; 269 | np = np + rr*length(int(:)); nr = nr + 1; 270 | else 271 | beta(j+1) = norm(r); % compute norm accurately. 272 | end 273 | 274 | if deflate 275 | [r,beta(j+1),rr] = reorth(options.Y,r,beta(j+1),1:size(options.Y,2), ... 276 | gamma,cgs); 277 | end 278 | 279 | if j 0 300 | % A vector numerically orthogonal to span(Q_k(:,1:j)) was found. 301 | % Continue iteration. 302 | bailout=0; 303 | break; 304 | end 305 | end 306 | if bailout 307 | ierr = -j; 308 | break; 309 | else 310 | r=r/nrmnew; % Continue with new normalized r as starting vector. 311 | force_reorth = 1; 312 | if delta>0 313 | fro = 0; % Turn off full reorthogonalization. 314 | end 315 | end 316 | elseif j delta then omega(j+1) will 318 | % immediately exceed delta, and thus forcing a reorth. to occur at the 319 | % next step. The components of omega will mainly be determined 320 | % by the initial value and not the recurrence, and therefore we 321 | % cannot tell reliably which components exceed eta => we might 322 | % as well switch to full reorthogonalization to avoid trouble. 323 | % The user is probably trying to determine pathologically 324 | % small ( < sqrt(eps)*||A||_2 ) eigenvalues. 325 | % warning(['Semiorthogonality cannot be maintained at iteration ', ... 326 | % num2str(j),'. The matrix is probably ill-conditioned.', ... 327 | % ' Switching to full reorthogonalization.']) 328 | fro = 1; 329 | ierr = j; 330 | end 331 | end 332 | 333 | % Set up tridiagonal T_k in sparse matrix data structure. 334 | T_k = spdiags([[beta(2:j);0] alpha(1:j) beta(1:j)],-1:1,j,j); 335 | if nargout<2 336 | Q_k = T_k; 337 | elseif j~=size(Q_k,2) 338 | Q_k = Q_k(:,1:j); 339 | end 340 | work = [nr np]; 341 | 342 | 343 | function [omega,omega_old] = update_omega(omega, omega_old, j, ... 344 | alpha,beta,eps1,anorm) 345 | % UPDATE_OMEGA: Update Simon's omega_recurrence for the Lanczos vectors. 346 | % 347 | % [omega,omega_old] = update_omega(omega, omega_old,j,eps1,alpha,beta,anorm) 348 | % 349 | 350 | % Rasmus Munk Larsen, DAIMI, 1998. 351 | 352 | % Estimate of contribution to roundoff errors from A*v 353 | % fl(A*v) = A*v + f, 354 | % where ||f|| \approx eps1*||A||. 355 | % For a full matrix A, a rule-of-thumb estimate is eps1 = sqrt(n)*eps. 356 | T = eps1*anorm; 357 | binv = 1/beta(j+1); 358 | 359 | omega_old = omega; 360 | % Update omega(1) using omega(0)==0. 361 | omega_old(1)= beta(2)*omega(2)+ (alpha(1)-alpha(j))*omega(1) - ... 362 | beta(j)*omega_old(1); 363 | omega_old(1) = binv*(omega_old(1) + sign(omega_old(1))*T); 364 | % Update remaining components. 365 | k=2:j-2; 366 | omega_old(k) = beta(k+1).*omega(k+1) + (alpha(k)-alpha(j)).*omega(k) ... 367 | + beta(k).*omega(k-1) - beta(j)*omega_old(k); 368 | omega_old(k) = binv*(omega_old(k) + sign(omega_old(k))*T); 369 | omega_old(j-1) = binv*T; 370 | % Swap omega and omega_old. 371 | temp = omega; 372 | omega = omega_old; 373 | omega_old = omega; 374 | omega(j) = eps1; 375 | 376 | 377 | function anorm = update_gbound(anorm,alpha,beta,j) 378 | %UPDATE_GBOUND Update Gerscgorin estimate of 2-norm 379 | % ANORM = UPDATE_GBOUND(ANORM,ALPHA,BETA,J) updates the Gerscgorin bound 380 | % for the tridiagonal in the Lanczos process after the J'th step. 381 | % Applies Gerscgorins circles to T_K'*T_k instead of T_k itself 382 | % since this gives a tighter bound. 383 | 384 | if j==1 % Apply Gerscgorin circles to T_k'*T_k to estimate || A ||_2 385 | i=j; 386 | % scale to avoid overflow 387 | scale = max(abs(alpha(i)),abs(beta(i+1))); 388 | alpha(i) = alpha(i)/scale; 389 | beta(i+1) = beta(i+1)/scale; 390 | anorm = 1.01*scale*sqrt(alpha(i)^2+beta(i+1)^2 + abs(alpha(i)*beta(i+1))); 391 | elseif j==2 392 | i=1; 393 | % scale to avoid overflow 394 | scale = max(max(abs(alpha(1:2)),max(abs(beta(2:3))))); 395 | alpha(1:2) = alpha(1:2)/scale; 396 | beta(2:3) = beta(2:3)/scale; 397 | 398 | anorm = max(anorm, scale*sqrt(alpha(i)^2+beta(i+1)^2 + ... 399 | abs(alpha(i)*beta(i+1) + alpha(i+1)*beta(i+1)) + ... 400 | abs(beta(i+1)*beta(i+2)))); 401 | i=2; 402 | anorm = max(anorm,scale*sqrt(abs(beta(i)*alpha(i-1) + alpha(i)*beta(i)) + ... 403 | beta(i)^2+alpha(i)^2+beta(i+1)^2 + ... 404 | abs(alpha(i)*beta(i+1))) ); 405 | elseif j==3 406 | % scale to avoid overflow 407 | scale = max(max(abs(alpha(1:3)),max(abs(beta(2:4))))); 408 | alpha(1:3) = alpha(1:3)/scale; 409 | beta(2:4) = beta(2:4)/scale; 410 | i=2; 411 | anorm = max(anorm,scale*sqrt(abs(beta(i)*alpha(i-1) + alpha(i)*beta(i)) + ... 412 | beta(i)^2+alpha(i)^2+beta(i+1)^2 + ... 413 | abs(alpha(i)*beta(i+1) + alpha(i+1)*beta(i+1)) + ... 414 | abs(beta(i+1)*beta(i+2))) ); 415 | i=3; 416 | anorm = max(anorm,scale*sqrt(abs(beta(i)*beta(i-1)) + ... 417 | abs(beta(i)*alpha(i-1) + alpha(i)*beta(i)) + ... 418 | beta(i)^2+alpha(i)^2+beta(i+1)^2 + ... 419 | abs(alpha(i)*beta(i+1))) ); 420 | else 421 | % scale to avoid overflow 422 | % scale = max(max(abs(alpha(j-2:j)),max(abs(beta(j-2:j+1))))); 423 | % alpha(j-2:j) = alpha(j-2:j)/scale; 424 | % beta(j-2:j+1) = beta(j-2:j+1)/scale; 425 | 426 | % Avoid scaling, which is slow. At j>3 the estimate is usually quite good 427 | % so just make sure that anorm is not made infinite by overflow. 428 | i = j-1; 429 | anorm1 = sqrt(abs(beta(i)*beta(i-1)) + ... 430 | abs(beta(i)*alpha(i-1) + alpha(i)*beta(i)) + ... 431 | beta(i)^2+alpha(i)^2+beta(i+1)^2 + ... 432 | abs(alpha(i)*beta(i+1) + alpha(i+1)*beta(i+1)) + ... 433 | abs(beta(i+1)*beta(i+2))); 434 | if isfinite(anorm1) 435 | anorm = max(anorm,anorm1); 436 | end 437 | i = j; 438 | anorm1 = sqrt(abs(beta(i)*beta(i-1)) + ... 439 | abs(beta(i)*alpha(i-1) + alpha(i)*beta(i)) + ... 440 | beta(i)^2+alpha(i)^2+beta(i+1)^2 + ... 441 | abs(alpha(i)*beta(i+1))); 442 | if isfinite(anorm1) 443 | anorm = max(anorm,anorm1); 444 | end 445 | end 446 | --------------------------------------------------------------------------------