Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 4c934124 authored by hhakim's avatar hhakim
Browse files

Add matfaust.FaustFactory.fact_hierarchical_constends(), review...

Add matfaust.FaustFactory.fact_hierarchical_constends(), review fact_palm4msa_constends(), add examples.
parent a3387cf5
Branches
Tags
No related merge requests found
......@@ -33,7 +33,7 @@ classdef ParamsHierarchicalFact < matfaust.factparams.ParamsFact
error('lengths of fact_constraints and res_constraints must be equal.')
end
if(~ isa(stop_crit1, 'StoppingCriterion'))
error('stop_crit1 (argument 3) must a StoppingCriterion')
error('stop_crit1 (argument 3) must be a StoppingCriterion')
end
if(~ isa(stop_crit2, 'StoppingCriterion'))
error('stop_crit2 (argument 4) must a StoppingCriterion')
......
......@@ -111,31 +111,6 @@ classdef FaustFactory
F = Faust(core_obj, isreal(M));
end
function [F, lambda] = fact_palm4msa_constends(M, p, A, B)
import matfaust.factparams.*
import matfaust.FaustFactory
consA = ConstraintList('const', A, size(A,1), size(A,2));
new_consts = {};
new_consts = [ {consA.clist{:}}, {p.constraints{:}} ];
if(ismatrix(B))
consB = ConstraintList('const', B, size(B,1), size(B,2));
new_consts = [ new_consts, {consB.clist{:}} ];
end
new_consts = ConstraintList(new_consts{:});
p = ParamsPalm4MSA(new_consts, p.stop_crit, 'is_update_way_R2L', p.is_update_way_R2L, ...
'init_lambda', p.init_lambda, 'step_size', p.step_size, 'constant_step_size', ...
p.constant_step_size, 'is_verbose', p.is_verbose, 'init_facts', p.init_facts);
[F, lambda ] = FaustFactory.fact_palm4msa(M, p);
f1 = get_factor(F, 1);
f1 = f1 / lambda;
nF = cell(1, get_num_factors(F));
nF{1} = f1;
for i=2:get_num_factors(F)
nF{i} = get_factor(F, i);
end
nF{2} = nF{2}*lambda;
F = matfaust.Faust(nF);
end
%==========================================================================================
%> @brief Factorizes the matrix M with Hierarchical Factorization using the parameters set in p.
......@@ -299,6 +274,131 @@ classdef FaustFactory
F = Faust(core_obj, isreal(M));
varargout = {F, lambda, p};
end
%==========================================================================================
%> @brief Approximates M by A S_1 … S_n B using FaustFactory.fact_palm4msa.
%>
%>
%> @Example
%> @code
%> import matfaust.*
%> import matfaust.factparams.*
%>
%> p = ParamsPalm4MSA(…
%> ConstraintList('spcol', 2, 10, 20, 'sp', 30, 20, 20),…
%> StoppingCriterion(50), 'is_verbose', false);
%> M = rand(10,10);
%> A = rand(10,10);
%> B = rand(20, 10);
%> [F, lamdba] = FaustFactory.fact_palm4msa_constends(M, p, A, B)
%>
%> assert(norm(A - get_factor(F,1))/norm(A) <= eps(double(1)))
%> assert(norm(B - get_factor(F,4))/norm(B) <= eps(double(1)))
%>
%> @endcode
%==========================================================================================
function [F, lambda] = fact_palm4msa_constends(M, p, A, varargin)
import matfaust.factparams.*
import matfaust.FaustFactory
if(~ ismatrix(A))
error('A must be a matrix.')
end
consA = ConstraintList('const', A, size(A,1), size(A,2));
new_consts = {};
new_consts = [ {consA.clist{:}}, {p.constraints{:}} ];
if(length(varargin) > 0)
B = varargin{1};
if(~ ismatrix(B))
error('B must be a matrix.')
end
consB = ConstraintList('const', B, size(B,1), size(B,2));
new_consts = [ new_consts, {consB.clist{:}} ];
end
new_consts = ConstraintList(new_consts{:});
p = ParamsPalm4MSA(new_consts, p.stop_crit, 'is_update_way_R2L', p.is_update_way_R2L, ...
'init_lambda', p.init_lambda, 'step_size', p.step_size, 'constant_step_size', ...
p.constant_step_size, 'is_verbose', p.is_verbose);
[F, lambda ] = FaustFactory.fact_palm4msa(M, p);
f1 = get_factor(F, 1);
f1 = f1 / lambda;
nF = cell(1, get_num_factors(F));
nF{1} = f1;
for i=2:get_num_factors(F)
nF{i} = get_factor(F, i);
end
nF{2} = nF{2}*lambda;
F = matfaust.Faust(nF);
end
%==========================================================================================
%> @brief Approximates M by A S_1 ... S_n B using FaustFactory.fact_hierarchical.
%>
%> @Example
%> @code
%> import matfaust.*
%> import matfaust.factparams.*
%>
%> p = ParamsHierarchicalFact(…
%> ConstraintList('spcol', 2, 10, 20, 'sp', 30, 10, 10), ConstraintList('sp', 4, 10, 20, 'splin', 5, 10, 10),…
%> StoppingCriterion(50), StoppingCriterion(50),…
%> 'is_fact_side_left', true, 'is_verbose', false…
%> );
%> M = rand(10,10);
%> A = rand(10,10);
%> B = rand(20, 10);
%> [F, lamdba, ~] = FaustFactory.fact_hierarchical_constends(M, p, A, B)
%>
%> assert(norm(A - get_factor(F,1))/norm(A) <= eps(double(1)))
%> assert(norm(B - get_factor(F,4))/norm(B) <= eps(double(1)))
%> @endcode
%>
%==========================================================================================
function varargout = fact_hierarchical_constends(M, p, A, B)
import matfaust.factparams.*
import matfaust.FaustFactory
if(~ ismatrix(A) || ~ ismatrix(B))
error('A and B must be matrices.')
end
consA = ConstraintList('const', A, size(A, 1), size(A, 2));
consB = ConstraintList('const', B, size(B, 1), size(B, 2));
consts = p.constraints;
nconsts = length(p.constraints);
% consts: factor constraints + residuum constraints
fac_cons = {};
res_cons = {};
for i=1:p.num_facts-1
fac_cons = { fac_cons{:}, consts{i} };
end
for i=p.num_facts:length(consts)
res_cons = { res_cons{:}, consts{i} };
end
assert(length(fac_cons) == length(res_cons))
% add two constants factor constraints for A and B to the old constraints
% According to the factorization direction, switch A and B positions
if(p.is_fact_side_left)
new_fact_cons = { consB.clist{:}, fac_cons{:} };
new_res_cons = { res_cons{:}, consA.clist{:} };
else
new_fact_cons = { consA.clist{:}, fac_cons{:} };
new_res_cons = { res_cons{:}, consB.clist{:} };
end
p = ParamsHierarchicalFact(new_fact_cons, new_res_cons,...
p.stop_crits{1}, p.stop_crits{2}, 'is_update_way_R2L', p.is_update_way_R2L, ...
'init_lambda', p.init_lambda, 'step_size', p.step_size, 'constant_step_size', ...
p.constant_step_size, 'is_verbose', p.is_verbose, 'is_fact_side_left', p.is_fact_side_left);
[F, lambda, p] = FaustFactory.fact_hierarchical(M, p);
f1 = get_factor(F, 1);
f1 = f1 / lambda;
nF = cell(1, get_num_factors(F));
nF{1} = f1;
for i=2:get_num_factors(F)
nF{i} = get_factor(F, i);
end
nF{2} = nF{2}*lambda;
F = matfaust.Faust(nF);
varargout = {F, lambda, p};
end
%===================================================================================
%> @brief Computes the FGFT for the Fourier matrix U which should be the eigenvectors of the Laplacian Lap.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment