NifTK  16.4.1 - 0798f20
CMIC's Translational Medical Imaging Platform
itkRayleighFunction.h
Go to the documentation of this file.
1 /*=============================================================================
2 
3  NifTK: A software platform for medical image computing.
4 
5  Copyright (c) University College London (UCL). All rights reserved.
6 
7  This software is distributed WITHOUT ANY WARRANTY; without even
8  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
9  PURPOSE.
10 
11  See LICENSE.txt in the top level directory for details.
12 
13 =============================================================================*/
14 
15 #ifndef itkRayleighFunction_h
16 #define itkRayleighFunction_h
17 
18 #include <vnl/vnl_least_squares_function.h>
19 
20 
21 class ITK_EXPORT RayleighFunction : public vnl_least_squares_function
22 {
23 public:
24 
25 RayleighFunction(unsigned int nDataPoints,
26  vnl_vector< double > &xData,
27  vnl_vector< double > &yData,
28  bool flgUseGradient )
29  : vnl_least_squares_function(2, nDataPoints,
30  flgUseGradient ? use_gradient : no_gradient)
31  {
32  m_nDataPoints = nDataPoints;
33 
34  m_xData = &xData;
35  m_yData = &yData;
36  }
37 
39  double compute(unsigned int i, double k, double s)
40  {
41  return compute( (*m_xData)[i], k, s );
42  }
43 
45  double compute(double x, double k, double s)
46  {
47  double sSq = s*s;
48  return k*x*exp( -x*x/(2.*sSq) )/sSq;
49  }
50 
52  double compute_dydk(unsigned int i, double k, double s)
53  {
54  return compute_dydk( (*m_xData)[i], k, s );
55  }
56 
58  double compute_dydk(double x, double k, double s)
59  {
60  double sSq = s*s;
61  return x*exp( -x*x/(2.*sSq) )/sSq;
62  }
63 
65  double compute_dydsig(unsigned int i, double k, double s)
66  {
67  return compute_dydsig( (*m_xData)[i], k, s );
68  }
69 
71  double compute_dydsig(double x, double k, double s)
72  {
73  double sSq = s*s;
74  return x*(k*x*x - 2.*k*sSq)*exp( -x*x/(2.*sSq) )/(sSq*sSq*s);
75  }
76 
78 
79  void f(const vnl_vector<double> &a, vnl_vector<double> &residual) override
80  {
81  for (unsigned int i=0; i<m_nDataPoints; ++i)
82  {
83  residual[i] = compute(i, a[0], a[1] ) - (*m_yData)[i];
84  }
85  }
86 
88 
89  void gradf(const vnl_vector<double> &a, vnl_matrix<double> &J) override
90  {
91  for (unsigned int i=0; i<m_nDataPoints; ++i) {
92  J(i,0) = compute_dydk(i, a[0], a[1] );
93  }
94 
95  for (unsigned int i=0; i<m_nDataPoints; ++i) {
96  J(i,1) = compute_dydsig(i, a[0], a[1] );
97  }
98  }
99 
100 protected:
101 
103  unsigned int m_nDataPoints;
104 
106  vnl_vector< double > *m_xData;
108  vnl_vector< double > *m_yData;
109 
110 
111 };
112 
113 #endif
vnl_vector< double > * m_xData
The 'x' ordinate data values.
Definition: itkRayleighFunction.h:106
RayleighFunction(unsigned int nDataPoints, vnl_vector< double > &xData, vnl_vector< double > &yData, bool flgUseGradient)
Definition: itkRayleighFunction.h:25
double compute(unsigned int i, double k, double s)
Compute the value of the Rayleigh distribution at a given index 'i'.
Definition: itkRayleighFunction.h:39
unsigned int m_nDataPoints
The number of data points.
Definition: itkRayleighFunction.h:103
double compute_dydsig(unsigned int i, double k, double s)
Compute the derivative with respect to 's' at index 'i'.
Definition: itkRayleighFunction.h:65
void f(const vnl_vector< double > &a, vnl_vector< double > &residual) override
Evaluate the vector of residual for parameters 'a'.
Definition: itkRayleighFunction.h:79
Definition: itkRayleighFunction.h:21
double compute(double x, double k, double s)
Compute the value of the Rayleigh distribution at a given 'x'.
Definition: itkRayleighFunction.h:45
double compute_dydk(double x, double k, double s)
Compute the derivative with respect to 'k' at 'x'.
Definition: itkRayleighFunction.h:58
void gradf(const vnl_vector< double > &a, vnl_matrix< double > &J) override
Evaluate the gradient with respect to each parameter.
Definition: itkRayleighFunction.h:89
GLboolean GLboolean GLboolean GLboolean a
Definition: glew.h:8272
GLint GLint GLint GLint GLint x
Definition: glew.h:1236
double compute_dydsig(double x, double k, double s)
Compute the derivative with respect to 's' at 'x'.
Definition: itkRayleighFunction.h:71
double compute_dydk(unsigned int i, double k, double s)
Compute the derivative with respect to 'k' at index 'i'.
Definition: itkRayleighFunction.h:52
vnl_vector< double > * m_yData
The 'y' ordinate data values.
Definition: itkRayleighFunction.h:108
GLdouble s
Definition: glew.h:1374