-  3.41.0
pyfaust.factparams.ParamsHierarchicalNoResCons Class Reference

This class is a simplified ParamsHierarchical in which you define only the pyfaust.fact.hierarchical resulting Faust factors constraints. More...

Public Member Functions

def __init__ (self, fact_constraints, stop_crit1, stop_crit2, is_update_way_R2L=False, init_lambda=1.0, step_size=10.0 **-16, constant_step_size=False, is_fact_side_left=False, is_verbose=False, factor_format='dynamic', packing_RL=True, no_normalization=False, no_lambda=False, norm2_max_iter=100, norm2_threshold=1e-6, grad_calc_opt_mode=ParamsFact.EXTERNAL_OPT, **kwargs)
 Constructor. More...
 
- Public Member Functions inherited from pyfaust.factparams.ParamsHierarchical
def __init__ (self, fact_constraints, res_constraints, stop_crit1, stop_crit2, is_update_way_R2L=False, init_lambda=1.0, step_size=10.0 **-16, constant_step_size=False, is_fact_side_left=False, is_verbose=False, factor_format='dynamic', packing_RL=True, no_normalization=False, no_lambda=False, norm2_max_iter=100, norm2_threshold=1e-6, grad_calc_opt_mode=ParamsFact.EXTERNAL_OPT, **kwargs)
 Constructor. More...
 
def are_constraints_consistent (self, M)
 This method verifies that the constraints are shape-consistent to the matrix/array M to factorize and with each other. More...
 
def __repr__ (self)
 Returns object representation. More...
 
- Public Member Functions inherited from pyfaust.factparams.ParamsFact
def __init__ (self, num_facts, is_update_way_R2L, init_lambda, constraints, step_size, constant_step_size, is_verbose, factor_format='dynamic', packing_RL=True, no_normalization=False, no_lambda=False, norm2_max_iter=100, norm2_threshold=1e-6, grad_calc_opt_mode=EXTERNAL_OPT, **kwargs)
 

Additional Inherited Members

- Static Public Member Functions inherited from pyfaust.factparams.ParamsFact
def factor_format_str2int (factor_format)
 
def factor_format_int2str (factor_format)
 
def get_constraints (projs)
 Returns a python list of constraints from the projs which is a ConstralintList or a list/tuple that can be a mix of ConstraintGeneric or pyfaust.proj.proj_gen. More...
 
- Public Attributes inherited from pyfaust.factparams.ParamsFact
 step_size
 
 constant_step_size
 
 norm2_max_iter
 
 norm2_threshold
 
 factor_format
 
 packing_RL
 
 no_normalization
 
 no_lambda
 
 use_MHTP
 

Detailed Description

This class is a simplified ParamsHierarchical in which you define only the pyfaust.fact.hierarchical resulting Faust factors constraints.

You don't have to define the intermediate residual factors as you normally do with a ParamsHierarchical. With a ParamsHierachicalNoResCons they are defined automatically/internally using pyfaust.proj.proj_id. It means that only the gradient descent of PALM4MSA modify the residual factors. The only residual factor you have to define the constraint for, is the last one (because it is present in the resulting Faust of pyfaust.fact.hierarchical).

The example below shows (for a Hadamard matrix factorization) the definition of a ParamsHierarchical instance and its simpler equivalent (with the same set of internal defaultly defined residual constraints) as a ParamsHierachicalNoResCons. It allows to get exactly what is exactly a ParamsHierarchicalNoResCons internally. This example is a detailed way to the same thing as ParamsHierarchicalWHTNoResCons.

See also
ParamsHierarchical, pyfaust.fact.hierarchical, ParamsHierarchicalNoResCons.__init__

Examples

This example shows two parameterizations that are equivalent. The first one, p1, is defined through a ParamsHierarchical instance while the second one, p2, is defined using a ParamsHierarchicalNoResCons instance.

>>> from pyfaust import wht
>>> from pyfaust.proj import skperm, proj_id
>>> from pyfaust.factparams import ParamsHierarchical, ParamsHierarchicalNoResCons, StoppingCriterion
>>> from pyfaust.fact import hierarchical
>>> from numpy import log2
>>> from numpy.linalg import norm
>>> # create a Hadamard matrix
>>> H = wht(32).toarray()
>>> d = H.shape[0]
>>> n = int(log2(d))
>>> res_projs = [skperm((d,d), int(d/2**(i+1)), normalized=True) if i == n-2 else proj_id((d,d)) for i in range(n-1)]
>>> fac_projs = [skperm((d,d), 2, normalized=True) for i in range(n-1)]
>>> stop_crit = StoppingCriterion(num_its=30)
>>> p1 = ParamsHierarchical(fac_projs, res_projs, stop_crit, stop_crit, is_update_way_R2L=True, packing_RL=False)
>>> simple_projs = fac_projs+[res_projs[-1]]
>>> p2 = ParamsHierarchicalNoResCons(simple_projs, stop_crit, stop_crit, is_update_way_R2L=True, packing_RL=False)
>>> # p1 and p2 are exactly the same set of parameters for hierarchical
>>> # let's verify the results
>>> # factorizing with p1 (ParamsHierarchical) into Faust F1
>>> F1 = hierarchical(H, p1, backend=2020)
>>> # factorizing with p2 (ParamsHierarchicalNoResCons)
>>> print("F1=", F1)

F1= Faust size 32x32, density 0.3125, nnz_sum 320, 5 factor(s):

  • FACTOR 0 (double) SPARSE, size 32x32, density 0.0625, nnz 64
  • FACTOR 1 (double) SPARSE, size 32x32, density 0.0625, nnz 64
  • FACTOR 2 (double) SPARSE, size 32x32, density 0.0625, nnz 64
  • FACTOR 3 (double) SPARSE, size 32x32, density 0.0625, nnz 64
  • FACTOR 4 (double) SPARSE, size 32x32, density 0.0625, nnz 64
>>> print("F1 error =", (F1-H).norm()/norm(H))

F1 error = 7.850462159063938e-16

>>> # factorizing with p2 (ParamsHierarchicalNoResCons) into Faust F2
>>> F2 = hierarchical(H, p2, backend=2020)
>>> print("F2=", F2)

F2= Faust size 32x32, density 0.3125, nnz_sum 320, 5 factor(s):

  • FACTOR 0 (double) SPARSE, size 32x32, density 0.0625, nnz 64
  • FACTOR 1 (double) SPARSE, size 32x32, density 0.0625, nnz 64
  • FACTOR 2 (double) SPARSE, size 32x32, density 0.0625, nnz 64
  • FACTOR 3 (double) SPARSE, size 32x32, density 0.0625, nnz 64
  • FACTOR 4 (double) SPARSE, size 32x32, density 0.0625, nnz 64
>>> print("F2 error =", (F2-H).norm()/norm(H))

F2 error = 7.850462159063938e-16

Constructor & Destructor Documentation

◆ __init__()

def pyfaust.factparams.ParamsHierarchicalNoResCons.__init__ (   self,
  fact_constraints,
  stop_crit1,
  stop_crit2,
  is_update_way_R2L = False,
  init_lambda = 1.0,
  step_size = 10.0**-16,
  constant_step_size = False,
  is_fact_side_left = False,
  is_verbose = False,
  factor_format = 'dynamic',
  packing_RL = True,
  no_normalization = False,
  no_lambda = False,
  norm2_max_iter = 100,
  norm2_threshold = 1e-6,
  grad_calc_opt_mode = ParamsFact.EXTERNAL_OPT,
**  kwargs 
)

Constructor.

Parameters
fact_constraintsthe list of pyfaust.proj.proj_gen or pyfaust.factparams.ConstraintGeneric that define the structure of the pyfaust.fact.hierarchical resulting Faust factors in the same order if is_fact_side_left==False, in the reverse order otherwise.
stop_crit1cf. pyfaust.fact.ParamsHierarchical.__init__
stop_crit2cf. pyfaust.fact.ParamsHierarchical.__init__
is_update_way_R2Lcf. pyfaust.fact.ParamsHierarchical.__init__
init_lambdacf. pyfaust.fact.ParamsHierarchical.__init__
step_sizecf. pyfaust.fact.ParamsHierarchical.__init__
constant_step_sizecf. pyfaust.fact.ParamsHierarchical.__init__
is_fact_side_leftcf. pyfaust.fact.ParamsHierarchical.__init__
is_verbosecf. pyfaust.fact.ParamsHierarchical.__init__
factor_formatcf. pyfaust.fact.ParamsHierarchical.__init__
packing_RLcf. pyfaust.fact.ParamsHierarchical.__init__
no_normalizationcf. pyfaust.fact.ParamsHierarchical.__init__
no_lambdacf. pyfaust.fact.ParamsHierarchical.__init__
norm2_max_itercf. pyfaust.fact.ParamsHierarchical.__init__
grad_calc_opt_modecf. pyfaust.fact.ParamsHierarchical.__init__

The documentation for this class was generated from the following file:
pyfaust.norm
def norm(F, ord='fro', **kwargs)
Returns Faust.norm(F, ord)` ornumpy.linalg.norm(F, ord)`` depending of F type.
Definition: __init__.py:3917
pyfaust.proj
This module provides matrix projectors.
Definition: proj.py:1
pyfaust.wht
def wht(n, normed=True, dev="cpu", dtype='float64')
Constructs a Faust implementing the Walsh-Hadamard Transform (WHT) of order n.
Definition: __init__.py:4142
pyfaust.factparams
The module for the parameterization of FAuST's algorithms (Palm4MSA and Hierarchical Factorization)....
Definition: factparams.py:1
pyfaust.fact.hierarchical
def hierarchical(M, p, ret_lambda=False, ret_params=False, backend=2016, on_gpu=False)
Factorizes the matrix M using the hierarchical PALM4MSA algorithm according to the parameters set in ...
Definition: fact.py:1021
pyfaust.fact
The pyfaust factorization module.
Definition: fact.py:1