aimsalgo  5.1.2
Neuroimaging image processing
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 
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 >
50 class LMSEstimator : public MEstimator< D >
51 {
52  public:
53  LMSEstimator() : MEstimator<D>() { }
54  virtual ~LMSEstimator() { }
55 
56  void doit(
58  const carto::rc_ptr<carto::Volume< float > >& y, float& a,
60 };
61 
62 
63 template < int D > inline
64 void
67  const carto::rc_ptr<carto::Volume< float > >& y, float& a,
69 {
70  ASSERT( x->getSizeY() == 1 && x->getSizeZ() == 1 && x->getSizeT() == 1 );
71  ASSERT( y->getSizeY() == 1 && y->getSizeZ() == 1 && y->getSizeT() == 1 );
72  ASSERT( x->getSizeX() == y->getSizeX() );
73 
74  int N = y->getSizeX();
75  carto::VolumeRef<float> mat( D + 1, D + 1 );
76  carto::VolumeRef<float> vec( D + 1 );
77 
78  mat = 0.0;
79  vec = 0.0;
80  mat( 0, 0 ) = float( N );
81  int k, n;
82  for ( k = 1; k <= D; k++ )
83  {
84  for ( n = 0; n < N; n++ )
85  mat( k, 0 ) += x->at( n ).item( k - 1 );
86  mat( 0, k ) = mat( k, 0 );
87  }
88 
89  int k1, k2;
90  for ( k1 = 1; k1 <= D; k1++ )
91  for ( k2 = 1; k2 <= k1; k2++ )
92  {
93  for ( n = 0; n < N; n++ )
94  mat( k1, k2 ) += x->at( n ).item( k1 - 1 ) * x->at( n ).item( k2 - 1 );
95  mat( k2, k1 ) = mat( k1, k2 );
96  }
97 
98 
99  for ( n = 0; n < N; n++ )
100  {
101  vec( 0 ) += y->at( n );
102  for ( k = 1; k <= D; k++ )
103  vec( k ) += y->at( n ) * x->at( n ).item( k - 1 );
104  }
105 
107  a = res( 0 );
108  for ( k = 1; k <= D; k++ )
109  b.item( k - 1 ) = res( k );
110 }
111 
112 
113 #endif
#define ASSERT(EX)
const T & item(int d) const
virtual ~LMSEstimator()
Definition: lms-estimator.h:54
void doit(const carto::rc_ptr< carto::Volume< AimsVector< float, D > > > &x, const carto::rc_ptr< carto::Volume< float > > &y, float &a, AimsVector< float, D > &b)
Definition: lms-estimator.h:65
const T & at(long x, long y=0, long z=0, long t=0) const
carto::VolumeRef< float > AimsLinearResolutionLU(const carto::VolumeRef< float > &matrix, const carto::VolumeRef< float > &b)