Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 309b2659 authored by hhakim's avatar hhakim
Browse files

Group factorization parameter classes into matfaust.factparams namespace.

Getting similar organization to pyfaust (d74741d0).
parent 80a4b818
No related branches found
No related tags found
No related merge requests found
Showing
with 63 additions and 56 deletions
......@@ -20,7 +20,8 @@ classdef FaustFactoryTest < matlab.unittest.TestCase
methods (Test)
function test_fact_palm4msa(this)
disp('Test FaustFactory.fact_palm4msa()')
import matfaust.*;
import matfaust.*
import matfaust.factparams.*
num_facts = 2;
is_update_way_R2L = false;
init_lambda = 1.0;
......@@ -50,7 +51,8 @@ classdef FaustFactoryTest < matlab.unittest.TestCase
function test_fact_palm4msaCplx(this)
disp('Test FaustFactory.fact_palm4msaCplx()')
import matfaust.*;
import matfaust.*
import matfaust.factparams.*
num_facts = 2;
is_update_way_R2L = false;
init_lambda = 1.0;
......@@ -78,7 +80,8 @@ classdef FaustFactoryTest < matlab.unittest.TestCase
function test_fact_hierarchical(this)
disp('Test FaustFactory.fact_hierarchical()')
import matfaust.*;
import matfaust.*
import matfaust.factparams.*
num_facts = 4;
is_update_way_R2L = false;
init_lambda = 1.0;
......@@ -117,7 +120,8 @@ classdef FaustFactoryTest < matlab.unittest.TestCase
function test_fact_hierarchicalCplx(this)
disp('Test FaustFactory.fact_hierarchicalCplx()')
import matfaust.*;
import matfaust.*
import matfaust.factparams.*
num_facts = 4;
is_update_way_R2L = false;
init_lambda = 1.0;
......
%% class ConstraintInt
%%
classdef ConstraintInt < matfaust.ConstraintGeneric
classdef ConstraintInt < matfaust.factparams.ConstraintGeneric
properties (SetAccess = public)
end
......@@ -11,11 +11,11 @@ classdef ConstraintInt < matfaust.ConstraintGeneric
if(~ isreal(param) || ~ isscalar(param))
error('ConstraintInt must receive an integer as param argument.')
end
if(~ isa(name, 'matfaust.ConstraintName') || ~ name.is_int_constraint())
if(~ isa(name, 'matfaust.factparams.ConstraintName') || ~ name.is_int_constraint())
error(['ConstraintInt first argument must be a ConstraintName with a int type name ', ...
'(name.is_int_constraint() must return True).'])
end
constraint = constraint@matfaust.ConstraintGeneric(name, num_rows, num_cols, floor(param));
constraint = constraint@matfaust.factparams.ConstraintGeneric(name, num_rows, num_cols, floor(param));
end
end
end
%% class ConstraintMat
%%
classdef ConstraintMat < matfaust.ConstraintGeneric
classdef ConstraintMat < matfaust.factparams.ConstraintGeneric
properties (SetAccess = public)
end
......@@ -11,8 +11,8 @@ classdef ConstraintMat < matfaust.ConstraintGeneric
if(~ ismatrix(param) || ~ isnumeric(param))
error('ConstraintMat must receive a matrix as param argument.')
end
constraint = constraint@matfaust.ConstraintGeneric(name, size(param, 1), size(param, 2), param);
if(~ isa(name, 'matfaust.ConstraintName') || ~ name.is_mat_constraint())
constraint = constraint@matfaust.factparams.ConstraintGeneric(name, size(param, 1), size(param, 2), param);
if(~ isa(name, 'matfaust.factparams.ConstraintName') || ~ name.is_mat_constraint())
error('ConstraintMat first argument must be a ConstraintName with a matrix type name.')
end
end
......
......@@ -20,7 +20,7 @@ classdef ConstraintName
methods
function cons_name = ConstraintName(name)
import matfaust.ConstraintName
import matfaust.factparams.ConstraintName
if(name > ConstraintName.NORMLIN || name < ConstraintName.SP) %|| name == ConstraintName.BLKDIAG)
msg = 'name must be an integer among ConstraintName.SP, ConstraintName.SPCOL, ConstraintName.NORMCOL, ConstraintName.SPLINCOL, ConstraintName.CONST, ConstraintName.SP_POS, ConstraintName.SUPP, ConstraintName.NORMLIN';
error(msg)
......@@ -29,7 +29,7 @@ classdef ConstraintName
end
function is_int = is_int_constraint(obj)
%import matfaust.ConstraintName
%import matfaust.factparams.ConstraintName
% use obj instead of ConstraintName to avoid to import the class
% obj has access to static attributes of its class
% (doing the same for is_real_constraint(), is_mat_constraint(), conv2str())
......
%% class ConstraintReal
%%
classdef ConstraintReal < matfaust.ConstraintGeneric
classdef ConstraintReal < matfaust.factparams.ConstraintGeneric
properties (SetAccess = public)
end
......@@ -10,8 +10,8 @@ classdef ConstraintReal < matfaust.ConstraintGeneric
if(~ isreal(param) || ~ isscalar(param))
error('ConstraintReal must receive a real as param argument.')
end
constraint = constraint@matfaust.ConstraintGeneric(name, num_rows, num_cols, param);
if(~ isa(name, 'matfaust.ConstraintName') || ~ name.is_real_constraint())
constraint = constraint@matfaust.factparams.ConstraintGeneric(name, num_rows, num_cols, param);
if(~ isa(name, 'matfaust.factparams.ConstraintName') || ~ name.is_real_constraint())
error('ConstraintReal first argument must be a ConstraintName with a real type name.')
end
end
......
......@@ -20,34 +20,34 @@ classdef (Abstract) ParamsFact
function p = ParamsFact(varargin)
MIN_NARGIN = 4;
if(nargin < MIN_NARGIN)
error(['matfaust.ParamsFact() must receive at least ', int2str(MIN_NARGIN),' arguments.'])
error(['matfaust.factparams.ParamsFact() must receive at least ', int2str(MIN_NARGIN),' arguments.'])
end
num_facts = varargin{1};
is_update_way_R2L = varargin{2};
init_lambda = varargin{3};
constraints = varargin{4};
% set default values
step_size = matfaust.ParamsFact.DEFAULT_STEP_SIZE;
is_verbose = matfaust.ParamsFact.DEFAULT_VERBOSITY;
constant_step_size = matfaust.ParamsFact.DEFAULT_CONSTANT_STEP_SIZE;
step_size = matfaust.factparams.ParamsFact.DEFAULT_STEP_SIZE;
is_verbose = matfaust.factparams.ParamsFact.DEFAULT_VERBOSITY;
constant_step_size = matfaust.factparams.ParamsFact.DEFAULT_CONSTANT_STEP_SIZE;
if(~ isscalar(num_facts) || ~ isreal(num_facts))
error('matfaust.ParamsFact 1st argument (num_facts) must be an integer.')
error('matfaust.factparams.ParamsFact 1st argument (num_facts) must be an integer.')
else
num_facts = floor(num_facts);
end
if(~ islogical(is_update_way_R2L))
error('matfaust.ParamsFact 2nd argument (is_update_way_R2L) must be logical.')
error('matfaust.factparams.ParamsFact 2nd argument (is_update_way_R2L) must be logical.')
end
if(~ isscalar(init_lambda))
error('matfaust.ParamsFact 3rd argument (init_lambda) must be a scalar.')
error('matfaust.factparams.ParamsFact 3rd argument (init_lambda) must be a scalar.')
end
if(~ iscell(constraints))
error('matfaust.ParamsFact 4th argument (constraints) must be a cell array.')
error('matfaust.factparams.ParamsFact 4th argument (constraints) must be a cell array.')
end
for i = 1:length(constraints) %TODO: check constraints length in sub-class
if(~ isa(constraints{i}, 'matfaust.ConstraintGeneric'))
error('matfaust.ParamsFact 5th argument (constraints) must contain matfaust.ConstraintGeneric objects.')
if(~ isa(constraints{i}, 'matfaust.factparams.ConstraintGeneric'))
error('matfaust.factparams.ParamsFact 5th argument (constraints) must contain matfaust.factparams.ConstraintGeneric objects.')
end
end
if(nargin > MIN_NARGIN)
......@@ -61,13 +61,13 @@ classdef (Abstract) ParamsFact
end
if(~ isscalar(step_size))
step_size
error(['matfaust.ParamsHierarchicalFact ', int2str(MIN_NARGIN+1), 'th argument (step_size) must be a real.'])
error(['matfaust.factparams.ParamsHierarchicalFact ', int2str(MIN_NARGIN+1), 'th argument (step_size) must be a real.'])
end
if(~ islogical(constant_step_size))
error(['matfaust.ParamsFact ', int2str(MIN_NARGIN+2), 'th argument (constant_step_size) must be logical.'])
error(['matfaust.factparams.ParamsFact ', int2str(MIN_NARGIN+2), 'th argument (constant_step_size) must be logical.'])
end
if(~ islogical(is_verbose))
error(['matfaust.ParamsFact ',int2str(MIN_NARGIN+3),' argument (is_verbose) must be logical.'])
error(['matfaust.factparams.ParamsFact ',int2str(MIN_NARGIN+3),' argument (is_verbose) must be logical.'])
end
p.num_facts = num_facts;
p.is_update_way_R2L = is_update_way_R2L;
......
%% class ParamsHierarchicalFact
%%
classdef ParamsHierarchicalFact < matfaust.ParamsFact
classdef ParamsHierarchicalFact < matfaust.factparams.ParamsFact
properties (SetAccess = public)
stop_crits
data_num_rows
......@@ -14,7 +14,7 @@ classdef ParamsHierarchicalFact < matfaust.ParamsFact
function p = ParamsHierarchicalFact(varargin)
MIN_NARGIN = 8;
if(nargin < MIN_NARGIN)
error(['matfaust.ParamsHierarchicalFact() must receive at least',int2str(MIN_NARGIN),' arguments'])
error(['matfaust.factparams.ParamsHierarchicalFact() must receive at least',int2str(MIN_NARGIN),' arguments'])
end
num_facts = varargin{1};
is_update_way_R2L = varargin{2};
......@@ -26,10 +26,10 @@ classdef ParamsHierarchicalFact < matfaust.ParamsFact
data_num_cols = floor(varargin{7});
stop_crits = varargin{8};
% set default values
is_fact_side_left = matfaust.ParamsHierarchicalFact.DEFAULT_IS_FACT_SIDE_LEFT;
step_size = matfaust.ParamsFact.DEFAULT_STEP_SIZE;
is_verbose = matfaust.ParamsFact.DEFAULT_VERBOSITY;
constant_step_size = matfaust.ParamsFact.DEFAULT_CONSTANT_STEP_SIZE;
is_fact_side_left = matfaust.factparams.ParamsHierarchicalFact.DEFAULT_IS_FACT_SIDE_LEFT;
step_size = matfaust.factparams.ParamsFact.DEFAULT_STEP_SIZE;
is_verbose = matfaust.factparams.ParamsFact.DEFAULT_VERBOSITY;
constant_step_size = matfaust.factparams.ParamsFact.DEFAULT_CONSTANT_STEP_SIZE;
if(nargin > MIN_NARGIN+1)
step_size = varargin{MIN_NARGIN+2};
if(nargin > MIN_NARGIN+2)
......@@ -43,31 +43,31 @@ classdef ParamsHierarchicalFact < matfaust.ParamsFact
end
end
% parent constructor handles verification for its own arguments
p = p@matfaust.ParamsFact(num_facts, is_update_way_R2L, init_lambda, ...
p = p@matfaust.factparams.ParamsFact(num_facts, is_update_way_R2L, init_lambda, ...
constraints, step_size, constant_step_size, is_verbose);
if(~ isscalar(data_num_rows) || ~ isreal(data_num_rows))
error('matfaust.ParamsHierarchicalFact 6th argument (data_num_rows) must be an integer.')
error('matfaust.factparams.ParamsHierarchicalFact 6th argument (data_num_rows) must be an integer.')
else
data_num_rows = floor(data_num_rows);
end
if(~ isscalar(data_num_cols) || ~ isreal(data_num_cols))
error('matfaust.ParamsHierarchicalFact 7th argument (data_num_cols) must be an integer.')
error('matfaust.factparams.ParamsHierarchicalFact 7th argument (data_num_cols) must be an integer.')
else
data_num_cols = floor(data_num_cols);
end
if(~ iscell(stop_crits))
error('matfaust.ParamsHierarchicalFact 8th argument (stop_crits) must be a cell array.')
error('matfaust.factparams.ParamsHierarchicalFact 8th argument (stop_crits) must be a cell array.')
if(length(stop_crits) ~= 2 )
error('matfaust.ParamsHierarchicalFact 8th argument (stop_crits) must be a cell array of 2 elements.')
error('matfaust.factparams.ParamsHierarchicalFact 8th argument (stop_crits) must be a cell array of 2 elements.')
end
for i = 1:length(stop_crits)
if(~ isa(stop_crits{i}, matfaust.StoppingCriterion))
error('matfaust.ParamsHierarchicalFact 8th argument (stop_crits) must contain matfaust.StoppingCriterion objects.')
if(~ isa(stop_crits{i}, matfaust.factparams.StoppingCriterion))
error('matfaust.factparams.ParamsHierarchicalFact 8th argument (stop_crits) must contain matfaust.factparams.StoppingCriterion objects.')
end
end
end
if(~ islogical(is_fact_side_left))
error('matfaust.ParamsHierarchicalFact 13th argument (is_fact_side_left) must be logical.')
error('matfaust.factparams.ParamsHierarchicalFact 13th argument (is_fact_side_left) must be logical.')
end
p.stop_crits = stop_crits;
p.is_fact_side_left = is_fact_side_left;
......
%% class ParamsPalm4MSA
%%
classdef ParamsPalm4MSA < matfaust.ParamsFact
classdef ParamsPalm4MSA < matfaust.factparams.ParamsFact
properties (SetAccess = public)
init_facts
stop_crit
end
methods
function p = ParamsPalm4MSA(varargin)
import matfaust.ParamsFact
import matfaust.factparams.ParamsFact
MIN_NARGIN = 5;
if(nargin < MIN_NARGIN)
error(['matfaust.ParamsPalm4MSA() must receive at least ', int2str(MIN_NARGIN),' arguments.'])
error(['matfaust.factparams.ParamsPalm4MSA() must receive at least ', int2str(MIN_NARGIN),' arguments.'])
end
num_facts = varargin{1};
is_update_way_R2L = varargin{2};
......@@ -36,7 +36,7 @@ classdef ParamsPalm4MSA < matfaust.ParamsFact
end
% parent constructor handles verification for its own arguments
p = p@matfaust.ParamsFact(num_facts, is_update_way_R2L, init_lambda, ...
p = p@matfaust.factparams.ParamsFact(num_facts, is_update_way_R2L, init_lambda, ...
constraints, step_size, constant_step_size, is_verbose);
if(is_init_facts_to_default || iscell(init_facts) && length(init_facts) == 0)
init_facts = cell(num_facts, 1)
......@@ -53,18 +53,18 @@ classdef ParamsPalm4MSA < matfaust.ParamsFact
init_facts{zeros_id} = ...
zeros(constraints{zeros_id}.num_rows, constraints{zeros_id}.num_cols)
elseif(~ iscell(init_facts)) % TODO: check init_facts length
error('matfaust.ParamsFactPalm4MSA 4th argument (init_facts) must be a cell array.')
error('matfaust.factparams.ParamsFactPalm4MSA 4th argument (init_facts) must be a cell array.')
else
for i = 1:length(init_facts)
if(~ ismatrix(init_facts{i}) || ~ isnumeric(init_facts{i}))
error('matfaust.ParamsFactPalm4MSA 4th argument (init_facts) must contain matrices.')
error('matfaust.factparams.ParamsFactPalm4MSA 4th argument (init_facts) must contain matrices.')
%TODO: check matrix dimensions
end
end
end
p.init_facts = init_facts
if(~ isa(stop_crit, 'matfaust.StoppingCriterion'))
error('matfaust.ParamsPalm4MSA argument (stop_crit) must be a matfaust.StoppingCriterion objects.')
if(~ isa(stop_crit, 'matfaust.factparams.StoppingCriterion'))
error('matfaust.factparams.ParamsPalm4MSA argument (stop_crit) must be a matfaust.factparams.StoppingCriterion objects.')
end
p.stop_crit = stop_crit;
end
......
......@@ -15,10 +15,10 @@ classdef StoppingCriterion
num_its = 500;
max_num_its = 1000;
if(nargin < 1)
error('matfaust.StoppingCriterion needs at least one argument.')
error('matfaust.factparams.StoppingCriterion needs at least one argument.')
else
if(~ isscalar(varargin{1}))
error('matfaust.StoppingCriterion 1th argument must be a scalar.')
error('matfaust.factparams.StoppingCriterion 1th argument must be a scalar.')
end
if(nargin == 1 && (varargin{1}-floor(varargin{1})) == 0) % num_its criterion
num_its = varargin{1};
......@@ -26,16 +26,16 @@ classdef StoppingCriterion
else
is_criterion_error = true; %varargin{1};
%if( ~islogical(is_criterion_error))
% error('matfaust.StoppingCriterion 1th argument (is_criterion_error) must be logical.')
% error('matfaust.factparams.StoppingCriterion 1th argument (is_criterion_error) must be logical.')
%end
error_treshold = varargin{1};
if(~ isscalar(error_treshold) || ~ isreal(error_treshold))
error('matfaust.StoppingCriterion 2nd argument (error_treshold) must be a real number.')
error('matfaust.factparams.StoppingCriterion 2nd argument (error_treshold) must be a real number.')
end
if(nargin > 1)
max_num_its = varargin{2};
if(~ isscalar(max_num_its) || ~ isreal(max_num_its))
error('matfaust.StoppingCriterion 3rd argument (max_num_its) must be an integer.')
error('matfaust.factparams.StoppingCriterion 3rd argument (max_num_its) must be an integer.')
end
max_num_its = floor(max_num_its);
end
......
......@@ -64,6 +64,7 @@ classdef FaustFactory
%>
%> @code
%> import matfaust.*
%> import matfaust.factparams.*
%> num_facts = 2
%> is_update_way_R2L = false
%> init_lambda = 1.0
......@@ -117,7 +118,8 @@ classdef FaustFactory
%>
%> @Example
%> @code
%> import matfaust.*;
%> import matfaust.*
%> import matfaust.factparams.*
%> num_facts = 4;
%> is_update_way_R2L = false;
%> init_lambda = 1.0;
......@@ -150,6 +152,7 @@ classdef FaustFactory
%==========================================================================================
function F = fact_hierarchical(M, p)
import matfaust.Faust
import matfaust.factparams.*
mex_constraints = cell(2, p.num_facts-1);
matfaust.FaustFactory.check_fact_mat('FaustFactory.fact_hierarchical', M)
%mex_fact_constraints = cell(1, p.num_facts-1)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment