Mentions légales du service

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

Handle more uniformly/generically the setting of normalized and pos attributes...

Handle more uniformly/generically the setting of normalized and pos attributes of matfaust.factparams.Constraint* classes
parent 0fae63ec
No related branches found
No related tags found
No related merge requests found
...@@ -30,9 +30,8 @@ classdef (Abstract) ConstraintGeneric ...@@ -30,9 +30,8 @@ classdef (Abstract) ConstraintGeneric
constraint.param = param; constraint.param = param;
% optional key-value arguments % optional key-value arguments
argc = length(varargin); argc = length(varargin);
constraint.normalized = false;
constraint.default_normalized = true; constraint.default_normalized = true;
constraint.pos = false; [constraint.normalized, constraint.pos] = constraint.get_default_parameters();
if(argc > 0) if(argc > 0)
for i=1:argc for i=1:argc
switch(varargin{i}) switch(varargin{i})
......
...@@ -18,5 +18,12 @@ classdef ConstraintInt < matfaust.factparams.ConstraintGeneric ...@@ -18,5 +18,12 @@ classdef ConstraintInt < matfaust.factparams.ConstraintGeneric
'(name.is_int_constraint() must return True).']) '(name.is_int_constraint() must return True).'])
end end
end end
function [normalized, pos] = get_default_parameters(self)
% all int constraints have the same default parameters
normalized = true;
pos = false;
end
end end
end end
...@@ -15,8 +15,8 @@ classdef ConstraintMat < matfaust.factparams.ConstraintGeneric ...@@ -15,8 +15,8 @@ classdef ConstraintMat < matfaust.factparams.ConstraintGeneric
param = real(param); param = real(param);
end end
if(isa(name, 'matfaust.factparams.ConstraintName') && name.name == matfaust.factparams.ConstraintName.BLKDIAG || isstr(name) && matfaust.factparams.ConstraintName.str2name_int(name) == matfaust.factparams.ConstraintName.BLKDIAG) if(isa(name, 'matfaust.factparams.ConstraintName') && name.name == matfaust.factparams.ConstraintName.BLKDIAG || isstr(name) && matfaust.factparams.ConstraintName.str2name_int(name) == matfaust.factparams.ConstraintName.BLKDIAG)
nrows = param(end,1); nrows = param(end, 1);
ncols = param(end,2); ncols = param(end, 2);
else else
nrows = size(param, 1); nrows = size(param, 1);
ncols = size(param, 2); ncols = size(param, 2);
...@@ -25,11 +25,33 @@ classdef ConstraintMat < matfaust.factparams.ConstraintGeneric ...@@ -25,11 +25,33 @@ classdef ConstraintMat < matfaust.factparams.ConstraintGeneric
if(~ isa(constraint.name, 'matfaust.factparams.ConstraintName') || ~ constraint.name.is_mat_constraint()) if(~ isa(constraint.name, 'matfaust.factparams.ConstraintName') || ~ constraint.name.is_mat_constraint())
error('ConstraintMat first argument must be a ConstraintName with a matrix type name.') error('ConstraintMat first argument must be a ConstraintName with a matrix type name.')
end end
if(constraint.default_normalized && constraint.name.name == matfaust.factparams.ConstraintName.CONST)
% for CONST proj the default is to not normalize end
constraint.normalized = false;
% for SUPP it is true (which is handled by ConstraintGeneric parent function [normalized, pos] = get_default_parameters(self)
import matfaust.factparams.ConstraintName
name = self.name.name;
switch(name)
%TODO: add ID
%case ConstraintName.ID:
% normalized = false;
% pos = false;
case {ConstraintName.TOEPLITZ,
ConstraintName.CIRC,
ConstraintName.HANKEL,
ConstraintName.SUPP,
ConstraintName.BLKDIAG}
normalized = true;
pos = false;
case ConstraintName.CONST
normalized = false;
pos = false;
otherwise
error('Invalid ConstraintName')
end
end end
end end
end end
end end
...@@ -12,12 +12,17 @@ classdef ConstraintReal < matfaust.factparams.ConstraintGeneric ...@@ -12,12 +12,17 @@ classdef ConstraintReal < matfaust.factparams.ConstraintGeneric
error('ConstraintReal must receive a real as param argument.') error('ConstraintReal must receive a real as param argument.')
end end
constraint = constraint@matfaust.factparams.ConstraintGeneric(name, num_rows, num_cols, param, varargin{:}); constraint = constraint@matfaust.factparams.ConstraintGeneric(name, num_rows, num_cols, param, varargin{:});
if(constraint.default_normalized && constraint.name.name == matfaust.factparams.ConstraintName.CONST)
constraint.normalized = false;
end
if(~ isa(constraint.name, 'matfaust.factparams.ConstraintName') || ~ constraint.name.is_real_constraint()) if(~ isa(constraint.name, 'matfaust.factparams.ConstraintName') || ~ constraint.name.is_real_constraint())
error('ConstraintReal first argument must be a ConstraintName with a real type name.') error('ConstraintReal first argument must be a ConstraintName with a real type name.')
end end
end end
function [normalized, pos] = get_default_parameters(self)
% all Real constraints have the same default parameters
normalized = false;
pos = false;
end
end end
end end
...@@ -15,8 +15,8 @@ classdef skperm < matfaust.proj.proj_gen ...@@ -15,8 +15,8 @@ classdef skperm < matfaust.proj.proj_gen
%> %>
%> @param shape: vector of size 2, to define the size of the input matrix. %> @param shape: vector of size 2, to define the size of the input matrix.
%> @param k: the sparsity parameter. %> @param k: the sparsity parameter.
%> @param 'normalized', true: normalizes the projection image according to its Frobenius norm. %> @param 'normalized', true: (the default) normalizes the projection image according to its Frobenius norm.
%> @param 'normalized', false: (the default) no normalization. %> @param 'normalized', false: no normalization.
%> @param 'pos', true: skips the negative values (replaced by zero) of the input matrix. %> @param 'pos', true: skips the negative values (replaced by zero) of the input matrix.
%> @param 'pos', false: (the default) negative values are not skipped. %> @param 'pos', false: (the default) negative values are not skipped.
%> @retval proj the skperm projector. %> @retval proj the skperm projector.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment