DMRITool  v0.1.1-139-g860d86b4
Diffusion MRI Tool
test_Spams.cxx
Go to the documentation of this file.
1 
19 #include "linalg.h"
20 #include "decomp.h"
21 
22 void mexFunction(int nlhs, mxArray *plhs[],
23  int nrhs, const mxArray *prhs[])
24 {
25 
26  // vnl_matrix<double> A;
27  // vnl_vector<double> b, w, x;
28 
29  // const double array_A [] =
30  // {
31  // 1, 1,
32  // -1, 2,
33  // 2, 1
34  // };
35  // const double array_b [] =
36  // {
37  // 2, 2, 3
38  // };
39 
40  // A = vnl_matrix<double>(array_A, 3, 2);
41  // utl::PrintVnlMatrix(A, "A");
42  // b = vnl_vector<double>(array_b, 3);
43  // utl::PrintVnlVector(b, "b");
44 
45  // w.set_size(2);
46  // w.fill(5);
47  // w[0]=2;
48 
49  // std::cout << "weighted lasso using spams" << std::endl << std::flush;
50  // typedef itk::SpamsWeightedLassoSolver<double> SoverType;
51  // SoverType::Pointer solver = SoverType::New();
52  // solver->SetA(A);
53  // solver->Setb(b);
54  // solver->Setw(w);
55  // solver->Solve();
56  // solver->Print(std::cout<<"solver = ");
57  // x = solver->Getx();
58  // std::cout << "x = " << x << std::endl << std::flush;
59  // std::cout << "cost = " << solver->EvaluateCostFunction() << std::endl << std::flush;
60 
61  spams::Matrix<double> D(3,2);
62  D(0,0) = 1; D(0,1) = 1;
63  D(1,0) = -1; D(1,1) = 2;
64  D(2,0) = 2; D(2,1) = 1;
65  D.print("D");
66 
67  double lambda = 1.0;
68 
69  spams::Matrix<double> X(3,1);
70  X(0,0)=2, X(1,0)=2, X(2,0)=-3;
72 
73  // lasso
74  spams::lasso2<double>(X,D,alpha,2,lambda);
75  alpha.print("alpha");
76 
77  // lasso (Cholesky-based)
78  // spams::lasso<double>(X,D,alpha,2,lambda);
79  // alpha.print("alpha");
80 
81  // lasso (non-negativity)
83  // spams::lasso<double>(X,D,alpha,2,lambda,0.0, mode, true);
84  // alpha.print("alpha");
85 }
void print(const string &name) const
Print the matrix to std::cout.
Definition: linalg.h:1085
Sparse Matrix class.
Definition: linalg.h:63
constraint_type
Definition: decomp.h:88
void print(const string &name) const
print the sparse matrix
Definition: linalg.h:4127
Contains sparse decomposition algorithms It requires the toolbox linalg.
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Definition: test_Spams.cxx:22
Dense Matrix class.
Definition: linalg.h:61