A.I.M.S algorithms


lms-estimator.h
Go to the documentation of this file.
1 /* This software and supporting documentation are distributed by
2  * Institut Federatif de Recherche 49
3  * CEA/NeuroSpin, Batiment 145,
4  * 91191 Gif-sur-Yvette cedex
5  * France
6  *
7  * This software is governed by the CeCILL-B license under
8  * French law and abiding by the rules of distribution of free software.
9  * You can use, modify and/or redistribute the software under the
10  * terms of the CeCILL-B license as circulated by CEA, CNRS
11  * and INRIA at the following URL "http://www.cecill.info".
12  *
13  * As a counterpart to the access to the source code and rights to copy,
14  * modify and redistribute granted by the license, users are provided only
15  * with a limited warranty and the software's author, the holder of the
16  * economic rights, and the successive licensors have only limited
17  * liability.
18  *
19  * In this respect, the user's attention is drawn to the risks associated
20  * with loading, using, modifying and/or developing or reproducing the
21  * software by the user in light of its specific status of free software,
22  * that may mean that it is complicated to manipulate, and that also
23  * therefore means that it is reserved for developers and experienced
24  * professionals having in-depth computer knowledge. Users are therefore
25  * encouraged to load and test the software's suitability as regards their
26  * requirements in conditions enabling the security of their systems and/or
27  * data to be ensured and, more generally, to use and operate it in the
28  * same conditions as regards security.
29  *
30  * The fact that you are presently reading this means that you have had
31  * knowledge of the CeCILL-B license and that you accept its terms.
32  */
33 
34 
35 #ifndef AIMS_ESTIMATION_LMS_ESTIMATOR_H
36 #define AIMS_ESTIMATION_LMS_ESTIMATOR_H
37 
38 
40 #include <aims/data/data.h>
41 #include <aims/vector/vector.h>
42 #include <aims/def/assert.h>
43 #include <aims/math/gausslu.h>
45 
46 //
47 // Linear Mean Squared M-estimator
48 //
49 template < int D >
51 {
52  public:
53  LMSEstimator() : MEstimator<D>() { }
54  virtual ~LMSEstimator() { }
55 
56  void doit( const AimsData< AimsVector< float, D > >& x,
57  const AimsData< float >& y, float& a,
59 };
60 
61 
62 template < int D > inline
63 void
65  const AimsData< float >& y, float& a,
67 {
68  ASSERT( x.dimY() == 1 && x.dimZ() == 1 && x.dimT() == 1 );
69  ASSERT( y.dimY() == 1 && y.dimZ() == 1 && y.dimT() == 1 );
70  ASSERT( x.dimX() == y.dimX() );
71 
72  int N = y.dimX();
73  AimsData<float> mat( D + 1, D + 1 );
74  AimsData<float> vec( D + 1 );
75 
76  mat = 0.0;
77  vec = 0.0;
78  mat( 0, 0 ) = float( N );
79  int k, n;
80  for ( k = 1; k <= D; k++ )
81  {
82  for ( n = 0; n < N; n++ )
83  mat( k, 0 ) += x( n ).item( k - 1 );
84  mat( 0, k ) = mat( k, 0 );
85  }
86 
87  int k1, k2;
88  for ( k1 = 1; k1 <= D; k1++ )
89  for ( k2 = 1; k2 <= k1; k2++ )
90  {
91  for ( n = 0; n < N; n++ )
92  mat( k1, k2 ) += x( n ).item( k1 - 1 ) * x( n ).item( k2 - 1 );
93  mat( k2, k1 ) = mat( k1, k2 );
94  }
95 
96 
97  for ( n = 0; n < N; n++ )
98  {
99  vec( 0 ) += y( n );
100  for ( k = 1; k <= D; k++ )
101  vec( k ) += y( n ) * x( n ).item( k - 1 );
102  }
103 
104  AimsData<float> res = AimsLinearResolutionLU( mat, vec );
105  a = res( 0 );
106  for ( k = 1; k <= D; k++ )
107  b.item( k - 1 ) = res( k );
108 }
109 
110 
111 #endif
virtual void doit(const AimsData< AimsVector< float, D > > &, const AimsData< float > &, float &, AimsVector< float, D > &)
Definition: m-estimator.h:54
AIMSDATA_API AimsData< float > AimsLinearResolutionLU(const AimsData< float > &matrix, const AimsData< float > &b)
int dimX() const
virtual ~LMSEstimator()
Definition: lms-estimator.h:54
void doit(const AimsData< AimsVector< float, D > > &x, const AimsData< float > &y, float &a, AimsVector< float, D > &b)
Definition: lms-estimator.h:64
int dimT() const
const T & item(int d) const
int dimZ() const
int dimY() const
#define AIMSALGO_API
#define ASSERT(EX)