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
|
/*=========================================================================
Program: Insight Segmentation & Registration Toolkit
Module: $RCSfile: itkWeightedCovarianceCalculator.h,v $
Language: C++
Date: $Date: 2009-03-04 19:29:54 $
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 __itkWeightedCovarianceCalculator_h
#define __itkWeightedCovarianceCalculator_h
#include "itkArray.h"
#include "itkVariableSizeMatrix.h"
#include "itkSampleAlgorithmBase.h"
namespace itk {
namespace Statistics {
/** \class WeightedCovarianceCalculator
* \brief Calculates the covariance matrix of the target sample data
* where each measurement vector has an associated weight value
*
* Recent API changes:
* The static const macro to get the length of a measurement vector,
* 'MeasurementVectorSize' has been removed to allow the length of a measurement
* vector to be specified at run time. It is now obtained from the input sample.
* Please use the function GetMeasurementVectorSize() to obtain the length.
* The mean output is an Array rather than a Vector. The covariance matrix is
* represented by a VariableSizeMatrix rather than a Matrix.
* \sa CovarianceCalculator SampleAlgorithmBase
*/
template< class TSample >
class WeightedCovarianceCalculator :
public SampleAlgorithmBase< TSample >
{
public:
/** Standard class typedefs. */
typedef WeightedCovarianceCalculator Self;
typedef SampleAlgorithmBase< TSample > Superclass;
typedef SmartPointer<Self> Pointer;
typedef SmartPointer<const Self> ConstPointer;
/** Standard Macros */
itkTypeMacro(WeightedCovarianceCalculator, SampleAlgorithmBase);
itkNewMacro(Self);
/** Length of a measurement vector */
typedef typename Superclass::MeasurementVectorSizeType MeasurementVectorSizeType;
/** Measurement vector typedef */
typedef typename TSample::MeasurementVectorType MeasurementVectorType;
/** Weight calculation function typedef */
typedef FunctionBase< MeasurementVectorType, double > WeightFunctionType;
/** Typedef for the mean output */
typedef Array< double > MeanType;
/** Typedef for Covariance output */
typedef VariableSizeMatrix< double > OutputType;
/** Array typedef for weights */
typedef Array< double > WeightArrayType;
/** Sets the weights using an array */
void SetWeights(WeightArrayType* array);
/** Gets the weights array */
WeightArrayType* GetWeights( void );
/** Sets the weights using an function the function should have a method,
* Evaluate(MeasurementVectorType&). */
void SetWeightFunction(WeightFunctionType* func);
/** Gets the weight function */
WeightFunctionType* GetWeightFunction( void );
/** Sets the mean (input) */
void SetMean(MeanType* mean);
/** Gets the mean */
MeanType* GetMean( void );
/** Returns the covariance matrix of the target sample data */
OutputType* GetOutput( void );
protected:
WeightedCovarianceCalculator();
virtual ~WeightedCovarianceCalculator();
void PrintSelf(std::ostream& os, Indent indent) const;
/** Calculates the covariance and save it */
void GenerateData( void );
void ComputeCovarianceWithGivenMean( void );
void ComputeCovarianceWithoutGivenMean( void );
private:
OutputType* m_Output;
MeanType* m_Mean;
MeanType* m_InternalMean;
WeightArrayType* m_Weights;
WeightFunctionType* m_WeightFunction;
}; // end of class
} // end of namespace Statistics
} // end of namespace itk
#ifndef ITK_MANUAL_INSTANTIATION
#include "itkWeightedCovarianceCalculator.txx"
#endif
#endif
|