项目作者: xylimeng

项目描述 :
Wavelets with adaptive recursive partitioning
高级语言: C++
项目地址: git://github.com/xylimeng/WARP.git
创建时间: 2017-11-01T06:35:25Z
项目社区:https://github.com/xylimeng/WARP

开源协议:MIT License

下载


WARP

Wavelets with adaptive recursive partitioning applied to image reconstruction (both 2D and 3D). Matlab users can directly use the code for real data analysis. The C++ source code is also available, which is portable toR and Matlab.

Instructions for Matlab users

  • Install the c++ library armadillo(http://arma.sourceforge.net) to your computer;
  • Let path be the directory containing the header file of armadillo;
  • Compile the c++ code for matlab by running the code mex_this(path).

Insturctions for R users

2D example

The following code is available in the file Demo.m. It usually takes 20sec if ran in a Macbook Pro with usual specifications, which increases by 1min if the step size in cycling spinning (step) is changed to 5.

  1. rng(0);
  2. load('lena_data.mat');
  3. obs_true = double(lena) ./ 255; % ground truth
  4. MSE = @(x) mean(mean((x - obs_true).^2, 1));
  5. sigma = 0.2;
  6. obs_raw = obs_true + randn(size(obs_true, 1)) .* sigma; % 2D observation
  7. obs = obs_raw(:); % vectorize obs
  8. dimension = size(obs_raw)'; % obtain size information as a column vector
  9. tic
  10. % default method to select parameters in the model
  11. hyper0 = hyper_default(obs(:), dimension);
  12. t1 = toc;
  13. % Bayesian model averaging without cycle spinning
  14. BMA_no_cs = treeFit(obs, dimension, hyper0, 0);
  15. BMA_no_cs = reshape(BMA_no_cs, dimension');
  16. t2 = toc;
  17. % BMA with cycle spinning;
  18. step = 1; % increase `step` will lead to better performance (smaller MSEs) but takes longer time.
  19. BMA_cs = treeFit(obs, dimension, hyper0, step);
  20. BMA_cs = reshape(BMA_cs, dimension');
  21. t3 = toc;
  22. figure;
  23. subplot(2, 2, 1)
  24. imshow(obs_true); title('True');
  25. subplot(2, 2, 2)
  26. imshow(obs_raw);
  27. title(sprintf('Noisy observation \n MSE = %.4f', MSE(obs_raw)));
  28. subplot(2, 2, 3)
  29. imshow(BMA_no_cs);
  30. title(sprintf('WARPed Haar without CS \n MSE = %.4f | Time = %.1fs', MSE(BMA_no_cs), t2));
  31. subplot(2, 2, 4)
  32. imshow(BMA_cs);
  33. title(sprintf('WARPed Haar with %d shifts \n MSE = %.4f | Time = %.1fs', (2 * step + 1)^2, MSE(BMA_cs), t3 - t2 + t1));

Although we do not recommend it, if you’d like to use a full optimization to select hyperparameters rather than the default method implemented in hyper_default, use the following code to obtain hyper0.

  1. idx = (1:2:numel(obs));
  2. a = (obs(idx) - obs(idx + 1)) ./ sqrt(2);
  3. sigma_hat = mad(a(:), 1) * 1.4826;
  4. x0 = [0, 0, 0, 0, 0]';
  5. options = optimoptions(@fminunc,'Algorithm','quasi-newton');
  6. f = @(x) -treeLikelihood(obs,[x; log(sigma_hat)]);
  7. [x, fval] = fminunc(f,x0, options);
  8. hyper0 = [x; log(sigma_hat)];