File: itkGaussianGoodnessOfFitComponent.h

package info (click to toggle)
insighttoolkit 3.18.0-5
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 110,432 kB
  • ctags: 74,559
  • sloc: cpp: 412,627; ansic: 196,210; fortran: 28,000; python: 3,852; tcl: 2,005; sh: 1,186; java: 583; makefile: 458; csh: 220; perl: 193; xml: 20
file content (170 lines) | stat: -rwxr-xr-x 6,506 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/*=========================================================================

  Program:   Insight Segmentation & Registration Toolkit
  Module:    $RCSfile: itkGaussianGoodnessOfFitComponent.h,v $
  Language:  C++
  Date:      $Date: 2009-03-04 15:23:48 $
  Version:   $Revision: 1.10 $

  Copyright (c) Insight Software Consortium. All rights reserved.
  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even 
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
     PURPOSE.  See the above copyright notices for more information.

=========================================================================*/
#ifndef __itkGaussianGoodnessOfFitComponent_h
#define __itkGaussianGoodnessOfFitComponent_h

#include "itkGoodnessOfFitComponentBase.h"
#include "itkGaussianDensityFunction.h"
#include "itkFunctionBase.h"
#include "itkWeightedCovarianceCalculator.h"
#include "itkSymmetricEigenAnalysis.h"

namespace itk { 
namespace Statistics {

/** \class GaussianGoodnessOfFitComponent 
 *  \brief is a GoodnessOfFitComponent for Gaussian distribution.
 *
 * Among the GoodnessOfFitComponentBase's methods, this class provides
 * implementations for the CalculateProjectionAxess, the
 * GetCumulativeProbability (univariate CDF), and the
 * GetProbabilityDensity (multivariate PDF)methods.
 *
 * The CalculateProjectionAxes method creats an array of projection
 * axes that are the eigen vectors generated from the weighted
 * covariance matrix of the resampled sample using a spherical kernel.
 *
 * <b>Recent API changes:</b>
 * The static const macro to get the length of a measurement vector,
 * \c MeasurementVectorSize has been removed to allow the length of a 
 * measurement vector to be specified at run time. This is now obtained from
 * the input sample. 
 * 
 * \sa GoodnessOfFitComponentBase, GoodnessOfFitMixtureModelCostFunction
 */

template< class TInputSample >
class GaussianGoodnessOfFitComponent 
  : public GoodnessOfFitComponentBase< TInputSample > 
{
public:
  /** Standard class typedefs */
  typedef GaussianGoodnessOfFitComponent             Self;
  typedef GoodnessOfFitComponentBase< TInputSample > Superclass;
  typedef SmartPointer< Self >                       Pointer;
  typedef SmartPointer< const Self >                 ConstPointer;
  
  /** Run-time type information (and related methods). */
  itkTypeMacro(GaussianGoodnessOfFitComponent, 
               GoodnessOfFitComponentBase);
  
  /** Method for creation through the object factory. */
  itkNewMacro(Self);

  
  /** Typedefs from input sample */
  typedef typename TInputSample::MeasurementType       MeasurementType;
  typedef typename TInputSample::MeasurementVectorType MeasurementVectorType;

  /** Typedefs from Superclass */
  typedef typename Superclass::CenterType                CenterType;
  typedef typename Superclass::RadiusType                RadiusType;
  typedef typename Superclass::MeanType                  MeanType;
  typedef typename Superclass::StandardDeviationType     StandardDeviationType;
  typedef typename Superclass::ResampledSampleType       ResampledSampleType;
  typedef typename Superclass::ProjectionAxisArrayType   ProjectionAxisArrayType;
  typedef typename Superclass::MeasurementVectorSizeType MeasurementVectorSizeType;
  typedef Array< double >                                ParametersType;

  /** Weight function type. The density values are used as weights of 
   * each instance (measurement vector) for the Covariance calulator */
  typedef GaussianDensityFunction< MeasurementVectorType > 
  ProbabilityDensityFunctionType;

  typedef typename ProbabilityDensityFunctionType::CovarianceType CovarianceType;

  /** Type of the covariance calculator. the output of this calculator is
   * a covariance matrix that is used as the input of the Projection 
   * calculator */
  typedef WeightedCovarianceCalculator< ResampledSampleType > 
  CovarianceCalculatorType;

  /** Default projection axis calculator type. */
  typedef Array< double > EigenValuesArrayType;
  typedef SymmetricEigenAnalysis< ProjectionAxisArrayType, EigenValuesArrayType >
                          ProjectionAxisCalculatorType;

  /** Gets the size of parameters which consists of mean
   * and standard deviation */
  unsigned int GetNumberOfParameters() const
  { return (unsigned int)(this->GetMeasurementVectorSize() + 1); }

  /** Sets the component distribution parameters */
  void SetParameters(const ParametersType &parameter);

  /** Gets the center point for the neighborhood sampling */
  CenterType* GetCenter();

  /** Gets the radius for the neighborhood sampling */
  RadiusType* GetRadius();
  
  /** Gets the mean of the distributon */
  MeanType* GetMean();

  /** Gets the standard deviation of the distribution */
  StandardDeviationType* GetStandardDeviation();

  /** Univariate (standard) cumulative probability function */
  double GetCumulativeProbability(double x) const;

  /** Multivariate probability density function */
  double GetProbabilityDensity(MeasurementVectorType &measurements) const;

  /** Prints all the parameters. Usually for debugging. */
  void PrintParameters(std::ostream &os) const;

  /** Gets the full distribution parameters which consists of
   * mean vector and covariance matrix in a single array */
  ParametersType GetFullParameters() const;

  /** Set the input sample */
  virtual void SetInputSample( const TInputSample* sample );

protected:
  GaussianGoodnessOfFitComponent();
  virtual ~GaussianGoodnessOfFitComponent();
  virtual void PrintSelf(std::ostream& os, Indent indent) const;

  /** Calculates the base axes for projection */
  virtual void CalculateProjectionAxes();

private:
  typename ProbabilityDensityFunctionType::Pointer 
                                             m_ProbabilityDensityFunction;
  typename CovarianceCalculatorType::Pointer m_CovarianceCalculator;
  ProjectionAxisCalculatorType *             m_ProjectionAxisCalculator;

  MeanType              m_Mean;
  CenterType            m_Center;
  RadiusType            m_Radius;
  StandardDeviationType m_StandardDeviation;
  CovarianceType        m_Covariance;

  unsigned int m_NumberOfParameters;

  int    m_LongestAxisIndex;
  double m_LargestEigenValue;
}; // end of class

} // end of namespace Statistics 
} // end of namespace itk

#ifndef ITK_MANUAL_INSTANTIATION
#include "itkGaussianGoodnessOfFitComponent.txx"
#endif

#endif