~ubuntu-branches/ubuntu/wily/openms/wily

« back to all changes in this revision

Viewing changes to source/TEST/NonNegativeLeastSquaresSolver_test.C

  • Committer: Package Import Robot
  • Author(s): Filippo Rusconi
  • Date: 2012-11-12 15:58:12 UTC
  • Revision ID: package-import@ubuntu.com-20121112155812-vr15wtg9b50cuesg
Tags: upstream-1.9.0
ImportĀ upstreamĀ versionĀ 1.9.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// -*- mode: C++; tab-width: 2; -*-
 
2
// vi: set ts=2:
 
3
//
 
4
// --------------------------------------------------------------------------
 
5
//                   OpenMS Mass Spectrometry Framework
 
6
// --------------------------------------------------------------------------
 
7
//  Copyright (C) 2003-2011 -- Oliver Kohlbacher, Knut Reinert
 
8
//
 
9
//  This library is free software; you can redistribute it and/or
 
10
//  modify it under the terms of the GNU Lesser General Public
 
11
//  License as published by the Free Software Foundation; either
 
12
//  version 2.1 of the License, or (at your option) any later version.
 
13
//
 
14
//  This library is distributed in the hope that it will be useful,
 
15
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
17
//  Lesser General Public License for more details.
 
18
//
 
19
//  You should have received a copy of the GNU Lesser General Public
 
20
//  License along with this library; if not, write to the Free Software
 
21
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
22
//
 
23
// --------------------------------------------------------------------------
 
24
// $Maintainer: Chris Bielow $
 
25
// $Authors: $
 
26
// --------------------------------------------------------------------------
 
27
 
 
28
#include <OpenMS/CONCEPT/ClassTest.h>
 
29
 
 
30
///////////////////////////
 
31
#include <OpenMS/MATH/MISC/NonNegativeLeastSquaresSolver.h>
 
32
///////////////////////////
 
33
 
 
34
using namespace OpenMS;
 
35
using namespace std;
 
36
 
 
37
START_TEST(NonNegativeLeastSquaresSolver, "$Id: NonNegativeLeastSquaresSolver_test.C 8210 2011-03-28 13:19:52Z aiche $")
 
38
 
 
39
/////////////////////////////////////////////////////////////
 
40
/////////////////////////////////////////////////////////////
 
41
 
 
42
NonNegativeLeastSquaresSolver* ptr = 0;
 
43
NonNegativeLeastSquaresSolver* nullPointer = 0;
 
44
START_SECTION(NonNegativeLeastSquaresSolver())
 
45
{
 
46
        ptr = new NonNegativeLeastSquaresSolver();
 
47
        TEST_NOT_EQUAL(ptr, nullPointer)
 
48
}
 
49
END_SECTION
 
50
 
 
51
START_SECTION(~NonNegativeLeastSquaresSolver())
 
52
{
 
53
        delete ptr;
 
54
}
 
55
END_SECTION
 
56
 
 
57
START_SECTION((static Int solve(const Matrix< double > &A, const Matrix< double > &b, Matrix< double > &x)))
 
58
{
 
59
        
 
60
        // CASE 1       
 
61
        double A_1[3][4] = 
 
62
                {
 
63
                        {1, 10, 4, 10},
 
64
                        {4, 5 , 1, 12},
 
65
                        {5, 1 , 9, 20},
 
66
                };
 
67
        double b_1[3][1] = {{4},{7},{4}};
 
68
        double x_1[4][1] = {{0.931153},{0.36833},{0},{0}};
 
69
 
 
70
        Matrix<double> A,b,x;
 
71
        A.setMatrix<3,4>(A_1);
 
72
        b.setMatrix<3,1>(b_1);
 
73
        x.resize(4,1);
 
74
        
 
75
        TOLERANCE_ABSOLUTE(0.0005);
 
76
        
 
77
        NonNegativeLeastSquaresSolver::solve(A,b,x);
 
78
        for (size_t i=0;i<x.rows();++i)
 
79
        {
 
80
                TEST_REAL_SIMILAR(x(i,0), x_1[i][0]);
 
81
        }       
 
82
        
 
83
        
 
84
                
 
85
        // CASE 2
 
86
        double A_2[4][4] = 
 
87
                {
 
88
                        {0.9290,    0.0200,         0,         0},
 
89
                        {0.0590,    0.9230,    0.0300,    0.0010},
 
90
                        {0.0020,    0.0560,    0.9240,    0.0400},
 
91
                        {                 0,    0.0010,    0.0450,    0.9240}
 
92
                };
 
93
        double b_2[4][1] = {{5},{45},{4},{31}};
 
94
        double x_2[4][1] = {{4.3395},{48.4364},{0},{33.4945}};  
 
95
        
 
96
        A.setMatrix<4,4>(A_2);
 
97
        b.setMatrix<4,1>(b_2);
 
98
        x.resize(4,1);
 
99
        
 
100
        NonNegativeLeastSquaresSolver::solve(A,b,x);
 
101
        for (size_t i=0;i<x.rows();++i)
 
102
        {
 
103
                TEST_REAL_SIMILAR(x(i,0), x_2[i][0]);
 
104
        }       
 
105
        
 
106
}
 
107
END_SECTION
 
108
 
 
109
 
 
110
/////////////////////////////////////////////////////////////
 
111
/////////////////////////////////////////////////////////////
 
112
END_TEST
 
113
 
 
114
 
 
115