1
// -*- mode: C++; tab-width: 2; -*-
4
// --------------------------------------------------------------------------
5
// OpenMS Mass Spectrometry Framework
6
// --------------------------------------------------------------------------
7
// Copyright (C) 2003-2011 -- Oliver Kohlbacher, Knut Reinert
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.
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.
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
23
// --------------------------------------------------------------------------
24
// $Maintainer: Chris Bielow $
26
// --------------------------------------------------------------------------
28
#include <OpenMS/CONCEPT/ClassTest.h>
30
///////////////////////////
31
#include <OpenMS/MATH/MISC/NonNegativeLeastSquaresSolver.h>
32
///////////////////////////
34
using namespace OpenMS;
37
START_TEST(NonNegativeLeastSquaresSolver, "$Id: NonNegativeLeastSquaresSolver_test.C 8210 2011-03-28 13:19:52Z aiche $")
39
/////////////////////////////////////////////////////////////
40
/////////////////////////////////////////////////////////////
42
NonNegativeLeastSquaresSolver* ptr = 0;
43
NonNegativeLeastSquaresSolver* nullPointer = 0;
44
START_SECTION(NonNegativeLeastSquaresSolver())
46
ptr = new NonNegativeLeastSquaresSolver();
47
TEST_NOT_EQUAL(ptr, nullPointer)
51
START_SECTION(~NonNegativeLeastSquaresSolver())
57
START_SECTION((static Int solve(const Matrix< double > &A, const Matrix< double > &b, Matrix< double > &x)))
67
double b_1[3][1] = {{4},{7},{4}};
68
double x_1[4][1] = {{0.931153},{0.36833},{0},{0}};
71
A.setMatrix<3,4>(A_1);
72
b.setMatrix<3,1>(b_1);
75
TOLERANCE_ABSOLUTE(0.0005);
77
NonNegativeLeastSquaresSolver::solve(A,b,x);
78
for (size_t i=0;i<x.rows();++i)
80
TEST_REAL_SIMILAR(x(i,0), x_1[i][0]);
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}
93
double b_2[4][1] = {{5},{45},{4},{31}};
94
double x_2[4][1] = {{4.3395},{48.4364},{0},{33.4945}};
96
A.setMatrix<4,4>(A_2);
97
b.setMatrix<4,1>(b_2);
100
NonNegativeLeastSquaresSolver::solve(A,b,x);
101
for (size_t i=0;i<x.rows();++i)
103
TEST_REAL_SIMILAR(x(i,0), x_2[i][0]);
110
/////////////////////////////////////////////////////////////
111
/////////////////////////////////////////////////////////////