Mentions légales du service

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

Modify C++ Faust::Palm4MSA, Faust::HierarchicalFact and Faust::ParamsPalm,...

Modify C++ Faust::Palm4MSA, Faust::HierarchicalFact and Faust::ParamsPalm, Faust::Params to allow setting norm2 threshold and max iter arbitrarily (default values changed faust_constant.h.in).

In faust_constant.h.in:
- Change default parameters from 1e-4 to 1e-6 precision (used among other things for spectral norm).
- Rename spectral norm default parameter for max number of iterations to FAUST_NORM2_MAX_ITER.

Minor changes (display related) in test_palm4MSA.cpp.in and hierarchicalFactorization.cpp.in.
parent ef267ce4
No related branches found
No related tags found
No related merge requests found
......@@ -241,7 +241,7 @@ int main(int argc, char* argv[])
std::cout<<"**************** RELATIVE ERROR BETWEEN FAUST AND DATA MATRIX **************** "<<std::endl;
std::cout<<" "<<relativeError<<std::endl<<std::endl;
hierFactCore.Display();
//time comparison between matrix vector product and faust-vector product
int niterTimeComp = 10;
if (niterTimeComp > 0)
......
......@@ -103,6 +103,7 @@ int main()
initLambda = (FPP2) init_double_from_matio(configPalm2Filename, "init_lambda");
nfacts = init_int_from_matio(configPalm2Filename, "nfacts");
niter = init_int_from_matio(configPalm2Filename, "niter");
//niter = 2000;
updateWay = init_bool_from_matio(configPalm2Filename, "update_way");
verbose = init_bool_from_matio(configPalm2Filename, "verbose");
......@@ -133,9 +134,11 @@ int main()
palm2.compute_facts();
std::vector<Faust::MatDense<FPP,Cpu> >& full_facts = const_cast< std::vector<Faust::MatDense<FPP,Cpu> >&>(palm2.get_facts());
FPP2 lambda = palm2.get_lambda();
cout << "out lambda: " << lambda << endl;
(full_facts[0]) *= FPP(lambda);
Faust::Transform<FPP, Cpu>* t = new Faust::Transform<FPP, Cpu>(full_facts);
t->Display();
//relativeError
Faust::MatDense<FPP,Cpu> faustProduct;
faustProduct=t->get_product();
......
......@@ -95,6 +95,8 @@ namespace Faust
protected:
const std::vector< std::vector<const Faust::ConstraintGeneric*>> cons;
Real<FPP> norm2_threshold;
int norm2_max_iter;
bool m_isUpdateWayR2L;
bool m_isFactSideLeft;
bool m_isVerbose;
......
......@@ -70,6 +70,8 @@ Faust::HierarchicalFact<FPP,DEVICE,FPP2>::HierarchicalFact(const Faust::MatDense
m_isFactSideLeft(params_.isFactSideLeft),
m_isVerbose(params_.isVerbose),
nbFact(params_.m_nbFact-1),
norm2_threshold(params_.norm2_threshold),
norm2_max_iter(params_.norm2_max_iter),
palm_2(Palm4MSA<FPP,DEVICE,FPP2>(M,params_, cublasHandle, false)),
palm_global(new Palm4MSA<FPP,DEVICE,FPP2>(M,params_, cublasHandle, true)),
cons_tmp_global(vector<const Faust::ConstraintGeneric*>()),
......
......@@ -190,6 +190,8 @@ namespace Faust
bool isInit; // only used for global factorization (if isGlobal)
Faust::MatDense<FPP,DEVICE> grad_over_c;
FPP2 c;
Real<FPP> norm2_threshold;
int norm2_max_iter;
Faust::MatDense<FPP,DEVICE> error; // error = lambda*L*S*R - data
Faust::BlasHandle<DEVICE> blas_handle;
/** is_complex == true if the algorithm is running on a complex matrix (to approximate) */
......
......@@ -92,6 +92,8 @@ Faust::Palm4MSA<FPP,DEVICE,FPP2>::Palm4MSA(const Faust::MatDense<FPP,DEVICE>& M,
verbose(params_.isVerbose),
isUpdateWayR2L(params_.isUpdateWayR2L),
isConstantStepSize(params_.isConstantStepSize),
norm2_threshold(params_.norm2_threshold),
norm2_max_iter(params_.norm2_max_iter),
isGradComputed(false),
isProjectionComputed(false),
isLastFact(false),
......@@ -134,6 +136,8 @@ Faust::Palm4MSA<FPP,DEVICE,FPP2>::Palm4MSA(const Faust::ParamsPalm<FPP,DEVICE,FP
verbose(params_palm_.isVerbose),
isUpdateWayR2L(params_palm_.isUpdateWayR2L),
isConstantStepSize(params_palm_.isConstantStepSize),
norm2_threshold(params_palm_.norm2_threshold),
norm2_max_iter(params_palm_.norm2_max_iter),
isGradComputed(false),
isProjectionComputed(false),
isLastFact(false),
......@@ -163,7 +167,6 @@ void Faust::Palm4MSA<FPP,DEVICE,FPP2>::compute_facts()
{
next_step();
}
}
template<typename FPP,Device DEVICE,typename FPP2>
......@@ -569,11 +572,8 @@ void Faust::Palm4MSA<FPP,DEVICE,FPP2>::compute_c()
if (!isConstantStepSize)
{
int flag1,flag2;
int nbr_iter = 10000;
FPP2 threshold = 1e-16;
FPP2 nL1=LorR.spectralNorm(nbr_iter,threshold,flag1,blas_handle);
FPP2 nR1=RorL[m_indFact].spectralNorm(nbr_iter,threshold,flag2,blas_handle);
FPP2 nL1=LorR.spectralNorm(norm2_max_iter,norm2_threshold,flag1,blas_handle);
FPP2 nR1=RorL[m_indFact].spectralNorm(norm2_max_iter,norm2_threshold,flag2,blas_handle);
c=lipschitz_multiplicator*nR1*nR1*nL1*nL1*m_lambda*m_lambda;
}
......
......@@ -177,6 +177,8 @@ namespace Faust
bool isConstantStepSize;
FPP2 step_size;
GradientCalcOptMode gradCalcOptMode;
Real<FPP> norm2_threshold;
unsigned int norm2_max_iter;
//default value
static const int defaultNiter1;
......
......@@ -140,7 +140,9 @@ Faust::Params<FPP,DEVICE,FPP2>::Params(
init_lambda(init_lambda_),
isConstantStepSize(constant_step_size_),
step_size(step_size_),
gradCalcOptMode(gradCalcOptMode)
gradCalcOptMode(gradCalcOptMode),
norm2_threshold(FAUST_PRECISION),
norm2_max_iter(FAUST_NORM2_MAX_ITER)
{
if (nbFact_ <= 2)
{
......@@ -253,7 +255,9 @@ Faust::Params<FPP,DEVICE,FPP2>::Params(
init_lambda(init_lambda_),
isConstantStepSize(constant_step_size_),
step_size(step_size_),
gradCalcOptMode(gradCalcOptMode)
gradCalcOptMode(gradCalcOptMode),
norm2_threshold(FAUST_PRECISION),
norm2_max_iter(FAUST_NORM2_MAX_ITER)
{
check_constraint_validity();
......@@ -278,7 +282,9 @@ Faust::Params<FPP,DEVICE,FPP2>::Params() : m_nbRow(0),
init_lambda(defaultLambda),
isConstantStepSize(defaultConstantStepSize),
step_size(defaultStepSize),
gradCalcOptMode(defaultGradCalcOptMode)
gradCalcOptMode(defaultGradCalcOptMode),
norm2_threshold(FAUST_PRECISION),
norm2_max_iter(FAUST_NORM2_MAX_ITER)
{}
......@@ -308,6 +314,8 @@ void Faust::Params<FPP,DEVICE,FPP2>::Display() const
std::cout<<"stop_crit_2facts : "<<stop_crit_2facts.get_crit()<<std::endl;
std::cout<<"stop_crit_global : "<<stop_crit_global.get_crit()<<std::endl;
std::cout << "gradCalcOptMode: "<< gradCalcOptMode << std::endl;
std::cout << "norm2_threshold:" << norm2_threshold << std::endl;
std::cout << "norm2_max_iter:" << norm2_max_iter << std::endl;
/*cout<<"INIT_FACTS :"<<endl;
for (int L=0;L<init_fact.size();L++)init_fact[L].Display();*/
......
......@@ -105,6 +105,8 @@ namespace Faust
FPP2 step_size;
FPP2 init_lambda;
GradientCalcOptMode gradCalcOptMode;
Real<FPP> norm2_threshold;
unsigned int norm2_max_iter;
void Display() const;
void init_factors();
......
......@@ -104,13 +104,15 @@ Faust::ParamsPalm<FPP,DEVICE,FPP2>::ParamsPalm(
init_lambda(init_lambda_),
isConstantStepSize(constant_step_size_),
step_size(step_size_),
gradCalcOptMode(gradCalcOptMode)
gradCalcOptMode(gradCalcOptMode),
norm2_max_iter(FAUST_NORM2_MAX_ITER),
norm2_threshold(FAUST_PRECISION)
{
check_constraint_validity();
}
template<typename FPP,Device DEVICE,typename FPP2>
Faust::ParamsPalm<FPP,DEVICE,FPP2>::ParamsPalm() : data(0,0),nbFact(0),cons(std::vector<const Faust::ConstraintGeneric*>()),init_lambda(defaultLambda),isConstantStepSize(defaultConstantStepSize),step_size(defaultStepSize), gradCalcOptMode(Faust::Params<FPP,DEVICE,FPP2>::defaultGradCalcOptMode) {}
Faust::ParamsPalm<FPP,DEVICE,FPP2>::ParamsPalm() : data(0,0),nbFact(0),cons(std::vector<const Faust::ConstraintGeneric*>()),init_lambda(defaultLambda),isConstantStepSize(defaultConstantStepSize),step_size(defaultStepSize), gradCalcOptMode(Faust::Params<FPP,DEVICE,FPP2>::defaultGradCalcOptMode), norm2_max_iter(FAUST_NORM2_MAX_ITER), norm2_threshold(FAUST_PRECISION) {}
template<typename FPP,Device DEVICE,typename FPP2>
void Faust::ParamsPalm<FPP,DEVICE,FPP2>::init_factors()
......@@ -163,6 +165,9 @@ void Faust::ParamsPalm<FPP,DEVICE,FPP2>::Display() const
std::cout<<"data : nbRow "<<data.getNbRow()<<" NbCol : "<< data.getNbCol()<<std::endl;
std::cout<<"stop_crit : "<<stop_crit.get_crit()<<std::endl;
std::cout << "gradCalcOptMode: "<< gradCalcOptMode << std::endl;
std::cout << "norm2_threshold:" << norm2_threshold << std::endl;
std::cout << "norm2_max_iter:" << norm2_max_iter << std::endl;
/*cout<<"INIT_FACTS :"<<endl;
for (int L=0;L<init_fact.size();L++)init_fact[L].Display();*/
......
......@@ -77,8 +77,8 @@ enum Device
typedef unsigned long int faust_unsigned_int;
typedef long int faust_int;
const double FAUST_PRECISION = 0.0001;
const faust_unsigned_int nbr_iter_norm = 100;
const double FAUST_PRECISION = 1e-6;
const faust_unsigned_int FAUST_NORM2_MAX_ITER = 100;
#include "Eigen/Core"
template<typename FPP>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment