Mentions légales du service

Skip to content
Snippets Groups Projects
Commit c1a3d455 authored by Nicolas Bellot's avatar Nicolas Bellot Committed by hhakim
Browse files

ajout demo matlab hadamard factorization

parent 5962cfa3
No related branches found
No related tags found
No related merge requests found
...@@ -206,16 +206,16 @@ endif(FAUST_USE_MEX) ...@@ -206,16 +206,16 @@ endif(FAUST_USE_MEX)
###### SRC DIRECTORY ##### ###### SRC DIRECTORY #####
set(FAUST_DEMO_SRC_DIR ${FAUST_MISC_DIR}/demo CACHE INTERNAL "") set(FAUST_DEMO_SRC_DIR ${FAUST_MISC_DIR}/demo CACHE INTERNAL "")
set(FAUST_DEMO_BSL_SRC_DIR ${FAUST_DEMO_SRC_DIR}/Brain_source_localization CACHE INTERNAL "") set(FAUST_DEMO_BSL_SRC_DIR ${FAUST_DEMO_SRC_DIR}/Brain_source_localization CACHE INTERNAL "")
set(FAUST_DEMO_HADAMARD_SRC_DIR ${FAUST_DEMO_SRC_DIR}/Hadamard_factorization CACHE INTERNAL "")
set(FAUST_DEMO_TOOLS_SRC_DIR ${FAUST_DEMO_SRC_DIR}/tools CACHE INTERNAL "") set(FAUST_DEMO_TOOLS_SRC_DIR ${FAUST_DEMO_SRC_DIR}/tools CACHE INTERNAL "")
set(FAUST_DEMO_BSL_DATA_SRC_DIR ${FAUST_DEMO_BSL_SRC_DIR}/data/ CACHE INTERNAL "") set(FAUST_DEMO_BSL_DATA_SRC_DIR ${FAUST_DEMO_BSL_SRC_DIR}/data/ CACHE INTERNAL "")
set(FAUST_DEMO_HADAMARD_SRC_DIR ${FAUST_DEMO_SRC_DIR}/Hadamard_factorization CACHE INTERNAL "")
###### BIN DIRECTORY ###### ###### BIN DIRECTORY ######
set(FAUST_DEMO_BIN_DIR ${FAUST_MATLAB_BIN_DIR}/demo CACHE INTERNAL "") set(FAUST_DEMO_BIN_DIR ${FAUST_MATLAB_BIN_DIR}/demo CACHE INTERNAL "")
set(FAUST_DEMO_BSL_BIN_DIR ${FAUST_DEMO_BIN_DIR}/Brain_source_localization CACHE INTERNAL "") set(FAUST_DEMO_BSL_BIN_DIR ${FAUST_DEMO_BIN_DIR}/Brain_source_localization CACHE INTERNAL "")
set(FAUST_DEMO_HADAMARD_BIN_DIR ${FAUST_DEMO_BIN_DIR}/Hadamard_factorization CACHE INTERNAL "")
set(FAUST_DEMO_TOOLS_BIN_DIR ${FAUST_DEMO_BIN_DIR}/tools CACHE INTERNAL "") set(FAUST_DEMO_TOOLS_BIN_DIR ${FAUST_DEMO_BIN_DIR}/tools CACHE INTERNAL "")
set(FAUST_DEMO_BSL_DATA_BIN_DIR ${FAUST_DEMO_BSL_BIN_DIR}/data/ CACHE INTERNAL "") set(FAUST_DEMO_BSL_DATA_BIN_DIR ${FAUST_DEMO_BSL_BIN_DIR}/data/ CACHE INTERNAL "")
set(FAUST_DEMO_BSL_OUTPUT_BIN_DIR ${FAUST_DEMO_BSL_BIN_DIR}/output/ CACHE INTERNAL "") set(FAUST_DEMO_BSL_OUTPUT_BIN_DIR ${FAUST_DEMO_BSL_BIN_DIR}/output/ CACHE INTERNAL "")
set(FAUST_DEMO_HADAMARD_BIN_DIR ${FAUST_DEMO_BIN_DIR}/Hadamard_factorization CACHE INTERNAL "")
#### INSTALL DIRECTORY #### #### INSTALL DIRECTORY ####
set(FAUST_DEMO_INSTALL_DIR ${FAUST_MATLAB_INSTALL_DIR}/demo CACHE INTERNAL "") set(FAUST_DEMO_INSTALL_DIR ${FAUST_MATLAB_INSTALL_DIR}/demo CACHE INTERNAL "")
set(FAUST_DEMO_BSL_INSTALL_DIR ${FAUST_DEMO_INSTALL_DIR}/Brain_source_localization CACHE INTERNAL "") set(FAUST_DEMO_BSL_INSTALL_DIR ${FAUST_DEMO_INSTALL_DIR}/Brain_source_localization CACHE INTERNAL "")
...@@ -223,6 +223,7 @@ endif(FAUST_USE_MEX) ...@@ -223,6 +223,7 @@ endif(FAUST_USE_MEX)
set(FAUST_DEMO_TOOLS_INSTALL_DIR ${FAUST_DEMO_INSTALL_DIR}/tools CACHE INTERNAL "") set(FAUST_DEMO_TOOLS_INSTALL_DIR ${FAUST_DEMO_INSTALL_DIR}/tools CACHE INTERNAL "")
set(FAUST_DEMO_BSL_DATA_INSTALL_DIR ${FAUST_DEMO_BSL_INSTALL_DIR}/data CACHE INTERNAL "") set(FAUST_DEMO_BSL_DATA_INSTALL_DIR ${FAUST_DEMO_BSL_INSTALL_DIR}/data CACHE INTERNAL "")
set(FAUST_DEMO_BSL_OUTPUT_INSTALL_DIR ${FAUST_DEMO_BSL_INSTALL_DIR}/output CACHE INTERNAL "") set(FAUST_DEMO_BSL_OUTPUT_INSTALL_DIR ${FAUST_DEMO_BSL_INSTALL_DIR}/output CACHE INTERNAL "")
set(FAUST_DEMO_HADAMARD_INSTALL_DIR ${FAUST_DEMO_INSTALL_DIR}/Hadamard_factorization CACHE INTERNAL "")
## examples directories including some examples of the use of the library FAuST ## examples directories including some examples of the use of the library FAuST
set(FAUST_TEST_DIR ${PROJECT_BINARY_DIR}/run_test CACHE INTERNAL "") set(FAUST_TEST_DIR ${PROJECT_BINARY_DIR}/run_test CACHE INTERNAL "")
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
% Brain source localization % Brain source localization
% %
% This script performs brain source localization using several gain % This script performs brain source localization using several gain
% matrices [2], including FAuSTs, and several solvers. It reproduces the % matrices [2], including FAuSTs, and OMP solver. It reproduces the
% source localization experiment of [1]. % source localization experiment of [1].
% The results are stored in "./output/results_BSL_user.mat". % The results are stored in "./output/results_BSL_user.mat".
% DURATION: Computations should take around 10 minutes. % DURATION: Computations should take around 10 minutes.
...@@ -95,9 +95,7 @@ for i=1:nb_approx_MEG ...@@ -95,9 +95,7 @@ for i=1:nb_approx_MEG
load([BSL_data_pathName 'M_' int2str(RCG_approxS_MEG(i)) ]); load([BSL_data_pathName 'M_' int2str(RCG_approxS_MEG(i)) ]);
facts{1}=lambda*facts{1}; facts{1}=lambda*facts{1};
X_approx =dvp(facts); X_approx =dvp(facts);
%X_hat = X' + 0.05*randn(size(X'));
X_approx = X_approx'; X_approx(:,sum(X_approx.^2,1)==0)=1; X_approx = X_approx'; X_approx(:,sum(X_approx.^2,1)==0)=1;
%X_hat_norm = X_hat;
X_norm_approx = X_approx./repmat(sqrt(sum(X_approx.^2,1)),size(X_approx,1),1); X_norm_approx = X_approx./repmat(sqrt(sum(X_approx.^2,1)),size(X_approx,1),1);
MEG_approxS_norm{i}=X_norm_approx; MEG_approxS_norm{i}=X_norm_approx;
...@@ -107,15 +105,11 @@ for i=1:nb_approx_MEG ...@@ -107,15 +105,11 @@ for i=1:nb_approx_MEG
sp_facts = faust_transpose(sp_facts_trans); sp_facts = faust_transpose(sp_facts_trans);
trans_fc=matlab_faust(facts); trans_fc=matlab_faust(facts);
fc=transpose(trans_fc); fc=transpose(trans_fc);
% f=@(x) x/2;
matlab_trans_faustS_mult{i}=@(x) f_mult(sp_facts_trans,x); matlab_trans_faustS_mult{i}=@(x) f_mult(sp_facts_trans,x);
matlab_faustS_mult{i}=@(x) f_mult(sp_facts,x); matlab_faustS_mult{i}=@(x) f_mult(sp_facts,x);
trans_faustS_mult{i}=@(x) trans_fc*x; trans_faustS_mult{i}=@(x) trans_fc*x;
faustS_mult{i}=@(x) fc*x; faustS_mult{i}=@(x) fc*x;
MEG_faustS{i}=trans_fc; MEG_faustS{i}=trans_fc;
% eval(['function y = fc_mult' int2str(i) '(x) y=fc*x;end']);
% eval(['foncteur{i}=@fc_mult' int2str(i) ';']);
end end
...@@ -133,14 +127,13 @@ for k=1:numel(dist_paliers)-1 ...@@ -133,14 +127,13 @@ for k=1:numel(dist_paliers)-1
%Parameters settings %Parameters settings
Gamma = zeros(size(X_norm,2),Ntraining); Gamma = zeros(size(X_norm,2),Ntraining);
for ii=1:Ntraining for ii=1:Ntraining
%disp(num2str(ii));
dist_sources = -1; dist_sources = -1;
while ~((dist_paliers(k)<dist_sources)&&(dist_sources<dist_paliers(k+1))) while ~((dist_paliers(k)<dist_sources)&&(dist_sources<dist_paliers(k+1)))
Gamma(:,ii) = sparse_coeffs(X_norm, 1, Sparsity); % Gamma(:,ii) = sparse_coeffs(X_norm, 1, Sparsity); %
idx = find(Gamma(:,ii)); idx = find(Gamma(:,ii));
dist_sources = norm(points(idx(1)) - points(idx(2))); dist_sources = norm(points(idx(1)) - points(idx(2)));
end end
% dist_sources = norm(points(idx(1)) - points(idx(2)))
end end
Data = X_norm*Gamma; Data = X_norm*Gamma;
...@@ -164,9 +157,7 @@ for k=1:numel(dist_paliers)-1 ...@@ -164,9 +157,7 @@ for k=1:numel(dist_paliers)-1
idx = find(Gamma(:,i)); idx = find(Gamma(:,i));
dist_sources = norm(points(idx(1)) - points(idx(2))); dist_sources = norm(points(idx(1)) - points(idx(2)));
%l1 solving
tol = 1e-4;
lambda = 0.3;
...@@ -185,31 +176,29 @@ for k=1:numel(dist_paliers)-1 ...@@ -185,31 +176,29 @@ for k=1:numel(dist_paliers)-1
compute_Times_matlab(1,k,i)=t1; compute_Times_matlab(1,k,i)=t1;
for ll=1:nb_approx_MEG for ll=1:nb_approx_MEG
X_approx_norm = MEG_approxS_norm{ll}; X_approx_norm = MEG_approxS_norm{ll};
% [sol_omp_hat(:,i), err_mse_omp_hat, iter_time_omp_hat]=greed_omp_chol(Data(:,i),X_approx_norm,size(X_approx_norm,2),'stopTol',1*Sparsity);
tic tic
[sol_omp_hat(:,i), err_mse_omp_hat, iter_time_omp_hat]=greed_omp_chol(Data(:,i),faustS_mult{ll},size(X_approx_norm,2),'stopTol',1*Sparsity,'P_trans',trans_faustS_mult{ll}); [sol_omp_hat(:,i), err_mse_omp_hat, iter_time_omp_hat]=greed_omp_chol(Data(:,i),faustS_mult{ll},size(X_approx_norm,2),'stopTol',1*Sparsity,'P_trans',trans_faustS_mult{ll});
t1=toc; t1=toc;
err_omp_hat(1,i) = norm(X_norm*Gamma(:,i)-X_approx_norm*sol_omp_hat(:,i))/norm(X_norm*Gamma(:,i)); err_omp_hat(1,i) = norm(X_norm*Gamma(:,i)-X_approx_norm*sol_omp_hat(:,i))/norm(X_norm*Gamma(:,i));
err_omp_hat(2,i) = isequal(find(Gamma(:,i)),find(sol_omp_hat(:,i)>1e-4)); err_omp_hat(2,i) = isequal(find(Gamma(:,i)),find(sol_omp_hat(:,i)>1e-4));
idx_omp = find(sol_omp_hat(:,i)); idx_omp = find(sol_omp_hat(:,i));
resDist(ll+1,k,1,i) = min(norm(points(idx(1)) - points(idx_omp(1))),norm(points(idx(1)) - points(idx_omp(2)))); resDist(ll+1,k,1,i) = min(norm(points(idx(1)) - points(idx_omp(1))),norm(points(idx(1)) - points(idx_omp(2))));
resDist(ll+1,k,2,i) = min(norm(points(idx(2)) - points(idx_omp(1))),norm(points(idx(2)) - points(idx_omp(2)))); resDist(ll+1,k,2,i) = min(norm(points(idx(2)) - points(idx_omp(1))),norm(points(idx(2)) - points(idx_omp(2))));
compute_Times(ll+1,k,i)=t1; compute_Times(ll+1,k,i)=t1;
tic tic
[sol_omp_hat(:,i), err_mse_omp_hat, iter_time_omp_hat]=greed_omp_chol(Data(:,i),matlab_faustS_mult{ll},size(X_approx_norm,2),'stopTol',1*Sparsity,'P_trans',matlab_trans_faustS_mult{ll}); [sol_omp_hat(:,i), err_mse_omp_hat, iter_time_omp_hat]=greed_omp_chol(Data(:,i),matlab_faustS_mult{ll},size(X_approx_norm,2),'stopTol',1*Sparsity,'P_trans',matlab_trans_faustS_mult{ll});
t2=toc; t2=toc;
err_omp_hat(1,i) = norm(X_norm*Gamma(:,i)-X_approx_norm*sol_omp_hat(:,i))/norm(X_norm*Gamma(:,i)); err_omp_hat(1,i) = norm(X_norm*Gamma(:,i)-X_approx_norm*sol_omp_hat(:,i))/norm(X_norm*Gamma(:,i));
err_omp_hat(2,i) = isequal(find(Gamma(:,i)),find(sol_omp_hat(:,i)>1e-4)); err_omp_hat(2,i) = isequal(find(Gamma(:,i)),find(sol_omp_hat(:,i)>1e-4));
idx_omp = find(sol_omp_hat(:,i)); idx_omp = find(sol_omp_hat(:,i));
resDist_matlab(ll+1,k,1,i) = min(norm(points(idx(1)) - points(idx_omp(1))),norm(points(idx(1)) - points(idx_omp(2)))); resDist_matlab(ll+1,k,1,i) = min(norm(points(idx(1)) - points(idx_omp(1))),norm(points(idx(1)) - points(idx_omp(2))));
resDist_matlab(ll+1,k,2,i) = min(norm(points(idx(2)) - points(idx_omp(1))),norm(points(idx(2)) - points(idx_omp(2)))); resDist_matlab(ll+1,k,2,i) = min(norm(points(idx(2)) - points(idx_omp(1))),norm(points(idx(2)) - points(idx_omp(2))));
compute_Times_matlab(ll+1,k,i)=t2; compute_Times_matlab(ll+1,k,i)=t2;
% % faust end
% [sol_omp_hat(:,i), err_mse_omp_hat, iter_time_omp_hat]=greed_omp_chol(Data(:,i),faustS_mult{ll},size(X_approx_norm,2),'stopTol',1*Sparsity,'P_trans',trans_faustS_mult{ll});
end
save('results_current','resDist','compute_Times');
end end
end end
toc toc
......
...@@ -8,6 +8,10 @@ file(GLOB MATLAB_SCRIPTS "*.m") ...@@ -8,6 +8,10 @@ file(GLOB MATLAB_SCRIPTS "*.m")
if(FAUST_USE_MEX) if(FAUST_USE_MEX)
configure_file(${FAUST_DEMO_SRC_DIR}/run_all_demo.m ${FAUST_DEMO_BIN_DIR}/run_all_demo.m COPYONLY)
install(FILES ${FAUST_DEMO_BIN_DIR}/run_all_demo.m DESTINATION ${FAUST_DEMO_INSTALL_DIR})
############# Brain source localization demo #################### ############# Brain source localization demo ####################
foreach(matlab_script BSL Fig_BSL) foreach(matlab_script BSL Fig_BSL)
...@@ -22,13 +26,20 @@ if(FAUST_USE_MEX) ...@@ -22,13 +26,20 @@ if(FAUST_USE_MEX)
endforeach() endforeach()
######### Hadamard factorization ###############################
configure_file(${FAUST_DEMO_HADAMARD_SRC_DIR}/demo_fact_hadamard.m ${FAUST_DEMO_HADAMARD_BIN_DIR}/demo_fact_hadamard.m COPYONLY)
install(FILES ${FAUST_DEMO_HADAMARD_BIN_DIR}/demo_fact_hadamard.m DESTINATION ${FAUST_DEMO_HADAMARD_INSTALL_DIR})
#################### Tools directory ############################
foreach(tools bplot dvp faust_transpose f_mult greed_omp_chol make_sparse sparse_coeffs UpdateCholesky hadamard_mat)
configure_file(${FAUST_DEMO_TOOLS_SRC_DIR}/${tools}.m ${FAUST_DEMO_TOOLS_BIN_DIR}/${tools}.m COPYONLY)
install(FILES ${FAUST_DEMO_TOOLS_BIN_DIR}/${tools}.m DESTINATION ${FAUST_DEMO_TOOLS_INSTALL_DIR})
endforeach()
endif() endif()
#################### Tools directory ############################
foreach(tools bplot dvp faust_transpose f_mult greed_omp_chol make_sparse sparse_coeffs UpdateCholesky)
configure_file(${FAUST_DEMO_TOOLS_SRC_DIR}/${tools}.m ${FAUST_DEMO_TOOLS_BIN_DIR}/${tools}.m COPYONLY)
install(FILES ${FAUST_DEMO_TOOLS_BIN_DIR}/${tools}.m DESTINATION ${FAUST_DEMO_TOOLS_INSTALL_DIR})
endforeach()
%% Description demo_fact_hadamard
%
% This demo hierarchically factorizes the Hadamard dictionary and then
% plots the results. This essentially reproduces figure 2 from [1].
%
% For more information on the FAuST Project, please visit the website of
% the project : <http://faust.gforge.inria.fr>
%
%% License:
% Copyright (2016): Luc Le Magoarou, Remi Gribonval
% INRIA Rennes, FRANCE
% http://www.inria.fr/
%
% The FAuST Toolbox is distributed under the terms of the GNU Affero
% General Public License.
% This program is free software: you can redistribute it and/or modify
% it under the terms of the GNU Affero General Public License as published
% by the Free Software Foundation.
%
% This program is distributed in the hope that it will be useful, but
% WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
% See the GNU Affero General Public License for more details.
%
% You should have received a copy of the GNU Affero General Public License
% along with this program. If not, see <http://www.gnu.org/licenses/>.
%
%% Contacts:
% Nicolas Bellot : nicolas.bellot@inria.fr
% Leman Adrien : adrien.leman@inria.fr
% Luc Le Magoarou: luc.le-magoarou@inria.fr
% Remi Gribonval : remi.gribonval@inria.fr
%
%% References:
% [1] Le Magoarou L. and Gribonval R., "Flexible multi-layer sparse
% approximations of matrices and applications", Journal of Selected
% Topics in Signal Processing, 2016.
% <https://hal.archives-ouvertes.fr/hal-01167948v1>
%%
n = 128;
M = log2(n);
%% Generating the data
[params.data,~] = hadamard_mat(M);
%% Setting of the parameters
params.nfacts = M;
params.cons = cell(2,M-1);
for j=1:M-1
params.cons{1,j} = {'splincol',2,n,n};
params.cons{2,j} = {'splincol',n/2^j,n,n};
end
params.niter1 = 30;
params.niter2 = 30;
params.update_way = 1;
params.verbose = 0;
[lambda, facts] = mexHierarchical_fact(params);
%% speed-up and relatice error
X = params.data;
hadamard_faust = matlab_faust(facts,lambda);
Xhat = get_product(hadamard_faust);
relative_error = norm(X - Xhat)/norm(X);
fprintf(['\n\n relative error between hadamard matrix and its transform : ' num2str(relative_error) '\n']);
nb_mult= 500;
dense_times=zeros(nb_mult,1);
faust_times=zeros(nb_mult,1);
for i=1:nb_mult
x=rand(n,1);
y_faust=rand(n,1);
y_X=rand(n,1);
tic
y_X=X*x;
t1=toc;
tic
y_faust=hadamard_faust*x;
t2=toc;
dense_times(i)=t1;
faust_times(i)=t2;
end
dense_t=mean(dense_times);
faust_t=mean(faust_times);
speed_up=dense_t/faust_t;
disp(['multiplication by hadamard matrix : ' num2str(dense_t) 'sec']);
disp(['multiplication by faust : ' num2str(faust_t) 'sec']);
disp(['multiplication speed-up using faust : ' num2str(speed_up) ]);
%% Plotting the results
figure;
hold on;
subplot(1,params.nfacts+1,1);
imagesc(Xhat); axis square
set(gca,'xtick',[],'ytick',[])
for kk = 1:params.nfacts
subplot(1,params.nfacts+1,1+kk)
imagesc(facts{kk}); axis square
set(gca,'xtick',[],'ytick',[])
end
figure;
hold on;
subplot(1,params.nfacts+1,1);
imagesc(Xhat); axis square
set(gca,'xtick',[],'ytick',[])
for kk = 1:params.nfacts
subplot(1,params.nfacts+1,1+kk)
spy(facts{kk}); axis square
set(gca,'xtick',[],'ytick',[])
end
%% script run_all_demo
% Script used to run all demo (brain source localisation, hadamard factorization)
% corresponding figures of the article [1].
%
% For more information on the FAuST Project, please visit the website of
% the project : <http://faust.gforge.inria.fr>
%
%% License:
% Copyright (2016): Luc Le Magoarou, Remi Gribonval
% INRIA Rennes, FRANCE
% http://www.inria.fr/
%
% The FAuST Toolbox is distributed under the terms of the GNU Affero
% General Public License.
% This program is free software: you can redistribute it and/or modify
% it under the terms of the GNU Affero General Public License as published
% by the Free Software Foundation.
%
% This program is distributed in the hope that it will be useful, but
% WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
% See the GNU Affero General Public License for more details.
%
% You should have received a copy of the GNU Affero General Public License
% along with this program. If not, see <http://www.gnu.org/licenses/>.
%
%% Contacts:
% Nicolas Bellot : nicolas.bellot@inria.fr
% Leman Adrien : adrien.leman@inria.fr
% Luc Le Magoarou: luc.le-magoarou@inria.fr
% Remi Gribonval : remi.gribonval@inria.fr
%
%% References:
% [1] Le Magoarou L. and Gribonval R., "Flexible multi-layer sparse
% approximations of matrices and applications", Journal of Selected
% Topics in Signal Processing, 2016.
% <https://hal.archives-ouvertes.fr/hal-01167948v1>
%
% [2] A. Gramfort, M. Luessi, E. Larson, D. Engemann, D. Strohmeier,
% C. Brodbeck, L. Parkkonen, M. Hamalainen, MNE software for processing
% MEG and EEG data <http://www.ncbi.nlm.nih.gov/pubmed/24161808>,
% NeuroImage, Volume 86, 1 February 2014, Pages 446-460, ISSN 1053-8119,
% [DOI] <http://dx.doi.org/10.1016/j.neuroimage.2013.10.027>
%%
%% brain source localization
disp('*********** Brain Source Localization *************');
BSL;
Fig_BSL;
%% Hadamard factorization
disp('*********** Hadamard Factorization *************');
demo_fact_hadamard
\ No newline at end of file
%% Description hadamard_mat
% Computation of tha Hadamard matrix and its "native" factorization
% [H, Fact] = hadamard_mat(n) computes the Hadamard matrix H of size
% 2^n*2^n and its factorization Fact.
%
% For more information on the FAuST Project, please visit the website of
% the project : <http://faust.gforge.inria.fr>
%
%% License:
% Copyright (2016): Luc Le Magoarou, Remi Gribonval
% INRIA Rennes, FRANCE
% http://www.inria.fr/
%
% The FAuST Toolbox is distributed under the terms of the GNU Affero
% General Public License.
% This program is free software: you can redistribute it and/or modify
% it under the terms of the GNU Affero General Public License as published
% by the Free Software Foundation.
%
% This program is distributed in the hope that it will be useful, but
% WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
% See the GNU Affero General Public License for more details.
%
% You should have received a copy of the GNU Affero General Public License
% along with this program. If not, see <http://www.gnu.org/licenses/>.
%
%% Contacts:
% Luc Le Magoarou: luc.le-magoarou@inria.fr
% Remi Gribonval : remi.gribonval@inria.fr
%
%% References:
% [1] Le Magoarou L. and Gribonval R., "Flexible multi-layer sparse
% approximations of matrices and applications", Journal of Selected
% Topics in Signal Processing, 2016.
% <https://hal.archives-ouvertes.fr/hal-01167948v1>
%%
function [H, Fact] = hadamard_mat(n)
bloc = [1 1;1 -1];
matbase = bloc;
for i = 1:2^(n-1)-1
matbase = blkdiag(matbase,bloc);
end
matbase = (1/sqrt(2))*matbase;
Perm = zeros(size(matbase));
for l = 1:size(Perm,1)/2
Perm(2*l-1,l)=1;
Perm(2*l,l+size(Perm,1)/2)=1;
end
Fact = zeros(2^n,2^n,n);
for i=1:n
Fact(:,:,i) = matbase*Perm;
end
H = Fact(:,:,1)^n;
end
\ No newline at end of file
...@@ -44,6 +44,7 @@ relpathlist={'',... ...@@ -44,6 +44,7 @@ relpathlist={'',...
'tools',... %% matlab_faust.m 'tools',... %% matlab_faust.m
'demo',... 'demo',...
'demo/Brain_source_localization',... 'demo/Brain_source_localization',...
'demo/Hadamard_factorization',...
}; };
fprintf('Welcome to wrapper matlab C++ FAuST_toolbox. FAuST root directory is %s\n',ROOT_DIR); fprintf('Welcome to wrapper matlab C++ FAuST_toolbox. FAuST root directory is %s\n',ROOT_DIR);
...@@ -62,11 +63,9 @@ clear relpathlist tmp_pathname ROOT_DIR k ...@@ -62,11 +63,9 @@ clear relpathlist tmp_pathname ROOT_DIR k
fprintf('\n FAuST is successfully installed. \n') fprintf('\n FAuST is successfully installed. \n')
fprintf(['\n To get started with the FAuST Toolbox : \n'])
fprintf(['\n launch run_all_demo.m \n'])
addpath('@FAUST_MATLABMEX_INSTALL@');%% access to the mexfunction
addpath('@FAUST_DEMO_INSTALL@');%% access
addpath('@FAUST_DEMOTOOLS_INSTALL@');%% access to the tools function (sparsify toolbox, figure toolbox ...)
addpath('@FAUST_DEMODATA_INSTALL@');%% access to the data
...@@ -59,7 +59,7 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) ...@@ -59,7 +59,7 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
mxCurrentField = mxGetField(prhs[0],0,"data"); mxCurrentField = mxGetField(prhs[0],0,"data");
getFaustMat( mxCurrentField,data ) ; getFaustMat( mxCurrentField,data ) ;
mexPrintf("DATA (%d,%d)",data.getNbRow(),data.getNbCol()); /*mexPrintf("DATA (%d,%d)",data.getNbRow(),data.getNbCol());
if ((data.getNbRow() < 10) && (data.getNbCol())) if ((data.getNbRow() < 10) && (data.getNbCol()))
{ {
for (int i = 0;i<data.getNbRow();i++) for (int i = 0;i<data.getNbRow();i++)
...@@ -71,7 +71,7 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) ...@@ -71,7 +71,7 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
} }
mexPrintf("\n"); mexPrintf("\n");
} }
} }*/
}else }else
{ {
mexErrMsgTxt("params.data must be specified"); mexErrMsgTxt("params.data must be specified");
...@@ -83,9 +83,8 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) ...@@ -83,9 +83,8 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{ {
mxCurrentField = mxGetField(prhs[0],0,"nfacts"); mxCurrentField = mxGetField(prhs[0],0,"nfacts");
mexPrintf("a\n");
nbFact =(int) mxGetScalar(mxCurrentField); nbFact =(int) mxGetScalar(mxCurrentField);
mexPrintf("NB FACT : %d",nbFact);
}else }else
{ {
mexErrMsgTxt("params.nfacts must be specified"); mexErrMsgTxt("params.nfacts must be specified");
...@@ -203,7 +202,7 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) ...@@ -203,7 +202,7 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
///////////// HIERARCHICAL LAUNCH /////////////// ///////////// HIERARCHICAL LAUNCH ///////////////
// creation des parametres // creation des parametres
try{ try{
std::cout<<"avant "<<std::endl;
Faust::Params<FFPP,Cpu> params(data,nbFact,consSS,std::vector<Faust::MatDense<FFPP,Cpu> >(),crit1,crit2,isVerbose,updateway,factside,init_lambda); Faust::Params<FFPP,Cpu> params(data,nbFact,consSS,std::vector<Faust::MatDense<FFPP,Cpu> >(),crit1,crit2,isVerbose,updateway,factside,init_lambda);
//DisplayParams(params); //DisplayParams(params);
......
...@@ -29,7 +29,7 @@ void testCoherence(const mxArray* params,std::vector<bool> & presentFields) ...@@ -29,7 +29,7 @@ void testCoherence(const mxArray* params,std::vector<bool> & presentFields)
{ {
const char * fieldName; const char * fieldName;
fieldName = mxGetFieldNameByNumber(params,i); fieldName = mxGetFieldNameByNumber(params,i);
mexPrintf("fieldname %d : %s\n",i,fieldName); //mexPrintf("fieldname %d : %s\n",i,fieldName);
if (strcmp(fieldName,"data") == 0) if (strcmp(fieldName,"data") == 0)
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment