Mentions légales du service

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

Add an overload of Faust::hierarchical2020 to use Faust::Params the same...

Add an overload of Faust::hierarchical2020 to use Faust::Params the same parameter structure as Faust:HierarchicalFact(2016).
parent a2c12fb5
No related branches found
No related tags found
No related merge requests found
...@@ -161,7 +161,7 @@ int main(int argc, char* argv[]) ...@@ -161,7 +161,7 @@ int main(int argc, char* argv[])
Faust::SpBlasHandle<Cpu> spblasHandle; Faust::SpBlasHandle<Cpu> spblasHandle;
// parameter setting // parameter setting
Faust::Params<FPP,Cpu,FPP2> params; Faust::Params<FPP,Cpu,Real<FPP>> params;
init_params_from_matiofile<FPP,Cpu,FPP2>(params,configFilename.c_str(),"params"); init_params_from_matiofile<FPP,Cpu,FPP2>(params,configFilename.c_str(),"params");
// params.Display(); // params.Display();
...@@ -180,9 +180,11 @@ int main(int argc, char* argv[]) ...@@ -180,9 +180,11 @@ int main(int argc, char* argv[])
auto res_cons = cons[1]; auto res_cons = cons[1];
vector<Faust::StoppingCriterion<Real<FPP>>> sc = {200,200}; vector<Faust::StoppingCriterion<Real<FPP>>> sc = {200,200};
Real<FPP> lambda; Real<FPP> lambda;
auto th = Faust::hierarchical(matrix, sc, fac_cons, res_cons, lambda, params.isUpdateWayR2L, // auto th = Faust::hierarchical(matrix, sc, fac_cons, res_cons, lambda, params.isUpdateWayR2L,
params.isFactSideLeft, /*use_csr */ true, /*packing_RL default to true*/true, // params.isFactSideLeft, /*use_csr */ true, /*packing_RL default to true*/true,
/* compute_norms_on_arrays */false, FAUST_PRECISION, FAUST_NORM2_MAX_ITER, /* is_verbose default to false */ true); // /* compute_norms_on_arrays */false, FAUST_PRECISION, FAUST_NORM2_MAX_ITER, /* is_verbose default to false */ true);
params.isVerbose = true;
auto th = Faust::hierarchical<FPP,Cpu>(matrix, params, lambda, false);
cout << "lambda=" << lambda << endl; cout << "lambda=" << lambda << endl;
th->multiply(lambda); th->multiply(lambda);
th->display(); th->display();
......
#ifndef __FAUST_HIERARCHICAL__ #ifndef __FAUST_HIERARCHICAL__
#define __FAUST_HIERARCHICAL__ #define __FAUST_HIERARCHICAL__
#include "faust_palm4msa2020.h" #include "faust_palm4msa2020.h"
#include "faust_Params.h"
namespace Faust namespace Faust
{ {
template<typename FPP, Device DEVICE> template<typename FPP, Device DEVICE>
...@@ -17,37 +18,12 @@ namespace Faust ...@@ -17,37 +18,12 @@ namespace Faust
const unsigned int norm2_max_iter=FAUST_NORM2_MAX_ITER, const unsigned int norm2_max_iter=FAUST_NORM2_MAX_ITER,
const bool is_verbose=false, const bool is_verbose=false,
const bool constant_step_size=false, const Real<FPP> step_size=FAUST_PRECISION); const bool constant_step_size=false, const Real<FPP> step_size=FAUST_PRECISION);
}
// this macro is only for hierarchical template<typename FPP, Device DEVICE>
#define DISPLAY_PARAMS() \ Faust::TransformHelper<FPP,DEVICE>* hierarchical(const Faust::MatDense<FPP,DEVICE>& A,
if(is_verbose)\ Faust::Params<FPP,DEVICE, Real<FPP>> &p,
{\ Real<FPP>& lambda, const bool compute_2norm_on_array);
std::cout << "Faust::hierarchical2020 parameters:" << endl;\
std::cout << "nfacts: " << fac_constraints.size()+1 << endl;\
std::cout << "verbose: " << is_verbose << endl;\
std::cout << "updateway R2L: " << is_update_way_R2L << endl;\
std::cout << "init_lambda: " << lambda << endl;\
std::cout << "is_fact_side_left: " << is_fact_side_left << endl;\
std::cout << "stop_crit_2facts: " << sc[0].get_crit() << endl;\
std::cout << "stop_crit_global: " << sc[1].get_crit() << endl;\
std::cout << "norm2_threshold: " << norm2_threshold << endl;\
std::cout << "norm2_max_iter: " << norm2_max_iter << endl;\
std::cout << "packing_RL:" << packing_RL << endl;\
std::cout << "use_csr:" << use_csr << endl;\
std::cout << "constant_step_size:" << constant_step_size << endl;\
std::cout << "step_size:" << step_size << endl;\
std::cout << "constraints: " << fac_constraints.size() << endl;\
cout << "FACTORS:" << endl;\
for(int i=0;i<fac_constraints.size();i++)\
fac_constraints[i]->Display();\
cout << "RESIDUUMS:" << endl;\
for(int i=0;i<res_constraints.size();i++)\
res_constraints[i]->Display();\
} }
// std::cout << "is_constant_step_size: " << is_constant_step_size << endl;\
// std::cout << "step_size: " << step_size << endl;\
#include "faust_hierarchical.hpp" #include "faust_hierarchical.hpp"
#endif #endif
template<typename FPP, Device DEVICE> template<typename FPP, Device DEVICE>
Faust::TransformHelper<FPP,DEVICE>* Faust::hierarchical(const Faust::MatDense<FPP,DEVICE>& A, Faust::TransformHelper<FPP,DEVICE>* Faust::hierarchical(const Faust::MatDense<FPP,DEVICE>& A,
// const int nites, Params<FPP,DEVICE, Real<FPP>> & p,
std::vector<StoppingCriterion<Real<FPP>>>& sc, Real<FPP>& lambda, const bool compute_2norm_on_array)
std::vector<const Faust::ConstraintGeneric*> & fac_constraints,
std::vector<const Faust::ConstraintGeneric*> & res_constraints,
Real<FPP>& lambda,
const bool is_update_way_R2L, const bool is_fact_side_left,
const bool use_csr, const bool packing_RL,
const bool compute_2norm_on_array,
const Real<FPP> norm2_threshold,
const unsigned int norm2_max_iter, const bool is_verbose,
const bool constant_step_size, const Real<FPP> step_size)
{ {
auto S = new Faust::TransformHelper<FPP,DEVICE>(); // A is copied auto S = new Faust::TransformHelper<FPP,DEVICE>(); // A is copied
S->push_back(&A); S->push_back(&A);
...@@ -21,10 +12,20 @@ Faust::TransformHelper<FPP,DEVICE>* Faust::hierarchical(const Faust::MatDense<FP ...@@ -21,10 +12,20 @@ Faust::TransformHelper<FPP,DEVICE>* Faust::hierarchical(const Faust::MatDense<FP
Faust::MatSparse<FPP,DEVICE> * tmp_sparse; Faust::MatSparse<FPP,DEVICE> * tmp_sparse;
std::vector<Faust::MatGeneric<FPP,DEVICE>*> Si_vec; std::vector<Faust::MatGeneric<FPP,DEVICE>*> Si_vec;
std::vector<Faust::ConstraintGeneric*> Si_cons; std::vector<Faust::ConstraintGeneric*> Si_cons;
Real<FPP> lambda_ = lambda; Real<FPP> lambda_ = p.init_lambda;
Real<FPP> glo_lambda = 1; Real<FPP> glo_lambda = 1;
if(sc.size() < 2) throw runtime_error("Faust::hierarchical() needs 2 StoppingCriterion objects (for local and global opt.)"); std::vector<const Faust::ConstraintGeneric*> & fac_constraints = p.cons[0];
DISPLAY_PARAMS(); //if is_verbose std::vector<const Faust::ConstraintGeneric*> & res_constraints = p.cons[1];
//TODO: remove these local variables and use directly p.
const bool is_update_way_R2L = p.isUpdateWayR2L;
const bool is_fact_side_left = p.isFactSideLeft;
const bool use_csr = p.use_csr;
const bool packing_RL = p.packing_RL;
const Real<FPP> norm2_threshold = p.norm2_threshold;
const unsigned int norm2_max_iter = p.norm2_max_iter;
const double step_size = p.step_size;
const bool constant_step_size = p.isConstantStepSize;
if(p.isVerbose) p.Display();
for(int i=0;i < fac_constraints.size();i++) for(int i=0;i < fac_constraints.size();i++)
{ {
cout << "Faust::hierarchical: " << i+1 << endl; cout << "Faust::hierarchical: " << i+1 << endl;
...@@ -72,7 +73,7 @@ Faust::TransformHelper<FPP,DEVICE>* Faust::hierarchical(const Faust::MatDense<FP ...@@ -72,7 +73,7 @@ Faust::TransformHelper<FPP,DEVICE>* Faust::hierarchical(const Faust::MatDense<FP
tmp_dense = new MatDense<FPP,Cpu>(*tmp_sparse); tmp_dense = new MatDense<FPP,Cpu>(*tmp_sparse);
} }
else tmp_sparse = nullptr; else tmp_sparse = nullptr;
Faust::palm4msa2(*tmp_dense, Si_cons, Si_th, lambda_, sc[0], is_update_way_R2L , use_csr, packing_RL, compute_2norm_on_array, Faust::palm4msa2(*tmp_dense, Si_cons, Si_th, lambda_, p.stop_crit_2facts, is_update_way_R2L , use_csr, packing_RL, compute_2norm_on_array,
norm2_threshold, norm2_max_iter, constant_step_size, step_size); norm2_threshold, norm2_max_iter, constant_step_size, step_size);
if(tmp_sparse != nullptr) if(tmp_sparse != nullptr)
// the Si factor has been converted into a MatDense in the memory // the Si factor has been converted into a MatDense in the memory
...@@ -96,15 +97,37 @@ Faust::TransformHelper<FPP,DEVICE>* Faust::hierarchical(const Faust::MatDense<FP ...@@ -96,15 +97,37 @@ Faust::TransformHelper<FPP,DEVICE>* Faust::hierarchical(const Faust::MatDense<FP
} }
//TODO: verify if the constraints order doesn't depend on //TODO: verify if the constraints order doesn't depend on
//is_fact_side_left //is_fact_side_left
std::vector<ConstraintGeneric*> glo_cons; std::vector<Faust::ConstraintGeneric*> glo_cons;
for(auto ite_cons=fac_constraints.begin(); ite_cons != fac_constraints.begin()+i+1;ite_cons++) for(auto ite_cons=fac_constraints.begin(); ite_cons != fac_constraints.begin()+i+1;ite_cons++)
glo_cons.push_back(const_cast<Faust::ConstraintGeneric*>(*ite_cons)); glo_cons.push_back(const_cast<Faust::ConstraintGeneric*>(*ite_cons));
glo_cons.push_back(const_cast<Faust::ConstraintGeneric*>(res_constraints[i])); glo_cons.push_back(const_cast<Faust::ConstraintGeneric*>(res_constraints[i]));
// global optimization // global optimization
Faust::palm4msa2(A, glo_cons, *S, glo_lambda, sc[1], is_update_way_R2L, use_csr, packing_RL, compute_2norm_on_array, Faust::palm4msa2(A, glo_cons, *S, glo_lambda, p.stop_crit_global ,is_update_way_R2L, use_csr, packing_RL, compute_2norm_on_array,
norm2_threshold, norm2_max_iter, constant_step_size, step_size); norm2_threshold, norm2_max_iter, constant_step_size, step_size);
} }
lambda = glo_lambda; lambda = glo_lambda;
return S; return S;
} }
template<typename FPP, Device DEVICE>
Faust::TransformHelper<FPP,DEVICE>* Faust::hierarchical(const Faust::MatDense<FPP,DEVICE>& A,
// const int nites,
std::vector<StoppingCriterion<Real<FPP>>>& sc,
std::vector<const Faust::ConstraintGeneric*> & fac_constraints,
std::vector<const Faust::ConstraintGeneric*> & res_constraints,
Real<FPP>& lambda,
const bool is_update_way_R2L, const bool is_fact_side_left,
const bool use_csr, const bool packing_RL,
const bool compute_2norm_on_array,
const Real<FPP> norm2_threshold,
const unsigned int norm2_max_iter, const bool is_verbose,
const bool constant_step_size, const Real<FPP> step_size)
{
Faust::Params<FPP,DEVICE,Real<FPP>> p(A.getNbRow(), A.getNbCol(), fac_constraints.size()+1, {fac_constraints, res_constraints}, {}, sc[0], sc[1], is_verbose, is_update_way_R2L, is_fact_side_left, lambda, constant_step_size, step_size);
p.use_csr = use_csr;
p.packing_RL = packing_RL;
p.norm2_threshold = norm2_threshold;
p.norm2_max_iter = norm2_max_iter;
return Faust::hierarchical(A, p, lambda, compute_2norm_on_array);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment