Mentions légales du service

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

Set a default value for norm arg in matfaust/pyfaust normlin/col projecctors.

It closes issue #146
parent 589f4b4f
Branches
Tags
No related merge requests found
...@@ -435,7 +435,7 @@ classdef FaustFactoryTest < matlab.unittest.TestCase ...@@ -435,7 +435,7 @@ classdef FaustFactoryTest < matlab.unittest.TestCase
n = randi([min_n 128], 1); n = randi([min_n 128], 1);
M = rand(m,n); M = rand(m,n);
s = rand(1,1)*50; s = rand(1,1)*50;
p = normcol([m, n], s); p = normcol([m, n], 's', s);
Mp = p(M); Mp = p(M);
for i=1:n for i=1:n
this.verifyLessThanOrEqual(norm(Mp(:,i)), s+1e-6) this.verifyLessThanOrEqual(norm(Mp(:,i)), s+1e-6)
...@@ -450,7 +450,7 @@ classdef FaustFactoryTest < matlab.unittest.TestCase ...@@ -450,7 +450,7 @@ classdef FaustFactoryTest < matlab.unittest.TestCase
n = randi([min_n 128], 1); n = randi([min_n 128], 1);
M = rand(m,n); M = rand(m,n);
s = rand()*50; s = rand()*50;
p = normlin([m, n], s); p = normlin([m, n], 's', s);
Mp = p(M); Mp = p(M);
for i=1:m for i=1:m
this.verifyLessThanOrEqual(norm(Mp(i,:)), s+1e-6) this.verifyLessThanOrEqual(norm(Mp(i,:)), s+1e-6)
......
...@@ -10,17 +10,33 @@ classdef normcol < matfaust.proj.proj_gen ...@@ -10,17 +10,33 @@ classdef normcol < matfaust.proj.proj_gen
%=============================================== %===============================================
%> @b Usage %> @b Usage
%> %>
%> &nbsp;&nbsp;&nbsp; @b normcol(shape, normval): returns a NORMCOL projector (functor), shape defines the size of the input matrix (e.g. [1, 10]), normval defines the sparsity of the output matrix (the 2-norm of each column).<br/> %> &nbsp;&nbsp;&nbsp; @b normcol(shape, s): returns a NORMCOL projector (functor), shape defines the size of the input matrix (e.g. [1, 10]), s defines the sparsity of the output matrix (the 2-norm of each column).<br/>
%> %>
%> @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 normval: the sparsity parameter. %> @param 's', value: (optional) the sparsity parameter, the 2-norm of the column (1 by default).
%=============================================== %===============================================
function proj = normcol(shape, normval)%, varargin) function proj = normcol(shape, varargin)
import matfaust.factparams.ConstraintReal import matfaust.factparams.ConstraintReal
if(normval < 0) % TODO: factorize this sparsing with normlin
error('A norm can''t be negative') if(length(varargin) > 0)
if(strcmp(varargin{1}, 's'))
disp('s in varargin')
if(length(varargin) < 2)
error('s value is missing')
end
s = varargin{2};
varargin(1:2) = []; % deleting the used cell
if(~ isreal(s) || ~ isscalar(s))
error('s must be a real scalar')
end
if(s < 0)
error('A norm can''t be negative')
end
% else % do nothing (ConstraintReal role)
end
end end
proj.constraint = ConstraintReal('normcol', shape(1), shape(2), normval)%, varargin{:}); proj.constraint = ConstraintReal('normcol', shape(1), shape(2), s)%, varargin{:});
end end
end end
end end
...@@ -10,17 +10,34 @@ classdef normlin < matfaust.proj.proj_gen ...@@ -10,17 +10,34 @@ classdef normlin < matfaust.proj.proj_gen
%=============================================== %===============================================
%> @b Usage %> @b Usage
%> %>
%> &nbsp;&nbsp;&nbsp; @b normlin(shape, normval): returns a NORMLIN projector (functor), shape defines the size of the input matrix (e.g. [1, 10]), normval defines the sparsity of the output matrix (the 2-norm of each row).<br/> %> &nbsp;&nbsp;&nbsp; @b normlin(shape, s): returns a NORMLIN projector (functor), shape defines the size of the input matrix (e.g. [1, 10]), s defines the sparsity of the output matrix (the 2-norm of each row).<br/>
%> %>
%> @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 normval: the sparsity parameter. %> @param 's', value: (optional) the sparsity parameter, the 2-norm of the row (1 by default).
%=============================================== %===============================================
function proj = normlin(shape, normval, varargin) function proj = normlin(shape, varargin)
import matfaust.factparams.ConstraintReal import matfaust.factparams.ConstraintReal
if(normval < 0) s = 1;
error('A norm can''t be negative') if(length(varargin) > 0)
if(strcmp(varargin{1}, 's'))
disp('s in varargin')
if(length(varargin) < 2)
error('s value is missing')
end
s = varargin{2};
varargin(1:2) = []; % deleting the used cell
if(~ isreal(s) || ~ isscalar(s))
error('s must be a real scalar')
end
if(s < 0)
error('A norm can''t be negative')
end
% else % do nothing (ConstraintReal role)
end
end end
proj.constraint = ConstraintReal('normlin', shape(1), shape(2), normval, varargin{:});
proj.constraint = ConstraintReal('normlin', shape(1), shape(2), s, varargin{:});
end end
end end
end end
...@@ -358,10 +358,11 @@ class normcol(proj_gen): ...@@ -358,10 +358,11 @@ class normcol(proj_gen):
Functor for the NORMCOL projector. A, the image matrix, is defined by \f$ \forall j \in \{0,...,shape[1]-1\} \f$ the j-th column \f$ A_{*,j} \f$ is such that \f$\| A_{*,j}\|_2 = s \f$. Functor for the NORMCOL projector. A, the image matrix, is defined by \f$ \forall j \in \{0,...,shape[1]-1\} \f$ the j-th column \f$ A_{*,j} \f$ is such that \f$\| A_{*,j}\|_2 = s \f$.
""" """
def __init__(self, shape, s): def __init__(self, shape, s=1):
""" """
Args: Args:
s: the column 2-norm. shape: the input matrix shape.
s: the column 2-norm (default to 1).
Example: Example:
>>> from pyfaust.proj import normcol >>> from pyfaust.proj import normcol
...@@ -398,12 +399,11 @@ class normlin(proj_gen): ...@@ -398,12 +399,11 @@ class normlin(proj_gen):
0.01 0.01
""" """
def __init__(self, shape, s): def __init__(self, shape, s=1):
""" """
Args: Args:
s: the row 2-norm. shape: the input matrix shape.
normalized: True to normalize the projection image according to its Frobenius norm. s: the row 2-norm (default to 1).
pos: True to skip negative values (replaced by zero) of the matrix to project.
""" """
if(s < 0): if(s < 0):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment