├── README.md ├── DMMCP.m ├── DWT.m ├── main.m ├── nmse.m ├── omp.m ├── ImCoef.m ├── feature.m ├── signal.m ├── HyperChao.m ├── Scramble1.m ├── TpEncrypt.m ├── WavRecov.m ├── WavletDim.m ├── RanScramble1.m ├── RanScramble2.m ├── TLDECRYPTEx.m ├── TLENCRYPTEx.m ├── image_block.m ├── Objectdetection.m ├── PartHadamardMtx.m ├── encryption_based_on_CS_chaotic ├── 图像处理基础算法源代码MATLAB集合 │ ├── 2 │ │ ├── 2 │ │ │ ├── P0201.m │ │ │ ├── P0208.m │ │ │ ├── P0202.m │ │ │ ├── P0207.m │ │ │ ├── P0209.m │ │ │ ├── Plane211.jpg │ │ │ ├── readme.txt │ │ │ ├── wrod213.bmp │ │ │ ├── P0203.m │ │ │ ├── P0210.m │ │ │ ├── P0205.m │ │ │ └── P0206.m │ │ ├── 2.rar │ │ └── 程序代码说明.txt │ ├── 3 │ │ ├── 3 │ │ │ ├── P0301.m │ │ │ ├── P0302.m │ │ │ ├── P0304.m │ │ │ ├── P0305.m │ │ │ ├── P0306.m │ │ │ ├── P0307.m │ │ │ ├── P0308.m │ │ │ ├── P0309.m │ │ │ ├── P0310.m │ │ │ ├── P0311.m │ │ │ ├── P0312.m │ │ │ ├── 3-22.jpg │ │ │ ├── readme.txt │ │ │ └── P0303.m │ │ ├── 3.rar │ │ └── 程序代码说明.txt │ ├── 4 │ │ ├── 4 │ │ │ ├── P0403.m │ │ │ ├── P0401.m │ │ │ ├── P0402.m │ │ │ ├── P0404.m │ │ │ ├── P0405.m │ │ │ ├── P0407.m │ │ │ ├── P0408.m │ │ │ ├── P0409.m │ │ │ ├── 4-11.jpg │ │ │ ├── bacteria.BMP │ │ │ ├── readme.txt │ │ │ ├── wrod213.bmp │ │ │ └── P0406.m │ │ ├── 4.rar │ │ └── 程序代码说明.txt │ ├── 5 │ │ ├── 5.rar │ │ └── 程序代码说明.txt │ ├── 6 │ │ ├── 6.rar │ │ └── 程序代码说明.txt │ ├── Matlab 命令.doc │ ├── Matlab 命令.rar │ ├── Matlab图形图像处理函数.pdf │ ├── Matlab图形图像处理函数.rar │ ├── Matlab图形图像处理函数详细列表.pdf │ └── Matlab图形图像处理函数详细列表.rar ├── CS_Examples │ ├── spgl1_1_7 │ │ ├── NormL1_dual.m │ │ ├── NormL1_primal.m │ │ ├── private │ │ │ ├── oneProjectorMex.mexglx │ │ │ ├── oneProjectorMex.mexmaci │ │ │ ├── oneProjectorMex.mexw32 │ │ │ ├── oneProjectorCore.h │ │ │ ├── ensure.m │ │ │ ├── oneProjector.m │ │ │ ├── heap.h │ │ │ ├── oneProjectorMex.m │ │ │ ├── oneProjectorMex.c │ │ │ ├── oneProjectorCore.c │ │ │ ├── heap.c │ │ │ └── lsqr.m │ │ ├── NormGroupL2_primal.m │ │ ├── NormGroupL2_dual.m │ │ ├── NormL12_primal.m │ │ ├── NormL12_dual.m │ │ ├── NormL1_project.m │ │ ├── NormGroupL2_project.m │ │ ├── NormL12_project.m │ │ ├── Contents.m │ │ ├── spgsetup.m │ │ ├── spg_bp.m │ │ ├── spg_lasso.m │ │ ├── spg_bpdn.m │ │ ├── spg_group.m │ │ ├── README │ │ ├── spg_mmv.m │ │ ├── ChangeLog │ │ └── spgSetParms.m │ ├── CS_OMP.m │ └── CS_SPGL1.m ├── omp │ ├── DWT.m │ ├── lena256.bmp │ ├── Wavelet_OMP.m │ ├── image_block.m │ └── Wavelet_size_OMP.m ├── white.tif ├── 二维图像 │ └── OMP │ │ ├── CS_OMP.m │ │ └── Wavelet_OMP │ │ ├── DWT.m │ │ ├── omp.m │ │ ├── nmse.m │ │ ├── test1.m │ │ ├── 原始图像.fig │ │ ├── lena256.bmp │ │ ├── psnr_test.m │ │ ├── CirculantMtx.m │ │ ├── Wavelet_OMP.m │ │ ├── 循环矩阵OMP重构图像.fig │ │ ├── 高斯矩阵OMP重构图像.fig │ │ ├── 伯努利矩阵OMP重构图像.fig │ │ ├── 托普利兹矩阵OMP重构图像.fig │ │ ├── 稀疏随机矩阵OMP重构图像.fig │ │ ├── 部分哈达吗矩阵OMP重构图像.fig │ │ ├── GaussMtx_Wavelet_OMP.m │ │ ├── Bernoulli_Wavelet_OMP.m │ │ ├── ToeplitzMtx_Wavelet_OMP.m │ │ ├── CirculantMtx_Wavelet_OMP.m │ │ ├── PartHadamardMtx_Wavelet_OMP.m │ │ ├── SparseRandomMtx_Wavelet_OMP.m │ │ ├── GaussMtx.m │ │ ├── SparseRandomMtx.m │ │ ├── ToeplitzMtx.m │ │ ├── BernoulliMtx.m │ │ └── PartHadamardMtx.m ├── Matlab重构算法 │ ├── SP算法 │ │ ├── SP.m │ │ └── SP.pdf │ └── software │ │ ├── lena.bmp │ │ ├── Demo_CS_GBP.m │ │ ├── Demo_CS_IHT.m │ │ ├── Demo_CS_OMP.m │ │ ├── Demo_CS_SP.m │ │ ├── Demo_CS_CoSaMP.m │ │ └── Demo_CS_IRLS.m ├── BCS implemented │ ├── BCSvb.m │ ├── indor2.pgm │ ├── cameraman.pgm │ ├── demo_BCSvb_1d.m │ ├── demo_BCSvb_2d.m │ └── demo_BCSvb_2d_small.m ├── Tensor_CS │ └── Fig_8 │ │ ├── .DS_Store │ │ ├── xyzbar.mat │ │ ├── WTbases.mat │ │ ├── .MegaCloud │ │ ├── normalize.m │ │ ├── dispRGB.m │ │ ├── XYZ2sRGB_exgamma.m │ │ ├── MakeFig8.m │ │ ├── Main.m │ │ └── tensor_OMPND.m └── TMSBL_code │ └── TMSBL_code │ ├── Master the Usage of TSBL in 1 Minute.pdf │ ├── Master the Usage of TMSBL in 3 Minutes.docx │ ├── Master the Usage of TMSBL in 3 Minutes.pdf │ ├── ReadMe.txt │ ├── perfSupp.m │ ├── demo_fig6_SNR10.m │ ├── demo_fig8.m │ ├── demo_fig3.m │ ├── demo_identicalVector.m │ ├── MFOCUSS.m │ ├── MSBL.m │ ├── demo_time_varying.m │ └── demo.m ├── PWLCM.m ├── icmic.m ├── Entropy.m ├── BitCircShift.m ├── LE_PWLCM.m ├── BD_Gauss.m ├── BD_PWLCM.m ├── test.m ├── BD_Chebyshev.m ├── LE_Tent.m ├── LT.m ├── testENDE.m ├── LE_Sine.m ├── BD_Henon.m ├── BD_GCCM_II.m ├── SHA256.m ├── psnr.m ├── BD_Tent.m ├── LE_Gauss.m ├── LE_Chebyshev.m ├── LE_LGCM_II.m ├── LE_LCCM_II.m ├── LE_GCCM_II.m ├── Diffentialattack.m ├── BD_Baker.m ├── LE_Henon.m ├── zConfusion.m ├── PRICKeyGen.m ├── TpDecrypt.m ├── kafang.m ├── testKey.m ├── hash.m └── ssim.m /README.md: -------------------------------------------------------------------------------- 1 | # Encryption_Matlab 2 | 与图像加密有关的一些代码 3 | -------------------------------------------------------------------------------- /DMMCP.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dingqinliu/Encryption_Matlab/HEAD/DMMCP.m -------------------------------------------------------------------------------- /DWT.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dingqinliu/Encryption_Matlab/HEAD/DWT.m -------------------------------------------------------------------------------- /main.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dingqinliu/Encryption_Matlab/HEAD/main.m -------------------------------------------------------------------------------- /nmse.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dingqinliu/Encryption_Matlab/HEAD/nmse.m -------------------------------------------------------------------------------- /omp.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dingqinliu/Encryption_Matlab/HEAD/omp.m -------------------------------------------------------------------------------- /ImCoef.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dingqinliu/Encryption_Matlab/HEAD/ImCoef.m -------------------------------------------------------------------------------- /feature.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dingqinliu/Encryption_Matlab/HEAD/feature.m -------------------------------------------------------------------------------- /signal.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dingqinliu/Encryption_Matlab/HEAD/signal.m -------------------------------------------------------------------------------- /HyperChao.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dingqinliu/Encryption_Matlab/HEAD/HyperChao.m -------------------------------------------------------------------------------- /Scramble1.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dingqinliu/Encryption_Matlab/HEAD/Scramble1.m -------------------------------------------------------------------------------- /TpEncrypt.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dingqinliu/Encryption_Matlab/HEAD/TpEncrypt.m -------------------------------------------------------------------------------- /WavRecov.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dingqinliu/Encryption_Matlab/HEAD/WavRecov.m -------------------------------------------------------------------------------- /WavletDim.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dingqinliu/Encryption_Matlab/HEAD/WavletDim.m -------------------------------------------------------------------------------- /RanScramble1.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dingqinliu/Encryption_Matlab/HEAD/RanScramble1.m -------------------------------------------------------------------------------- /RanScramble2.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dingqinliu/Encryption_Matlab/HEAD/RanScramble2.m -------------------------------------------------------------------------------- /TLDECRYPTEx.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dingqinliu/Encryption_Matlab/HEAD/TLDECRYPTEx.m -------------------------------------------------------------------------------- /TLENCRYPTEx.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dingqinliu/Encryption_Matlab/HEAD/TLENCRYPTEx.m -------------------------------------------------------------------------------- /image_block.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dingqinliu/Encryption_Matlab/HEAD/image_block.m -------------------------------------------------------------------------------- /Objectdetection.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dingqinliu/Encryption_Matlab/HEAD/Objectdetection.m -------------------------------------------------------------------------------- /PartHadamardMtx.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dingqinliu/Encryption_Matlab/HEAD/PartHadamardMtx.m -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/图像处理基础算法源代码MATLAB集合/2/2/P0201.m: -------------------------------------------------------------------------------- 1 | A=[1,4,7,3] 2 | [Max, n]=max(A) -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/图像处理基础算法源代码MATLAB集合/2/2/P0208.m: -------------------------------------------------------------------------------- 1 | I=imread('wrod213.bmp'); 2 | imshow(I); 3 | figure,imshow(~I); -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/CS_Examples/spgl1_1_7/NormL1_dual.m: -------------------------------------------------------------------------------- 1 | function d = NormL1_dual(x,weights) 2 | 3 | d = norm(x./weights,inf); 4 | -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/CS_Examples/spgl1_1_7/NormL1_primal.m: -------------------------------------------------------------------------------- 1 | function p = NormL1_primal(x,weights) 2 | 3 | p = norm(x.*weights,1); 4 | -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/图像处理基础算法源代码MATLAB集合/2/2/P0202.m: -------------------------------------------------------------------------------- 1 | result=1; 2 | for i=2:1:10 3 | result=result*i; 4 | end 5 | Answer=result -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/omp/DWT.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dingqinliu/Encryption_Matlab/HEAD/encryption_based_on_CS_chaotic/omp/DWT.m -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/white.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dingqinliu/Encryption_Matlab/HEAD/encryption_based_on_CS_chaotic/white.tif -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/图像处理基础算法源代码MATLAB集合/2/2/P0207.m: -------------------------------------------------------------------------------- 1 | I=imread('Plane211.jpg'); 2 | I2=rgb2gray(I); 3 | imshow(I); 4 | figure,imshow(I2); 5 | -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/omp/lena256.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dingqinliu/Encryption_Matlab/HEAD/encryption_based_on_CS_chaotic/omp/lena256.bmp -------------------------------------------------------------------------------- /PWLCM.m: -------------------------------------------------------------------------------- 1 | function y=PWLCM(x,p) 2 | if x

2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/二维图像/OMP/Wavelet_OMP/CirculantMtx.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dingqinliu/Encryption_Matlab/HEAD/encryption_based_on_CS_chaotic/二维图像/OMP/Wavelet_OMP/CirculantMtx.m -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/二维图像/OMP/Wavelet_OMP/Wavelet_OMP.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dingqinliu/Encryption_Matlab/HEAD/encryption_based_on_CS_chaotic/二维图像/OMP/Wavelet_OMP/Wavelet_OMP.m -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/二维图像/OMP/Wavelet_OMP/循环矩阵OMP重构图像.fig: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dingqinliu/Encryption_Matlab/HEAD/encryption_based_on_CS_chaotic/二维图像/OMP/Wavelet_OMP/循环矩阵OMP重构图像.fig -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/二维图像/OMP/Wavelet_OMP/高斯矩阵OMP重构图像.fig: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dingqinliu/Encryption_Matlab/HEAD/encryption_based_on_CS_chaotic/二维图像/OMP/Wavelet_OMP/高斯矩阵OMP重构图像.fig -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/图像处理基础算法源代码MATLAB集合/2/2/Plane211.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dingqinliu/Encryption_Matlab/HEAD/encryption_based_on_CS_chaotic/图像处理基础算法源代码MATLAB集合/2/2/Plane211.jpg -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/图像处理基础算法源代码MATLAB集合/2/2/readme.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dingqinliu/Encryption_Matlab/HEAD/encryption_based_on_CS_chaotic/图像处理基础算法源代码MATLAB集合/2/2/readme.txt -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/图像处理基础算法源代码MATLAB集合/2/2/wrod213.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dingqinliu/Encryption_Matlab/HEAD/encryption_based_on_CS_chaotic/图像处理基础算法源代码MATLAB集合/2/2/wrod213.bmp -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/图像处理基础算法源代码MATLAB集合/3/3/readme.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dingqinliu/Encryption_Matlab/HEAD/encryption_based_on_CS_chaotic/图像处理基础算法源代码MATLAB集合/3/3/readme.txt -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/图像处理基础算法源代码MATLAB集合/4/4/bacteria.BMP: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dingqinliu/Encryption_Matlab/HEAD/encryption_based_on_CS_chaotic/图像处理基础算法源代码MATLAB集合/4/4/bacteria.BMP -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/图像处理基础算法源代码MATLAB集合/4/4/readme.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dingqinliu/Encryption_Matlab/HEAD/encryption_based_on_CS_chaotic/图像处理基础算法源代码MATLAB集合/4/4/readme.txt -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/图像处理基础算法源代码MATLAB集合/4/4/wrod213.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dingqinliu/Encryption_Matlab/HEAD/encryption_based_on_CS_chaotic/图像处理基础算法源代码MATLAB集合/4/4/wrod213.bmp -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/BCS implemented/demo_BCSvb_2d_small.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dingqinliu/Encryption_Matlab/HEAD/encryption_based_on_CS_chaotic/BCS implemented/demo_BCSvb_2d_small.m -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/二维图像/OMP/Wavelet_OMP/伯努利矩阵OMP重构图像.fig: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dingqinliu/Encryption_Matlab/HEAD/encryption_based_on_CS_chaotic/二维图像/OMP/Wavelet_OMP/伯努利矩阵OMP重构图像.fig -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/二维图像/OMP/Wavelet_OMP/托普利兹矩阵OMP重构图像.fig: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dingqinliu/Encryption_Matlab/HEAD/encryption_based_on_CS_chaotic/二维图像/OMP/Wavelet_OMP/托普利兹矩阵OMP重构图像.fig -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/二维图像/OMP/Wavelet_OMP/稀疏随机矩阵OMP重构图像.fig: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dingqinliu/Encryption_Matlab/HEAD/encryption_based_on_CS_chaotic/二维图像/OMP/Wavelet_OMP/稀疏随机矩阵OMP重构图像.fig -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/图像处理基础算法源代码MATLAB集合/Matlab图形图像处理函数.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dingqinliu/Encryption_Matlab/HEAD/encryption_based_on_CS_chaotic/图像处理基础算法源代码MATLAB集合/Matlab图形图像处理函数.pdf -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/图像处理基础算法源代码MATLAB集合/Matlab图形图像处理函数.rar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dingqinliu/Encryption_Matlab/HEAD/encryption_based_on_CS_chaotic/图像处理基础算法源代码MATLAB集合/Matlab图形图像处理函数.rar -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/二维图像/OMP/Wavelet_OMP/部分哈达吗矩阵OMP重构图像.fig: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dingqinliu/Encryption_Matlab/HEAD/encryption_based_on_CS_chaotic/二维图像/OMP/Wavelet_OMP/部分哈达吗矩阵OMP重构图像.fig -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/图像处理基础算法源代码MATLAB集合/3/3/P0303.m: -------------------------------------------------------------------------------- 1 | I=imread('rice.tif'); 2 | imshow(I); 3 | figure,imhist(I); 4 | J=imadjust(I,[0.15 0.9], [0 1]); 5 | figure,imshow(J); 6 | figure,imhist(J); 7 | -------------------------------------------------------------------------------- /icmic.m: -------------------------------------------------------------------------------- 1 | clear; 2 | clf; 3 | u=3.0:0.001:6.0; 4 | x=1; 5 | for i=1:300 6 | x=sin(u./x); 7 | end 8 | for j=1:80 9 | x=sin(u./x); 10 | plot(u,x,'k.','markersize',2) 11 | hold on; 12 | end 13 | 怎么办我代码传不上了 -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/Tensor_CS/Fig_8/normalize.m: -------------------------------------------------------------------------------- 1 | % Normalize Dictionary 2 | function [D] = normalize(D) 3 | M = size(D,2); 4 | for m = 1:M 5 | D(:,m) = D(:,m)./norm(D(:,m),'fro'); 6 | end 7 | 8 | end -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/二维图像/OMP/Wavelet_OMP/GaussMtx_Wavelet_OMP.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dingqinliu/Encryption_Matlab/HEAD/encryption_based_on_CS_chaotic/二维图像/OMP/Wavelet_OMP/GaussMtx_Wavelet_OMP.m -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/图像处理基础算法源代码MATLAB集合/Matlab图形图像处理函数详细列表.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dingqinliu/Encryption_Matlab/HEAD/encryption_based_on_CS_chaotic/图像处理基础算法源代码MATLAB集合/Matlab图形图像处理函数详细列表.pdf -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/图像处理基础算法源代码MATLAB集合/Matlab图形图像处理函数详细列表.rar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dingqinliu/Encryption_Matlab/HEAD/encryption_based_on_CS_chaotic/图像处理基础算法源代码MATLAB集合/Matlab图形图像处理函数详细列表.rar -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/二维图像/OMP/Wavelet_OMP/Bernoulli_Wavelet_OMP.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dingqinliu/Encryption_Matlab/HEAD/encryption_based_on_CS_chaotic/二维图像/OMP/Wavelet_OMP/Bernoulli_Wavelet_OMP.m -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/二维图像/OMP/Wavelet_OMP/ToeplitzMtx_Wavelet_OMP.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dingqinliu/Encryption_Matlab/HEAD/encryption_based_on_CS_chaotic/二维图像/OMP/Wavelet_OMP/ToeplitzMtx_Wavelet_OMP.m -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/图像处理基础算法源代码MATLAB集合/2/2/P0203.m: -------------------------------------------------------------------------------- 1 | r=1; 2 | i=2; 3 | for i=2:1000 4 | if (r<1000) 5 | r=r*i; 6 | else 7 | break; 8 | end 9 | end 10 | Answer_r=r -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/图像处理基础算法源代码MATLAB集合/2/2/P0210.m: -------------------------------------------------------------------------------- 1 | I=imread('Plane211.jpg'); 2 | I2=rgb2gray(I); 3 | imshow(I); 4 | figure,imshow(I2); 5 | figure,subplot(1,2,1),imshow(I); 6 | subplot(1,2,2),imshow(I2); 7 | -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/二维图像/OMP/Wavelet_OMP/CirculantMtx_Wavelet_OMP.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dingqinliu/Encryption_Matlab/HEAD/encryption_based_on_CS_chaotic/二维图像/OMP/Wavelet_OMP/CirculantMtx_Wavelet_OMP.m -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/二维图像/OMP/Wavelet_OMP/PartHadamardMtx_Wavelet_OMP.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dingqinliu/Encryption_Matlab/HEAD/encryption_based_on_CS_chaotic/二维图像/OMP/Wavelet_OMP/PartHadamardMtx_Wavelet_OMP.m -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/二维图像/OMP/Wavelet_OMP/SparseRandomMtx_Wavelet_OMP.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dingqinliu/Encryption_Matlab/HEAD/encryption_based_on_CS_chaotic/二维图像/OMP/Wavelet_OMP/SparseRandomMtx_Wavelet_OMP.m -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/CS_Examples/spgl1_1_7/private/oneProjectorMex.mexglx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dingqinliu/Encryption_Matlab/HEAD/encryption_based_on_CS_chaotic/CS_Examples/spgl1_1_7/private/oneProjectorMex.mexglx -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/CS_Examples/spgl1_1_7/private/oneProjectorMex.mexmaci: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dingqinliu/Encryption_Matlab/HEAD/encryption_based_on_CS_chaotic/CS_Examples/spgl1_1_7/private/oneProjectorMex.mexmaci -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/CS_Examples/spgl1_1_7/private/oneProjectorMex.mexw32: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dingqinliu/Encryption_Matlab/HEAD/encryption_based_on_CS_chaotic/CS_Examples/spgl1_1_7/private/oneProjectorMex.mexw32 -------------------------------------------------------------------------------- /Entropy.m: -------------------------------------------------------------------------------- 1 | function y=Entropy(P) 2 | P=double(P);[M,N]=size(P);P=transpose(P(:));T=zeros(1,256); 3 | for i=1:256 4 | T(i)=sum(P==(i-1)); 5 | T(i)=T(i)/(M*N); 6 | end 7 | y=-T(T>0)*transpose(log2(T(T>0))); 8 | end 9 | 为什么总是push失败 -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/图像处理基础算法源代码MATLAB集合/2/2/P0205.m: -------------------------------------------------------------------------------- 1 | clear; 2 | close all; 3 | I=imread('cameraman.tif'); 4 | imshow(I); 5 | whos 6 | I2=imresize(I,0.5); 7 | figure,imshow(I2); 8 | imwrite(I2,'cameraman.bmp'); 9 | imfinfo('cameraman.bmp') -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/TMSBL_code/TMSBL_code/Master the Usage of TSBL in 1 Minute.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dingqinliu/Encryption_Matlab/HEAD/encryption_based_on_CS_chaotic/TMSBL_code/TMSBL_code/Master the Usage of TSBL in 1 Minute.pdf -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/TMSBL_code/TMSBL_code/Master the Usage of TMSBL in 3 Minutes.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dingqinliu/Encryption_Matlab/HEAD/encryption_based_on_CS_chaotic/TMSBL_code/TMSBL_code/Master the Usage of TMSBL in 3 Minutes.docx -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/TMSBL_code/TMSBL_code/Master the Usage of TMSBL in 3 Minutes.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dingqinliu/Encryption_Matlab/HEAD/encryption_based_on_CS_chaotic/TMSBL_code/TMSBL_code/Master the Usage of TMSBL in 3 Minutes.pdf -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/CS_Examples/spgl1_1_7/NormGroupL2_primal.m: -------------------------------------------------------------------------------- 1 | function p = NormGroupL2_primal(groups,x,weights) 2 | 3 | if isreal(x) 4 | p = sum(weights.*sqrt(sum(groups * x.^2,2))); 5 | else 6 | p = sum(weights.*sqrt(sum(groups * abs(x).^2,2))); 7 | end 8 | -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/CS_Examples/spgl1_1_7/NormGroupL2_dual.m: -------------------------------------------------------------------------------- 1 | function d = NormGroupL2_dual(groups,x,weights) 2 | 3 | if isreal(x) 4 | d = norm(sqrt(sum(groups * x.^2,2))./weights,inf); 5 | else 6 | d = norm(sqrt(sum(groups * abs(x).^2,2))./weights,inf); 7 | end 8 | -------------------------------------------------------------------------------- /BitCircShift.m: -------------------------------------------------------------------------------- 1 | function y=BitCircShift(x,k); 2 | if abs(k)>7||k==0 3 | y=x;return; 4 | 5 | end 6 | if k>0 7 | t1=mod(x*pow2(k),256);t2=floor(x/pow2(8-k));t2=floor(x/pow2(8-k)); 8 | else 9 | t1=floor(x*pow2(k));t2=mod(x,pow2(-k))*pow2(8+k); 10 | end 11 | y=t1+t2; 12 | end 13 | 14 | -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/CS_Examples/spgl1_1_7/NormL12_primal.m: -------------------------------------------------------------------------------- 1 | function p = NormL12_primal(g,x,weights) 2 | 3 | m = round(length(x) / g); n = g; 4 | 5 | if isreal(x) 6 | p = sum(weights.*sqrt(sum(reshape(x,m,n).^2,2))); 7 | else 8 | p = sum(weights.*sqrt(sum(abs(reshape(x,m,n)).^2,2))); 9 | end 10 | -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/CS_Examples/spgl1_1_7/NormL12_dual.m: -------------------------------------------------------------------------------- 1 | function d = NormL12_dual(g,x,weights) 2 | 3 | m = round(length(x) / g); n = g; 4 | 5 | if isreal(x) 6 | d = norm(sqrt(sum(reshape(x,m,n).^2,2))./weights,inf); 7 | else 8 | d = norm(sqrt(sum(abs(reshape(x,m,n)).^2,2))./weights,inf); 9 | end 10 | 11 | 12 | -------------------------------------------------------------------------------- /LE_PWLCM.m: -------------------------------------------------------------------------------- 1 | clc;clear; 2 | p1=0:0.0001:0.5; 3 | p2=0.5:0.0001:1; 4 | p=0:0.0001:1; 5 | 6 | for i=1:length(p1) 7 | y1(i)=log(abs(1/p1(i))); 8 | end 9 | 10 | for i=1:length(p2) 11 | y2(i)=log(abs(1/(1-p2(i)))); 12 | end 13 | y=[y1 y2(2:end)]; 14 | plot(p,y,'r.','markersize',2); 15 | xlabel('u');ylabel('Lyapunov Exponent'); 16 | 17 | -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/CS_Examples/spgl1_1_7/NormL1_project.m: -------------------------------------------------------------------------------- 1 | function x = NormL1_project(x,weights,tau) 2 | 3 | if isreal(x) 4 | x = oneProjector(x,weights,tau); 5 | else 6 | xa = abs(x); 7 | idx = xa < eps; 8 | xc = oneProjector(xa,weights,tau); 9 | xc = xc ./ xa; xc(idx) = 0; 10 | x = x .* xc; 11 | end 12 | -------------------------------------------------------------------------------- /BD_Gauss.m: -------------------------------------------------------------------------------- 1 | clc;clear all;close all 2 | axis([0,1,-0.4,1]); 3 | x0=0.1;t=800;M=850; 4 | r=0:0.002:1; 5 | [m,n]=size(r); 6 | hold on 7 | for i=1:n 8 | x(1)=exp(-5*x0^2)-r(i); 9 | for j =2:M 10 | x(j)=exp(-5*x(j-1)^2)-r(i); 11 | end 12 | xn{i}=x(t:M); 13 | pause(0.1); 14 | plot(r(i),xn{i},'r.','Markersize',2); 15 | 16 | xlabel('r');ylabel('x'); 17 | end -------------------------------------------------------------------------------- /BD_PWLCM.m: -------------------------------------------------------------------------------- 1 | clc;clear all;close all 2 | axis([0.1,0.5,0,1]); 3 | x0=0.1;t=800;M=850; 4 | r=0.1:0.001:0.49; 5 | [m,n]=size(r); 6 | hold on 7 | for i=1:n 8 | x(1)=pwlcm(r(i),x0); 9 | for j =2:M 10 | x(j)=pwlcm(r(i),x(j-1)); 11 | end 12 | xn=x(t:M); 13 | pause(0.1); 14 | plot(r(i),xn,'r.','Markersize',2); 15 | 16 | xlabel('r');ylabel('x(i)'); 17 | end -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/二维图像/OMP/Wavelet_OMP/GaussMtx.m: -------------------------------------------------------------------------------- 1 | function [ Phi ] = GaussMtx( M,N ) 2 | %GaussMtx Summary of this function goes here 3 | % Generate Bernoulli matrix 4 | % M -- RowNumber 5 | % N -- ColumnNumber 6 | % Phi -- The Gauss matrix 7 | 8 | %% Generate Gauss matrix 9 | Phi = randn(M,N); 10 | %Phi = Phi/sqrt(M); 11 | end -------------------------------------------------------------------------------- /test.m: -------------------------------------------------------------------------------- 1 | x=zeros(1);y=zeros(1); 2 | x(1)=0.5; 3 | y(1)=0.5; 4 | 5 | a=0.6; 6 | k=0.8; 7 | 8 | for n=1:40000 9 | x(n+1)=sin(21./a*(y(n)+3)*k*x(n)*(1-k*x(n))); 10 | y(n+1)=sin(21./(a*(k*x(n+1)+3)*y(n)*(1-y(n)))); 11 | 12 | end 13 | figure; 14 | H=plot(x(1000:end),y(1000:end),'b');%1000 15 | set(H,'linestyle','none','marker','.','markersize',1) 16 | xlabel('x');ylabel('y'); -------------------------------------------------------------------------------- /BD_Chebyshev.m: -------------------------------------------------------------------------------- 1 | clc;clear all;close all 2 | axis([0,1,-1,1]); 3 | x0=0.1;t=800;M=850; 4 | r=0:0.002:1; 5 | [m,n]=size(r); 6 | tic; 7 | hold on 8 | for i=1:n 9 | x(1)=cos((r(i)+1)*acos(x0)); 10 | for j =2:M 11 | x(j)=cos((r(i)+1)*acos(x(j-1))); 12 | end 13 | xn{i}=x(t:M); 14 | pause(0.1); 15 | plot(r(i),xn{i},'r.','Markersize',2); 16 | 17 | xlabel('r');ylabel('x(i)'); 18 | end 19 | toc; -------------------------------------------------------------------------------- /LE_Tent.m: -------------------------------------------------------------------------------- 1 | clc;clear; 2 | u=0:0.001:1; 3 | n=length(u); 4 | 5 | 6 | for i=1:n 7 | y(i)=log(abs(2*u(i))); 8 | end 9 | figure; 10 | plot(u,y,'r.','markersize',2); 11 | hold on 12 | x=get(gca,'xlim'); 13 | y=0; 14 | plot(x,[y y],'k'); 15 | axis([0,1,-5,1]); 16 | hold off 17 | 18 | set(gca,'Xtick',0:0.2:1); 19 | set(gca,'Ytick',-5:1:1); 20 | xlabel('u');ylabel('Lyapunov Exponent'); 21 | 22 | -------------------------------------------------------------------------------- /LT.m: -------------------------------------------------------------------------------- 1 | %clc;clear all; 2 | function s=LT(r,x0,n) 3 | s=zeros(1,n); 4 | for i=1:n+800; 5 | if x0<0.5 6 | x1=mod(r*x0*(1-x0)+(4-r)*x0/2,1); 7 | else 8 | x1=mod(r*x0*(1-x0)+(4-r)*(1-x0)/2,1); 9 | end 10 | if i>800 11 | s(i-800)=x1; 12 | end 13 | x0=x1; 14 | if mod(i,2000)==0 15 | x0=x0+(10^(-10))*sin(x0); 16 | end 17 | end 18 | end -------------------------------------------------------------------------------- /testENDE.m: -------------------------------------------------------------------------------- 1 | clc;clear;close all; 2 | P=imread('lena.jpg'); 3 | P=rgb2gray(P); 4 | figure(1);imshow(P); 5 | K=[0.13 0.55 0.25 0.52 0.32]; 6 | C=TLENCRYPTEx(P,K,1,1); 7 | figure(2);imshow(uint8(C)); 8 | % for i=1:256 9 | % for j=1:512 10 | % 11 | % C(j,i)=0; 12 | % end 13 | % end 14 | % 15 | % figure(2);imshow(uint8(C)); 16 | % P1=TLDECRYPTEx(C,K,1,1); 17 | % figure(4);imshow(uint8(P1)); 18 | 19 | 20 | -------------------------------------------------------------------------------- /LE_Sine.m: -------------------------------------------------------------------------------- 1 | clear all;clc; 2 | u=0:0.001:1;p=100;k=length(u); 3 | for n=1:k 4 | for m=2:p 5 | x(1,n)=0.1; 6 | x(m,n)=u(n)*sin(pi*x(m-1,n)); 7 | end 8 | end 9 | 10 | for r=1:k 11 | for h=2:p 12 | A{1,r}=[pi*u(r)*cos(pi*x(1,r))]; 13 | A{h,r}=[pi*u(r)*cos(pi*x(h,r))]*A{h-1,r}; 14 | end 15 | end 16 | 17 | for t=1:k 18 | vv(:,t)=eig(A{p,t}); 19 | v=abs(vv); 20 | LE1=1/p*log(v); 21 | end 22 | plot(u,LE1,'b'); -------------------------------------------------------------------------------- /BD_Henon.m: -------------------------------------------------------------------------------- 1 | clc;clear all;close all 2 | x0=0.1;y0=0.2;b=1;n=850;t=800; 3 | 4 | hold on 5 | for a = 0:0.002:1 6 | x(1)=1+y0-a*x0^2; 7 | y(1)=b*x0; 8 | for i =2:n 9 | x(i)=1+y(i-1)-7/5*a*x(i-1)^2; 10 | y(i)=3/10*b*x(i-1); 11 | end 12 | xn=x(t+1:n); 13 | pause(0.1); 14 | plot(a,xn,'r.','Markersize',2); 15 | xlabel('a');ylabel('x'); 16 | set(gca,'XLim',[0 1]); 17 | set(gca,'XTick',[0:0.2:1]); 18 | set(gca,'YLim',[-1.5 1.5]); 19 | set(gca,'YTick',[-1.5:0.5:1.5]); 20 | end -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/图像处理基础算法源代码MATLAB集合/2/2/P0206.m: -------------------------------------------------------------------------------- 1 | clear; 2 | close all; 3 | I=imread('rice.tif'); 4 | Imshow(I); 5 | Stru=strel('disk',16); 6 | Back=imopen(I,Stru ); 7 | I2=imsubtract(I,Back); 8 | figure, imshow(I2); 9 | Threshold=graythresh(I2); 10 | BW=im2bw(I2,Threshold); 11 | figure, imshow(BW); 12 | [Labeled Number_Object]=bwlabel(BW,8); 13 | GrainData=regionprops(Labeled, 'basic'); 14 | AllGrain=[GrainData.Area]; 15 | Max=max(AllGrain) 16 | Mean=mean(AllGrain) -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/CS_Examples/spgl1_1_7/NormGroupL2_project.m: -------------------------------------------------------------------------------- 1 | function x = NormGroupL2_project(groups,x,weights,tau) 2 | % Projection binary group matrix 3 | 4 | % Compute two-norms of rows 5 | if isreal(x) 6 | xa = sqrt(sum(groups * x.^2,2)); 7 | else 8 | xa = sqrt(sum(groups * abs(x).^2,2)); 9 | end 10 | 11 | % Project one one-norm ball 12 | idx = xa < eps; 13 | xc = oneProjector(xa,weights,tau); 14 | 15 | % Scale original 16 | xc = xc ./ xa; xc(idx) = 0; 17 | x = full(groups' * xc).*x; 18 | -------------------------------------------------------------------------------- /BD_GCCM_II.m: -------------------------------------------------------------------------------- 1 | clc;clear all;close all; 2 | % addpath(genpath('E:\matlab123\bin\Signal_processing\gx_package\g1')) 3 | axis([0,1,0,1]); 4 | x0=0.1;t=800;M=850; 5 | r=0:0.002:1; 6 | [m,n]=size(r); 7 | tic; 8 | hold on 9 | for i=1:n 10 | x(1)=g(mod(exp(-5*x0^2)-r(i)+cos((2-r(i))*acos(x0)),1)); 11 | for j =2:M 12 | x(j)=g(mod(exp(-5*x(j-1)^2)-r(i)+cos((2-r(i))*acos(x(j-1))),1)); 13 | end 14 | 15 | xn{i}=x(t:M); 16 | pause(0.1); 17 | plot(r(i),xn{i},'r.','Markersize',2); 18 | 19 | xlabel('r');ylabel('x'); 20 | end 21 | toc; 22 | -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/二维图像/OMP/Wavelet_OMP/SparseRandomMtx.m: -------------------------------------------------------------------------------- 1 | function [ Phi ] = SparseRandomMtx( M,N,d ) 2 | %SparseRandomMtx Summary of this function goes here 3 | % Generate SparseRandom matrix 4 | % M -- RowNumber 5 | % N -- ColumnNumber 6 | % d -- The number of '1' in every column,d=0.5 13 | x(1)=2*r(i)*(1-x0); 14 | end 15 | for j =2:M 16 | if x(j-1)<0.5 17 | x(j)=2*r(i)*x(j-1); 18 | end 19 | 20 | if x(j-1)>=0.5 21 | x(j)=2*r(i)*(1-x(j-1)); 22 | end 23 | end 24 | xn{i}=x(t+1:M); 25 | pause(0.1); 26 | plot(r(i),xn{i},'r.','Markersize',2); 27 | 28 | xlabel('r');ylabel('x(i)'); 29 | end -------------------------------------------------------------------------------- /LE_Gauss.m: -------------------------------------------------------------------------------- 1 | clc;clear; 2 | u=0:0.0001:1.3;x0=0.1;n=3000;t=1000; 3 | len=length(u); 4 | for i=1:len 5 | temp=0; 6 | for j=1:n 7 | x=exp(-5*x0^2)-u(i); 8 | x0=x; 9 | if j>t 10 | temp=temp+log(abs(-10*x*exp(-5*x^2))); 11 | end 12 | end 13 | LE(i)=temp/(n-t+1); 14 | end 15 | 16 | figure(1); 17 | plot(u,LE,'r.','markersize',2); 18 | 19 | hold on 20 | x=get(gca,'xlim'); 21 | y=0; 22 | plot(x,[y y],'k'); 23 | axis([0,1,-5,1]); 24 | hold off 25 | 26 | set(gca,'Xtick',0:0.2:1); 27 | set(gca,'Ytick',-5:1:1); 28 | xlabel('u');ylabel('Lyapunov Exponent'); 29 | 30 | -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/CS_Examples/spgl1_1_7/NormL12_project.m: -------------------------------------------------------------------------------- 1 | function x = NormL12_project(g,x,weights,tau) 2 | % Projection with number of groups equal to g 3 | 4 | % Convert to matrix 5 | m = round(length(x) / g); n = g; 6 | x = reshape(x,m,n); 7 | 8 | % Compute two-norms of rows 9 | if isreal(x) 10 | xa = sqrt(sum(x.^2,2)); 11 | else 12 | xa = sqrt(sum(abs(x).^2,2)); 13 | end 14 | 15 | % Project one one-norm ball 16 | idx = xa < eps; 17 | xc = oneProjector(xa,weights,tau); 18 | 19 | % Scale original 20 | xc = xc ./ xa; xc(idx) = 0; 21 | x = spdiags(xc,0,m,m)*x; 22 | 23 | % Vectorize result 24 | x = x(:); 25 | -------------------------------------------------------------------------------- /LE_Chebyshev.m: -------------------------------------------------------------------------------- 1 | clc;clear; 2 | u=0:0.0001:1;x0=0.1;n=3000;t=1000; 3 | len=length(u); 4 | for i=1:len 5 | temp=0; 6 | for j=1:n 7 | x=cos((u(i)+1)*acos(x0)); 8 | x0=x; 9 | if j>t 10 | temp=temp+log(abs((u(i)+1)*sin((u(i)+1)*acos(x))/(1-x^2)^0.5)); 11 | end 12 | end 13 | LE(i)=temp/(n-t+1); 14 | end 15 | 16 | figure(1); 17 | plot(u,LE,'r.','markersize',2); 18 | 19 | hold on 20 | x=get(gca,'xlim'); 21 | y=0; 22 | plot(x,[y y],'k'); 23 | axis([0,1,-5,1]); 24 | hold off 25 | 26 | set(gca,'Xtick',0:0.2:1); 27 | set(gca,'Ytick',-5:1:1); 28 | xlabel('u');ylabel('Lyapunov Exponent'); 29 | 30 | -------------------------------------------------------------------------------- /LE_LGCM_II.m: -------------------------------------------------------------------------------- 1 | clc;clear; 2 | u=0:0.001:1;x0=0.1;n=3000;t=1000; 3 | len=length(u); 4 | for i=1:len 5 | temp=0; 6 | for j=1:n 7 | x=g(mod(exp(-5*x0^2)-(1-u(i))+4*u(i)*x0*(1-x0),1)); 8 | x0=x; 9 | if j>t 10 | temp=temp+log(abs(8*(4*u(i)-8*u(i)*x-10*x*exp(-5*x^2)))); 11 | 12 | end 13 | end 14 | LE(i)=temp/(n-t+1); 15 | end 16 | 17 | figure(1); 18 | plot(u,LE,'r'); 19 | 20 | hold on 21 | x=get(gca,'xlim'); 22 | y=0; 23 | plot(x,[y y],'k'); 24 | axis([0,1,-5,3]); 25 | hold off 26 | 27 | set(gca,'Xtick',0:0.2:1); 28 | set(gca,'Ytick',-5:1:3); 29 | xlabel('u');ylabel('Lyapunov Exponent'); 30 | 31 | -------------------------------------------------------------------------------- /LE_LCCM_II.m: -------------------------------------------------------------------------------- 1 | clc;clear; 2 | u=0:0.001:1;x0=0.1;n=3000;t=1000; 3 | len=length(u); 4 | for i=1:len 5 | temp=0; 6 | for j=1:n 7 | x=g(mod(cos((2-u(i))*acos(x0))+4*u(i)*x0*(1-x0),1)); 8 | x0=x; 9 | if j>t 10 | temp=temp+log(abs(8*(sin((2-u(i))*acos(x0))*(2-u(i))*(1-x^2)^(-1/2)+4*u(i)-8*u(i)*x))); 11 | end 12 | end 13 | LE(i)=temp/(n-t+1); 14 | end 15 | 16 | figure(1); 17 | plot(u,LE,'r'); 18 | 19 | hold on 20 | x=get(gca,'xlim'); 21 | y=0; 22 | plot(x,[y y],'k'); 23 | axis([0,1,-5,3]); 24 | hold off 25 | 26 | set(gca,'Xtick',0:0.2:1); 27 | set(gca,'Ytick',-5:1:3); 28 | xlabel('u');ylabel('Lyapunov Exponent'); 29 | 30 | -------------------------------------------------------------------------------- /LE_GCCM_II.m: -------------------------------------------------------------------------------- 1 | clc;clear; 2 | u=0:0.001:1;x0=0.1;n=3000;t=1000; 3 | len=length(u); 4 | for i=1:len 5 | temp=0; 6 | for j=1:n 7 | x=g(mod(exp(-5*x0^2)-u(i)+cos((2-u(i))*acos(x0)),1)); 8 | x0=x; 9 | if j>t 10 | temp=temp+log(abs(8*(sin((2-u(i))*acos(x0))*(2-u(i))*(1-x^2)^(-1/2)-10*x*exp(-5*x^2)))); 11 | 12 | end 13 | end 14 | LE(i)=temp/(n-t+1); 15 | end 16 | 17 | figure(1); 18 | plot(u,LE,'r'); 19 | 20 | hold on 21 | x=get(gca,'xlim'); 22 | y=0; 23 | plot(x,[y y],'k'); 24 | axis([0,1,-5,3]); 25 | hold off 26 | 27 | set(gca,'Xtick',0:0.2:1); 28 | set(gca,'Ytick',-5:1:3); 29 | xlabel('u');ylabel('Lyapunov Exponent'); 30 | 31 | -------------------------------------------------------------------------------- /Diffentialattack.m: -------------------------------------------------------------------------------- 1 | clc;clear;close all; 2 | tic; 3 | nubLe=zeros(1,3);%nubBa=zeros(1,3);nubPe=zeros(1,3); 4 | for i=1:20 5 | M=192;N=256; 6 | X=imread('peppers.bmp'); 7 | X=double(X); 8 | [r,x0,x1,x2]=SHA256(X); 9 | [C]=Encrypt1(X,r,x0,x1,x2,M,N); 10 | 11 | ix=mod(floor(rand*10^8),M)+1;iy=mod(floor(rand*10^8),N)+1; 12 | P1N=X;P1N(ix,iy)=mod(P1N(ix,iy)+1,256); 13 | %P2N=P2;P2N(ix,iy)=mod(P2N(ix,iy)+1,256); 14 | %P3N=P3;P3N(ix,iy)=mod(P3N(ix,iy)+1,256); 15 | [r,x0,x1,x2]=SHA256(P1N); 16 | [C1N]=Encrypt1(P1N,r,x0,x1,x2,M,N);%C2N=TpEncrypt(P2N,K);C3N=TpEncrypt(P3N,K); 17 | nubLe=nubLe+NPCRUACIBACI(C,C1N); 18 | %nubBa=nubBa+NPCRUACIBACI(C2,C2N); 19 | %nubPe=nubPe+NPCRUACIBACI(C3,C3N); 20 | end 21 | nubLe=nubLe/20;%nubBa=nubBa/200;nubPe=nubPe/200; -------------------------------------------------------------------------------- /BD_Baker.m: -------------------------------------------------------------------------------- 1 | clc;clear all;close all 2 | axis([0,1,0,10]); 3 | x0=0.1;y0=0.2;t=800;M=850; 4 | r=0.002:0.005:1; 5 | [m,n]=size(r); 6 | hold on 7 | for i=1:n 8 | if x0<=r(i) 9 | x(1)=x0/r(i); 10 | y(1)=y0*r(i); 11 | end 12 | 13 | if x0>r(i) 14 | x(1)=(x0-r(i))*(1-r(i))^(-1); 15 | y(1)=(1-r(i))*(y0+1); 16 | end 17 | for j =2:M 18 | if x(j-1)<=r(i) 19 | x(j)=x(j-1)/r(i); 20 | y(j)=y(j-1)*r(i); 21 | end 22 | 23 | if x(j-1)>r(i) 24 | x(j)=(x(j-1)-r(i))*(1-r(i))^(-1); 25 | y(j)=(1-r(i))*(y(j-1)+1); 26 | end 27 | end 28 | xn{i}=x(t+1:M); 29 | yn{i}=y(t+1:M); 30 | pause(0.1); 31 | figure(1); 32 | plot(r(i),yn{i},'r.','Markersize',2); 33 | 34 | xlabel('r');ylabel('x(i)'); 35 | end -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/CS_Examples/spgl1_1_7/Contents.m: -------------------------------------------------------------------------------- 1 | % SPGL1: A solver for large-scale sparse reconstruction 2 | % Version 1.7 (May 20, 2009) 3 | % 4 | % Files 5 | % spg_bp - Solve the basis pursuit (BP) problem 6 | % spg_bpdn - Solve the basis pursuit denoise (BPDN) problem 7 | % spg_lasso - Solve the LASSO problem 8 | % spg_mmv - Solve the multiple measurement vector (MMV) problem 9 | % spg_group - Solve the group-sparse BPDN problem 10 | % spgdemo - Demonstrates the use of the SPGL1 solver 11 | % spgl1 - Expert driver for BP, BPDN, and LASSO problems 12 | % spgSetParms - Set options for SPGL1 13 | % spgsetup - Compile the SPGL1 MEX interfaces 14 | % 15 | % $Id: Contents.m 1384 2009-05-20 19:09:37Z ewout78 $ 16 | -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/二维图像/OMP/Wavelet_OMP/BernoulliMtx.m: -------------------------------------------------------------------------------- 1 | function [ Phi ] = BernoulliMtx( M,N ) 2 | %BernoulliMtx Summary of this function goes here 3 | % Generate Bernoulli matrix 4 | % M -- RowNumber 5 | % N -- ColumnNumber 6 | % Phi -- The Bernoulli matrix 7 | 8 | %% (1)Generate Bernoulli matrix(The first kind) 9 | % 1--P=0.5 -1--P=0.5 10 | Phi = randi([0,1],M,N);%If your MATLAB version is too low,please use randint instead 11 | Phi(Phi==0) = -1; 12 | %Phi = Phi/sqrt(M); 13 | % %% (2)Generate Bernoulli matrix(The second kind) 14 | % % 1--P=1/6 -1--P=1/6 0--2/3 15 | % Phi = randi([-1,4],M,N);%If your MATLAB version is too low,please use randint instead 16 | % Phi(Phi==2) = 0;%P=1/6 17 | % Phi(Phi==3) = 0;%P=1/6 18 | % Phi(Phi==4) = 0;%P=1/6 19 | % %Phi = Phi*sqrt(3/M); 20 | end -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/Tensor_CS/Fig_8/dispRGB.m: -------------------------------------------------------------------------------- 1 | function [] = dispRGB(Y0,mag) 2 | % Y: reflectances tensor 3 | I = size(Y0); 4 | if I(3)==31 5 | Y = zeros(I(1),I(2),33); 6 | Y(:,:,1) = Y0(:,:,1); 7 | Y(:,:,33) = Y0(:,:,31); 8 | Y(:,:,2:32) = Y0; 9 | else 10 | Y = Y0; 11 | end 12 | 13 | Y = Y/max(Y(:)); 14 | 15 | %load illum_6500.mat; 16 | %radiances = zeros(size(Y)); % initialize array 17 | %for i = 33 18 | % radiances(:,:,i) = Y(:,:,i)*illum_6500(i); 19 | %end 20 | 21 | radiances = Y; 22 | 23 | [r c w] = size(radiances); 24 | radiances = reshape(radiances, r*c, w); 25 | 26 | load xyzbar.mat; 27 | XYZ = (xyzbar'*radiances')'; 28 | 29 | XYZ = reshape(XYZ, r, c, 3); 30 | XYZ = max(XYZ, 0); 31 | XYZ = XYZ/max(XYZ(:)); 32 | 33 | RGB = XYZ2sRGB_exgamma(XYZ); 34 | RGB = max(RGB, 0); 35 | RGB = min(RGB, 1); 36 | 37 | figure; imshow(RGB.^0.4, 'Border','tight','InitialMagnification',mag); 38 | 39 | end -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/二维图像/OMP/Wavelet_OMP/PartHadamardMtx.m: -------------------------------------------------------------------------------- 1 | function [ Phi ] = PartHadamardMtx( M,N ) 2 | %PartHadamardMtx Summary of this function goes here 3 | % Generate part Hadamard matrix 4 | % M -- RowNumber 5 | % N -- ColumnNumber 6 | % Phi -- The part Hadamard matrix 7 | 8 | %% parameter initialization 9 | %Because the MATLAB function hadamard handles only the cases where n, n/12, 10 | %or n/20 is a power of 2 11 | L_t = max(M,N);%Maybe L_t does not meet requirement of function hadamard 12 | L_t1 = (12 - mod(L_t,12)) + L_t; 13 | L_t2 = (20 - mod(L_t,20)) + L_t; 14 | L_t3 = 2^ceil(log2(L_t)); 15 | L = min([L_t1,L_t2,L_t3]);%Get the minimum L 16 | %% Generate part Hadamard matrix 17 | Phi = []; 18 | Phi_t = hadamard(L); 19 | RowIndex = randperm(L); 20 | Phi_t_r = Phi_t(RowIndex(1:M),:); 21 | ColIndex = randperm(L); 22 | Phi = Phi_t_r(:,ColIndex(1:N)); 23 | end -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/Tensor_CS/Fig_8/XYZ2sRGB_exgamma.m: -------------------------------------------------------------------------------- 1 | function sRGB = XYZ2sRGB_exgamma(XYZ) 2 | 3 | % See IEC_61966-2-1.pdf 4 | % No gamma correction has been incorporated here, nor any clipping, so this 5 | % transformation remains strictly linear. Nor is there any data-checking. 6 | % DHF 9-Feb-11 7 | 8 | % Image dimensions 9 | d = size(XYZ); 10 | r = prod(d(1:end-1)); % product of sizes of all dimensions except last, wavelength 11 | w = d(end); % size of last dimension, wavelength 12 | 13 | % Reshape for calculation, converting to w columns with r rows. 14 | XYZ = reshape(XYZ, [r w]); 15 | 16 | % Forward transformation from 1931 CIE XYZ values to sRGB values (Eqn 6 in 17 | % IEC_61966-2-1.pdf). 18 | M = [3.2406 -1.5372 -0.4986 19 | -0.9689 1.8758 0.0414 20 | 0.0557 -0.2040 1.0570]; 21 | sRGB = (M*XYZ')'; 22 | 23 | % Reshape to recover shape of original input. 24 | sRGB = reshape(sRGB, d); 25 | 26 | return; 27 | 28 | -------------------------------------------------------------------------------- /LE_Henon.m: -------------------------------------------------------------------------------- 1 | clc;close all;clear all 2 | N = 1000; 3 | a = (0:0.001:1.4)'; 4 | b = 0.3; 5 | na = length(a); 6 | LE1 = zeros(na,1); 7 | LE2 = zeros(na,1); 8 | x = 0.2; y = 0.3; 9 | for i=1:na 10 | LCEvector = zeros(2,1); 11 | Q = eye(2); 12 | for j=1:N 13 | xprev = x; 14 | yprev = y; 15 | x = 1-a(i)*xprev*xprev+yprev; 16 | y = b*xprev; 17 | Ji = [-2*a(i)*x,1;b 0]; 18 | B = Ji*Q; 19 | [Q,R] = qr(B); 20 | LCEvector = LCEvector+log(diag(abs(R))); 21 | % LE = LCEvector/N; 22 | end 23 | LE = LCEvector/N; 24 | LE1(i) = LE(1); 25 | LE2(i) = LE(2); 26 | end 27 | 28 | figure(1) 29 | plot(a,LE1,'b','linewidth',1.5) ; 30 | hold on 31 | plot(a,LE2,'r','linewidth',1.5); 32 | set(gca,'XLim',[0 1.4]); 33 | set(gca,'YLim',[-2 1]); 34 | legend('\lambda1','\lambda2'); 35 | hold on 36 | plot([0 1.4],[0 0],'k--','linewidth',1) 37 | hold off 38 | xlabel('a');ylabel('LE'); 39 | set(gca,'fontsize',16) 40 | 41 | -------------------------------------------------------------------------------- /zConfusion.m: -------------------------------------------------------------------------------- 1 | function dctVector = zigzag(A, needNumCoefficient) 2 | 3 | if size(A, 1) ~= size(A, 2) 4 | display('Warning: your matrix should be square!'); 5 | if size(A, 1) > size(A, 2) 6 | A = A(1:size(A, 2), 1:size(A, 2)); 7 | else 8 | A = A(1:size(A, 1), 1:size(A, 1)); 9 | end 10 | end 11 | 12 | if needNumCoefficient > (size(A, 1) * size(A, 2)) 13 | needNumCoefficient = size(A, 1) * size(A, 2); 14 | end 15 | 16 | A = A'; 17 | count = 1; 18 | for dim_sum = 2 : (size(A, 1) + size(A, 2)) 19 | if mod(dim_sum, 2) == 0 20 | for i = 1 : size(A, 1) 21 | if dim_sum - i <= size(A, 1) & dim_sum - i > 0 22 | dctVector(count) = A(i, dim_sum - i); 23 | count = count + 1; 24 | end 25 | end 26 | else 27 | for i = 1 : size(A, 1) 28 | if dim_sum - i <= size(A, 1) & dim_sum - i >0 29 | dctVector(count) = A(dim_sum - i, i); 30 | count = count + 1; 31 | end 32 | end 33 | end 34 | end 35 | dctVector = dctVector(1:needNumCoefficient); 36 | dctVector = dctVector'; 37 | 38 | end -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/Tensor_CS/Fig_8/MakeFig8.m: -------------------------------------------------------------------------------- 1 | 2 | function [] = MakeFig8() 3 | 4 | clear all 5 | clc 6 | 7 | load BOMPresults33.mat 8 | 9 | load ../Datasets/Hyperspectral/ref_cyflower1bb_reg1.mat 10 | I0 = zeros(1024,1024,32); 11 | I0(1:1017,:,:) = reflectances(1:1017,1:1024,2:33); 12 | for i=1018:1024 13 | I0(i,:,:) = I0(i-1,:,:); 14 | end 15 | 16 | clear 'reflectances' 17 | 18 | div = 2; 19 | 20 | rangerow = 625:625+150-1; 21 | rangecol = 750:750+150-1; 22 | L1 = length(rangerow); 23 | L2 = length(rangecol); 24 | 25 | %% 26 | I0 = I0(:,:,1:31); 27 | dispRGB(I0,25); 28 | title({['Original Hyperspectral Image (1024x1024x32),RGB display']}); 29 | 30 | %% 31 | dispRGB(I0(rangerow,rangecol,:),170); 32 | title({['Zoom Original (150x150x32) (RGB display)']}); 33 | 34 | %% 35 | AproxtensorOMP = AproxtensorOMP(:,:,1:31); 36 | dispRGB(AproxtensorOMP,25); 37 | title({['N-BOMP: Reconstructed Image (1024x1024x32), RGB display, PSNR=',num2str(PSNRNBOMP),'dB']}); 38 | 39 | %% 40 | dispRGB(AproxtensorOMP(rangerow,rangecol,:),170); 41 | title({['Zoom Reconstruction (150x150x32) (RGB display)']}); 42 | 43 | end -------------------------------------------------------------------------------- /PRICKeyGen.m: -------------------------------------------------------------------------------- 1 | function [X,Y,R,W] = PRICKeyGen(P,K) 2 | P=double(P); 3 | [M,N] = size(P); 4 | x0=K(1);p=K(2);y0=K(3);q=K(4);r1=K(5);r2=K(6);r3=K(7);r4=K(8); 5 | for i= 1:r1+r2 6 | x1 = PWLCM(x0,p); 7 | x0=x1; 8 | end 9 | x= zeros(1,M*N); 10 | for i= 1:M*N 11 | x1 = PWLCM(x0,p); 12 | x(i)=x1; 13 | x0=x1; 14 | end 15 | for i= 1:r3+r4 16 | y1=PWLCM(y0,q); 17 | y0=yl; 18 | end 19 | y= zeros(1,M*N); 20 | for i= 1:M*N 21 | y1= PWLCM(y0,q); 22 | y(i)=y1; 23 | y0=y1; 24 | end 25 | X=zeros(M,N); 26 | Y=zeros(M,N); 27 | R=zeros(M,N); 28 | W=zeros(M,N); 29 | 30 | a1=(r1+1)/(r1+r3+2); 31 | b1=1-a1; 32 | a2=(r2+1)/(r2+r4+2); 33 | b2=1-a2; 34 | a3=(r1+1)/(r1+r4+2); 35 | b3=1-a3; 36 | a4=(r2+1)/(r2+r3+2); 37 | b4=1-a4; 38 | for i=1:M 39 | for j= 1:N 40 | X(i,j)= mod(floor((a1*x((i-1)*N+j)+b1*y((i-1)*N+j))*power(10,14)),256); 41 | Y(i,j)= mod(floor((a2*x((i-1)*N+j)+b2*y((i-1)*N+j))*power(10,13)),256); 42 | R(i,j)= mod(floor((a3*x((i-1)*N+j)+b3*y((i-1)*N+j))*power(10,12)),N); 43 | W(i,j)= mod(floor((a4*x((i-1)*N+j)+b4*y((i-1)*N+j))*power(10,11)),N); 44 | end 45 | end 46 | end 47 | -------------------------------------------------------------------------------- /TpDecrypt.m: -------------------------------------------------------------------------------- 1 | function P=TpDecrypt(C,K) 2 | [M,N]=size(C);C=double(C);n=3*M*N;s=zeros(1,n); 3 | h=0.002;t=800;a=10;b=8/3;c=28;r=-1;x0=K(1);y0=K(2);z0=K(3);w0=K(4); 4 | for i=1:n+t 5 | K11=a*(y0-x0)+w0;K12=a*(y0-(x0+K11*h/2))+w0; 6 | K13=a*(y0-(x0+K12*h/2))+w0;K14=a*(y0-(x0+K13*h))+w0; 7 | x1=x0+(K11+K12+K13+K14)*h/6; 8 | K21=c*x1-y0-x1*z0;K22=c*x1-(y0+K21*h/2)-x1*z0; 9 | K23=c*x1-(y0+K22*h/2)-x1*z0;K24=c*x1-(y0+K23*h)-x1*z0; 10 | y1=y0+(K21+K22+K23+K24)*h/6; 11 | K31=x1*y1-b*z0;K32=x1*y1-b*(z0+K31*h/2); 12 | K33=x1*y1-b*(z0+K32*h/2);K34=x1*y1-b*(z0+K33*h); 13 | z1=z0+(K31+K32+K33+K34)*h/6; 14 | K41=-y1*z1+r*w0;K42=-y1*z1+r*(w0+K41*h/2); 15 | K43=-y1*z1+r*(w0+K42*h/2);K44=-y1*z1+r*(w0+K43*h); 16 | w1=w0+(K41+K42+K43+K44)*h/6; 17 | 18 | x0=x1;y0=y1;z0=z1;w0=w1; 19 | if i>t 20 | s(i-t)=x1; 21 | if mod((i-t),3000)==0 22 | x0=x0+h*sin(y0); 23 | end 24 | end 25 | end 26 | 27 | X=mod(floor((s(1:M*N)+100)*10^10),M*N)+1;[~,idx]=unique(X);X1=zeros(1,M*N); 28 | X1(1:length(idx))=X(sort(idx));X1(length(idx)+1:M*N)=setdiff(1:M*N,X1);X=X1; 29 | 30 | TBL=GF257Table();S=mod(floor(s(M*N+1:3*M*N)*pow2(16)),256); 31 | S1=S(1:M*N);S2=S(M*N+1:2*M*N); 32 | A=C(:);D=zeros(1,M*N);E=zeros(1,M*N); 33 | A0=0;D(M*N)=LookUpGF257Ex(A(M*N),A0,S2(M*N),TBL); 34 | for i=M*N-1:-1:1 35 | D(i)=LookUpGF257Ex(A(i),A(i+1),S2(i),TBL); 36 | end 37 | E0=0;E(1)=LookUpGF257Ex(D(1),E0,S1(1),TBL); 38 | for i=2:M*N 39 | E(i)=LookUpGF257Ex(D(i),D(i-1),S1(i),TBL); 40 | end 41 | for i=1:floor(M*N/2) 42 | t=E(X(i));E(X(i))=E(X(M*N-i+1));E(X(M*N-i+1))=t; 43 | end 44 | P=reshape(E,M,N);P=uint8(P); 45 | end 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/CS_Examples/spgl1_1_7/private/oneProjectorCore.h: -------------------------------------------------------------------------------- 1 | /* oneProjectorCore.h 2 | $Id $ 3 | 4 | ---------------------------------------------------------------------- 5 | This file is part of SPGL1 (Spectral Projected Gradient for L1). 6 | 7 | Copyright (C) 2007 Ewout van den Berg and Michael P. Friedlander, 8 | Department of Computer Science, University of British Columbia, Canada. 9 | All rights reserved. E-mail: <{ewout78,mpf}@cs.ubc.ca>. 10 | 11 | SPGL1 is free software; you can redistribute it and/or modify it 12 | under the terms of the GNU Lesser General Public License as 13 | published by the Free Software Foundation; either version 2.1 of the 14 | License, or (at your option) any later version. 15 | 16 | SPGL1 is distributed in the hope that it will be useful, but WITHOUT 17 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 18 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General 19 | Public License for more details. 20 | 21 | You should have received a copy of the GNU Lesser General Public 22 | License along with SPGL1; if not, write to the Free Software 23 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 24 | USA 25 | ---------------------------------------------------------------------- 26 | */ 27 | #ifndef __ONEPROJECTORCORE_H__ 28 | #define __ONEPROJECTORCORE_H__ 29 | 30 | /* The entries in b are non-negative, those in d strictly positive */ 31 | int projectI( double xPtr[], double bPtr[], double tau, int n ); 32 | int projectD( double xPtr[], double bPtr[], double dPtr[], double dOrg[], double tau, int n ); 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /kafang.m: -------------------------------------------------------------------------------- 1 | clc;clear;close all; 2 | K=[1.1 2.2 3.3 4.4]; 3 | P=imread('lenna.bmp'); 4 | % P2=imread('Green.bmp');P3=imread('Blue.bmp'); 5 | P1=rgb2gray(P); 6 | % P2=rgb2gray(P2);P3=rgb2gray(P3); 7 | 8 | % P_R1=P;P_G1=P;P_B1=P;tic; 9 | % P_R1(:,:,2)=0;P_R1(:,:,3)=0;P_G1(:,:,1)=0;P_G1(:,:,3)=0;P_B1(:,:,1)=0;P_B1(:,:,2)=0; 10 | % P=double(P);P_R=P(:,:,1);P_G=P(:,:,2);P_B=P(:,:,3); 11 | % % imhist(uint8(P(:,:,1))); 12 | 13 | 14 | P1=double(P1); 15 | % P2=double(P2);P3=double(P3); 16 | iptsetpref('imshowborder','tight'); 17 | 18 | figure(1);imshow(P1); 19 | % figure(2);imshow(P2);figure(3);imshow(P3); 20 | % figure(1);imshow(uint8(P(:,:,1)));figure(2);imshow(uint8(P_G));figure(3);imshow(P_B); 21 | % C1=TpEncrypt(P1,K);C2=TpEncrypt(P2,K);C3=TpEncrypt(P3,K); 22 | % figure(4);imshow(C1);figure(5);imshow(C2);figure(6);imshow(C3); 23 | 24 | % P1=double(P1);P2=double(P2);P3=double(P3); 25 | figure(7); 26 | hist(P1(:),256);set(gca,'fontsize',18); 27 | % hist(P_R,256);set(gca,'fontsize',18); 28 | % figure(8);hist(P2(:),256);set(gca,'fontsize',18); 29 | % figure(9);hist(P3(:),256);set(gca,'fontsize',18); 30 | % C1=double(C1);C2=double(C2);C3=double(C3); 31 | % figure(10);hist(C1(:),256);set(gca,'fontsize',18); 32 | % figure(11);hist(C2(:),256);set(gca,'fontsize',18); 33 | % figure(12);hist(C3(:),256);set(gca,'fontsize',18); 34 | 35 | [M,N]=size(P1);g=M*N/256; 36 | fp1=hist(P1(:),256); 37 | % fp2=hist(P2(:),256);fp3=hist(P3(:),256); 38 | % fp1=hist(P_R,256); 39 | % fp2=hist(P2(:),256);fp3=hist(P3(:),256); 40 | chai1=sum((fp1-g).^2)/g; 41 | % chai2=sum((fp2-g).^2)/g;chai3=sum((fp3-g).^2)/g; 42 | % fc1=hist(C1(:),256);fc2=hist(C2(:),256);fc3=hist(C3(:),256); 43 | % chai4=sum((fc1-g).^2)/g;chai5=sum((fc2-g).^2)/g;chai6=sum((fc3-g).^2)/g; -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/CS_Examples/spgl1_1_7/private/ensure.m: -------------------------------------------------------------------------------- 1 | function ensure(condition) 2 | 3 | % ensure.m 4 | % $Id: ensure.m 800 2008-02-26 22:32:04Z mpf $ 5 | % 6 | % ---------------------------------------------------------------------- 7 | % This file is part of SPGL1 (Spectral Projected Gradient for L1). 8 | % 9 | % Copyright (C) 2007 Ewout van den Berg and Michael P. Friedlander, 10 | % Department of Computer Science, University of British Columbia, Canada. 11 | % All rights reserved. E-mail: <{ewout78,mpf}@cs.ubc.ca>. 12 | % 13 | % SPGL1 is free software; you can redistribute it and/or modify it 14 | % under the terms of the GNU Lesser General Public License as 15 | % published by the Free Software Foundation; either version 2.1 of the 16 | % License, or (at your option) any later version. 17 | % 18 | % SPGL1 is distributed in the hope that it will be useful, but WITHOUT 19 | % ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 20 | % or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General 21 | % Public License for more details. 22 | % 23 | % You should have received a copy of the GNU Lesser General Public 24 | % License along with SPGL1; if not, write to the Free Software 25 | % Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 26 | % USA 27 | % ---------------------------------------------------------------------- 28 | 29 | if ~condition 30 | [ST,I] = dbstack; 31 | msg = 'Assertion failed'; 32 | if length(ST) > 1 33 | msg = sprintf('%s in %s; function %s line %d', ... 34 | msg, ST(2).file, ST(2).name, ST(2).line); 35 | end 36 | 37 | errstr.message = msg; 38 | error(errstr); 39 | end 40 | 41 | end % function ensure 42 | -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/CS_Examples/spgl1_1_7/spgsetup.m: -------------------------------------------------------------------------------- 1 | %SETUP Compile the SPGL1 MEX interfaces 2 | 3 | % setup.m 4 | % $Id: spgsetup.m 1019 2008-06-17 19:33:48Z mpf $ 5 | % 6 | % ---------------------------------------------------------------------- 7 | % This file is part of SPGL1 (Spectral Projected Gradient for L1). 8 | % 9 | % Copyright (C) 2007 Ewout van den Berg and Michael P. Friedlander, 10 | % Department of Computer Science, University of British Columbia, Canada. 11 | % All rights reserved. E-mail: <{ewout78,mpf}@cs.ubc.ca>. 12 | % 13 | % SPGL1 is free software; you can redistribute it and/or modify it 14 | % under the terms of the GNU Lesser General Public License as 15 | % published by the Free Software Foundation; either version 2.1 of the 16 | % License, or (at your option) any later version. 17 | % 18 | % SPGL1 is distributed in the hope that it will be useful, but WITHOUT 19 | % ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 20 | % or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General 21 | % Public License for more details. 22 | % 23 | % You should have received a copy of the GNU Lesser General Public 24 | % License along with SPGL1; if not, write to the Free Software 25 | % Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 26 | % USA 27 | % ---------------------------------------------------------------------- 28 | 29 | root = pwd; 30 | try 31 | cd('private') 32 | mex oneProjectorMex.c oneProjectorCore.c heap.c -output oneProjectorMex -DNDEBUG 33 | fprintf('Successfully compiled oneProjector.\n'); 34 | cd(root) 35 | catch 36 | cd(root) 37 | fprintf('Could not compile oneProjector.'); 38 | fprintf('You can still use the slower ".m" version.'); 39 | rethrow(lasterr); 40 | end 41 | 42 | -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/CS_Examples/spgl1_1_7/spg_bp.m: -------------------------------------------------------------------------------- 1 | function [x,r,g,info] = spg_bp(A,b,options ) 2 | %SPG_BP Solve the basis pursuit (BP) problem 3 | % 4 | % SPG_BP is designed to solve the basis pursuit problem 5 | % 6 | % (BP) minimize ||X||_1 subject to AX = B, 7 | % 8 | % where A is an M-by-N matrix, B is an M-vector, and SIGMA is a 9 | % nonnegative scalar. In all cases below, A can be an explicit M-by-N 10 | % matrix or matrix-like object for which the operations A*x and A'*y 11 | % are defined (i.e., matrix-vector multiplication with A and its 12 | % adjoint.) 13 | % 14 | % Also, A can be a function handle that points to a function with the 15 | % signature 16 | % 17 | % v = A(w,mode) which returns v = A *w if mode == 1; 18 | % v = A'*w if mode == 2. 19 | % 20 | % X = SPG_BP(A,B) solves the BP problem. 21 | % 22 | % X = SPG_BP(A,B,OPTIONS) specifies options that are set using 23 | % SPGSETPARMS. 24 | % 25 | % [X,R,G,INFO] = SPG_BP(A,B,OPTIONS) additionally returns the 26 | % residual R = B - A*X (which should be small), the objective gradient G 27 | % = A'*R, and an INFO structure. (See SPGL1 for a description of this 28 | % last output argument.) 29 | % 30 | % See also spgl1, spgSetParms, spg_bpdn, spg_lasso. 31 | 32 | % Copyright 2008, Ewout van den Berg and Michael P. Friedlander 33 | % http://www.cs.ubc.ca/labs/scl/spgl1 34 | % $Id: spg_bp.m 1074 2008-08-19 05:24:28Z ewout78 $ 35 | 36 | if ~exist('options','var'), options = []; end 37 | if ~exist('b','var') || isempty(b) 38 | error('Second argument cannot be empty.'); 39 | end 40 | if ~exist('A','var') || isempty(A) 41 | error('First argument cannot be empty.'); 42 | end 43 | 44 | sigma = 0; 45 | tau = 0; 46 | x0 = []; 47 | [x,r,g,info] = spgl1(A,b,tau,sigma,x0,options); 48 | -------------------------------------------------------------------------------- /testKey.m: -------------------------------------------------------------------------------- 1 | clc;clear;close all 2 | P1=imread('lenna.bmp');%P2=imread('lx2.jpg');P3=imread('timg.jpg'); 3 | P1=rgb2gray(P1);%P2=rgb2gray(P2);P3=rgb2gray(P3); 4 | x0=rand(1,1000)*80-40;y0=rand(1,1000)*80-40; 5 | z0=rand(1,1000)*80+1;w0=rand(1,1000)*500-250; 6 | nubLex=zeros(1,3);nubLey=zeros(1,3);nubLez=zeros(1,3);nubLew=zeros(1,3); 7 | %nubBax=zeros(1,3);nubBay=zeros(1,3);nubBaz=zeros(1,3);nubBaw=zeros(1,3); 8 | %nubPex=zeros(1,3);nubPey=zeros(1,3);nubPez=zeros(1,3);nubPew=zeros(1,3); 9 | for i=1:1000 10 | K1=[x0(i) y0(i) z0(i) w0(i)]; 11 | CLe1=TpEncrypt(P1,K1);%CBa1=TpEncrypt(P2,K1);CPe1=TpEncrypt(P3,K1); 12 | K2=[x0(i)+10^(-13) y0(i) z0(i) w0(i)]; 13 | CLe2=TpEncrypt(P1,K2);%CBa2=TpEncrypt(P2,K2);CPe2=TpEncrypt(P3,K2); 14 | K3=[x0(i) y0(i)+10^(-13) z0(i) w0(i)]; 15 | CLe3=TpEncrypt(P1,K3);%CBa3=TpEncrypt(P2,K3);CPe3=TpEncrypt(P3,K3); 16 | K4=[x0(i) y0(i) z0++10^(-13) w0(i)]; 17 | CLe4=TpEncrypt(P1,K4);%CBa4=TpEncrypt(P2,K4);CPe4=TpEncrypt(P3,K4); 18 | K5=[x0(i) y0(i) z0(i) w0(i)+10^(-12)]; 19 | CLe5=TpEncrypt(P1,K5);%CBa5=TpEncrypt(P1,K5);CPe5=TpEncrypt(P1,K5); 20 | 21 | nubLex=nubLex+NPCRUACIBACI(CLe1,CLe2); 22 | nubLey=nubLey+NPCRUACIBACI(CLe1,CLe3); 23 | nubLez=nubLez+NPCRUACIBACI(CLe1,CLe4); 24 | nubLew=nubLew+NPCRUACIBACI(CLe1,CLe5); 25 | 26 | % nubBax=nubBax+NPCRUACIBACI(CBa1,CBa2); 27 | % nubBay=nubBay+NPCRUACIBACI(CBa1,CBa3); 28 | % nubBaz=nubBaz+NPCRUACIBACI(CBa1,CBa4); 29 | % nubBaw=nubBaw+NPCRUACIBACI(CBa1,CBa5); 30 | 31 | % nubPex=nubPex+NPCRUACIBACI(CPe1,CPe2); 32 | % nubPey=nubPey+NPCRUACIBACI(CPe1,CPe3); 33 | % nubPez=nubPez+NPCRUACIBACI(CPe1,CPe4); 34 | % nubPew=nubPew+NPCRUACIBACI(CPe1,CPe5); 35 | end 36 | nubLex=nubLex/1000;nubLey=nubLey/1000;nubLez=nubLez/1000;nubLew=nubLew/1000; 37 | % nubBax=nubBax/1000;nubBay=nubBay/1000;nubBaz=nubBaz/1000;nubBaw=nubBaw/1000; 38 | % nubPex=nubPex/1000;nubPey=nubPey/1000;nubPez=nubPez/1000;nubPew=nubPew/1000; -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/TMSBL_code/TMSBL_code/ReadMe.txt: -------------------------------------------------------------------------------- 1 | 2 | 1. Description: 3 | This package includes the codes of T-SBL/T-MSBL and simulations in the following paper 4 | 5 | Zhilin Zhang, Bhaskar D. Rao, Sparse Signal Recovery with 6 | Temporally Correlated Source Vectors Using Sparse Bayesian Learning, 7 | IEEE Journal of Selected Topics in Signal Processing, 8 | Special Issue on Adaptive Sparse Representation of 9 | Data and Applications in Signal and Image Processing, 2011 10 | 11 | Feel free to contact me for any questions (z4zhang@ucsd.edu) 12 | 13 | 14 | 2. Version: 2.3 (updated on July 30, 2011) 15 | 16 | 17 | 3. I strongly suggest you to spend 3 minutes to read the pdf file before use the codes: 18 | 19 | Z.Zhang, Master the Usage of TSBL and TMSBL in 3 Minutes 20 | 21 | 22 | 4. File Description: 23 | [ Core codes ] 24 | TSBL.m : code of T-SBL (version: 1.4) 25 | TMSBL.m : code of T-MSBL (version: 1.9) 26 | 27 | [ Auxiliary codes] 28 | perfSupp.m : code for measuring failure rates 29 | MSBL.m : code of M-SBL (used for performance comparison) 30 | MFOCUSS.m : code of M-FOCUSS (used for performance comparison) 31 | 32 | [ Demo codes] 33 | demo.m : demo for comparison of T-SBL,T-MSBL and M-SBL 34 | demo_fig3.m : demo for re-producing Fig.3 in the above IEEE paper 35 | demo_fig6_SNR10.m : demo for re-producing Fig.6 in the above IEEE paper 36 | demo_fig8.m : demo for re-producing Fig.8 in the above IEEE paper 37 | demo_time_varying.m : demo showing the use of T-MSBL for the time-varying sparsity model 38 | demo_identicalVector.m : demo showing the use of T-MSBL for the MMV model with identical source vectors 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/CS_Examples/spgl1_1_7/spg_lasso.m: -------------------------------------------------------------------------------- 1 | function [x,r,g,info] = spg_lasso(A,b,tau,options ) 2 | %SPG_LASSO Solve the LASSO problem 3 | % 4 | % SPG_LASSO is designed to solve the LASSO problem 5 | % 6 | % (LASSO) minimize ||AX - B||_2 subject to ||X||_1 <= tau, 7 | % 8 | % where A is an M-by-N matrix, B is an M-vector, and TAU is a 9 | % nonnegative scalar. In all cases below, A can be an explicit M-by-N 10 | % matrix or matrix-like object for which the operations A*x and A'*y 11 | % are defined (i.e., matrix-vector multiplication with A and its 12 | % adjoint.) 13 | % 14 | % Also, A can be a function handle that points to a function with the 15 | % signature 16 | % 17 | % v = A(w,mode) which returns v = A *w if mode == 1; 18 | % v = A'*w if mode == 2. 19 | % 20 | % X = SPG_LASSO(A,B,TAU) solves the LASSO problem. 21 | % 22 | % X = SPG_LASSO(A,B,TAU,OPTIONS) specifies options that are set using 23 | % SPGSETPARMS. 24 | % 25 | % [X,R,G,INFO] = SPG_LASSO(A,B,TAU,OPTIONS) additionally returns the 26 | % residual R = B - A*X, the objective gradient G = A'*R, and an INFO 27 | % structure. (See SPGL1 for a description of this last output argument.) 28 | % 29 | % See also spgl1, spgSetParms, spg_bp, spg_bpdn. 30 | 31 | % Copyright 2008, Ewout van den Berg and Michael P. Friedlander 32 | % http://www.cs.ubc.ca/labs/scl/spgl1 33 | % $Id: spg_lasso.m 1074 2008-08-19 05:24:28Z ewout78 $ 34 | 35 | if ~exist('options','var'), options = []; end 36 | if ~exist('tau','var'), tau = []; end 37 | if ~exist('b','var') || isempty(b) 38 | error('Second argument cannot be empty.'); 39 | end 40 | if ~exist('A','var') || isempty(A) 41 | error('First argument cannot be empty.'); 42 | end 43 | 44 | sigma = []; 45 | x0 = []; 46 | [x,r,g,info] = spgl1(A,b,tau,sigma,x0,options); 47 | -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/CS_Examples/spgl1_1_7/spg_bpdn.m: -------------------------------------------------------------------------------- 1 | function [x,r,g,info] = spg_bpdn( A, b, sigma, options ) 2 | %SPG_BPDN Solve the basis pursuit denoise (BPDN) problem 3 | % 4 | % SPG_BPDN is designed to solve the basis pursuit denoise problem 5 | % 6 | % (BPDN) minimize ||X||_1 subject to ||A X - B|| <= SIGMA, 7 | % 8 | % where A is an M-by-N matrix, B is an M-vector, and SIGMA is a 9 | % nonnegative scalar. In all cases below, A can be an explicit M-by-N 10 | % matrix or matrix-like object for which the operations A*x and A'*y 11 | % are defined (i.e., matrix-vector multiplication with A and its 12 | % adjoint.) 13 | % 14 | % Also, A can be a function handle that points to a function with the 15 | % signature 16 | % 17 | % v = A(w,mode) which returns v = A *w if mode == 1; 18 | % v = A'*w if mode == 2. 19 | % 20 | % X = SPG_BPDN(A,B,SIGMA) solves the BPDN problem. If SIGMA=0 or 21 | % SIGMA=[], then the basis pursuit (BP) problem is solved; i.e., the 22 | % constraints in the BPDN problem are taken as AX=B. 23 | % 24 | % X = SPG_BPDN(A,B,SIGMA,OPTIONS) specifies options that are set using 25 | % SPGSETPARMS. 26 | % 27 | % [X,R,G,INFO] = SPG_BPDN(A,B,SIGMA,OPTIONS) additionally returns the 28 | % residual R = B - A*X, the objective gradient G = A'*R, and an INFO 29 | % structure. (See SPGL1 for a description of this last output argument.) 30 | % 31 | % See also spgl1, spgSetParms, spg_bp, spg_lasso. 32 | 33 | % Copyright 2008, Ewout van den Berg and Michael P. Friedlander 34 | % http://www.cs.ubc.ca/labs/scl/spgl1 35 | % $Id: spg_bpdn.m 1074 2008-08-19 05:24:28Z ewout78 $ 36 | 37 | if ~exist('options','var'), options = []; end 38 | if ~exist('sigma','var'), sigma = []; end 39 | if ~exist('b','var') || isempty(b) 40 | error('Second argument cannot be empty.'); 41 | end 42 | if ~exist('A','var') || isempty(A) 43 | error('First argument cannot be empty.'); 44 | end 45 | 46 | tau = 0; 47 | x0 = []; 48 | [x,r,g,info] = spgl1(A,b,tau,sigma,x0,options); 49 | -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/TMSBL_code/TMSBL_code/perfSupp.m: -------------------------------------------------------------------------------- 1 | function [F, P, R, ind] = perfSupp(estSource, trueSourceIndex, varargin) 2 | % F-Measure of support recovery 3 | % 4 | % *** INPUT Parameters *** 5 | % estSource : estimated sources 6 | % trueSourceIndex : true support location index 7 | % varargin{1} == 'firstLargest' & varargin{2} == D 8 | % : select the support of D largest sources (in terms of 2-norm) 9 | % varargin{1} == 'largerThan' & varargin{2} == D 10 | % : select the support of elements larger than D 11 | % 12 | % *** OUTPUT Parameters *** 13 | % F : F-Measure of support recovery (=1: perfect): 14 | % F = (2*P*R)/(R+P) 15 | % P : Precision of support recovery: 16 | % P = (common set of estimated support and true support)/(set of estimated support); 17 | % R : Recall of support recovery: 18 | % R = (common set of estimated support and true support)/(set of true support); 19 | % ind : the support index used to measure performance 20 | % 21 | % Use: 22 | % F = perfSupp(estSource, trueSourceIndex, 'firstLargest', 10); 23 | % [F,P,R] = perfSupp(estSource, trueSourceIndex, 'largerThan', 1e-5); 24 | % 25 | % Author: Zhilin Zhang 26 | % Date : July, 2010 27 | % Version : 1.2 28 | 29 | 30 | 31 | if length(varargin) == 2 32 | switch lower(varargin{1}) 33 | case 'firstlargest' 34 | numThreshold = varargin{2}; 35 | estSource = sum(estSource.^2,2); 36 | [sortedSource,sortInd] = sort(estSource, 1, 'descend'); 37 | ind = sortInd(1:numThreshold); 38 | 39 | case 'largerthan' 40 | valThreshold = varargin{2}; 41 | estSource = sum(estSource.^2,2); 42 | ind = find(estSource >= valThreshold); 43 | 44 | end 45 | else 46 | error('Optional parameters are wrong!\n'); 47 | end 48 | 49 | commonSupp = intersect(ind,trueSourceIndex); 50 | 51 | if isempty(commonSupp), 52 | F = 0; P = 0; R = 0; 53 | else 54 | P = length(commonSupp)/length(ind); 55 | R = length(commonSupp)/length(trueSourceIndex); 56 | F = 2 * P * R/(P + R); 57 | end 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/TMSBL_code/TMSBL_code/demo_fig6_SNR10.m: -------------------------------------------------------------------------------- 1 | % This demo produces the Fig.6 when SNR = 10dB and T-MSBL and MSBL use 2 | % their lambda lerning rules to learn lambda during learning procedures 3 | 4 | clear; 5 | 6 | SNR = 10; % SNR 7 | N = 25; % row number of the dictionary matrix 8 | M = 125; % column number of the dictionary matrix 9 | K = 7; % source number 10 | L = 4; % number of measurement vectors 11 | beta = ones(K,1)*(0.8); % temporal correlation of each source 12 | 13 | for it = 1:100 % repeat 100 times for this demo 14 | 15 | fprintf('\nTrial #%d: \n',it); 16 | 17 | % dictionary matrix with columns draw uniformly from the surface of a unit hypersphere 18 | Phi = randn(N,M); 19 | Phi = Phi./(ones(N,1)*sqrt(sum(Phi.^2))); 20 | 21 | % Generate L source vectors 22 | nonzeroW(:,1) = randn(K,1); 23 | alpha = ones(K,1); 24 | for i = 2 : L*100 25 | nonzeroW(:,i) = beta .* nonzeroW(:,i-1) + sqrt(1-beta.^2).*(sqrt(alpha).*randn(K,1)); 26 | end 27 | nonzeroW = nonzeroW(:,end-L+1:end); 28 | 29 | % normalize along row 30 | nonzeroW = nonzeroW./( sqrt(sum(nonzeroW.^2,2)) * ones(1,L) ); 31 | 32 | % select active sources at random locations 33 | ind = randperm(M); 34 | indice = ind(1:K); 35 | Wgen = zeros(M,L); 36 | Wgen(indice,:) = nonzeroW; 37 | 38 | 39 | % noiseless signal 40 | signal = Phi * Wgen; 41 | 42 | 43 | % observation noise 44 | stdnoise = std(reshape(signal,N*L,1))*10^(-SNR/20); 45 | noise = randn(N,L) * stdnoise; 46 | 47 | 48 | % noisy signal 49 | Y = signal + noise; 50 | 51 | 52 | 53 | %============================ T-MSBL ========================== 54 | [Weight3, gamma_ind3, gamma_est3, count3] = TMSBL(Phi, Y, 'noise','mild'); 55 | 56 | [F3,P3,R3,IND3] = perfSupp(Weight3,indice,'firstlargest',K); 57 | fail_TMSBL(it) = (F3~=1); 58 | mse_TMSBL(it) = (norm(Wgen - Weight3,'fro')/norm(Wgen,'fro'))^2; 59 | 60 | fprintf(' TMSBL: Mean MSE = %4.3f; Mean FR = %4.3f; \n',mean(mse_TMSBL), mean(fail_TMSBL)); 61 | 62 | 63 | %============================ MSBL ========================== 64 | lambda_ini = 1e-2; 65 | [Weight1,gamma1,gamma_used1,count1] = MSBL(Phi, Y, lambda_ini, 1); 66 | 67 | [F1,P1,R1,IND1] = perfSupp(Weight1,indice,'firstlargest',K); 68 | fail_MSBL(it) = (F1~=1); 69 | mse_MSBL(it) = (norm(Wgen - Weight1,'fro')/norm(Wgen,'fro'))^2; 70 | 71 | fprintf(' MSBL: Mean MSE = %4.3f; Mean FR = %4.3f; \n', mean(mse_MSBL), mean(fail_MSBL)); 72 | 73 | 74 | 75 | 76 | end -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/Tensor_CS/Fig_8/Main.m: -------------------------------------------------------------------------------- 1 | %% Written by C. Caiafa, 2013. 2 | %% email: ccaiafa@gmail.com (http://web.fi.uba.ar/~ccaiafa/Cesar/Cesar.html) 3 | 4 | %% Hyperspectral Compressive Sampling Imaging results. 5 | % This Matlab Code generates the results shown in Fig 8 (case with sampling ratio=33%) in the paper 6 | % "Multidimensional Compressed Sensing and its Applications", by C. Caiafa 7 | % and A. Cichocki, submitted to Wiley Interdisciplinary Reviews: Data 8 | % Mining and Knowledge Discovery (2013) 9 | 10 | % Block-sparsity is assumed on a separable (Kronecker) orthogonal basis given by the Daubechies WT. 11 | % A random (Gaussian) separable 2D operator was used for sensing every slice of the hyperspectral cube 12 | % 1024x1024x32.The reconstruction was obtained by applied the NBOMP 13 | % algorithm on the 3D compressive signal Z 14 | 15 | % This demo requires to have the following packages installed: 16 | % - MATLAB Tensor Toolbox Version 2.4, Brett W. Bader and Tamara G. Kolda, 17 | % available at http://csmr.ca.sandia.gov/~tgkolda/TensorToolbox/, March 2010. 18 | 19 | 20 | %% This code takes about 90 minutes to run in a notebook computer (MacBookPro, 2.3GHz) 21 | %% To generate Fig 8 just call MakeFig8() which displays the saved results (case sampling ratio=33%) 22 | clear 23 | clc 24 | 25 | load ../Datasets/Hyperspectral/ref_cyflower1bb_reg1.mat 26 | I0 = zeros(1024,1024,32); 27 | I0(1:1017,:,:) = reflectances(1:1017,1:1024,2:33); 28 | clear 'reflectances' 29 | 30 | I = size(I0); 31 | 32 | K = [1.75, 1.75, 1]; 33 | M = round([I(1)/K(1), I(2)/K(2), I(3)/K(3)]); 34 | 35 | epsilon = 0.02; 36 | 37 | load WTbases; % load Daubechies WT bases 38 | 39 | % Define sensing matrices 40 | SM1 = normalize(randn(M(1),I(1))); 41 | SM2 = normalize(randn(M(2),I(2))); 42 | SM3 = eye(I(3),I(3)); 43 | 44 | Y = double(ttensor(tensor(I0),{SM1,SM2,SM3})); % Compressive measurement 45 | 46 | D0{1} = normalize(SM1*W{1}'); 47 | D0{2} = normalize(SM2*W{2}'); 48 | D0{3} = normalize(SM3*W{3}'); 49 | 50 | % Compute NBOMP 51 | disp('Computing block-sparse representation using Tensor-OMP...') 52 | tic 53 | [Test, Ind] = tensor_OMPND(D0,Y,I,epsilon); 54 | TimetensorOMP = toc; 55 | 56 | Z=Test(Ind{:}); 57 | 58 | Trunc = zeros(I); 59 | Trunc(Ind{1},Ind{2},Ind{3}) = Z; 60 | 61 | AproxtensorOMP = ttensor(tensor(Trunc),{W{1}',W{2}',W{3}'}); 62 | 63 | AproxtensorOMP = double(AproxtensorOMP)/norm(AproxtensorOMP); 64 | I0 = I0/norm(tensor(I0)); 65 | 66 | errortensorOMP = norm(tensor(I0 - AproxtensorOMP)) 67 | 68 | PSNRtensorOMP = 20*log10(max(I0(:))/sqrt(mean((I0(:) - AproxtensorOMP(:)).^2))) 69 | 70 | samplingratio = prod(size(Y))/prod(I); 71 | 72 | save BOMPresults33.mat 73 | 74 | %% Produce Fig 8 (case sampling ratio=33%) 75 | MakeFig8() 76 | 77 | 78 | 79 | -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/CS_Examples/spgl1_1_7/spg_group.m: -------------------------------------------------------------------------------- 1 | function [x,r,g,info] = spg_group( A, b, groups, sigma, options ) 2 | %SPG_GROUP Solve jointly-sparse basis pursuit denoise (BPDN) 3 | % 4 | % SPG_GROUP is designed to solve the basis pursuit denoise problem 5 | % 6 | % (BPDN) minimize sum_k ||X_{i : GROUPS(i) = k}||_2 7 | % subject to ||A X - B||_2,2 <= SIGMA, 8 | % 9 | % where A is an M-by-N matrix, B is a vector, GROUPS is vector 10 | % containing the group number of the corresponding index in X, and 11 | % SIGMA is a nonnegative scalar. In all cases below, A can be an 12 | % explicit M-by-N matrix or matrix-like object for which the 13 | % operations A*x and A'*y are defined (i.e., matrix-vector 14 | % multiplication with A and its adjoint.) 15 | % 16 | % Also, A can be a function handle that points to a function with the 17 | % signature 18 | % 19 | % v = A(w,mode) which returns v = A *w if mode == 1; 20 | % v = A'*w if mode == 2. 21 | % 22 | % X = SPG_GROUP(A,B,G,SIGMA) solves the BPDN problem. If SIGMA=0, 23 | % SIGMA=[] or SIGMA is omitted, then the jointly-sparse basis 24 | % pursuit (BP) problem is solved; i.e., the constraints in the BPDN 25 | % problem are taken as AX=B. 26 | % 27 | % X = SPG_GROUP(A,B,G,SIGMA,OPTIONS) specifies options that are set 28 | % using SPGSETPARMS. 29 | % 30 | % [X,R,G,INFO] = SPG_GROUP(A,B,GROUPS,SIGMA,OPTIONS) additionally 31 | % returns the residual R = B - A*X, the objective gradient G = A'*R, 32 | % and an INFO structure. (See SPGL1 for a description of this last 33 | % output argument.) 34 | % 35 | % See also spgl1, spgSetParms, spg_bp, spg_lasso. 36 | 37 | % Copyright 2008, Ewout van den Berg and Michael P. Friedlander 38 | % http://www.cs.ubc.ca/labs/scl/spgl1 39 | % $Id$ 40 | 41 | if ~exist('options','var'), options = []; end 42 | if ~exist('sigma','var') || isempty(sigma), sigma = 0; end 43 | if ~exist('groups','var') || isempty(groups) 44 | error('Third argument cannot be empty.'); 45 | end 46 | if ~exist('b','var') || isempty(b) 47 | error('Second argument cannot be empty.'); 48 | end 49 | if ~exist('A','var') || isempty(A) 50 | error('First argument cannot be empty.'); 51 | end 52 | 53 | % Preprocess the groups, normalize numbering 54 | g = groups(:); 55 | gidx = unique(g); 56 | groups = sparse(length(gidx),length(g)); 57 | for i=1:length(gidx) 58 | groups(i,g == gidx(i)) = 1; 59 | end 60 | 61 | % Set projection specific functions 62 | options.project = @(x,weight,tau) NormGroupL2_project(groups,x,weight,tau); 63 | options.primal_norm = @(x,weight ) NormGroupL2_primal(groups,x,weight); 64 | options.dual_norm = @(x,weight ) NormGroupL2_dual(groups,x,weight); 65 | 66 | tau = 0; 67 | x0 = []; 68 | [x,r,g,info] = spgl1(A,b,tau,sigma,x0,options); 69 | -------------------------------------------------------------------------------- /hash.m: -------------------------------------------------------------------------------- 1 | function h = hash(inp,meth) 2 | % HASH - Convert an input variable into a message digest using any of 3 | % several common hash algorithms 4 | % 5 | % USAGE: h = hash(inp,'meth') 6 | % 7 | % inp = input variable, of any of the following classes: 8 | % char, uint8, logical, double, single, int8, uint8, 9 | % int16, uint16, int32, uint32, int64, uint64 10 | % h = hash digest output, in hexadecimal notation 11 | % meth = hash algorithm, which is one of the following: 12 | % MD2, MD5, SHA-1, SHA-256, SHA-384, or SHA-512 13 | % 14 | % NOTES: (1) If the input is a string or uint8 variable, it is hashed 15 | % as usual for a byte stream. Other classes are converted into 16 | % their byte-stream values. In other words, the hash of the 17 | % following will be identical: 18 | % 'abc' 19 | % uint8('abc') 20 | % char([97 98 99]) 21 | % The hash of the follwing will be different from the above, 22 | % because class "double" uses eight byte elements: 23 | % double('abc') 24 | % [97 98 99] 25 | % You can avoid this issue by making sure that your inputs 26 | % are strings or uint8 arrays. 27 | % (2) The name of the hash algorithm may be specified in lowercase 28 | % and/or without the hyphen, if desired. For example, 29 | % h=hash('my text to hash','sha256'); 30 | % (3) Carefully tested, but no warranty. Use at your own risk. 31 | % (4) Michael Kleder, Nov 2005 32 | % 33 | % EXAMPLE: 34 | % 35 | % algs={'MD2','MD5','SHA-1','SHA-256','SHA-384','SHA-512'}; 36 | % for n=1:6 37 | % h=hash('my sample text',algs{n}); 38 | % disp([algs{n} ' (' num2str(length(h)*4) ' bits):']) 39 | % disp(h) 40 | % end 41 | 42 | inp=inp(:); 43 | % convert strings and logicals into uint8 format 44 | if ischar(inp) || islogical(inp) 45 | inp=uint8(inp); 46 | else % convert everything else into uint8 format without loss of data 47 | inp=typecast(inp,'uint8'); 48 | end 49 | 50 | % verify hash method, with some syntactical forgiveness: 51 | meth=upper(meth); 52 | switch meth 53 | case 'SHA1' 54 | meth='SHA-1'; 55 | case 'SHA256' 56 | meth='SHA-256'; 57 | case 'SHA384' 58 | meth='SHA-384'; 59 | case 'SHA512' 60 | meth='SHA-512'; 61 | otherwise 62 | end 63 | algs={'MD2','MD5','SHA-1','SHA-256','SHA-384','SHA-512'}; 64 | if isempty(strmatch(meth,algs,'exact')) 65 | error(['Hash algorithm must be ' ... 66 | 'MD2, MD5, SHA-1, SHA-256, SHA-384, or SHA-512']); 67 | end 68 | 69 | % create hash 70 | x=java.security.MessageDigest.getInstance(meth); 71 | x.update(inp); 72 | h=typecast(x.digest,'uint8'); 73 | h=dec2hex(h)'; 74 | if(size(h,1))==1 % remote possibility: all hash bytes 128, so pad: 75 | h=[repmat('0',[1 size(h,2)]);h]; 76 | end 77 | h=lower(h(:)'); 78 | 79 | return -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/CS_Examples/spgl1_1_7/README: -------------------------------------------------------------------------------- 1 | SPGL1: Spectral Projected Gradient for L1 minimization 2 | ------------------------------------------------------ 3 | 4 | 1. Introduction 5 | =============== 6 | 7 | Thank you for downloading the SPGL1 solver! SPGL1 is a Matlab solver 8 | for large-scale one-norm regularized least squares. It is designed to 9 | solve any of the following three problems: 10 | 11 | 1. Basis pursuit denoise (BPDN): 12 | minimize ||x||_1 subject to ||Ax - b||_2 <= sigma, 13 | 14 | 2. Basis pursuit (BP): 15 | minimize ||x||_1 subject to Ax = b 16 | 17 | 3. Lasso: 18 | minimize ||Ax - b||_2 subject to ||x||_1 <= tau, 19 | 20 | The matrix A can be defined explicily, or as an operator (i.e., a 21 | function) that return both both Ax and A'y. SPGL1 can solve these 22 | three problems in both the real and complex domains. 23 | 24 | 25 | 2. Quick start 26 | ============== 27 | 28 | Start Matlab and make sure the working directory is set to the 29 | directory containing the SPGL1 source files. When this is done, run 30 | 31 | >> spgdemo 32 | 33 | at the Matlab prompt. This script illustrates various uses of SPGL1: 34 | 35 | - Solve (BPDN) for some sigma > 0 36 | - Solve (Lasso) 37 | - Solve (BP) 38 | - Solve a (BP) problem in complex variables 39 | - Sample the entire Pareto frontier (i.e., ||Ax-b||_2 vs ||x||_1) 40 | for a small test problem. 41 | 42 | 43 | 3. Installation 44 | =============== 45 | 46 | 3.1 MEX interface 47 | ------------------ 48 | 49 | A vital component of SPGL1 is a routine (oneProjector.m) for 50 | projecting vectors onto the one-norm ball. The default distribution 51 | includes a pure Matlab version of oneProjector which should work on 52 | all platforms, and also a C-version of this routine that is more 53 | efficient on large problems. Precompiled MEX interfaces to the C 54 | implementation of oneProjector are included for Windows 55 | (oneProjector.dll), Linux/x86 (oneProjector.mexglx) and MacOSX/Intel 56 | (oneProjector.mexmaci). If you need to compile the MEX interface on 57 | your own machine, run the following command at the Matlab prompt: 58 | 59 | >> spgsetup 60 | 61 | or, equivalently, change to the "private" directory and issue the 62 | command 63 | 64 | >> mex oneProjector.c oneProjector_core.c -output oneProjector -DNDEBUG 65 | 66 | If the MEX interface cannot be found, SPGL1 falls back to the slower 67 | Matlab implementation of oneProjector. 68 | 69 | 3.2 Path 70 | --------- 71 | 72 | In order to use SPGL1 from any directory other than the one 73 | containing the main spgl1 routine, add the SPGL1 package to your 74 | default path: 75 | 76 | >> addpath 77 | 78 | where is the location of spgl1.m. You can also add this 79 | command to your startup.m file. 80 | 81 | 4. References 82 | ============= 83 | 84 | The algorithm implemented by SPGL1 is described in the paper 85 | 86 | E. van den Berg and M. P. Friedlander, "Probing the Pareto frontier 87 | for basis pursuit solutions", UBC Computer Science Technical Report 88 | TR-2008-01, January 2008. Available at 89 | http://www.optimization-online.org/DB_FILE/2008/01/1889.pdf 90 | 91 | 92 | $Id: README 769 2008-01-29 23:19:36Z mpf $ 93 | -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/CS_Examples/spgl1_1_7/private/oneProjector.m: -------------------------------------------------------------------------------- 1 | function [x,itn] = oneProjector(b,d,tau) 2 | % ONEPROJECTOR Projects b onto the weighted one-norm ball of radius tau 3 | % 4 | % [X,ITN] = ONEPROJECTOR(B,TAU) returns the orthogonal projection 5 | % of the vector b onto the one-norm ball of radius tau. The return 6 | % vector X which solves the problem 7 | % 8 | % minimize ||b-x||_2 st ||x||_1 <= tau. 9 | % x 10 | % 11 | % [X,ITN] = ONEPROJECTOR(B,D,TAU) returns the orthogonal 12 | % projection of the vector b onto the weighted one-norm ball of 13 | % radius tau, which solves the problem 14 | % 15 | % minimize ||b-x||_2 st || Dx ||_1 <= tau. 16 | % x 17 | % 18 | % If D is empty, all weights are set to one, i.e., D = I. 19 | % 20 | % In both cases, the return value ITN given the number of elements 21 | % of B that were thresholded. 22 | % 23 | % See also spgl1. 24 | 25 | % oneProjector.m 26 | % $Id: oneProjector.m 1200 2008-11-21 19:58:28Z mpf $ 27 | % 28 | % ---------------------------------------------------------------------- 29 | % This file is part of SPGL1 (Spectral Projected Gradient for L1). 30 | % 31 | % Copyright (C) 2007 Ewout van den Berg and Michael P. Friedlander, 32 | % Department of Computer Science, University of British Columbia, Canada. 33 | % All rights reserved. E-mail: <{ewout78,mpf}@cs.ubc.ca>. 34 | % 35 | % SPGL1 is free software; you can redistribute it and/or modify it 36 | % under the terms of the GNU Lesser General Public License as 37 | % published by the Free Software Foundation; either version 2.1 of the 38 | % License, or (at your option) any later version. 39 | % 40 | % SPGL1 is distributed in the hope that it will be useful, but WITHOUT 41 | % ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 42 | % or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General 43 | % Public License for more details. 44 | % 45 | % You should have received a copy of the GNU Lesser General Public 46 | % License along with SPGL1; if not, write to the Free Software 47 | % Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 48 | % USA 49 | % ---------------------------------------------------------------------- 50 | 51 | % Check arguments 52 | if nargin < 2 53 | error('The oneProjector function requires at least two parameters'); 54 | end 55 | if nargin < 3 56 | tau = d; 57 | d = []; 58 | end 59 | 60 | % Check weight vector 61 | if isempty(d), d = 1; end; 62 | 63 | if ~isscalar(d) && ( length(b) ~= length(d) ) 64 | error('Vectors b and d must have the same length'); 65 | end 66 | 67 | % Quick return for the easy cases. 68 | if isscalar(d) && d == 0 69 | x = b; 70 | itn = 0; 71 | return 72 | end 73 | 74 | % Get sign of b and set to absolute values 75 | s = sign(b); 76 | b = abs(b); 77 | 78 | % Perform the projection 79 | if isscalar(d) 80 | [x,itn] = oneProjectorMex(b,tau/d); 81 | else 82 | d = abs(d); 83 | idx = find(d > eps); % Get index of all non-zero entries of d 84 | x = b; % Ensure x_i = b_i for all i not in index set idx 85 | [x(idx),itn] = oneProjectorMex(b(idx),d(idx),tau); 86 | end 87 | 88 | % Restore signs in x 89 | x = x.*s; 90 | -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/CS_Examples/spgl1_1_7/spg_mmv.m: -------------------------------------------------------------------------------- 1 | function [x,r,g,info] = spg_mmv( A, B, sigma, options ) 2 | %SPG_MMV Solve multi-measurement basis pursuit denoise (BPDN) 3 | % 4 | % SPG_MMV is designed to solve the basis pursuit denoise problem 5 | % 6 | % (BPDN) minimize ||X||_1,2 subject to ||A X - B||_2,2 <= SIGMA, 7 | % 8 | % where A is an M-by-N matrix, B is an M-by-G matrix, and SIGMA is a 9 | % nonnegative scalar. In all cases below, A can be an explicit M-by-N 10 | % matrix or matrix-like object for which the operations A*x and A'*y 11 | % are defined (i.e., matrix-vector multiplication with A and its 12 | % adjoint.) 13 | % 14 | % Also, A can be a function handle that points to a function with the 15 | % signature 16 | % 17 | % v = A(w,mode) which returns v = A *w if mode == 1; 18 | % v = A'*w if mode == 2. 19 | % 20 | % X = SPG_MMV(A,B,SIGMA) solves the BPDN problem. If SIGMA=0 or 21 | % SIGMA=[], then the basis pursuit (BP) problem is solved; i.e., the 22 | % constraints in the BPDN problem are taken as AX=B. 23 | % 24 | % X = SPG_MMV(A,B,SIGMA,OPTIONS) specifies options that are set using 25 | % SPGSETPARMS. 26 | % 27 | % [X,R,G,INFO] = SPG_BPDN(A,B,SIGMA,OPTIONS) additionally returns the 28 | % residual R = B - A*X, the objective gradient G = A'*R, and an INFO 29 | % structure. (See SPGL1 for a description of this last output argument.) 30 | % 31 | % See also spgl1, spgSetParms, spg_bp, spg_lasso. 32 | 33 | % Copyright 2008, Ewout van den Berg and Michael P. Friedlander 34 | % http://www.cs.ubc.ca/labs/scl/spgl1 35 | % $Id$ 36 | 37 | if ~exist('options','var'), options = []; end 38 | if ~exist('sigma','var'), sigma = 0; end 39 | if ~exist('B','var') || isempty(B) 40 | error('Second argument cannot be empty.'); 41 | end 42 | if ~exist('A','var') || isempty(A) 43 | error('First argument cannot be empty.'); 44 | end 45 | 46 | groups = size(B,2); 47 | 48 | if isa(A,'function_handle') 49 | y = A(B(:,1),2); m = size(B,1); n = length(y); 50 | A = @(x,mode) blockDiagonalImplicit(A,m,n,groups,x,mode); 51 | else 52 | m = size(A,1); n = size(A,2); 53 | A = @(x,mode) blockDiagonalExplicit(A,m,n,groups,x,mode); 54 | end 55 | 56 | % Set projection specific functions 57 | options.project = @(x,weight,tau) NormL12_project(groups,x,weight,tau); 58 | options.primal_norm = @(x,weight ) NormL12_primal(groups,x,weight); 59 | options.dual_norm = @(x,weight ) NormL12_dual(groups,x,weight); 60 | 61 | tau = 0; 62 | x0 = []; 63 | [x,r,g,info] = spgl1(A,B(:),tau,sigma,x0,options); 64 | 65 | n = round(length(x) / groups); 66 | m = size(B,1); 67 | x = reshape(x,n,groups); 68 | y = reshape(r,m,groups); 69 | g = reshape(g,n,groups); 70 | 71 | 72 | function y = blockDiagonalImplicit(A,m,n,g,x,mode) 73 | 74 | if mode == 1 75 | y = zeros(m*g,1); 76 | for i=1:g 77 | y(1+(i-1)*m:i*m) = A(x(1+(i-1)*n:i*n),mode); 78 | end 79 | else 80 | y = zeros(n*g,1); 81 | for i=1:g 82 | y(1+(i-1)*n:i*n) = A(x(1+(i-1)*m:i*m),mode); 83 | end 84 | end 85 | 86 | 87 | function y = blockDiagonalExplicit(A,m,n,g,x,mode) 88 | 89 | if mode == 1 90 | y = A * reshape(x,n,g); 91 | y = y(:); 92 | else 93 | x = reshape(x,m,g); 94 | y = (x' * A)'; 95 | y = y(:); 96 | end 97 | -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/TMSBL_code/TMSBL_code/demo_fig8.m: -------------------------------------------------------------------------------- 1 | % This demo produces the Fig.8 in the paper. 2 | % Enjoy increasing the temporal correlation to see the performance of T-MSBL 3 | 4 | clear; 5 | 6 | double tmpCorr; 7 | 8 | % Set the temporal correlation value. You can add more "9"s to it (i.e. allow 9 | % the temporal correlation approximates 1 closer. But note that, 10 | % practically, when tmpCorr is larger than a value, the matrix computation 11 | % will have numerical problems. 12 | % In this demo, it is advised that |tmpCorr| <= 1e-13. 13 | tmpCorr = 0.999999999; 14 | 15 | 16 | % Problem dimension 17 | K = 12; % source number 18 | L = 3; % number of measurement vectors 19 | N = 40; % row number of the dictionary matrix 20 | M = 128; % column number of the dictionary matrix 21 | iterNum = 100; % number of repeating the experiment 22 | 23 | % generate Hadamard matrix of the size 128 x 128 24 | H = hadamard(M); 25 | 26 | 27 | for it = 1:iterNum 28 | fprintf('\n\nTrial #%d:\n',it); 29 | 30 | % generate the dictionary matrix, whose 40 rows are randomly chosen 31 | % from the rows of the Hadamard matrix 32 | rowLoc = randperm(M); 33 | loc = rowLoc(1:N); 34 | Phi = H(loc,:); 35 | 36 | % Generate L source vectors 37 | beta = ones(K,1)*tmpCorr; 38 | nonzeroW(:,1) = randn(K,1); 39 | alpha = ones(K,1); 40 | for i = 2 : L 41 | nonzeroW(:,i) = beta .* nonzeroW(:,i-1) + sqrt(1-beta.^2).*(sqrt(alpha).*randn(K,1)); 42 | end 43 | 44 | % rescale the rows 45 | nonzeroW = nonzeroW./( sqrt(sum(nonzeroW.^2,2)) * ones(1,L) ); 46 | AdjustNorm = 0.3+rand(K,1)*(1-0.3); 47 | nonzeroW = diag(AdjustNorm) * nonzeroW; 48 | 49 | 50 | % select active sources at random locations 51 | ind = randperm(M); 52 | indice = ind(1:K); 53 | Wgen = zeros(M,L); 54 | Wgen(indice,:) = nonzeroW; 55 | 56 | 57 | % noiseless signal 58 | Y = Phi * Wgen; 59 | 60 | 61 | 62 | %============================ 1.T-MSBL ========================== 63 | [Weight1, gamma_ind1, gamma_est1, count1] = TMSBL(Phi, Y, 'noise','no'); 64 | 65 | % Failure Rate 66 | F1 = perfSupp(Weight1,indice,'firstlargest',K); 67 | FR_TMSBL(it) = (F1~=1); 68 | 69 | % MSE 70 | MSE1 = (norm(Weight1-Wgen,'fro')/norm(Wgen,'fro'))^2; 71 | MSE_TMSBL(it) = MSE1; 72 | 73 | fprintf('T-MSBL(Using 3 Measurement Vectors): Fail_Rate = %4.3f%%; MSE = %3.2f%%; \n',mean(FR_TMSBL)*100,mean(MSE_TMSBL)*100); 74 | 75 | 76 | 77 | %============================ 3.MSBL for MMV ========================== 78 | lambda1 = 1e-15; 79 | Learn_Lambda = 0; 80 | [Weight3,gamma3,gamma_used3,count3] = MSBL(Phi, Y, lambda1, Learn_Lambda); 81 | 82 | % Failure Rate 83 | F3 = perfSupp(Weight3,indice,'firstlargest',K); 84 | FR_MSBL(it) = (F3~=1); 85 | 86 | % MSE 87 | MSE3 = (norm(Weight3-Wgen,'fro')/norm(Wgen,'fro'))^2; 88 | MSE_MSBL(it) = MSE3; 89 | 90 | fprintf(' MSBL(Using 3 Measurement Vectors): Fail_Rate = %4.3f%%; MSE = %3.2f%%; \n',mean(FR_MSBL)*100,mean(MSE_MSBL)*100); 91 | 92 | 93 | %============================ 4.MSBL for SMV ========================== 94 | [Weight4,gamma4,gamma_used4,count4] = MSBL(Phi, Y(:,1), lambda1, Learn_Lambda); 95 | 96 | % Failure Rate 97 | F4 = perfSupp(Weight4,indice,'firstlargest',K); 98 | FR_SBL(it) = (F4~=1); 99 | 100 | % MSE 101 | MSE4 = (norm(Weight4-Wgen(:,1),'fro')/norm(Wgen(:,1),'fro'))^2; 102 | MSE_SBL(it) = MSE4; 103 | 104 | fprintf(' MSBL(Using 1 Measurement Vector) : Fail_Rate = %4.3f%%; MSE = %3.2f%%; \n',mean(FR_SBL)*100,mean(MSE_SBL)*100); 105 | end 106 | 107 | -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/TMSBL_code/TMSBL_code/demo_fig3.m: -------------------------------------------------------------------------------- 1 | % Goal: This demo produces the Fig.3(d) when source number is 14 2 | 3 | clear; 4 | 5 | % Experiment variables (will be varied to produce each sub-figures) 6 | % Here we produce Fig.3(d) when source nubmer is 14 7 | K = 14; % soure number 8 | beta = ones(K,1)*0.99; % temporal correlation of each source 9 | 10 | % problem dimension 11 | N = 25; % column number of the dictionary matrix 12 | M = 125; % row number of the dictionary matrix 13 | L = 4; % number of measurement vectors 14 | iterNum = 50; % In the paper we repeated 1000 times. But here we repeat 50 times to save time 15 | 16 | for it = 1:iterNum 17 | fprintf('\n\nTrial #%d:\n',it); 18 | 19 | % Dictionary matrix with columns draw uniformly from the surface of a unit hypersphere 20 | Phi = randn(N,M); 21 | Phi = Phi./(ones(N,1)*sqrt(sum(Phi.^2))); 22 | 23 | % Generate L source vectors 24 | nonzeroW(:,1) = randn(K,1); 25 | alpha = ones(K,1); 26 | for i = 2 : L*20 27 | nonzeroW(:,i) = beta .* nonzeroW(:,i-1) + sqrt(1-beta.^2).*(sqrt(alpha).*randn(K,1)); 28 | end 29 | % get stable AR signals with length L 30 | nonzeroW = nonzeroW(:,end-L+1:end); 31 | 32 | % normalize along row 33 | nonzeroW = nonzeroW./( sqrt(sum(nonzeroW.^2,2)) * ones(1,L) ); 34 | 35 | % rescale rows such that their norms uniformly distribute in [1/3, 1] 36 | AdjustNorm = 1/3+rand(K,1)*(1-1/3); 37 | nonzeroW = diag(AdjustNorm) * nonzeroW; 38 | 39 | % select active sources at random locations 40 | ind = randperm(M); 41 | indice = ind(1:K); 42 | Wgen = zeros(M,L); 43 | Wgen(indice,:) = nonzeroW; 44 | 45 | % noiseless signal 46 | Y = Phi * Wgen; 47 | 48 | 49 | %============================ 1.T-MSBL ========================== 50 | [Weight1, gamma_ind1, gamma_est1, count1] = TMSBL(Phi, Y, 'noise','no'); 51 | 52 | F1 = perfSupp(Weight1,indice,'firstlargest',K); 53 | FR_TMSBL(it) = (F1~=1); 54 | 55 | MSE1 = (norm(Weight1-Wgen,'fro')/norm(Wgen,'fro'))^2; 56 | MSE_TMSBL(it) = MSE1; 57 | 58 | fprintf(' T-MSBL: MSE = %3.2f%%; Fail_Rate = %4.3f%%; \n',mean(MSE_TMSBL)*100,mean(FR_TMSBL)*100); 59 | 60 | 61 | %============================ 2.T-SBL ========================== 62 | [Weight2, gamma_ind2, gamma_est2, count2, B2] = TSBL(Phi, Y, 'SNR','inf'); 63 | 64 | F2 = perfSupp(Weight2,indice,'firstlargest',K); 65 | FR_TSBL(it) = (F2~=1); 66 | 67 | MSE2 = (norm(Weight2-Wgen,'fro')/norm(Wgen,'fro'))^2; 68 | MSE_TSBL(it) = MSE2; 69 | 70 | fprintf(' T-SBL: MSE = %3.2f%%; Fail_Rate = %4.3f%%; \n',mean(MSE_TSBL)*100,mean(FR_TSBL)*100); 71 | 72 | 73 | 74 | %============================ 3.MSBL ========================== 75 | lambda1 = 1e-10; 76 | Learn_Lambda = 0; 77 | [Weight3,gamma3,gamma_used3,count3] = MSBL(Phi, Y, lambda1, Learn_Lambda); 78 | 79 | F3 = perfSupp(Weight3,indice,'firstlargest',K); 80 | FR_MSBL(it) = (F3~=1); 81 | 82 | MSE3 = (norm(Weight3-Wgen,'fro')/norm(Wgen,'fro'))^2; 83 | MSE_MSBL(it) = MSE3; 84 | 85 | fprintf(' M-SBL: MSE = %3.2f%%; Fail_Rate = %4.3f%%; \n',mean(MSE_MSBL)*100,mean(FR_MSBL)*100); 86 | 87 | 88 | 89 | %============================ 4.MFOCUSS =========================== 90 | [Weight4, gamma_ind4, gamma_est4, count4] = MFOCUSS(Phi, Y, lambda1); 91 | 92 | F4 = perfSupp(Weight4,indice,'firstlargest',K); 93 | FR_FOCUSS(it) = (F4~=1); 94 | 95 | MSE4 = (norm(Weight4-Wgen,'fro')/norm(Wgen,'fro'))^2; 96 | MSE_FOCUSS(it) = MSE4; 97 | 98 | fprintf(' FOCUSS: MSE = %3.2f%%; Fail_Rate = %4.3f%%; \n',mean(MSE_FOCUSS)*100,mean(FR_FOCUSS)*100); 99 | 100 | 101 | end -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/Tensor_CS/Fig_8/tensor_OMPND.m: -------------------------------------------------------------------------------- 1 | %% Matlab Code for the N-Way OMP algorithm as described in the paper: 2 | % "Computing Sparse Representations of Multidimensional Signals Using Kronecker Bases" by C. Caiafa & A. Cichocki, 3 | % Neural Computation Journal, Vol. 25, No. 1 , pp. 186-220, 2013. 4 | % Find a s-sparse representation of a tensor Y, i.e. 5 | % Y = X \times_1 D_1 \times_2 D_2...\times_N D_N 6 | % where X(i_1,i_2,...,i_N)=0 for all i_n \notin I_n and |I_n|=s(n) 7 | 8 | 9 | function [X,Ind] = tensor_OMPND(D,Y,s,epsilon) 10 | [I] = size(Y); 11 | N = size(I,2); 12 | 13 | for n = 1:N 14 | M(n) = size(D{n},2); 15 | end 16 | 17 | norma = norm(reshape(Y,[I(1),prod(I)/I(1)]),'fro'); 18 | 19 | R = Y; % initial residual 20 | Ind = cell(1,N); % set of indices to select for each mode 21 | L = cell(1,N); % Triangular matrices used in Cholesky factorization of each mode 22 | Dsub = cell(1,N); % subset of selected atoms per each mode 23 | 24 | % auxiliar variables for searching the maximum of a tensor 25 | v = cell(1,N); 26 | add = cell(1,N); 27 | 28 | ni = zeros(1,N); % number of selected indices in each mode 29 | 30 | % Initialization 31 | for n = 1:N 32 | Ind{n} = []; 33 | L{n} = 1; 34 | ni(n) = 0; 35 | end 36 | X = zeros(M); % coefficients 37 | cond = 0; % this condition is true when ni(n)=s(n) for all n (all nonzero coefficients where computed) 38 | posi = zeros(1,N); % additional index to add 39 | 40 | 41 | % multiway cross correlation 42 | B = double(ttensor(tensor(Y),transp(D))); 43 | 44 | condchange = 1; 45 | error = Inf; 46 | % Main loop where selected indices in each mode are found 47 | %Dred = D; 48 | while ((condchange && (~cond) && (error > epsilon))) 49 | niant = ni; 50 | proj = abs(double(ttensor(tensor(R),transp(D)))); % multiway correlation between dictionary and residual 51 | 52 | for n = 1:N 53 | [proj,v{n}] = max(abs(proj)); 54 | add{n} = 1; 55 | end 56 | 57 | posi(N) = v{N}; 58 | add{N} = posi(N); 59 | for n = N-1:-1:1 60 | posi(n) = v{n}(add{:}); 61 | add{n} = posi(n); 62 | end 63 | 64 | for n = 1:N 65 | if ((~ismember(posi(n),Ind{n})) && (ni(n) < s(n))) 66 | Ind{n} = [Ind{n},posi(n)]; 67 | Dsub{n} = [Dsub{n},D{n}(:,posi(n))]; 68 | ni(n) = ni(n) + 1; 69 | if ni(n) > 1 70 | w = L{n}\((D{n}(:,Ind{n}(1:ni(n) - 1)))'*D{n}(:,Ind{n}(ni(n)))); 71 | L{n} = [L{n}, zeros(ni(n)-1,1); w', sqrt(1 - w'*w)]; 72 | end 73 | end 74 | end 75 | 76 | Z = B(Ind{:}); 77 | 78 | 79 | for n = 1: N 80 | Z = L{n}\reshape(permute(Z,permorder(n,N)),[ni(n),prod(ni)/ni(n)]); 81 | Z = L{n}'\Z; 82 | Z = permute(reshape(Z,ni(permorder(n,N))),permorderinv(n,N)); 83 | end 84 | Z = tensor(Z,ni); 85 | 86 | R = Y - double(ttensor(Z,Dsub)); 87 | error = norm(reshape(R,[I(1),prod(I)/I(1)]),'fro')/norma; 88 | disp([num2str(ni),' ', num2str(error)]) 89 | 90 | cond = 1; 91 | for n =1:N 92 | cond = cond && (ni(n) == s(n)); 93 | end 94 | 95 | condchange = sum(ni-niant); 96 | 97 | % for n = 1:N 98 | % Dred{n}(:,Ind{n}(ni(n)))=0; 99 | % end 100 | end 101 | 102 | X(Ind{:}) = Z; 103 | X=sptensor(X); 104 | 105 | end 106 | 107 | function [D] = transp(D) 108 | N = size(D,2); 109 | for n = 1:N 110 | D{n} = D{n}'; 111 | end 112 | end 113 | 114 | function [v] = permorder(n,N) 115 | v = 1:N; 116 | if n == 1 117 | return; 118 | end 119 | v(1) = n; 120 | for m = 1:n-1 121 | v(m+1) = m; 122 | end 123 | end 124 | 125 | function [v] = permorderinv(n,N) 126 | v = 1:N; 127 | if n == 1 128 | return; 129 | end 130 | v(1:n-1) = 2:n; 131 | v(n) = 1; 132 | 133 | end 134 | 135 | function [indx] = multi_index(M,pos) 136 | N = size(M,2); 137 | indx = zeros(1,N); 138 | for n = N:-1:2 139 | indx(n) = floor(((pos - 1)/prod(M(1:n-1)))) + 1; 140 | pos = pos - (indx(n)-1)*prod(M(1:n-1)); 141 | end 142 | indx(1) = pos; 143 | 144 | end 145 | -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/CS_Examples/spgl1_1_7/private/heap.h: -------------------------------------------------------------------------------- 1 | /* $Id: heap.h 800 2008-02-26 22:32:04Z mpf $ */ 2 | 3 | #ifndef __HEAP_H__ 4 | #define __HEAP_H__ 5 | 6 | #define swap_double(a,b) { double c; c = (a); (a) = (b); (b) = c; } 7 | 8 | /* 9 | \brief Perform the "sift" operation for the heap-sort algorithm. 10 | 11 | A heap is a collection of items arranged in a binary tree. Each 12 | child node is smaller than or equal to its parent. If x[k] is the 13 | parent, than its children are x[2k+1] and x[2k+2]. 14 | 15 | This routine promotes ("sifts up") children that are larger than 16 | their parents. Thus, the largest element of the heap is the root node. 17 | 18 | \param[in] root The root index from which to start sifting. 19 | \param[in] lastChild The last child (largest node index) in the sift operation. 20 | \param[in,out] x The array to be sifted. 21 | */ 22 | void heap_sift( int root, int lastChild, double x[] ); 23 | 24 | 25 | /*! 26 | \brief Perform the "sift" operation for the heap-sort algorithm. 27 | 28 | A heap is a collection of items arranged in a binary tree. Each 29 | child node is smaller than or equal to its parent. If x[k] is the 30 | parent, than its children are x[2k+1] and x[2k+2]. 31 | 32 | This routine promotes ("sifts up") children that are larger than 33 | their parents. Thus, the largest element of the heap is the root node. 34 | 35 | Elements in y are associated with those in x and are reordered accordingly. 36 | 37 | \param[in] root The root index from which to start sifting. 38 | \param[in] lastChild The last child (largest node index) in the sift operation. 39 | \param[in,out] x The array to be sifted. 40 | \param[in,out] y The array to be sifted accordingly. 41 | */ 42 | void heap_sift_2( int root, int lastChild, double x[], double y[] ); 43 | 44 | 45 | /*! 46 | \brief Discard the largest element and contract the heap. 47 | 48 | On entry, the numElems of the heap are stored in x[0],...,x[numElems-1], 49 | and the biggest element is x[0]. The following operations are performed: 50 | -# Swap the first and last elements of the heap 51 | -# Shorten the length of the heap by one. 52 | -# Restore the heap property to the contracted heap. 53 | This effectively makes x[0] the next largest element 54 | in the list. 55 | 56 | \param[in] numElems The number of elements in the current heap. 57 | \param[in,out] x The array to be modified. 58 | 59 | \return The number of elements in the heap after it has been contracted. 60 | */ 61 | int heap_del_max(int numElems, double x[]); 62 | 63 | 64 | /*! 65 | \brief Discard the largest element of x and contract the heaps. 66 | 67 | On entry, the numElems of the heap are stored in x[0],...,x[numElems-1], 68 | and the largest element is x[0]. The following operations are performed: 69 | -# Swap the first and last elements of both heaps 70 | -# Shorten the length of the heaps by one. 71 | -# Restore the heap property to the contracted heap x. 72 | This effectively makes x[0] the next largest element 73 | in the list. 74 | 75 | \param[in] numElems The number of elements in the current heap. 76 | \param[in,out] x The array to be modified. 77 | \param[in,out] y The array to be modified accordingly 78 | 79 | \return The number of elements in each heap after they have been contracted. 80 | */ 81 | int heap_del_max_2( int numElems, double x[], double y[] ); 82 | 83 | 84 | /*! 85 | \brief Build a heap by adding one element at a time. 86 | 87 | \param[in] n The length of x and ix. 88 | \param[in,out] x The array to be heapified. 89 | 90 | */ 91 | void heap_build( int n, double x[] ); 92 | 93 | 94 | /*! 95 | \brief Build a heap by adding one element at a time. 96 | 97 | \param[in] n The length of x and ix. 98 | \param[in,out] x The array to be heapified. 99 | \param[in,out] y The array to be reordered in sync. with x. 100 | 101 | */ 102 | void heap_build_2( int n, double x[], double y[] ); 103 | 104 | 105 | #endif 106 | -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/CS_Examples/spgl1_1_7/ChangeLog: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------ 2 | Version 1.7 3 | ------------------------------------------------------------------------ 4 | 5 | 2009-05-20 Ewout van den Berg 6 | * spg_mmv.m: Fixed bug in handling implicit matrices. Thanks to 7 | Muhammad Usman for reporting this bug. 8 | 9 | 2008-09-18 Ewout van den Berg 10 | * spgSetParms.m: Replaced isstr by ischar. 11 | 12 | ------------------------------------------------------------------------ 13 | Version 1.6 14 | ------------------------------------------------------------------------ 15 | 16 | 2008-05-02 Ewout van den Berg 17 | 18 | * spgl1.m: The options structure now contains three fields to 19 | specify routines for computing the primal norm, dual norm, and 20 | for the Euclidean projection onto the associated ball. 21 | 22 | * spg_mmv.m: New interface for multiple measurement vector case 23 | of BP and BPDN. 24 | 25 | * spg_group.m: New interface for group sparse BP and BPDN. 26 | 27 | ------------------------------------------------------------------------ 28 | Version 1.5 29 | ------------------------------------------------------------------------ 30 | 31 | 2008-06-17 Michael P. Friedlander 32 | 33 | * spg_lasso.m, spg_bp.m, spg_bpdn.m: New interfaces. These are 34 | specialized to specialized problem classes, and are simply 35 | easy-to-use wrappers to spgl1.m. 36 | 37 | * spgexamples.m: Added html documentation. 38 | 39 | 2008-05-02 Ewout van den Berg 40 | 41 | * spgl1.m: Added support for class implementation of A. 42 | 43 | ------------------------------------------------------------------------ 44 | Version 1.4 45 | ------------------------------------------------------------------------ 46 | 47 | 2008-03-17 Ewout van den Berg 48 | 49 | * spgl1.m: Added isreal(x) check in projection code to ensure the 50 | proper procedure is used even if realx is set incorrectly. 51 | * spgl1.m: Check added to ensure tau is not updated in two 52 | successive iterations. Thanks to Gilles Hennenfent for reporting 53 | this problem. 54 | 55 | 2008-03-02 Ewout van den Berg 56 | 57 | * spgdemo.m: Added demo for basis pursuit with weighted one-norm 58 | 59 | 2008-02-23 Ewout van den Berg 60 | 61 | * spgl1.m: Fixed bug in handling weighted one-norm ball orthogonal 62 | projection. Thanks to Xiangrui Meng for reporting this bug. 63 | * private/oneProjector.m: New one-projector wrapper. 64 | * private/oneProjectorMex.c: New mex-interface to one-projector. 65 | * private/oneProjectorCore.c: New implementation of (weighted) 66 | one-norm ball orthogonal projection code. 67 | 68 | ------------------------------------------------------------------------ 69 | Version 1.3 70 | ------------------------------------------------------------------------ 71 | 72 | 2007-12-04 Michael P. Friedlander 73 | 74 | * lsqr.m: Moved to "private" dir so that it won't interfere with 75 | default lsqr function. 76 | 77 | 2007-12-03 Ewout van den Berg 78 | 79 | * spgl1.m: Changed single tau stopping criterion 'f < optTol' to 80 | 'rNorm < optTol*bNorm'. 81 | * spgl1.m: Implemented the code of dealing with the maximum number 82 | of matrix-vector operations option. 83 | 84 | 2007-11-21 Ewout van den Berg 85 | 86 | * spgl1.m: added the safeguard 'max(0,...)' to update for tau; 87 | tau = max(0,tau + (rNorm * aError1) / gNorm); 88 | This is needed to avoid tau from becoming negative, e.g., in 89 | case sigma and the intial tau are large. 90 | 91 | 2007-11-30 Ewout van den Berg 92 | 93 | * spgl1.m: EXIT_MATVEC_LIMIT exit condition added 94 | * spgl1.m, spgSetParms.m: added .maxMatvec option 95 | 96 | 2007-11-26 Ewout van den Berg 97 | 98 | * spgl1.m: added .rGap field in info 99 | * ensure.m: added, used instead of the assert function 100 | * spgl1.m, spgSetParms.m: added .iscomplex flag to options 101 | 102 | 2007-11-17 Michael P. Friedlander 103 | 104 | * spgl1.m: Default number of iterations did not match comment 105 | string. Fixed. (Reported by Ozgur Yilmaz.) 106 | 107 | -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/CS_Examples/spgl1_1_7/private/oneProjectorMex.m: -------------------------------------------------------------------------------- 1 | function [x, itn] = oneProjectorMex(b,d,tau) 2 | % [x, itn] = oneProjectorMex(b,d,tau) 3 | % Return the orthogonal projection of the vector b >=0 onto the 4 | % (weighted) L1 ball. In case vector d is specified, matrix D is 5 | % defined as diag(d), otherwise the identity matrix is used. 6 | % 7 | % On exit, 8 | % x solves minimize ||b-x||_2 st ||Dx||_1 <= tau. 9 | % itn is the number of elements of b that were thresholded. 10 | % 11 | % See also spgl1, oneProjector. 12 | 13 | % oneProjectorMex.m 14 | % $Id: oneProjectorMex.m 1200 2008-11-21 19:58:28Z mpf $ 15 | % 16 | % ---------------------------------------------------------------------- 17 | % This file is part of SPGL1 (Spectral Projected Gradient for L1). 18 | % 19 | % Copyright (C) 2007 Ewout van den Berg and Michael P. Friedlander, 20 | % Department of Computer Science, University of British Columbia, Canada. 21 | % All rights reserved. E-mail: <{ewout78,mpf}@cs.ubc.ca>. 22 | % 23 | % SPGL1 is free software; you can redistribute it and/or modify it 24 | % under the terms of the GNU Lesser General Public License as 25 | % published by the Free Software Foundation; either version 2.1 of the 26 | % License, or (at your option) any later version. 27 | % 28 | % SPGL1 is distributed in the hope that it will be useful, but WITHOUT 29 | % ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 30 | % or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General 31 | % Public License for more details. 32 | % 33 | % You should have received a copy of the GNU Lesser General Public 34 | % License along with SPGL1; if not, write to the Free Software 35 | % Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 36 | % USA 37 | % ---------------------------------------------------------------------- 38 | 39 | if nargin < 3 40 | tau = d; 41 | d = 1; 42 | end 43 | 44 | if isscalar(d) 45 | [x,itn] = oneProjectorMex_I(b,tau/abs(d)); 46 | else 47 | [x,itn] = oneProjectorMex_D(b,d,tau); 48 | end 49 | 50 | end % function oneProjectorMex 51 | 52 | 53 | % ---------------------------------------------------------------------- 54 | function [x,itn] = oneProjectorMex_I(b,tau) 55 | % ---------------------------------------------------------------------- 56 | 57 | % Initialization 58 | n = length(b); 59 | x = zeros(n,1); 60 | bNorm = norm(b,1); 61 | 62 | % Check for quick exit. 63 | if (tau >= bNorm), x = b; itn = 0; return; end 64 | if (tau < eps ), itn = 0; return; end 65 | 66 | % Preprocessing (b is assumed to be >= 0) 67 | [b,idx] = sort(b,'descend'); % Descending. 68 | 69 | csb = -tau; 70 | alphaPrev = 0; 71 | for j= 1:n 72 | csb = csb + b(j); 73 | alpha = csb / j; 74 | 75 | % We are done as soon as the constraint can be satisfied 76 | % without exceeding the current minimum value of b 77 | if alpha >= b(j) 78 | break; 79 | end 80 | 81 | alphaPrev = alpha; 82 | end 83 | 84 | % Set the solution by applying soft-thresholding with 85 | % the previous value of alpha 86 | x(idx) = max(0,b - alphaPrev); 87 | 88 | % Set number of iterations 89 | itn = j; 90 | end 91 | 92 | 93 | % ---------------------------------------------------------------------- 94 | function [x,itn] = oneProjectorMex_D(b,d,tau) 95 | % ---------------------------------------------------------------------- 96 | 97 | % Initialization 98 | n = length(b); 99 | x = zeros(n,1); 100 | 101 | % Check for quick exit. 102 | if (tau >= norm(d.*b,1)), x = b; itn = 0; return; end 103 | if (tau < eps ), itn = 0; return; end 104 | 105 | % Preprocessing (b is assumed to be >= 0) 106 | [bd,idx] = sort(b ./ d,'descend'); % Descending. 107 | b = b(idx); 108 | d = d(idx); 109 | 110 | % Optimize 111 | csdb = 0; csd2 = 0; 112 | soft = 0; alpha1 = 0; i = 1; 113 | while (i <= n) 114 | csdb = csdb + d(i).*b(i); 115 | csd2 = csd2 + d(i).*d(i); 116 | 117 | alpha1 = (csdb - tau) / csd2; 118 | alpha2 = bd(i); 119 | 120 | if alpha1 >= alpha2 121 | break; 122 | end 123 | 124 | soft = alpha1; i = i + 1; 125 | end 126 | x(idx(1:i-1)) = b(1:i-1) - d(1:i-1) * max(0,soft); 127 | 128 | % Set number of iterations 129 | itn = i; 130 | end 131 | -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/CS_Examples/spgl1_1_7/private/oneProjectorMex.c: -------------------------------------------------------------------------------- 1 | /* oneProjector.c 2 | $Id: oneProjectorMex.c 800 2008-02-26 22:32:04Z mpf $ 3 | 4 | ---------------------------------------------------------------------- 5 | This file is part of SPGL1 (Spectral Projected Gradient for L1). 6 | 7 | Copyright (C) 2007 Ewout van den Berg and Michael P. Friedlander, 8 | Department of Computer Science, University of British Columbia, Canada. 9 | All rights reserved. E-mail: <{ewout78,mpf}@cs.ubc.ca>. 10 | 11 | SPGL1 is free software; you can redistribute it and/or modify it 12 | under the terms of the GNU Lesser General Public License as 13 | published by the Free Software Foundation; either version 2.1 of the 14 | License, or (at your option) any later version. 15 | 16 | SPGL1 is distributed in the hope that it will be useful, but WITHOUT 17 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 18 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General 19 | Public License for more details. 20 | 21 | You should have received a copy of the GNU Lesser General Public 22 | License along with SPGL1; if not, write to the Free Software 23 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 24 | USA 25 | ---------------------------------------------------------------------- 26 | */ 27 | #include "oneProjectorCore.h" 28 | #include "mex.h" 29 | 30 | 31 | /* ----------------------------------------------------------------------- */ 32 | void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) 33 | /* ----------------------------------------------------------------------- */ 34 | { const mxArray *vectorD; 35 | const mxArray *tau; 36 | mxArray *vectorB; 37 | mxArray *vectorX; 38 | mxArray *vectorDcopy; 39 | int *ptr; 40 | int i, n; 41 | unsigned int dims[2]; 42 | 43 | 44 | /* Free memory and exit if no parameters are given */ 45 | if (nrhs == 0) 46 | { if (nlhs != 0) { mexErrMsgTxt("No output arguments expected."); } 47 | return ; 48 | } 49 | 50 | /* Check for proper number of arguments */ 51 | if ((nrhs != 2) && (nrhs != 3)) { mexErrMsgTxt("Two or three input arguments required."); } 52 | if ((nlhs > 2) ) { mexErrMsgTxt("Too many output arguments."); } 53 | 54 | /* Extract the arguments */ 55 | if (nrhs == 2) 56 | { vectorB = (mxArray *)prhs[0]; 57 | vectorD = NULL; 58 | tau = prhs[1]; 59 | } 60 | else 61 | { vectorB = (mxArray *)prhs[0]; 62 | vectorD = prhs[1]; 63 | tau = prhs[2]; 64 | if (mxIsEmpty(vectorD)) vectorD = NULL; 65 | } 66 | 67 | /* Verify validity of input argument 'b' */ 68 | if (mxIsEmpty(vectorB)) 69 | { /* If vector B is empty, simply return an empty projection */ 70 | plhs[0] = mxCreateNumericMatrix(0, 0, mxDOUBLE_CLASS, mxREAL); 71 | mexWarnMsgTxt("Returning empty projection."); 72 | return ; 73 | } 74 | if (!mxIsDouble(vectorB) || ((mxGetM(vectorB) > 1) && 75 | (mxGetN(vectorB) > 1)) || (mxGetNumberOfDimensions(vectorB) != 2)) 76 | { mexErrMsgTxt("Parameter 'b' has to be a double vector."); 77 | } 78 | 79 | /* Verify validity of input argument 'd' */ 80 | if (vectorD != NULL) 81 | { if (!mxIsDouble(vectorD) || ((mxGetM(vectorD) > 1) && 82 | (mxGetN(vectorD) > 1)) || (mxGetNumberOfDimensions(vectorD) != 2)) 83 | { mexErrMsgTxt("Parameter 'd' has to be a double vector."); 84 | } 85 | if (mxGetNumberOfElements(vectorD) != mxGetNumberOfElements(vectorB)) 86 | { mexErrMsgTxt("Parameters 'b' and 'd' have to be of equal length."); 87 | } 88 | 89 | /* Assume are entries of 'd' all positive */ 90 | } 91 | 92 | /* Verify validity of input argument 'lambda' */ 93 | if ((mxIsEmpty(vectorB)) || (mxGetNumberOfElements(tau) != 1) || 94 | (mxGetScalar(tau) < 0)) 95 | { mexErrMsgTxt("Parameter 'tau' has to be a non-negative scalar."); 96 | } 97 | 98 | /* Get the problem size */ 99 | n = mxGetNumberOfElements(vectorB); 100 | 101 | /* Replicate vector b into return argument x */ 102 | vectorX = mxDuplicateArray(vectorB); 103 | plhs[0] = vectorX; 104 | 105 | 106 | /* Call the appropriate projection subroutine */ 107 | if (vectorD == NULL) 108 | { i = projectI(mxGetPr(vectorX), mxGetPr(vectorB), *mxGetPr(tau), n); 109 | } 110 | else 111 | { vectorDcopy = mxDuplicateArray(vectorD); 112 | i = projectD(mxGetPr(vectorX), mxGetPr(vectorB), 113 | mxGetPr(vectorDcopy), mxGetPr(vectorD), 114 | *mxGetPr(tau), n); 115 | mxDestroyArray(vectorDcopy); 116 | } 117 | 118 | /* Return the number of iterations for projection */ 119 | if (nlhs > 1) 120 | { plhs[1] = mxCreateDoubleScalar((double)i); 121 | } 122 | 123 | return ; 124 | } 125 | -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/CS_Examples/spgl1_1_7/spgSetParms.m: -------------------------------------------------------------------------------- 1 | function options = spgSetParms(varargin) 2 | %SPGSETPARMS Set options for SPGL1 3 | % 4 | % options = spgSetParms('param1',val1,'param2',val2,...) creates an 5 | % options structure in which the named parameters have the specified 6 | % values. Unspecified parameters are empty and their default 7 | % values are used. 8 | % 9 | % spgSetParms with no input arguments and no output arguments 10 | % displays all parameter names and their possible values. 11 | % 12 | % options = spgSetParms (with no input arguments) creates an options 13 | % structure where all the fields are empty. 14 | % 15 | % spgSetParms.m 16 | % $Id: spgSetParms.m 1093 2008-09-23 04:23:26Z ewout78 $ 17 | 18 | % Print out possible values of properties. 19 | if nargin == 0 && nargout == 0 20 | fprintf(' Default parameters for l1Set.m:\n'); 21 | fprintf(' fid : [ positive integer | 1 ]\n'); 22 | fprintf(' verbosity : [ integer: 1, 2, or 3 | 3 ]\n'); 23 | fprintf(' iterations : [ positive integer | 10*m ]\n'); 24 | fprintf(' nPrevVals : [ positive integer | 10 ]\n'); 25 | fprintf(' bpTol : [ positive scalar | 1e-06 ]\n'); 26 | fprintf(' optTol : [ positive scalar | 1e-04 ]\n'); 27 | fprintf(' decTol : [ positive scalar | 1e-04 ]\n'); 28 | fprintf(' stepMin : [ positive scalar | 1e-16 ]\n'); 29 | fprintf(' stepMax : [ positive scalar | 1e+05 ]\n'); 30 | fprintf(' rootMethod : [ 1=linear, 2=quadratic | 2 ]\n'); 31 | fprintf('activeSetIt : [ positive integer | Inf ]\n'); 32 | fprintf('subspaceMin : [ 0=no, 1=yes | 0 ]\n'); 33 | fprintf(' iscomplex : [ 0=no, 1=yes, NaN=auto | NaN ]\n'); 34 | fprintf(' maxMatvec : [ positive integer | Inf ]\n'); 35 | fprintf(' weights : [ vector | 1 ]\n'); 36 | fprintf(' project : [ projection function | @()]\n'); 37 | fprintf('primal_norm : [ primal norm eval fun | @()]\n'); 38 | fprintf(' dual_norm : [ dual norm eval fun | @()]\n'); 39 | fprintf('\n'); 40 | return; 41 | end 42 | 43 | Names = [ 44 | 'fid ' 45 | 'verbosity ' 46 | 'iterations ' 47 | 'nPrevVals ' 48 | 'bpTol ' 49 | 'optTol ' 50 | 'decTol ' 51 | 'stepMin ' 52 | 'stepMax ' 53 | 'rootMethod ' 54 | 'activeSetIt ' 55 | 'subspaceMin ' 56 | 'iscomplex ' 57 | 'maxMatvec ' 58 | 'weights ' 59 | 'project ' 60 | 'primal_norm ' 61 | 'dual_norm ' 62 | ]; 63 | [m,n] = size(Names); 64 | names = lower(Names); 65 | 66 | % Combine all leading options structures o1, o2, ... in l1Set(o1,o2,...). 67 | options = []; 68 | for j = 1:m 69 | eval(['options.' Names(j,:) '= [];']); 70 | end 71 | i = 1; 72 | while i <= nargin 73 | arg = varargin{i}; 74 | if ischar(arg), break; end 75 | if ~isempty(arg) % [] is a valid options argument 76 | if ~isa(arg,'struct') 77 | error(sprintf(['Expected argument %d to be a string parameter name ' ... 78 | 'or an options structure\ncreated with OPTIMSET.'], i)); 79 | end 80 | for j = 1:m 81 | if any(strcmp(fieldnames(arg),deblank(Names(j,:)))) 82 | eval(['val = arg.' Names(j,:) ';']); 83 | else 84 | val = []; 85 | end 86 | if ~isempty(val) 87 | eval(['options.' Names(j,:) '= val;']); 88 | end 89 | end 90 | end 91 | i = i + 1; 92 | end 93 | 94 | % A finite state machine to parse name-value pairs. 95 | if rem(nargin-i+1,2) ~= 0 96 | error('Arguments must occur in name-value pairs.'); 97 | end 98 | expectval = 0; % start expecting a name, not a value 99 | while i <= nargin 100 | arg = varargin{i}; 101 | 102 | if ~expectval 103 | if ~ischar(arg) 104 | error(sprintf('Expected argument %d to be a string parameter name.', i)); 105 | end 106 | 107 | lowArg = lower(arg); 108 | j = strmatch(lowArg,names); 109 | if isempty(j) % if no matches 110 | error(sprintf('Unrecognized parameter name ''%s''.', arg)); 111 | elseif length(j) > 1 % if more than one match 112 | % Check for any exact matches (in case any names are subsets of others) 113 | k = strmatch(lowArg,names,'exact'); 114 | if length(k) == 1 115 | j = k; 116 | else 117 | msg = sprintf('Ambiguous parameter name ''%s'' ', arg); 118 | msg = [msg '(' deblank(Names(j(1),:))]; 119 | for k = j(2:length(j))' 120 | msg = [msg ', ' deblank(Names(k,:))]; 121 | end 122 | msg = sprintf('%s).', msg); 123 | error(msg); 124 | end 125 | end 126 | expectval = 1; % we expect a value next 127 | 128 | else 129 | eval(['options.' Names(j,:) '= arg;']); 130 | expectval = 0; 131 | 132 | end 133 | i = i + 1; 134 | end 135 | 136 | if expectval 137 | error(sprintf('Expected value for parameter ''%s''.', arg)); 138 | end 139 | 140 | -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/TMSBL_code/TMSBL_code/demo_identicalVector.m: -------------------------------------------------------------------------------- 1 | % Goal: compare T-MSBL, MSBL, MFOCUSS when source vectors are identical 2 | % Author: Zhilin Zhang (z4zhang@ucsd.edu) 3 | % Date: May 23, 2011 4 | % Version: 1.2 5 | 6 | 7 | clear all; 8 | 9 | % Experiment Assignment 10 | run_TMSBL = 1; % Run T-MSBL 11 | run_MSBL = 1; % Run MSBL 12 | run_FOCUSS= 1; % Run M-FOCUSS 13 | iterNum = 50; % Trial number (i.e. number of repeating the experiment) 14 | % For statistical result, iterNum should not less than 50 15 | 16 | % Problem dimension 17 | N = 40; % Row number of the dictionary matrix 18 | M = N * 5; % Column number of the dictionary matrix 19 | L = 4; % Number of measurement vectors 20 | K = 7; % Number of nonzero rows (i.e. source number) in the solution matrix 21 | beta = ones(K,1)*1; % The source vectors are identical 22 | 23 | %==================================================================== 24 | SNR = 10; % Note: When you change the SNR, you may need to accordingly change 25 | % the input arguments for each algorithm 26 | %==================================================================== 27 | 28 | for it = 1 : iterNum 29 | fprintf('\n\nTrial #%d:\n',it); 30 | 31 | % Generate dictionary matrix with columns draw uniformly from the surface of a unit hypersphere 32 | Phi = randn(N,M); 33 | Phi = Phi./(ones(N,1)*sqrt(sum(Phi.^2))); 34 | 35 | % Generate the K nonzero rows, each row being an AR(1) process. All the AR(1) 36 | % processes have different AR coefficients, which are randomly chosen from [0.7,1) 37 | nonzeroW(:,1) = randn(K,1); 38 | for i = 2 : L*100 39 | nonzeroW(:,i) = beta .* nonzeroW(:,i-1) + sqrt(1-beta.^2).*(ones(K,1).*randn(K,1)); 40 | end 41 | nonzeroW = nonzeroW(:,end-L+1:end); % Ensure the AR processes are stable 42 | 43 | % Normalize each row 44 | nonzeroW = nonzeroW./( sqrt(sum(nonzeroW.^2,2)) * ones(1,L) ); 45 | 46 | % Rescale each row such that the squared row-norm distributes in [1,scalefactor] 47 | scalefactor = 3; 48 | mag = rand(1,K); mag = mag - min(mag); 49 | mag = mag/(max(mag))*(scalefactor-1) + 1; 50 | nonzeroW = diag(sqrt(mag)) * nonzeroW; 51 | 52 | % Locations of nonzero rows are randomly chosen 53 | ind = randperm(M); 54 | indice = ind(1:K); 55 | Wgen = zeros(M,L); 56 | Wgen(indice,:) = nonzeroW; 57 | 58 | % Noiseless signal 59 | signal = Phi * Wgen; 60 | 61 | % Observation noise 62 | stdnoise = std(reshape(signal,N*L,1))*10^(-SNR/20); 63 | noise = randn(N,L) * stdnoise; 64 | 65 | % Noisy signal 66 | Y = signal + noise; 67 | 68 | 69 | %============================ T-MSBL ========================== 70 | if run_TMSBL == 1, 71 | tic; 72 | 73 | % Depends on the SNR, choosing suitable values for input arguments: 74 | % If no noise, Weight = TMSBL(Phi, Y, 'noise','no','fix_B',eye(L)); 75 | % If SNR >= 23 dB, Weight = TMSBL(Phi, Y, 'noise','small','fix_B',eye(L)); 76 | % If 6dB < SNR <= 22 dB, Weight = TMSBL(Phi, Y, 'noise','mild','fix_B',eye(L)); 77 | % If SNR <= 6 dB, Weight = TMSBL(Phi, Y, 'noise','large','fix_B',eye(L)); 78 | % Note: See the TMSBL code for details on input arguments ans set your 79 | % own values for specific problems. 80 | 81 | [Weight1, gamma_ind1, gamma_est1, count1] = TMSBL(Phi, Y, 'noise','mild','fix_B',eye(L)); 82 | 83 | time1 = toc; 84 | TIME1(it) = time1; 85 | 86 | 87 | % failure rate: F1 = 1: perfect recovery; F1 = 0: worst recovery 88 | F1 = perfSupp(Weight1,indice,'firstlargest', K); 89 | fail_TMSBL(it) = (F1~=1); 90 | 91 | % Mean Square Error (MSE) 92 | mse_TMSBL(it) = (norm(Wgen - Weight1,'fro')/norm(Wgen,'fro'))^2; 93 | 94 | fprintf(' T-MSBL: time = %5.2f; Findex = %3.2f, Ave-MSE = %3.2f%%; Ave-Fail_Rate = %4.3f%%; Ave-Time = %4.3f\n',... 95 | time1,F1,mean(mse_TMSBL)*100,mean(fail_TMSBL)*100,mean(TIME1)); 96 | end 97 | %============================================================ 98 | 99 | 100 | 101 | 102 | %============================ MSBL ========================== 103 | lambda = 1e-3; % Initial value for the regularization parameter. 104 | Learn_Lambda = 1; % Using its lambda learning rule 105 | 106 | if run_MSBL == 1, 107 | tic; 108 | [Weight3,gamma_est3,gamma_used3,count3] = MSBL(Phi,Y, lambda, Learn_Lambda); 109 | time3 = toc; 110 | TIME3(it) = time3; 111 | 112 | 113 | % Failure rate 114 | F3 = perfSupp(Weight3,indice,'firstlargest', K); 115 | fail_MSBL(it) = (F3~=1); 116 | 117 | % MSE 118 | perf_MSBL(it) = (norm(Wgen - Weight3,'fro')/norm(Wgen,'fro'))^2; 119 | 120 | fprintf(' MSBL: time = %5.2f; Findex = %3.2f, Ave-MSE = %3.2f%%; Ave-Fail_Rate = %4.3f%%; Ave-Time = %4.3f\n',... 121 | time3,F3,mean(perf_MSBL)*100,mean(fail_MSBL)*100,mean(TIME3)); 122 | end 123 | 124 | 125 | % ====================== MFOCUSS with near-optimal regularization ========= 126 | if run_FOCUSS == 1, 127 | tic; 128 | lambda_opt = stdnoise^2; % use the noise variance 129 | [Weight4, gamma_ind4, gamma_est4, count4] = MFOCUSS(Phi, Y, lambda_opt); 130 | 131 | time4 = toc; 132 | TIME4(it) = time4; 133 | 134 | 135 | % Failure rate 136 | F4 = perfSupp(Weight4,indice,'firstlargest', K); 137 | fail_MFOCUSS(it) = (F4~=1); 138 | 139 | % MSE 140 | perf_MFOCUSS(it) = (norm(Wgen - Weight4,'fro')/norm(Wgen,'fro'))^2; 141 | 142 | fprintf('MFOCUSS(optimal): time = %5.2f; Findex = %3.2f, Ave-MSE = %3.2f%%; Ave-Fail_Rate = %4.3f%%; Ave-Time = %4.3f\n',... 143 | time4,F4,mean(perf_MFOCUSS)*100,mean(fail_MFOCUSS)*100,mean(TIME4)); 144 | end 145 | 146 | end 147 | 148 | 149 | 150 | 151 | -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/TMSBL_code/TMSBL_code/MFOCUSS.m: -------------------------------------------------------------------------------- 1 | function [X, gamma_ind, gamma_est, count] = MFOCUSS(Phi, Y, lambda, varargin) 2 | % MFOCUSS algorithm for the MMV model 3 | % 4 | % ============================== INPUTS ============================== 5 | % Phi : N X M dictionary matrix 6 | % 7 | % Y : N X L measurement matrix, i.e. Y = Phi * X + V. 8 | % 9 | % lambda : Regularization parameter. Generally it is close to the noise variance. 10 | % In the noiseless cases, simply setting lambda = 1e-10 leads to good performance. 11 | % In noisy cases, need the modified L-curve method to find optimal lambda. 12 | % See Ref [1] for details. 13 | % 14 | % 'p' : p-norm. p lies in [0,1]. Default value: p = 0.8 15 | % 16 | % 'PRUNE_GAMMA' : Threshold for prunning small gamma_i. 17 | % In noisy cases, you can set PRUNE_GAMMA = 1e-3 or 1e-4. 18 | % In strongly noisy cases (SNR<=5 dB), suggest to set PRUNE_GAMMA = 0.01; 19 | % Default value: MIN_GAMMA = 1e-4. 20 | % 21 | % 'MAX_ITERS' : Maximum number of iterations. 22 | % Default value: MAX_ITERS = 800 23 | % 24 | % 'EPSILON' : Threshold to stop the whole algorithm. 25 | % Default value: EPSILON = 1e-8 26 | % 27 | % 'PRINT' : Display flag. If PRINT = 1: show output; If PRINT = 0: supress output 28 | % Default value: PRINT = 0 29 | % 30 | % ============================== OUTPUTS ============================== 31 | % X : Estimated solution matrix(size: M X L) 32 | % gamma_ind : Indexes of nonzero gamma_i 33 | % gamma_est : Final values of all the gamma_i (including zeros). An M X 1 vector 34 | % count : number of iterations used 35 | % 36 | % ============== Examples of Commands =============== 37 | % [Example 1] 38 | % lambda = 1e-3; 39 | % [X,gamma_ind,gamma_est,count] ... 40 | % = MFOCUSS(Phi,Y,lambda,'p',0.8,'prune_gamma',1e-4,'max_iters',500,'epsilon',1e-8,'print',0); 41 | % 42 | % [Example 2] 43 | % lambda = 1e-5; 44 | % [X,gamma_ind,gamma_est,count] = MFOCUSS(Phi,Y, lambda); 45 | % 46 | % ============================== Reference ============================= 47 | % [1] Cotter, S.F.; Rao, B.D.; Kjersti Engan; Kreutz-Delgado, K.; 48 | % Sparse solutions to linear inverse problems with multiple measurement vectors 49 | % 50 | % ============================== Author ============================== 51 | % Zhilin Zhang (z4zhang@ucsd.edu) 52 | % Mainbody was written by David Wipf 53 | % 54 | % ============================== Version ============================== 55 | % 1.0 (05/12/2011) 56 | % 57 | % ============================== See Also ============================== 58 | % TSBL TMSBL ARSBL tMFOCUSS 59 | % 60 | 61 | % Dimension of the Problem 62 | [N M] = size(Phi); 63 | [N L] = size(Y); 64 | 65 | % Default Control Parameters 66 | PRUNE_GAMMA = 1e-4; % threshold for prunning small gamma_i 67 | p = 0.8; % p-norm 68 | EPSILON = 1e-8; % threshold for stopping iteration. 69 | MAX_ITERS = 800; % maximum iterations 70 | PRINT = 0; % not show progress information 71 | 72 | % get input argument values 73 | if(mod(length(varargin),2)==1) 74 | error('Optional parameters should always go by pairs\n'); 75 | else 76 | for i=1:2:(length(varargin)-1) 77 | switch lower(varargin{i}) 78 | case 'p' 79 | p = varargin{i+1}; 80 | case 'prune_gamma' 81 | PRUNE_GAMMA = varargin{i+1}; 82 | case 'epsilon' 83 | EPSILON = varargin{i+1}; 84 | case 'print' 85 | PRINT = varargin{i+1}; 86 | case 'max_iters' 87 | MAX_ITERS = varargin{i+1}; 88 | otherwise 89 | error(['Unrecognized parameter: ''' varargin{i} '''']); 90 | end 91 | end 92 | end 93 | 94 | if (PRINT) fprintf('\nRunning M-FOCUSS for the MMV Problem...\n'); end 95 | 96 | 97 | % Initializations 98 | gamma = ones(M,1); % initialization of gamma_i 99 | keep_list = [1:M]'; % record the index of nonzero gamma_i 100 | m = length(keep_list); % number of nonzero gamma_i 101 | mu = zeros(M,L); % initialization of the solution matrix 102 | count = 0; % record iterations 103 | 104 | 105 | % Learning loop 106 | while (1) 107 | 108 | % =========== Prune weights as their hyperparameters go to zero =========== 109 | if (min(gamma) < PRUNE_GAMMA ) 110 | index = find(gamma > PRUNE_GAMMA); 111 | gamma = gamma(index); 112 | Phi = Phi(:,index); % corresponding columns in Phi 113 | keep_list = keep_list(index); 114 | m = length(gamma); 115 | 116 | if (m == 0) break; end; 117 | end; 118 | 119 | 120 | % ====== Compute new weights ====== 121 | G = repmat(sqrt(gamma)',N,1); 122 | PhiG = Phi.*G; 123 | [U,S,V] = svd(PhiG,'econ'); 124 | 125 | [d1,d2] = size(S); 126 | if (d1 > 1) diag_S = diag(S); 127 | else diag_S = S(1); end; 128 | 129 | U_scaled = U(:,1:min(N,m)).*repmat((diag_S./(diag_S.^2 + sqrt(lambda) + 1e-16))',N,1); 130 | Xi = G'.*(V*U_scaled'); 131 | 132 | mu_old = mu; 133 | mu = Xi*Y; 134 | 135 | 136 | % *** Update hyperparameters *** 137 | gamma_old = gamma; 138 | mu2_bar = sum(abs(mu).^2,2); 139 | gamma = (mu2_bar/L).^(1-p/2); 140 | 141 | 142 | % ========= Check stopping conditions, etc. ========= 143 | count = count + 1; 144 | if (PRINT) disp(['iters: ',num2str(count),' num coeffs: ',num2str(m), ... 145 | ' gamma change: ',num2str(max(abs(gamma - gamma_old)))]); end; 146 | if (count >= MAX_ITERS) break; end; 147 | 148 | if (size(mu) == size(mu_old)) 149 | dmu = max(max(abs(mu_old - mu))); 150 | if (dmu < EPSILON) break; end; 151 | end; 152 | 153 | end; 154 | 155 | 156 | gamma_ind = sort(keep_list); 157 | gamma_est = zeros(M,1); 158 | gamma_est(keep_list,1) = gamma; 159 | 160 | % expand the final solution 161 | X = zeros(M,L); 162 | X(keep_list,:) = mu; 163 | 164 | if (PRINT) fprintf('\nM-FOCUSS finished !\n'); end 165 | return; -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/CS_Examples/spgl1_1_7/private/oneProjectorCore.c: -------------------------------------------------------------------------------- 1 | /* oneProjectorCore.c 2 | $Id: oneProjectorCore.c 800 2008-02-26 22:32:04Z mpf $ 3 | 4 | ---------------------------------------------------------------------- 5 | This file is part of SPGL1 (Spectral Projected Gradient for L1). 6 | 7 | Copyright (C) 2007 Ewout van den Berg and Michael P. Friedlander, 8 | Department of Computer Science, University of British Columbia, Canada. 9 | All rights reserved. E-mail: <{ewout78,mpf}@cs.ubc.ca>. 10 | 11 | SPGL1 is free software; you can redistribute it and/or modify it 12 | under the terms of the GNU Lesser General Public License as 13 | published by the Free Software Foundation; either version 2.1 of the 14 | License, or (at your option) any later version. 15 | 16 | SPGL1 is distributed in the hope that it will be useful, but WITHOUT 17 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 18 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General 19 | Public License for more details. 20 | 21 | You should have received a copy of the GNU Lesser General Public 22 | License along with SPGL1; if not, write to the Free Software 23 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 24 | USA 25 | ---------------------------------------------------------------------- 26 | */ 27 | 28 | #include 29 | #include 30 | #include 31 | #include /* provides DBL_EPSILON */ 32 | #include 33 | 34 | #include "oneProjectorCore.h" 35 | #include "heap.h" 36 | 37 | 38 | /* ----------------------------------------------------------------------- */ 39 | int projectI(double xPtr[], double bPtr[], double tau, int n) 40 | /* ----------------------------------------------------------------------- */ 41 | { int 42 | i, j; 43 | double 44 | b, /* Current element of vector b */ 45 | csb, /* Cumulative sum of b */ 46 | alpha = 0, 47 | soft = 0; /* Soft thresholding value */ 48 | 49 | /* The vector xPtr[] is initialized to bPtr[] prior to the function call */ 50 | 51 | /* Check if tau is essentially zero. Exit with x = 0. */ 52 | if (tau < DBL_EPSILON) { 53 | for (i = 0; i < n; i++) xPtr[i] = 0; 54 | return 0; 55 | } 56 | 57 | /* Check if ||b||_1 <= lambda. Exit with x = b. */ 58 | for (csb = 0, i = 0; i < n; i++) csb += bPtr[i]; 59 | if (csb <= tau) 60 | return 0; 61 | 62 | /* Set up the heap */ 63 | heap_build(n, xPtr); 64 | 65 | /* Initialise csb with -tau so we don't have to subtract this at every iteration */ 66 | csb = -tau; 67 | 68 | /* Determine threshold value `soft' */ 69 | for (i = n, j = 0; j < n; soft = alpha) 70 | { 71 | b = xPtr[0]; /* Get current maximum heap element */ 72 | j ++; /* Give compiler some room for optimization */ 73 | csb += b; /* Update the cumulative sum of b */ 74 | 75 | /* Move heap to next maximum value */ 76 | i = heap_del_max(i, xPtr); 77 | 78 | /* Compute the required step to satisfy the tau constraint */ 79 | alpha = csb / j; 80 | 81 | /* We are done as soon as the constraint can be satisfied */ 82 | /* without exceeding the current minimum value in `vector' b */ 83 | if (alpha >= b) 84 | break; 85 | } 86 | 87 | /* Set the solution by applying soft-thresholding with `soft' */ 88 | for (i = 0; i < n; i++) 89 | { b = bPtr[i]; 90 | if (b <= soft) 91 | xPtr[i] = 0; 92 | else xPtr[i] = b - soft; 93 | } 94 | 95 | return j; 96 | } 97 | 98 | 99 | /* ----------------------------------------------------------------------- */ 100 | int projectD(double xPtr[], double bPtr[], double dPtr[], double dOrg[], double tau, int n) 101 | /* ----------------------------------------------------------------------- */ 102 | { int 103 | i, j; 104 | double 105 | csdb, /* Cumulative sum of d.*b */ 106 | csd2, /* Cumulative sum of d.^2 */ 107 | b, /* Current element of vector b */ 108 | d, /* Current element of vector d */ 109 | bd, /* Current element of vector b / d */ 110 | alpha = 0, 111 | soft = 0; 112 | 113 | /* Check if tau is essentially zero. Exit with x = 0. */ 114 | if (tau < DBL_EPSILON) 115 | { for (i = 0; i < n; i++) xPtr[i] = 0; 116 | return 0; 117 | } 118 | 119 | /* Preliminary check on trivial solution x = b (meanwhile, scale x) */ 120 | for (csdb = 0, i = 0; i < n; i++) 121 | { d = dPtr[i]; 122 | b = xPtr[i]; 123 | csdb += (d * b); 124 | xPtr[i] = b / d; 125 | } 126 | 127 | if (csdb <= tau) 128 | { 129 | /* Reset the entries of x to b */ 130 | memcpy((void *)xPtr, (void *)bPtr, n * sizeof(double)); 131 | return 0; 132 | } 133 | 134 | /* Set up the heap (we have to sort on b./d) */ 135 | heap_build_2(n, xPtr, dPtr); 136 | 137 | /* Initialise csbd with -tau so we don't have to subtract this at every iteration */ 138 | csdb = -tau; 139 | csd2 = 0; 140 | 141 | /* Determine the threshold level `soft' */ 142 | for (i = n, j = 0; j < n; soft = alpha) 143 | { 144 | bd = xPtr[0]; /* Get current maximum b / d */ 145 | j ++; /* Give compiler some room for optimization */ 146 | d = dPtr[0]; /* Get current value of d */ 147 | d *= d; /* Compute d squared */ 148 | csd2 += d; /* Update the cumulative sum of d.*d */ 149 | csdb += bd * d; /* Update the cumulative sum of d.*b */ 150 | 151 | /* Move heap to next maximum value */ 152 | i = heap_del_max_2(i, xPtr, dPtr); 153 | 154 | /* Compute the required step to satisfy the lambda constraint */ 155 | alpha = csdb / csd2; 156 | 157 | /* We are done as soon as the constraint can be satisfied */ 158 | /* without exceeding the current minimum value of b / d */ 159 | if (alpha >= bd) break; 160 | } 161 | 162 | /* Set the solution */ 163 | for (i = 0; i < n; i++) 164 | { b = bPtr[i]; 165 | alpha = dOrg[i] * soft; /* Use the original values of d here */ 166 | if (b <= alpha) 167 | xPtr[i] = 0; 168 | else xPtr[i] = b - alpha; 169 | } 170 | 171 | return j; 172 | } 173 | -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/TMSBL_code/TMSBL_code/MSBL.m: -------------------------------------------------------------------------------- 1 | function [X,gamma_ind,gamma_est,count] = MSBL(Phi, Y, lambda, Learn_Lambda, varargin) 2 | % Sparse Bayesian Learning for Mulitple Measurement Vector (MMV) problems. 3 | % *** The version is suitable for noisy cases *** 4 | % It can also be used for single measurement vector problem without any modification. 5 | % 6 | % Command Format: 7 | % [X,gamma_ind,gamma_est,count] ... 8 | % = MSBL(Phi,Y,lambda,Learn_Lambda,'prune_gamma',1e-4,'max_iters',500,'epsilon',1e-8,'print',0); 9 | % [X,gamma_ind,gamma_est,count] = MSBL(Phi,Y, lambda, Learn_Lambda, 'prune_gamma', 1e-4); 10 | % [X,gamma_ind,gamma_est,count] = MSBL(Phi,Y, lambda, Learn_Lambda); 11 | % 12 | % ===== INPUTS ===== 13 | % Phi : N X M dictionary matrix 14 | % 15 | % Y : N X L measurement matrix 16 | % 17 | % lambda : Regularization parameter. Sometimes you can set it being the 18 | % noise variance value, which leads to sub-optimal 19 | % performance. The optimal value is generally slightly larger than the 20 | % noise variance vlaue. You need cross-validation methods or 21 | % other methods to find it. 22 | % 23 | % Learn_Lambda : If Learn_Lambda = 1, use the lambda as initial value and learn the optimal lambda 24 | % using its lambda learning rule. But note the 25 | % learning rule is not robust when SNR <= 15 dB. 26 | % If Learn_Lambda = 0, not use the lambda learning rule, but instead, use the 27 | % input lambda as the final value. 28 | % 29 | % 'PRUNE_GAMMA' : Threshold for prunning small hyperparameters gamma_i. 30 | % In noisy cases, you can set MIN_GAMMA = 1e-3 or 1e-4. 31 | % In strong noisy cases (e.g. SNR < 5 dB), set MIN_GAMMA = 1e-2 for better 32 | % performance. 33 | % [ Default value: MIN_GAMMA = 1e-3 ] 34 | % 35 | % 'MAX_ITERS' : Maximum number of iterations. 36 | % [ Default value: MAX_ITERS = 2000 ] 37 | % 38 | % 'EPSILON' : Threshold to stop the whole algorithm. 39 | % [ Default value: EPSILON = 1e-8 ] 40 | % 41 | % 'PRINT' : Display flag. If = 1: show output; If = 0: supress output 42 | % [ Default value: PRINT = 0 ] 43 | % 44 | % ===== OUTPUTS ===== 45 | % X : the estimated solution matrix, or called source matrix (size: M X L) 46 | % gamma_ind : indexes of nonzero gamma_i 47 | % gamma_est : final value of the M X 1 vector of hyperparameter values 48 | % count : number of iterations used 49 | % 50 | % 51 | % *** Reference *** 52 | % [1] David P. Wipf, Bhaskar D. Rao, An Empirical Bayesian Strategy for Solving 53 | % the Simultaneous Sparse Approximation Problem, IEEE Trans. Signal 54 | % Processing, Vol.55, No.7, 2007. 55 | % 56 | % *** Author *** 57 | % Zhilin Zhang (z4zhang@ucsd.edu) 58 | % (Modified based on David Wipf's original code such that the code is suitable for noisy cases) 59 | % 60 | % *** Version *** 61 | % 1.1 (02/12/2011) 62 | % 63 | % *** See Also *** 64 | % TSBL TMSBL 65 | % 66 | 67 | 68 | 69 | % Dimension of the Problem 70 | [N M] = size(Phi); 71 | [N L] = size(Y); 72 | 73 | % Default Control Parameters 74 | PRUNE_GAMMA = 1e-3; % threshold for prunning small hyperparameters gamma_i 75 | EPSILON = 1e-8; % threshold for stopping iteration. 76 | MAX_ITERS = 2000; % maximum iterations 77 | PRINT = 0; % don't show progress information 78 | 79 | 80 | if(mod(length(varargin),2)==1) 81 | error('Optional parameters should always go by pairs\n'); 82 | else 83 | for i=1:2:(length(varargin)-1) 84 | switch lower(varargin{i}) 85 | case 'prune_gamma' 86 | PRUNE_GAMMA = varargin{i+1}; 87 | case 'epsilon' 88 | EPSILON = varargin{i+1}; 89 | case 'print' 90 | PRINT = varargin{i+1}; 91 | case 'max_iters' 92 | MAX_ITERS = varargin{i+1}; 93 | otherwise 94 | error(['Unrecognized parameter: ''' varargin{i} '''']); 95 | end 96 | end 97 | end 98 | 99 | if (PRINT) fprintf('\nRunning MSBL ...\n'); end 100 | 101 | 102 | % Initializations 103 | gamma = ones(M,1); 104 | keep_list = [1:M]'; 105 | m = length(keep_list); 106 | mu = zeros(M,L); 107 | count = 0; % iteration count 108 | 109 | 110 | % *** Learning loop *** 111 | while (1) 112 | 113 | % *** Prune weights as their hyperparameters go to zero *** 114 | if (min(gamma) < PRUNE_GAMMA ) 115 | index = find(gamma > PRUNE_GAMMA); 116 | gamma = gamma(index); % use all the elements larger than MIN_GAMMA to form new 'gamma' 117 | Phi = Phi(:,index); % corresponding columns in Phi 118 | keep_list = keep_list(index); 119 | m = length(gamma); 120 | end; 121 | 122 | 123 | mu_old =mu; 124 | Gamma = diag(gamma); 125 | G = diag(sqrt(gamma)); 126 | 127 | % ****** estimate the solution matrix ***** 128 | [U,S,V] = svd(Phi*G,'econ'); 129 | 130 | [d1,d2] = size(S); 131 | if (d1 > 1) diag_S = diag(S); 132 | else diag_S = S(1); end; 133 | 134 | Xi = G * V * diag((diag_S./(diag_S.^2 + lambda + 1e-16))) * U'; 135 | mu = Xi * Y; 136 | 137 | % *** Update hyperparameters, i.e. Eq(18) in the reference *** 138 | gamma_old = gamma; 139 | mu2_bar = sum(abs(mu).^2,2)/L; 140 | 141 | Sigma_w_diag = real( gamma - (sum(Xi'.*(Phi*Gamma)))'); 142 | gamma = mu2_bar + Sigma_w_diag; 143 | 144 | % ***** the lambda learning rule ***** 145 | % You can use it to estimate the lambda when SNR >= 15 dB. But when SNR < 15 dB, 146 | % you'd better use other methods to estimate the lambda, since it is not robust 147 | % in strongly noisy cases. 148 | if Learn_Lambda == 1 149 | lambda = (norm(Y - Phi * mu,'fro')^2/L)/(N-m + sum(Sigma_w_diag./gamma_old)); 150 | end; 151 | 152 | 153 | % *** Check stopping conditions, etc. *** 154 | count = count + 1; 155 | if (PRINT) disp(['iters: ',num2str(count),' num coeffs: ',num2str(m), ... 156 | ' gamma change: ',num2str(max(abs(gamma - gamma_old)))]); end; 157 | if (count >= MAX_ITERS) break; end; 158 | 159 | if (size(mu) == size(mu_old)) 160 | dmu = max(max(abs(mu_old - mu))); 161 | if (dmu < EPSILON) break; end; 162 | end; 163 | 164 | end; 165 | 166 | 167 | % Expand hyperparameters 168 | gamma_ind = sort(keep_list); 169 | gamma_est = zeros(M,1); 170 | gamma_est(keep_list,1) = gamma; 171 | 172 | % expand the final solution 173 | X = zeros(M,L); 174 | X(keep_list,:) = mu; 175 | 176 | if (PRINT) fprintf('\nFinish running ...\n'); end 177 | return; 178 | 179 | 180 | 181 | -------------------------------------------------------------------------------- /ssim.m: -------------------------------------------------------------------------------- 1 | function [mssim, ssim_map] = ssim(img1, img2, K, window, L) 2 | img1=rgb2gray(img1); 3 | img2=rgb2gray(img2); 4 | % ======================================================================== 5 | % SSIM Index with automatic downsampling, Version 1.0 6 | % Copyright(c) 2009 Zhou Wang 7 | % All Rights Reserved. 8 | % 9 | % ---------------------------------------------------------------------- 10 | % Permission to use, copy, or modify this software and its documentation 11 | % for educational and research purposes only and without fee is hereby 12 | % granted, provided that this copyright notice and the original authors' 13 | % names appear on all copies and supporting documentation. This program 14 | % shall not be used, rewritten, or adapted as the basis of a commercial 15 | % software or hardware product without first obtaining permission of the 16 | % authors. The authors make no representations about the suitability of 17 | % this software for any purpose. It is provided "as is" without express 18 | % or implied warranty. 19 | %---------------------------------------------------------------------- 20 | % 21 | % This is an implementation of the algorithm for calculating the 22 | % Structural SIMilarity (SSIM) index between two images 23 | % 24 | % Please refer to the following paper and the website with suggested usage 25 | % 26 | % Z. Wang, A. C. Bovik, H. R. Sheikh, and E. P. Simoncelli, "Image 27 | % quality assessment: From error visibility to structural similarity," 28 | % IEEE Transactios on Image Processing, vol. 13, no. 4, pp. 600-612, 29 | % Apr. 2004. 30 | % 31 | % http://www.ece.uwaterloo.ca/~z70wang/research/ssim/ 32 | % 33 | % Note: This program is different from ssim_index.m, where no automatic 34 | % downsampling is performed. (downsampling was done in the above paper 35 | % and was described as suggested usage in the above website.) 36 | % 37 | % Kindly report any suggestions or corrections to zhouwang@ieee.org 38 | % 39 | %---------------------------------------------------------------------- 40 | % 41 | %Input : (1) img1: the first image being compared 42 | % (2) img2: the second image being compared 43 | % (3) K: constants in the SSIM index formula (see the above 44 | % reference). defualt value: K = [0.01 0.03] 45 | % (4) window: local window for statistics (see the above 46 | % reference). default widnow is Gaussian given by 47 | % window = fspecial('gaussian', 11, 1.5); 48 | % (5) L: dynamic range of the images. default: L = 255 49 | % 50 | %Output: (1) mssim: the mean SSIM index value between 2 images. 51 | % If one of the images being compared is regarded as 52 | % perfect quality, then mssim can be considered as the 53 | % quality measure of the other image. 54 | % If img1 = img2, then mssim = 1. 55 | % (2) ssim_map: the SSIM index map of the test image. The map 56 | % has a smaller size than the input images. The actual size 57 | % depends on the window size and the downsampling factor. 58 | % 59 | %Basic Usage: 60 | % Given 2 test images img1 and img2, whose dynamic range is 0-255 61 | % 62 | % [mssim, ssim_map] = ssim(img1, img2); 63 | % 64 | %Advanced Usage: 65 | % User defined parameters. For example 66 | % 67 | % K = [0.05 0.05]; 68 | % window = ones(8); 69 | % L = 100; 70 | % [mssim, ssim_map] = ssim(img1, img2, K, window, L); 71 | % 72 | %Visualize the results: 73 | % 74 | % mssim %Gives the mssim value 75 | % imshow(max(0, ssim_map).^4) %Shows the SSIM index map 76 | %======================================================================== 77 | 78 | 79 | if (nargin < 2 | nargin > 5) 80 | ssim_index = -Inf; 81 | ssim_map = -Inf; 82 | return; 83 | end 84 | 85 | if (size(img1) ~= size(img2)) 86 | ssim_index = -Inf; 87 | ssim_map = -Inf; 88 | return; 89 | end 90 | 91 | [M N] = size(img1); 92 | 93 | if (nargin == 2) 94 | if ((M < 11) | (N < 11)) 95 | ssim_index = -Inf; 96 | ssim_map = -Inf; 97 | return 98 | end 99 | window = fspecial('gaussian', 11, 1.5); % 100 | K(1) = 0.01; % default settings 101 | K(2) = 0.03; % 102 | L = 255; % 103 | end 104 | 105 | if (nargin == 3) 106 | if ((M < 11) | (N < 11)) 107 | ssim_index = -Inf; 108 | ssim_map = -Inf; 109 | return 110 | end 111 | window = fspecial('gaussian', 11, 1.5); 112 | L = 255; 113 | if (length(K) == 2) 114 | if (K(1) < 0 | K(2) < 0) 115 | ssim_index = -Inf; 116 | ssim_map = -Inf; 117 | return; 118 | end 119 | else 120 | ssim_index = -Inf; 121 | ssim_map = -Inf; 122 | return; 123 | end 124 | end 125 | 126 | if (nargin == 4) 127 | [H W] = size(window); 128 | if ((H*W) < 4 | (H > M) | (W > N)) 129 | ssim_index = -Inf; 130 | ssim_map = -Inf; 131 | return 132 | end 133 | L = 255; 134 | if (length(K) == 2) 135 | if (K(1) < 0 | K(2) < 0) 136 | ssim_index = -Inf; 137 | ssim_map = -Inf; 138 | return; 139 | end 140 | else 141 | ssim_index = -Inf; 142 | ssim_map = -Inf; 143 | return; 144 | end 145 | end 146 | 147 | if (nargin == 5) 148 | [H W] = size(window); 149 | if ((H*W) < 4 | (H > M) | (W > N)) 150 | ssim_index = -Inf; 151 | ssim_map = -Inf; 152 | return 153 | end 154 | if (length(K) == 2) 155 | if (K(1) < 0 | K(2) < 0) 156 | ssim_index = -Inf; 157 | ssim_map = -Inf; 158 | return; 159 | end 160 | else 161 | ssim_index = -Inf; 162 | ssim_map = -Inf; 163 | return; 164 | end 165 | end 166 | 167 | 168 | img1 = double(img1); 169 | img2 = double(img2); 170 | 171 | % automatic downsampling 172 | f = max(1,round(min(M,N)/256)); 173 | %downsampling by f 174 | %use a simple low-pass filter 175 | if(f>1) 176 | lpf = ones(f,f); 177 | lpf = lpf/sum(lpf(:)); 178 | img1 = imfilter(img1,lpf,'symmetric','same'); 179 | img2 = imfilter(img2,lpf,'symmetric','same'); 180 | 181 | img1 = img1(1:f:end,1:f:end); 182 | img2 = img2(1:f:end,1:f:end); 183 | end 184 | 185 | C1 = (K(1)*L)^2; 186 | C2 = (K(2)*L)^2; 187 | window = window/sum(sum(window)); 188 | 189 | mu1 = filter2(window, img1, 'valid'); 190 | mu2 = filter2(window, img2, 'valid'); 191 | mu1_sq = mu1.*mu1; 192 | mu2_sq = mu2.*mu2; 193 | mu1_mu2 = mu1.*mu2; 194 | sigma1_sq = filter2(window, img1.*img1, 'valid') - mu1_sq; 195 | sigma2_sq = filter2(window, img2.*img2, 'valid') - mu2_sq; 196 | sigma12 = filter2(window, img1.*img2, 'valid') - mu1_mu2; 197 | 198 | if (C1 > 0 & C2 > 0) 199 | ssim_map = ((2*mu1_mu2 + C1).*(2*sigma12 + C2))./((mu1_sq + mu2_sq + C1).*(sigma1_sq + sigma2_sq + C2)); 200 | else 201 | numerator1 = 2*mu1_mu2 + C1; 202 | numerator2 = 2*sigma12 + C2; 203 | denominator1 = mu1_sq + mu2_sq + C1; 204 | denominator2 = sigma1_sq + sigma2_sq + C2; 205 | ssim_map = ones(size(mu1)); 206 | index = (denominator1.*denominator2 > 0); 207 | ssim_map(index) = (numerator1(index).*numerator2(index))./(denominator1(index).*denominator2(index)); 208 | index = (denominator1 ~= 0) & (denominator2 == 0); 209 | ssim_map(index) = numerator1(index)./denominator1(index); 210 | end 211 | 212 | mssim = mean2(ssim_map); 213 | 214 | return -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/CS_Examples/spgl1_1_7/private/heap.c: -------------------------------------------------------------------------------- 1 | /* heap.c 2 | $Id $ 3 | 4 | ---------------------------------------------------------------------- 5 | This file is part of SPGL1 (Spectral Projected Gradient for L1). 6 | 7 | Copyright (C) 2007 Ewout van den Berg and Michael P. Friedlander, 8 | Department of Computer Science, University of British Columbia, Canada. 9 | All rights reserved. E-mail: <{ewout78,mpf}@cs.ubc.ca>. 10 | 11 | SPGL1 is free software; you can redistribute it and/or modify it 12 | under the terms of the GNU Lesser General Public License as 13 | published by the Free Software Foundation; either version 2.1 of the 14 | License, or (at your option) any later version. 15 | 16 | SPGL1 is distributed in the hope that it will be useful, but WITHOUT 17 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 18 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General 19 | Public License for more details. 20 | 21 | You should have received a copy of the GNU Lesser General Public 22 | License along with SPGL1; if not, write to the Free Software 23 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 24 | USA 25 | ---------------------------------------------------------------------- 26 | */ 27 | 28 | #include 29 | 30 | #include "heap.h" 31 | 32 | 33 | /* ======================================================================= */ 34 | /* H E L P E R F U N C T I O N S */ 35 | /* ======================================================================= */ 36 | 37 | 38 | /* 39 | \brief Perform the "sift" operation for the heap-sort algorithm. 40 | 41 | A heap is a collection of items arranged in a binary tree. Each 42 | child node is smaller than or equal to its parent. If x[k] is the 43 | parent, than its children are x[2k+1] and x[2k+2]. 44 | 45 | This routine promotes ("sifts up") children that are larger than 46 | their parents. Thus, the largest element of the heap is the root node. 47 | 48 | \param[in] root The root index from which to start sifting. 49 | \param[in] lastChild The last child (largest node index) in the sift operation. 50 | \param[in,out] x The array to be sifted. 51 | */ 52 | void heap_sift( int root, int lastChild, double x[] ) 53 | { 54 | int child; 55 | 56 | for (; (child = (root * 2) + 1) <= lastChild; root = child) { 57 | 58 | if (child < lastChild) 59 | if ( x[child] < x[child+1] ) 60 | child++; 61 | 62 | if ( x[child] <= x[root] ) 63 | break; 64 | 65 | swap_double( x[root], x[child] ); 66 | } 67 | } 68 | 69 | 70 | /*! 71 | \brief Perform the "sift" operation for the heap-sort algorithm. 72 | 73 | A heap is a collection of items arranged in a binary tree. Each 74 | child node is smaller than or equal to its parent. If x[k] is the 75 | parent, than its children are x[2k+1] and x[2k+2]. 76 | 77 | This routine promotes ("sifts up") children that are larger than 78 | their parents. Thus, the largest element of the heap is the root node. 79 | 80 | Elements in y are associated with those in x and are reordered accordingly. 81 | 82 | \param[in] root The root index from which to start sifting. 83 | \param[in] lastChild The last child (largest node index) in the sift operation. 84 | \param[in,out] x The array to be sifted. 85 | \param[in,out] y The array to be sifted accordingly. 86 | */ 87 | void heap_sift_2( int root, int lastChild, double x[], double y[] ) 88 | { 89 | int child; 90 | 91 | for (; (child = (root * 2) + 1) <= lastChild; root = child) { 92 | 93 | if (child < lastChild) 94 | if ( x[child] < x[child+1] ) 95 | child++; 96 | 97 | if ( x[child] <= x[root] ) 98 | break; 99 | 100 | swap_double( x[root], x[child] ); 101 | swap_double( y[root], y[child] ); 102 | } 103 | } 104 | 105 | 106 | /*! 107 | \brief Discard the largest element and contract the heap. 108 | 109 | On entry, the numElems of the heap are stored in x[0],...,x[numElems-1], 110 | and the biggest element is x[0]. The following operations are performed: 111 | -# Swap the first and last elements of the heap 112 | -# Shorten the length of the heap by one. 113 | -# Restore the heap property to the contracted heap. 114 | This effectively makes x[0] the next largest element 115 | in the list. 116 | 117 | \param[in] numElems The number of elements in the current heap. 118 | \param[in,out] x The array to be modified. 119 | 120 | \return The number of elements in the heap after it has been contracted. 121 | */ 122 | int heap_del_max(int numElems, double x[]) 123 | { 124 | int lastChild = numElems - 1; 125 | 126 | assert(numElems > 0); 127 | 128 | /* Swap the largest element with the lastChild. */ 129 | swap_double(x[0], x[lastChild]); 130 | 131 | /* Contract the heap size, thereby discarding the largest element. */ 132 | lastChild--; 133 | 134 | /* Restore the heap property of the contracted heap. */ 135 | heap_sift(0, lastChild, x); 136 | 137 | return numElems - 1; 138 | } 139 | 140 | 141 | /*! 142 | \brief Discard the largest element of x and contract the heaps. 143 | 144 | On entry, the numElems of the heap are stored in x[0],...,x[numElems-1], 145 | and the largest element is x[0]. The following operations are performed: 146 | -# Swap the first and last elements of both heaps 147 | -# Shorten the length of the heaps by one. 148 | -# Restore the heap property to the contracted heap x. 149 | This effectively makes x[0] the next largest element 150 | in the list. 151 | 152 | \param[in] numElems The number of elements in the current heap. 153 | \param[in,out] x The array to be modified. 154 | \param[in,out] y The array to be modified accordingly 155 | 156 | \return The number of elements in each heap after they have been contracted. 157 | */ 158 | int heap_del_max_2( int numElems, double x[], double y[] ) 159 | { 160 | int lastChild = numElems - 1; 161 | 162 | assert(numElems > 0); 163 | 164 | /* Swap the largest element with the lastChild. */ 165 | swap_double( x[0], x[lastChild] ); 166 | swap_double( y[0], y[lastChild] ); 167 | 168 | /* Contract the heap size, thereby discarding the largest element. */ 169 | lastChild--; 170 | 171 | /* Restore the heap property of the contracted heap. */ 172 | heap_sift_2( 0, lastChild, x, y ); 173 | 174 | return numElems - 1; 175 | } 176 | 177 | 178 | /*! 179 | 180 | \brief Build a heap by adding one element at a time. 181 | 182 | \param[in] n The length of x and ix. 183 | \param[in,out] x The array to be heapified. 184 | 185 | */ 186 | void heap_build( int n, double x[] ) 187 | { 188 | int i; 189 | 190 | for (i = n/2; i >= 0; i--) heap_sift( i, n-1, x ); 191 | } 192 | 193 | 194 | /*! 195 | 196 | \brief Build a heap by adding one element at a time. 197 | 198 | \param[in] n The length of x and ix. 199 | \param[in,out] x The array to be heapified. 200 | \param[in,out] y The array to be reordered in sync. with x. 201 | 202 | */ 203 | void heap_build_2( int n, double x[], double y[] ) 204 | { 205 | int i; 206 | 207 | for (i = n/2; i >= 0; i--) heap_sift_2( i, n-1, x, y ); 208 | } 209 | -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/TMSBL_code/TMSBL_code/demo_time_varying.m: -------------------------------------------------------------------------------- 1 | % Show how to use T-MSBL in the time-varying sparsity model. 2 | % To show the results by KF-CS and LS-CS, you need to download the codes 3 | % from: http://home.engineering.iastate.edu/~namrata/research/LSCS_KFCS_code.zip 4 | % 5 | % However, you can see the comparison in the following reference: 6 | % 7 | % Z. Zhang, B. D. Rao, Exploiting Correlation in Sparse Signal Recovery Problems: 8 | % Multiple Measurement Vectors, Block Sparsity, and Time-Varying Sparsity 9 | % ICML 2011 Workshop on Structured Sparsity: Learning and Inference 10 | % 11 | % Or similar comparison in my blogs: 12 | % 13 | % http://marchonscience.blogspot.com/2011/04/is-mmv-more-suitable-for-dynamic.html 14 | % http://marchonscience.blogspot.com/2011/04/is-mmv-more-suitable-for-dynamic_17.html 15 | % http://marchonscience.blogspot.com/2011/04/is-mmv-more-suitable-for-dynamic_18.html 16 | % 17 | % Feel free to send any questions to me: z4zhang@ucsd.edu 18 | % May 19, 2010 19 | 20 | clear; clc; close all; 21 | 22 | 23 | L = 50; % snapshot number 24 | M = 256; % column number of the dictionary matrix 25 | N = 60; % row number of the dictionary matrix 26 | K = 15; % number of the nonzero coefficients at the initial stage 27 | addNZ = 10; % added number of nonzero coefficients at each addition time 28 | segLen = 20; % duration of each added coefficient 29 | remNZ = 5; % removed number of nonzero coefficients at each deletion time 30 | 31 | iteration = 20; % independently repeat the experiments to see the averaged results 32 | 33 | for it = 1 : iteration 34 | fprintf('Trial #%d\n',it); 35 | 36 | % generate the dictionary matrix from Gaussian distribution 37 | Phi = randn(N,M); 38 | Phi = Phi./(ones(N,1)*sqrt(sum(Phi.^2))); 39 | 40 | % generate the K time series existing during the whole time 41 | beta = 1- rand(K,1)*0.3; % randomly choose temporal correlation of 42 | % time series of each coefficient 43 | longS(:,1) = randn(K,1); 44 | for i = 2 : L*20 45 | longS(:,i) = beta .* longS(:,i-1) + sqrt(1-beta.^2).*(randn(K,1)); 46 | end 47 | longS = longS(:,end-L+1:end); % stable time series 48 | longS = longS./( sqrt(sum(longS.^2,2)) * ones(1,L) ); 49 | 50 | % generate time series of coefficients 51 | D = addNZ * 3; % possible largest number of nonzero coefficients 52 | beta = 1- rand(D,1)*0.3; % randomly choose temporal correlation of 53 | % time series of each coefficient 54 | pool(:,1) = randn(D,1); 55 | for i = 2 : segLen*20 56 | pool(:,i) = beta .* pool(:,i-1) + sqrt(1-beta.^2).*(randn(D,1)); 57 | end 58 | pool = pool(:,end-segLen+1:end); % stable time series 59 | pool = pool./( sqrt(sum(pool.^2,2)) * ones(1,segLen) ); 60 | 61 | % initial stage of a time series should have increasing magnitude 62 | pool(:,[1,2,3]) = pool(:,[1,2,3]) .* (ones(D,1) * [0.2, 0.6, 1]); 63 | 64 | % when a time series disappears, the magnitude should be decreasing 65 | pool(:,[segLen-2,segLen-1,segLen]) = pool(:,[segLen-2,segLen-1,segLen]).*(ones(D,1)*[1,0.6,0.2]); 66 | 67 | % select K time series at L=1, 68 | ind = randperm(M); 69 | indice0 = ind(1:K); 70 | Wgen = zeros(M,L); 71 | Wgen(indice0,:) = longS; 72 | 73 | % select another addNZ time series at L = 16 74 | restLoc = setdiff([1:M],indice0); 75 | ind = randperm(length(restLoc)); 76 | indice1 = restLoc(ind(1:addNZ)); 77 | Wgen(indice1,[16:15+segLen]) = pool(1:addNZ,:); 78 | 79 | % delete existing time series at L=26 80 | candidateLoc = union(indice0,indice1); 81 | ind_rem = randperm(K+addNZ); 82 | indice_rem = candidateLoc(ind_rem(1:remNZ)); 83 | Wgen(indice_rem,[24:end]) = Wgen(indice_rem,[24:end]).*(ones(remNZ,1)*[0.8,0.4,zeros(1,25)]); 84 | 85 | % select another addNZ time series at L = 31 86 | restLoc2 = setdiff([1:M],union(indice0,indice1)); 87 | ind2 = randperm(length(restLoc2)); 88 | indice2 = restLoc2(ind2(1:addNZ)); 89 | Wgen(indice2,[31:30+segLen]) = pool(addNZ+1:addNZ*2,:); 90 | 91 | % % See the pictures of the generated signals 92 | % imagesc(Wgen); colorbar; 93 | 94 | % noiseless signal 95 | signal = Phi * Wgen; 96 | 97 | % observation noise 98 | stdnoise = 0.01; 99 | noise = randn(N,L) * stdnoise; 100 | 101 | % noisy signal 102 | Y = signal + noise; 103 | 104 | % compute total SNR 105 | SNR_rec(it) = 20*log10(norm(signal,'fro')/norm(noise,'fro')); 106 | 107 | 108 | % ===================Run T-MSBL step by 5 ================= 109 | tic; 110 | X_tsbl5 = []; 111 | for i=1:10 112 | 113 | % According to the SNR range, choose suitable input arguments 114 | % See the codes for details 115 | [X_tsbl1] = TMSBL(Phi, Y(:,[(i-1)*5+1:i*5]), 'noise','small'); 116 | 117 | 118 | X_tsbl5 = [X_tsbl5,X_tsbl1]; 119 | end 120 | TIME_tsbl5(it) = toc; 121 | 122 | for t = 1:L 123 | err_tsbl5(it,t) = norm( Wgen(:,t)-X_tsbl5(:,t) )^2; 124 | energy(it,t) = norm( Wgen(:,t) )^2; 125 | end 126 | 127 | 128 | % =================== Run T-MSBL step by 2 ================= 129 | tic; 130 | X_tsbl2 = []; 131 | for i=1:25 132 | % According to the SNR range, choose suitable input arguments 133 | % See the codes for details 134 | [X_tsbl1] = TMSBL(Phi, Y(:,[(i-1)*2+1:i*2]), 'noise','small'); 135 | 136 | X_tsbl2 = [X_tsbl2,X_tsbl1]; 137 | end 138 | TIME_tsbl2(it) = toc; 139 | 140 | for t = 1:L 141 | err_tsbl2(it,t) = norm( Wgen(:,t)-X_tsbl2(:,t) )^2; 142 | end 143 | 144 | 145 | 146 | % ===================Run MSBL steps by 5================= 147 | lambda = std(Y(:,1))*1e-2; 148 | Learn_Lambda = 1; 149 | 150 | tic; 151 | X_msbl5 = []; 152 | for i = 1 : 10 153 | [X_msbl1,gamma2,gamma_used2,count2] = MSBL(Phi, Y(:,[(i-1)*5+1:i*5]), lambda, Learn_Lambda); 154 | 155 | X_msbl5 = [X_msbl5,X_msbl1]; 156 | end 157 | 158 | TIME_msbl5(it) = toc; 159 | 160 | for t = 1:L 161 | err_msbl5(it,t) = norm( Wgen(:,t)-X_msbl5(:,t) )^2; 162 | end 163 | 164 | % ===================Run MSBL2 steps by 2================= 165 | lambda = std(Y(:,1))*1e-2; 166 | Learn_Lambda = 1; 167 | tic; 168 | X_msbl2 = []; 169 | for i = 1 : 25 170 | [X_msbl1,gamma2,gamma_used2,count2] = MSBL(Phi, Y(:,[(i-1)*2+1:i*2]), lambda, Learn_Lambda); 171 | X_msbl2 = [X_msbl2,X_msbl1]; 172 | end 173 | 174 | TIME_msbl2(it) = toc; 175 | 176 | for t = 1:L 177 | err_msbl2(it,t) = norm( Wgen(:,t)-X_msbl2(:,t) )^2; 178 | end 179 | 180 | 181 | % % ===================Run KF-CS =============== 182 | % tot = 50; n = N; m = M; lambdap = 0.1; 183 | % global n 184 | % global m 185 | % global tot 186 | % global lambdap 187 | % global tot 188 | % Pi0 = 0.8 * eye(M); 189 | % Q = 0.8 * eye(M); 190 | % R = stdnoise^2 * eye(N); 191 | % tic; 192 | % [X_kfcs,T_hat] = kfcs_full(Y,Pi0,Phi,Q,R); 193 | % TIME_kfcs(it) = toc; 194 | % 195 | % for t = 1:L 196 | % err_kfcs(it,t) = norm( Wgen(:,t)-X_kfcs(:,t) )^2; 197 | % end 198 | % 199 | % %========================== LS-CS ===================== 200 | % tic; 201 | % [x_upd_lscs,T_hat_lscs,x_upd_csres] = lscs_full(Y,Pi0,Phi,Q,R); 202 | % TIME_LSCS(it) = toc; 203 | % for t = 1:tot 204 | % err_lscs(it,t) = norm( Wgen(:,t)-x_upd_lscs(:,t) )^2; 205 | % end 206 | 207 | save data_demo_timevarying; 208 | end 209 | 210 | figure(1); 211 | semilogy(mean(err_tsbl2,1)./mean(energy,1),'r','linewidth',2.5); 212 | hold on;semilogy(mean(err_tsbl5,1)./mean(energy,1),'r-.','linewidth',2.5); 213 | hold on;semilogy(mean(err_msbl2,1)./mean(energy,1),'linewidth',2.5); 214 | hold on;semilogy(mean(err_msbl5,1)./mean(energy,1),'-.','linewidth',2.5); 215 | % hold on;semilogy(mean(err_kfcs,1)./mean(energy,1),'k','linewidth',2.5); 216 | % hold on;semilogy(mean(err_lscs,1)./mean(energy,1),'c','linewidth',2.5); 217 | legend('T-MSBL steps by 2','T-MSBL steps by 5','M-SBL steps by 2','M-SBL steps by 5'); 218 | ylabel('\bf\fontsize{20}Normalized MSE'); 219 | xlabel('\bf\fontsize{20}Time'); 220 | 221 | 222 | -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/TMSBL_code/TMSBL_code/demo.m: -------------------------------------------------------------------------------- 1 | % Goal: Compare T-MSBL, T-SBL, MSBL, MFOCUSS 2 | % In this demo, you will see T-MSBL and T-SBL outperform other two 3 | % algorithms. Particularly, please note that T-MSBL and T-SBL 4 | % adaptively learn the regularization parameter lambda, while MSBL 5 | % freezes lambda to the true noise variance (which is a near 6 | % optimal value). When T-MSBL and T-SBL freeze their lambda to the 7 | % optimal values, their performance can be further better. 8 | % 9 | % This demo also shows the lambda learning rule of MSBL is very 10 | % poor. It should not be used in low SNR cases. 11 | % 12 | % Author: Zhilin Zhang (z4zhang@ucsd.edu) 13 | % Date: May 20, 2011 14 | % Version: 1.1 15 | 16 | 17 | clear all; 18 | 19 | % Experiment Assignment 20 | run_TMSBL = 1; % Run T-MSBL 21 | run_TSBL = 1; % Run T-SBL 22 | run_MSBL = 1; % Run MSBL 23 | run_FOCUSS= 1; % Run M-FOCUSS 24 | iterNum = 50; % Trial number (i.e. number of repeating the experiment) 25 | % For statistical result, iterNum should not less than 50 26 | 27 | % Problem dimension 28 | N = 30; % Row number of the dictionary matrix 29 | M = N * 5; % Column number of the dictionary matrix 30 | L = 3; % Number of measurement vectors 31 | K = 7; % Number of nonzero rows (i.e. source number) in the solution matrix 32 | beta = ones(K,1)*0.9; % Temporal correlation of each nonzero row in the solution matrix. 33 | % In biomedical applications, such as EEG, MRI,etc, such temporal 34 | % correlation could be higher than 0.95 35 | 36 | %==================================================================== 37 | SNR = 10; % Note: When you change the SNR, you may need to accordingly change 38 | % the input arguments for each algorithm 39 | %==================================================================== 40 | 41 | for it = 1 : iterNum 42 | fprintf('\n\nTrial #%d:\n',it); 43 | 44 | % Generate dictionary matrix with columns draw uniformly from the surface of a unit hypersphere 45 | Phi = randn(N,M); 46 | Phi = Phi./(ones(N,1)*sqrt(sum(Phi.^2))); 47 | 48 | % Generate the K nonzero rows, each row being an AR(1) process. All the AR(1) 49 | % processes have different AR coefficients, which are randomly chosen from [0.7,1) 50 | nonzeroW(:,1) = randn(K,1); 51 | for i = 2 : L*100 52 | nonzeroW(:,i) = beta .* nonzeroW(:,i-1) + sqrt(1-beta.^2).*(ones(K,1).*randn(K,1)); 53 | end 54 | nonzeroW = nonzeroW(:,end-L+1:end); % Ensure the AR processes are stable 55 | 56 | % Normalize each row 57 | nonzeroW = nonzeroW./( sqrt(sum(nonzeroW.^2,2)) * ones(1,L) ); 58 | 59 | % Rescale each row such that the squared row-norm distributes in [1,scalefactor] 60 | scalefactor = 3; 61 | mag = rand(1,K); mag = mag - min(mag); 62 | mag = mag/(max(mag))*(scalefactor-1) + 1; 63 | nonzeroW = diag(sqrt(mag)) * nonzeroW; 64 | 65 | % Locations of nonzero rows are randomly chosen 66 | ind = randperm(M); 67 | indice = ind(1:K); 68 | Wgen = zeros(M,L); 69 | Wgen(indice,:) = nonzeroW; 70 | 71 | % Noiseless signal 72 | signal = Phi * Wgen; 73 | 74 | % Observation noise 75 | stdnoise = std(reshape(signal,N*L,1))*10^(-SNR/20); 76 | noise = randn(N,L) * stdnoise; 77 | 78 | % Noisy signal 79 | Y = signal + noise; 80 | 81 | 82 | %=================== T-MSBL (adaptively learn the lambda) ==================== 83 | if run_TMSBL == 1, 84 | tic; 85 | 86 | % Depends on the SNR, choosing suitable values for input arguments: 87 | % If no noise, Weight = TMSBL(Phi, Y, 'noise','no'); 88 | % If SNR >= 23 dB, Weight = TMSBL(Phi, Y, 'noise','small'); 89 | % If 6dB < SNR <= 22 dB, Weight = TMSBL(Phi, Y, 'noise','mild'); 90 | % If SNR <= 6 dB, Weight = TMSBL(Phi, Y, 'noise','large'); 91 | % Note that you need not to know exactly the SNR value. Just roughly estimate it. 92 | % For example, when the true SNR is 6 dB, either set 'noise'='mild' or 93 | % 'noise'='large' has the similar performance. 94 | % 95 | % Note: See the TMSBL code for details on input arguments ans set your 96 | % own values for specific problems. 97 | 98 | Weight1 = TMSBL(Phi, Y, 'noise','mild'); 99 | 100 | time1 = toc; 101 | TIME1(it) = time1; 102 | 103 | 104 | % failure rate: F1 = 1: perfect recovery; F1 = 0: worst recovery 105 | F1 = perfSupp(Weight1,indice,'firstlargest', K); 106 | fail_TMSBL(it) = (F1~=1); 107 | 108 | % Mean Square Error (MSE) 109 | mse_TMSBL(it) = (norm(Wgen - Weight1,'fro')/norm(Wgen,'fro'))^2; 110 | 111 | fprintf(' T-MSBL(learn lambda): time = %5.2f; Findex = %3.2f, Ave-MSE = %3.2f%%; Ave-Time = %4.3f\n',... 112 | time1,F1,mean(mse_TMSBL)*100,mean(TIME1)); 113 | end 114 | %==================================================================== 115 | 116 | 117 | 118 | %======================= T-SBL (adaptively learn the lambda)========== 119 | if run_TSBL == 1, 120 | % Similar to TMSBL, see the code for details about the input argument 121 | tic; 122 | Weight2 = TSBL(Phi, Y, 'SNR','low'); 123 | time2 = toc; 124 | TIME2(it) = time2; 125 | 126 | 127 | % failure rate: F2 = 1: perfect recovery; F2 = 0: worst recovery 128 | F2 = perfSupp(Weight2,indice,'firstlargest', K); 129 | fail_TSBL(it) = (F2~=1); 130 | 131 | % Mean Square Error (MSE) 132 | mse_TSBL(it) = (norm(Wgen - Weight2,'fro')/norm(Wgen,'fro'))^2; 133 | 134 | fprintf(' T-SBL(learn lambda): time = %5.2f; Findex = %3.2f, Ave-MSE = %3.2f%%; Ave-Time = %4.3f\n',... 135 | time2,F2,mean(mse_TSBL)*100,mean(TIME2)); 136 | end 137 | 138 | 139 | 140 | 141 | %================== MSBL (adaptively learn the lambda) ======================= 142 | lambda = 1e-2; % Initial value for the regularization parameter. 143 | Learn_Lambda = 1; % Using its lambda learning rule 144 | 145 | if run_MSBL == 1, 146 | tic; 147 | Weight3 = MSBL(Phi,Y, lambda, Learn_Lambda); 148 | time3 = toc; 149 | TIME3(it) = time3; 150 | 151 | 152 | % Failure rate 153 | F3 = perfSupp(Weight3,indice,'firstlargest', K); 154 | fail_MSBL(it) = (F3~=1); 155 | 156 | % MSE 157 | perf_MSBL(it) = (norm(Wgen - Weight3,'fro')/norm(Wgen,'fro'))^2; 158 | 159 | fprintf(' MSBL(learn lambda): time = %5.2f; Findex = %3.2f, Ave-MSE = %3.2f%%; Ave-Time = %4.3f\n',... 160 | time3,F3,mean(perf_MSBL)*100,mean(TIME3)); 161 | 162 | 163 | % now MSBL using the true noise variance as the lambda value and freeze it 164 | lambda0 = stdnoise^2; 165 | Learn_Lambda0 = 0; % do not use its lambda learning rule 166 | tic; 167 | Weight33 = MSBL(Phi,Y, lambda0, Learn_Lambda0); 168 | time33 = toc; 169 | TIME33(it) = time33; 170 | 171 | 172 | % Failure rate 173 | F33 = perfSupp(Weight33,indice,'firstlargest', K); 174 | fail_MSBL33(it) = (F33~=1); 175 | 176 | % MSE 177 | perf_MSBL33(it) = (norm(Wgen - Weight33,'fro')/norm(Wgen,'fro'))^2; 178 | 179 | fprintf('MSBL(lambda=noise var): time = %5.2f; Findex = %3.2f, Ave-MSE = %3.2f%%; Ave-Time = %4.3f\n',... 180 | time33,F33,mean(perf_MSBL33)*100,mean(TIME33)); 181 | 182 | 183 | end 184 | 185 | 186 | % ====================== MFOCUSS with near-optimal regularization ========= 187 | if run_FOCUSS == 1, 188 | tic; 189 | lambda_opt = stdnoise^2; % use the noise variance 190 | Weight4 = MFOCUSS(Phi, Y, lambda_opt); 191 | 192 | time4 = toc; 193 | TIME4(it) = time4; 194 | 195 | 196 | % Failure rate 197 | F4 = perfSupp(Weight4,indice,'firstlargest', K); 198 | fail_MFOCUSS(it) = (F4~=1); 199 | 200 | % MSE 201 | perf_MFOCUSS(it) = (norm(Wgen - Weight4,'fro')/norm(Wgen,'fro'))^2; 202 | 203 | fprintf('MFOCUSS(lambda=noise var): time = %5.2f; Findex = %3.2f, Ave-MSE = %3.2f%%; Ave-Time = %4.3f\n',... 204 | time4,F4,mean(perf_MFOCUSS)*100,mean(TIME4)); 205 | end 206 | 207 | end 208 | 209 | 210 | 211 | 212 | -------------------------------------------------------------------------------- /encryption_based_on_CS_chaotic/CS_Examples/spgl1_1_7/private/lsqr.m: -------------------------------------------------------------------------------- 1 | function [ x, istop, itn, r1norm, r2norm, anorm, acond, arnorm, xnorm, var ]... 2 | = lsqr( m, n, A, b, damp, atol, btol, conlim, itnlim, show ) 3 | % 4 | % [ x, istop, itn, r1norm, r2norm, anorm, acond, arnorm, xnorm, var ]... 5 | % = lsqr( m, n, A, b, damp, atol, btol, conlim, itnlim, show ); 6 | % 7 | % LSQR solves Ax = b or min ||b - Ax||_2 if damp = 0, 8 | % or min || (b) - ( A )x || otherwise. 9 | % || (0) (damp I) ||2 10 | % A is an m by n matrix defined or a function handle of aprod( mode,x ), 11 | % that performs the matrix-vector operations. 12 | % If mode = 1, aprod must return y = Ax without altering x. 13 | % If mode = 2, aprod must return y = A'x without altering x. 14 | 15 | %----------------------------------------------------------------------- 16 | % LSQR uses an iterative (conjugate-gradient-like) method. 17 | % For further information, see 18 | % 1. C. C. Paige and M. A. Saunders (1982a). 19 | % LSQR: An algorithm for sparse linear equations and sparse least squares, 20 | % ACM TOMS 8(1), 43-71. 21 | % 2. C. C. Paige and M. A. Saunders (1982b). 22 | % Algorithm 583. LSQR: Sparse linear equations and least squares problems, 23 | % ACM TOMS 8(2), 195-209. 24 | % 3. M. A. Saunders (1995). Solution of sparse rectangular systems using 25 | % LSQR and CRAIG, BIT 35, 588-604. 26 | % 27 | % Input parameters: 28 | % atol, btol are stopping tolerances. If both are 1.0e-9 (say), 29 | % the final residual norm should be accurate to about 9 digits. 30 | % (The final x will usually have fewer correct digits, 31 | % depending on cond(A) and the size of damp.) 32 | % conlim is also a stopping tolerance. lsqr terminates if an estimate 33 | % of cond(A) exceeds conlim. For compatible systems Ax = b, 34 | % conlim could be as large as 1.0e+12 (say). For least-squares 35 | % problems, conlim should be less than 1.0e+8. 36 | % Maximum precision can be obtained by setting 37 | % atol = btol = conlim = zero, but the number of iterations 38 | % may then be excessive. 39 | % itnlim is an explicit limit on iterations (for safety). 40 | % show = 1 gives an iteration log, 41 | % show = 0 suppresses output. 42 | % 43 | % Output parameters: 44 | % x is the final solution. 45 | % istop gives the reason for termination. 46 | % istop = 1 means x is an approximate solution to Ax = b. 47 | % = 2 means x approximately solves the least-squares problem. 48 | % r1norm = norm(r), where r = b - Ax. 49 | % r2norm = sqrt( norm(r)^2 + damp^2 * norm(x)^2 ) 50 | % = r1norm if damp = 0. 51 | % anorm = estimate of Frobenius norm of Abar = [ A ]. 52 | % [damp*I] 53 | % acond = estimate of cond(Abar). 54 | % arnorm = estimate of norm(A'*r - damp^2*x). 55 | % xnorm = norm(x). 56 | % var (if present) estimates all diagonals of (A'A)^{-1} (if damp=0) 57 | % or more generally (A'A + damp^2*I)^{-1}. 58 | % This is well defined if A has full column rank or damp > 0. 59 | % (Not sure what var means if rank(A) < n and damp = 0.) 60 | % 61 | % 62 | % 1990: Derived from Fortran 77 version of LSQR. 63 | % 22 May 1992: bbnorm was used incorrectly. Replaced by anorm. 64 | % 26 Oct 1992: More input and output parameters added. 65 | % 01 Sep 1994: Matrix-vector routine is now a parameter 'aprodname'. 66 | % Print log reformatted. 67 | % 14 Jun 1997: show added to allow printing or not. 68 | % 30 Jun 1997: var added as an optional output parameter. 69 | % 07 Aug 2002: Output parameter rnorm replaced by r1norm and r2norm. 70 | % Michael Saunders, Systems Optimization Laboratory, 71 | % Dept of MS&E, Stanford University. 72 | % 03 Jul 2007: Modified 'aprodname' to A, which can either be an m by n 73 | % matrix, or a function handle. 74 | % Ewout van den Berg, University of British Columbia 75 | % 03 Jul 2007: Modified 'test2' condition, omitted 'test1'. 76 | % Ewout van den Berg, University of British Columbia 77 | %----------------------------------------------------------------------- 78 | 79 | % Initialize. 80 | 81 | msg=['The exact solution is x = 0 ' 82 | 'Ax - b is small enough, given atol, btol ' 83 | 'The least-squares solution is good enough, given atol ' 84 | 'The estimate of cond(Abar) has exceeded conlim ' 85 | 'Ax - b is small enough for this machine ' 86 | 'The least-squares solution is good enough for this machine' 87 | 'Cond(Abar) seems to be too large for this machine ' 88 | 'The iteration limit has been reached ']; 89 | 90 | wantvar= nargout >= 6; 91 | if wantvar, var = zeros(n,1); end 92 | 93 | if show 94 | disp(' ') 95 | disp('LSQR Least-squares solution of Ax = b') 96 | str1 = sprintf('The matrix A has %8g rows and %8g cols', m, n); 97 | str2 = sprintf('damp = %20.14e wantvar = %8g', damp,wantvar); 98 | str3 = sprintf('atol = %8.2e conlim = %8.2e', atol, conlim); 99 | str4 = sprintf('btol = %8.2e itnlim = %8g' , btol, itnlim); 100 | disp(str1); disp(str2); disp(str3); disp(str4); 101 | end 102 | 103 | itn = 0; istop = 0; nstop = 0; 104 | ctol = 0; if conlim > 0, ctol = 1/conlim; end; 105 | anorm = 0; acond = 0; 106 | dampsq = damp^2; ddnorm = 0; res2 = 0; 107 | xnorm = 0; xxnorm = 0; z = 0; 108 | cs2 = -1; sn2 = 0; 109 | 110 | % Set up the first vectors u and v for the bidiagonalization. 111 | 112 | % These satisfy beta*u = b, alfa*v = A'u. 113 | 114 | u = b(1:m); x = zeros(n,1); 115 | alfa = 0; beta = norm( u ); 116 | if beta > 0 117 | u = (1/beta) * u; v = Aprod(u,2); 118 | alfa = norm( v ); 119 | end 120 | if alfa > 0 121 | v = (1/alfa) * v; w = v; 122 | end 123 | 124 | arnorm = alfa * beta; 125 | if arnorm == 0 126 | if show, disp(msg(1,:)); end 127 | return 128 | end 129 | arnorm0= arnorm; 130 | 131 | rhobar = alfa; phibar = beta; bnorm = beta; 132 | rnorm = beta; 133 | r1norm = rnorm; 134 | r2norm = rnorm; 135 | head1 = ' Itn x(1) r1norm r2norm '; 136 | head2 = ' Compatible LS Norm A Cond A'; 137 | 138 | if show 139 | disp(' ') 140 | disp([head1 head2]) 141 | test1 = 1; test2 = alfa / beta; 142 | str1 = sprintf( '%6g %12.5e', itn, x(1) ); 143 | str2 = sprintf( ' %10.3e %10.3e', r1norm, r2norm ); 144 | str3 = sprintf( ' %8.1e %8.1e', test1, test2 ); 145 | disp([str1 str2 str3]) 146 | end 147 | 148 | %------------------------------------------------------------------ 149 | % Main iteration loop. 150 | %------------------------------------------------------------------ 151 | while itn < itnlim 152 | itn = itn + 1; 153 | % Perform the next step of the bidiagonalization to obtain the 154 | % next beta, u, alfa, v. These satisfy the relations 155 | % beta*u = a*v - alfa*u, 156 | % alfa*v = A'*u - beta*v. 157 | 158 | u = Aprod(v,1) - alfa*u; 159 | beta = norm( u ); 160 | if beta > 0 161 | u = (1/beta) * u; 162 | anorm = norm([anorm alfa beta damp]); 163 | v = Aprod(u, 2) - beta*v; 164 | alfa = norm( v ); 165 | if alfa > 0, v = (1/alfa) * v; end 166 | end 167 | 168 | % Use a plane rotation to eliminate the damping parameter. 169 | % This alters the diagonal (rhobar) of the lower-bidiagonal matrix. 170 | 171 | rhobar1 = norm([rhobar damp]); 172 | cs1 = rhobar / rhobar1; 173 | sn1 = damp / rhobar1; 174 | psi = sn1 * phibar; 175 | phibar = cs1 * phibar; 176 | 177 | % Use a plane rotation to eliminate the subdiagonal element (beta) 178 | % of the lower-bidiagonal matrix, giving an upper-bidiagonal matrix. 179 | 180 | rho = norm([rhobar1 beta]); 181 | cs = rhobar1/ rho; 182 | sn = beta / rho; 183 | theta = sn * alfa; 184 | rhobar = - cs * alfa; 185 | phi = cs * phibar; 186 | phibar = sn * phibar; 187 | tau = sn * phi; 188 | 189 | % Update x and w. 190 | 191 | t1 = phi /rho; 192 | t2 = - theta/rho; 193 | dk = (1/rho)*w; 194 | 195 | x = x + t1*w; 196 | w = v + t2*w; 197 | ddnorm = ddnorm + norm(dk)^2; 198 | if wantvar, var = var + dk.*dk; end 199 | 200 | % Use a plane rotation on the right to eliminate the 201 | % super-diagonal element (theta) of the upper-bidiagonal matrix. 202 | % Then use the result to estimate norm(x). 203 | 204 | delta = sn2 * rho; 205 | gambar = - cs2 * rho; 206 | rhs = phi - delta * z; 207 | zbar = rhs / gambar; 208 | xnorm = sqrt(xxnorm + zbar^2); 209 | gamma = norm([gambar theta]); 210 | cs2 = gambar / gamma; 211 | sn2 = theta / gamma; 212 | z = rhs / gamma; 213 | xxnorm = xxnorm + z^2; 214 | 215 | % Test for convergence. 216 | % First, estimate the condition of the matrix Abar, 217 | % and the norms of rbar and Abar'rbar. 218 | 219 | acond = anorm * sqrt( ddnorm ); 220 | res1 = phibar^2; 221 | res2 = res2 + psi^2; 222 | rnorm = sqrt( res1 + res2 ); 223 | arnorm = alfa * abs( tau ); 224 | 225 | % 07 Aug 2002: 226 | % Distinguish between 227 | % r1norm = ||b - Ax|| and 228 | % r2norm = rnorm in current code 229 | % = sqrt(r1norm^2 + damp^2*||x||^2). 230 | % Estimate r1norm from 231 | % r1norm = sqrt(r2norm^2 - damp^2*||x||^2). 232 | % Although there is cancellation, it might be accurate enough. 233 | 234 | r1sq = rnorm^2 - dampsq * xxnorm; 235 | r1norm = sqrt( abs(r1sq) ); if r1sq < 0, r1norm = - r1norm; end 236 | r2norm = rnorm; 237 | 238 | % Now use these norms to estimate certain other quantities, 239 | % some of which will be small near a solution. 240 | 241 | test1 = rnorm / bnorm; 242 | test2 = arnorm / arnorm0; 243 | % test2 = arnorm/( anorm * rnorm ); 244 | test3 = 1 / acond; 245 | t1 = test1 / (1 + anorm * xnorm / bnorm); 246 | rtol = btol + atol * anorm * xnorm / bnorm; 247 | 248 | % The following tests guard against extremely small values of 249 | % atol, btol or ctol. (The user may have set any or all of 250 | % the parameters atol, btol, conlim to 0.) 251 | % The effect is equivalent to the normal tests using 252 | % atol = eps, btol = eps, conlim = 1/eps. 253 | 254 | if itn >= itnlim, istop = 7; end 255 | if 1 + test3 <= 1, istop = 6; end 256 | if 1 + test2 <= 1, istop = 5; end 257 | if 1 + t1 <= 1, istop = 4; end 258 | 259 | % Allow for tolerances set by the user. 260 | 261 | if test3 <= ctol, istop = 3; end 262 | if test2 <= atol, istop = 2; end 263 | % if test1 <= rtol, istop = 1; end 264 | 265 | % See if it is time to print something. 266 | 267 | prnt = 0; 268 | if n <= 40 , prnt = 1; end 269 | if itn <= 10 , prnt = 1; end 270 | if itn >= itnlim-10, prnt = 1; end 271 | if rem(itn,10) == 0 , prnt = 1; end 272 | if test3 <= 2*ctol , prnt = 1; end 273 | if test2 <= 10*atol , prnt = 1; end 274 | % if test1 <= 10*rtol , prnt = 1; end 275 | if istop ~= 0 , prnt = 1; end 276 | 277 | if prnt == 1 278 | if show 279 | str1 = sprintf( '%6g %12.5e', itn, x(1) ); 280 | str2 = sprintf( ' %10.3e %10.3e', r1norm, r2norm ); 281 | str3 = sprintf( ' %8.1e %8.1e', test1, test2 ); 282 | str4 = sprintf( ' %8.1e %8.1e', anorm, acond ); 283 | disp([str1 str2 str3 str4]) 284 | end 285 | end 286 | if istop > 0, break, end 287 | end 288 | 289 | % End of iteration loop. 290 | % Print the stopping condition. 291 | 292 | if show 293 | disp(' ') 294 | disp('LSQR finished') 295 | disp(msg(istop+1,:)) 296 | disp(' ') 297 | str1 = sprintf( 'istop =%8g r1norm =%8.1e', istop, r1norm ); 298 | str2 = sprintf( 'anorm =%8.1e arnorm =%8.1e', anorm, arnorm ); 299 | str3 = sprintf( 'itn =%8g r2norm =%8.1e', itn, r2norm ); 300 | str4 = sprintf( 'acond =%8.1e xnorm =%8.1e', acond, xnorm ); 301 | disp([str1 ' ' str2]) 302 | disp([str3 ' ' str4]) 303 | disp(' ') 304 | end 305 | 306 | %----------------------------------------------------------------------- 307 | % End of lsqr.m 308 | %----------------------------------------------------------------------- 309 | 310 | 311 | 312 | function z = Aprod(x,mode) 313 | if mode == 1 314 | if isnumeric(A), z = A*x; 315 | else z = A(x,1); 316 | end 317 | else 318 | if isnumeric(A), z = (x'*A)'; 319 | else z = A(x,2); 320 | end 321 | end 322 | end % function Aprod 323 | 324 | end 325 | --------------------------------------------------------------------------------