NifTK  16.4.1 - 0798f20
CMIC's Translational Medical Imaging Platform
itkExponentialDecayFunction.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 itkExponentialDecayFunction_h
16 #define itkExponentialDecayFunction_h
17 
18 #include <vnl/vnl_least_squares_function.h>
19 
20 
21 class ITK_EXPORT ExponentialDecayFunction : public vnl_least_squares_function
22 {
23 public:
24 
25 ExponentialDecayFunction(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  return k*exp( -s*x );
48  }
49 
51  double compute_dydk(unsigned int i, double k, double s)
52  {
53  return compute_dydk( (*m_xData)[i], k, s );
54  }
55 
57  double compute_dydk(double x, double k, double s)
58  {
59  return exp( -s*x );
60  }
61 
63  double compute_dydsig(unsigned int i, double k, double s)
64  {
65  return compute_dydsig( (*m_xData)[i], k, s );
66  }
67 
69  double compute_dydsig(double x, double k, double s)
70  {
71  return -k*x*exp( -s*x );
72  }
73 
75 
76  void f(const vnl_vector<double> &a, vnl_vector<double> &residual) override
77  {
78  for (unsigned int i=0; i<m_nDataPoints; ++i)
79  {
80  residual[i] = compute(i, a[0], a[1] ) - (*m_yData)[i];
81  }
82  }
83 
85 
86  void gradf(const vnl_vector<double> &a, vnl_matrix<double> &J) override
87  {
88  for (unsigned int i=0; i<m_nDataPoints; ++i) {
89  J(i,0) = compute_dydk(i, a[0], a[1] );
90  }
91 
92  for (unsigned int i=0; i<m_nDataPoints; ++i) {
93  J(i,1) = compute_dydsig(i, a[0], a[1] );
94  }
95  }
96 
97 protected:
98 
100  unsigned int m_nDataPoints;
101 
103  vnl_vector< double > *m_xData;
105  vnl_vector< double > *m_yData;
106 
107 
108 };
109 
110 #endif
double compute(double x, double k, double s)
Compute the value of the exponential decay function at a given 'x'.
Definition: itkExponentialDecayFunction.h:45
double compute_dydsig(unsigned int i, double k, double s)
Compute the derivative with respect to 's' at index 'i'.
Definition: itkExponentialDecayFunction.h:63
double compute_dydk(unsigned int i, double k, double s)
Compute the derivative with respect to 'k' at index 'i'.
Definition: itkExponentialDecayFunction.h:51
unsigned int m_nDataPoints
The number of data points.
Definition: itkExponentialDecayFunction.h:100
GLboolean GLboolean GLboolean GLboolean a
Definition: glew.h:8272
void gradf(const vnl_vector< double > &a, vnl_matrix< double > &J) override
Evaluate the gradient with respect to each parameter.
Definition: itkExponentialDecayFunction.h:86
Definition: itkExponentialDecayFunction.h:21
GLint GLint GLint GLint GLint x
Definition: glew.h:1236
void f(const vnl_vector< double > &a, vnl_vector< double > &residual) override
Evaluate the vector of residual for parameters 'a'.
Definition: itkExponentialDecayFunction.h:76
ExponentialDecayFunction(unsigned int nDataPoints, vnl_vector< double > &xData, vnl_vector< double > &yData, bool flgUseGradient)
Definition: itkExponentialDecayFunction.h:25
double compute_dydk(double x, double k, double s)
Compute the derivative with respect to 'k' at 'x'.
Definition: itkExponentialDecayFunction.h:57
vnl_vector< double > * m_yData
The 'y' ordinate data values.
Definition: itkExponentialDecayFunction.h:105
GLdouble s
Definition: glew.h:1374
vnl_vector< double > * m_xData
The 'x' ordinate data values.
Definition: itkExponentialDecayFunction.h:103
double compute(unsigned int i, double k, double s)
Compute the value of the exponential decay function at a given index 'i'.
Definition: itkExponentialDecayFunction.h:39
double compute_dydsig(double x, double k, double s)
Compute the derivative with respect to 's' at 'x'.
Definition: itkExponentialDecayFunction.h:69