ITK
4.1.0
Insight Segmentation and Registration Toolkit
|
00001 /*========================================================================= 00002 * 00003 * Copyright Insight Software Consortium 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0.txt 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 * 00017 *=========================================================================*/ 00018 #ifndef __itkExpectationMaximizationMixtureModelEstimator_h 00019 #define __itkExpectationMaximizationMixtureModelEstimator_h 00020 00021 #include "itkMixtureModelComponentBase.h" 00022 #include "itkGaussianMembershipFunction.h" 00023 #include "itkSimpleDataObjectDecorator.h" 00024 00025 namespace itk 00026 { 00027 namespace Statistics 00028 { 00060 template< class TSample > 00061 class ITK_EXPORT ExpectationMaximizationMixtureModelEstimator:public Object 00062 { 00063 public: 00065 typedef ExpectationMaximizationMixtureModelEstimator Self; 00066 typedef Object Superclass; 00067 typedef SmartPointer< Self > Pointer; 00068 typedef SmartPointer< const Self > ConstPointer; 00069 00071 itkTypeMacro(ExpectationMaximizationMixtureModelEstimator, 00072 Object); 00073 itkNewMacro(Self); 00075 00077 typedef TSample SampleType; 00078 typedef typename TSample::MeasurementType MeasurementType; 00079 typedef typename TSample::MeasurementVectorType MeasurementVectorType; 00080 00083 typedef GaussianMembershipFunction< MeasurementVectorType > 00084 GaussianMembershipFunctionType; 00085 00086 typedef typename GaussianMembershipFunctionType::Pointer 00087 GaussianMembershipFunctionPointer; 00088 00089 typedef MembershipFunctionBase< MeasurementVectorType > MembershipFunctionType; 00090 typedef typename MembershipFunctionType::ConstPointer MembershipFunctionPointer; 00091 typedef std::vector< MembershipFunctionPointer > MembershipFunctionVectorType; 00092 typedef SimpleDataObjectDecorator< 00093 MembershipFunctionVectorType > MembershipFunctionVectorObjectType; 00094 typedef typename 00095 MembershipFunctionVectorObjectType::Pointer MembershipFunctionVectorObjectPointer; 00096 00098 typedef MixtureModelComponentBase< TSample > ComponentType; 00099 00101 typedef std::vector< ComponentType * > ComponentVectorType; 00102 00104 typedef MembershipFunctionBase< MeasurementVectorType > 00105 ComponentMembershipFunctionType; 00106 00108 typedef Array< double > ProportionVectorType; 00109 00111 void SetSample(const TSample *sample); 00112 00114 const TSample * GetSample() const; 00115 00118 void SetInitialProportions(ProportionVectorType & propotion); 00119 00120 const ProportionVectorType & GetInitialProportions() const; 00121 00123 const ProportionVectorType & GetProportions() const; 00124 00126 typedef SimpleDataObjectDecorator< 00127 ProportionVectorType > MembershipFunctionsWeightsArrayObjectType; 00128 typedef typename 00129 MembershipFunctionsWeightsArrayObjectType::Pointer MembershipFunctionsWeightsArrayPointer; 00130 00132 const MembershipFunctionsWeightsArrayObjectType * GetMembershipFunctionsWeightsArray() const; 00133 00138 void SetMaximumIteration(int numberOfIterations); 00139 00140 int GetMaximumIteration() const; 00141 00143 int GetCurrentIteration() 00144 { 00145 return m_CurrentIteration; 00146 } 00147 00149 int AddComponent(ComponentType *component); 00150 00152 unsigned int GetNumberOfComponents() const; 00153 00155 void Update(); 00156 00158 enum TERMINATION_CODE { CONVERGED = 0, NOT_CONVERGED = 1 }; 00159 00161 TERMINATION_CODE GetTerminationCode() const; 00162 00165 ComponentMembershipFunctionType * GetComponentMembershipFunction(int componentIndex) const; 00166 00169 const MembershipFunctionVectorObjectType * GetOutput() const; 00170 00171 protected: 00172 ExpectationMaximizationMixtureModelEstimator(); 00173 virtual ~ExpectationMaximizationMixtureModelEstimator() {} 00174 void PrintSelf(std::ostream & os, Indent indent) const; 00175 00176 bool CalculateDensities(); 00177 00178 double CalculateExpectation() const; 00179 00180 bool UpdateComponentParameters(); 00181 00182 bool UpdateProportions(); 00183 00185 void GenerateData(); 00186 00187 private: 00189 const TSample *m_Sample; 00190 00191 int m_MaxIteration; 00192 int m_CurrentIteration; 00193 00194 TERMINATION_CODE m_TerminationCode; 00195 ComponentVectorType m_ComponentVector; 00196 ProportionVectorType m_InitialProportions; 00197 ProportionVectorType m_Proportions; 00198 00199 MembershipFunctionVectorObjectPointer m_MembershipFunctionsObject; 00200 MembershipFunctionsWeightsArrayPointer m_MembershipFunctionsWeightArrayObject; 00201 }; // end of class 00202 } // end of namespace Statistics 00203 } // end of namespace itk 00204 00205 #ifndef ITK_MANUAL_INSTANTIATION 00206 #include "itkExpectationMaximizationMixtureModelEstimator.hxx" 00207 #endif 00208 00209 #endif 00210