Mentions légales du service

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

Complete the cpp unit test for PALM4MSA.

- Execute all iterations of the algorithm (not just the first step like it was),
- construct a Faust from resulting factors,
- compute and print out the relative error of the Faust relatively to the initial matrix.
parent 2741ed28
Branches
Tags
No related merge requests found
...@@ -58,64 +58,78 @@ typedef @TEST_FPP@ FPP; ...@@ -58,64 +58,78 @@ typedef @TEST_FPP@ FPP;
*/ */
int main() int main()
{ {
Faust::MatDense<FPP,Cpu> data, initFacts1, initFacts2; Faust::MatDense<FPP,Cpu> data, initFacts1, initFacts2;
char configPalm2Filename[] = "@FAUST_DATA_MAT_DIR@/config_compared_palm2.mat"; char configPalm2Filename[] = "@FAUST_DATA_MAT_DIR@/config_compared_palm2.mat";
init_faust_mat_from_matio(data, configPalm2Filename, "data"); init_faust_mat_from_matio(data, configPalm2Filename, "data");
init_faust_mat_from_matio(initFacts1, configPalm2Filename, "init_facts1"); init_faust_mat_from_matio(initFacts1, configPalm2Filename, "init_facts1");
init_faust_mat_from_matio(initFacts2, configPalm2Filename, "init_facts2"); init_faust_mat_from_matio(initFacts2, configPalm2Filename, "init_facts2");
int cons1Name, cons1Parameter, cons1Row, cons1Col; int cons1Name, cons1Parameter, cons1Row, cons1Col;
int cons2Name, cons2Row, cons2Col; int cons2Name, cons2Row, cons2Col;
FPP cons2Parameter; FPP cons2Parameter;
int nfacts, niter; int nfacts, niter;
bool updateWay, verbose; bool updateWay, verbose;
double initLambda; double initLambda;
cons1Name = init_int_from_matio(configPalm2Filename, "cons1_name"); cons1Name = init_int_from_matio(configPalm2Filename, "cons1_name");
cons1Parameter = init_int_from_matio(configPalm2Filename, "cons1_parameter"); cons1Parameter = init_int_from_matio(configPalm2Filename, "cons1_parameter");
cons1Row = init_int_from_matio(configPalm2Filename, "cons1_row"); cons1Row = init_int_from_matio(configPalm2Filename, "cons1_row");
cons1Col = init_int_from_matio(configPalm2Filename, "cons1_col"); cons1Col = init_int_from_matio(configPalm2Filename, "cons1_col");
cons2Name = init_int_from_matio(configPalm2Filename, "cons2_name"); cons2Name = init_int_from_matio(configPalm2Filename, "cons2_name");
cons2Parameter = (FPP) init_double_from_matio(configPalm2Filename, "cons2_parameter"); cons2Parameter = (FPP) init_double_from_matio(configPalm2Filename, "cons2_parameter");
cons2Row = init_int_from_matio(configPalm2Filename, "cons2_row"); cons2Row = init_int_from_matio(configPalm2Filename, "cons2_row");
cons2Col = init_int_from_matio(configPalm2Filename, "cons2_col"); cons2Col = init_int_from_matio(configPalm2Filename, "cons2_col");
initLambda = (FPP) init_double_from_matio(configPalm2Filename, "init_lambda"); initLambda = (FPP) init_double_from_matio(configPalm2Filename, "init_lambda");
nfacts = init_int_from_matio(configPalm2Filename, "nfacts"); nfacts = init_int_from_matio(configPalm2Filename, "nfacts");
niter = init_int_from_matio(configPalm2Filename, "niter"); niter = init_int_from_matio(configPalm2Filename, "niter");
updateWay = init_bool_from_matio(configPalm2Filename, "update_way"); updateWay = init_bool_from_matio(configPalm2Filename, "update_way");
verbose = init_bool_from_matio(configPalm2Filename, "verbose"); verbose = init_bool_from_matio(configPalm2Filename, "verbose");
// Creation du vecteur de contrainte // Creation du vecteur de contrainte
const Faust::ConstraintInt<FPP,Cpu> cons1(static_cast<faust_constraint_name>(cons1Name), cons1Parameter, cons1Row, cons1Col); const Faust::ConstraintInt<FPP,Cpu> cons1(static_cast<faust_constraint_name>(cons1Name), cons1Parameter, cons1Row, cons1Col);
const Faust::ConstraintFPP<FPP,Cpu> cons2(static_cast<faust_constraint_name>(cons2Name), cons2Parameter, cons2Row, cons2Col); const Faust::ConstraintFPP<FPP,Cpu> cons2(static_cast<faust_constraint_name>(cons2Name), cons2Parameter, cons2Row, cons2Col);
vector<const Faust::ConstraintGeneric<FPP,Cpu>*> cons; vector<const Faust::ConstraintGeneric<FPP,Cpu>*> cons;
cons.push_back(&cons1); cons.push_back(&cons1);
cons.push_back(&cons2); cons.push_back(&cons2);
// Creation du vecteur de matrice initFact; // Creation du vecteur de matrice initFact;
vector<Faust::MatDense<FPP,Cpu> > initFact; vector<Faust::MatDense<FPP,Cpu> > initFact;
initFact.push_back(initFacts1); initFact.push_back(initFacts1);
initFact.push_back(initFacts2); initFact.push_back(initFacts2);
// Creation du critere d'arret // Creation du critere d'arret
Faust::StoppingCriterion<FPP> crit(niter); Faust::StoppingCriterion<FPP> crit(niter);
Faust::ParamsPalm<FPP,Cpu> params(data, nfacts, cons, initFact, crit, verbose, updateWay, initLambda); Faust::ParamsPalm<FPP,Cpu> params(data, nfacts, cons, initFact, crit, verbose, updateWay, initLambda);
Faust::BlasHandle<Cpu> blasHandle;
Faust::Palm4MSA<FPP,Cpu> palm2(params,blasHandle,true); Faust::BlasHandle<Cpu> blasHandle;
palm2.next_step(); Faust::Palm4MSA<FPP,Cpu> palm2(params,blasHandle,true);
// palm2.next_step();
palm2.compute_facts();
const std::vector<Faust::MatDense<FPP,Cpu> >& full_facts = palm2.get_facts();
return 0; Faust::Transform<FPP, Cpu>* t = new Faust::Transform<FPP, Cpu>(full_facts);
//relativeError
Faust::MatDense<FPP,Cpu> faustProduct;
faustProduct=t->get_product();
faustProduct-=data;
FPP relativeError = faustProduct.norm()/data.norm();
std::cout<<std::endl;
std::cout<<"**************** RELATIVE ERROR BETWEEN FAUST AND DATA MATRIX **************** "<<std::endl;
std::cout<< "\t\t" << relativeError<<std::endl<<std::endl;
return 0;
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment