LCOV - code coverage report
Current view: top level - source/tests - TestLasso.cpp (source / functions) Hit Total Coverage
Test: LibForBES Unit Tests Lines: 32 32 100.0 %
Date: 2016-04-18 Functions: 8 8 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : #include "FBProblem.h"
       2             : 
       3             : #include "TestLasso.h"
       4             : 
       5             : #define DOUBLES_EQUAL_DELTA 1e-8
       6             : #define MAXIT 1000
       7             : #define TOLERANCE 1e-12
       8             : 
       9           1 : CPPUNIT_TEST_SUITE_REGISTRATION(TestLasso);
      10             : 
      11           1 : TestLasso::TestLasso() {
      12           1 : }
      13             : 
      14           2 : TestLasso::~TestLasso() {
      15           2 : }
      16             : 
      17           1 : void TestLasso::setUp() {
      18           1 : }
      19             : 
      20           1 : void TestLasso::tearDown() {
      21           1 : }
      22             : 
      23           1 : void TestLasso::runTest() {
      24             :         /* Define the problem data */
      25           1 :         const size_t n = 5;
      26           1 :         const size_t m = 4;
      27             :         double data_A[] = {
      28             :                 1,  2, -1, -1,
      29             :                 -2, -1,  0, -1,
      30             :                 3,  0,  4, -1,
      31             :                 -4, -1, -3,  1,
      32           1 :                 5,  3,  2,  3 };
      33           1 :         double data_minus_b[] = {-1, -2, -3, -4};
      34           1 :         Matrix A(m, n, data_A);
      35           2 :         Matrix minus_b(m, 1, data_minus_b);
      36             : 
      37           1 :         double ref_xstar[] = {-0.010238907850120, 0.0, 0.0, 0.0, 0.511945392491510};
      38             : 
      39           1 :         LinearOperator * OpA = new MatrixOperator(A);
      40           1 :         Function * f = new QuadraticLoss();
      41           1 :         double lambda = 5.0;
      42           1 :         Function * g = new Norm1(lambda);
      43             : 
      44           2 :         FBStoppingRelative sc(TOLERANCE);
      45             : 
      46             :         // Define the FB problem
      47           2 :         FBProblem prob = FBProblem(*f, *OpA, minus_b, *g);
      48             :         // Initial guess and gamma - Construct a new instance of FBSplitting
      49           2 :         Matrix x0(n, 1);
      50           1 :         double gamma = 1e-2;
      51           1 :         FBSplitting * solver = new FBSplitting(prob, x0, gamma, sc, MAXIT);
      52             :         // Run the solver and get the solution
      53           1 :         solver->run();
      54           2 :         Matrix xstar = solver->getSolution();
      55             : 
      56           6 :         for (int i=0; i < n; i++) {
      57           5 :                 CPPUNIT_ASSERT_DOUBLES_EQUAL(ref_xstar[i], xstar.get(i, 0), DOUBLES_EQUAL_DELTA);
      58           1 :         }
      59           4 : }

Generated by: LCOV version 1.10