[Insight-users] ExpectationMaximization problem

Luis Ibanez luis.ibanez at kitware.com
Tue Jun 17 13:33:04 EDT 2008


Hi Moti,

Unfortunately the estimator doesn't throw iteration events,
(please feel free to add a bug report on this, as a feature request)

Therefore, in order to track the problem you will have to add some
debugging code to the estimator itself.

The first thing to verify is whether is running any iterations at all
or whether it is giving up at the beginning.

Please do the following :

1) Open the file:

     Insight/Code/Numerics/Statistics/
       itkExpectationMaximizationMixtureModelEstimator.txx

2)  Go to the method GenerateData(), and in lines 307-310

      while (iteration < m_MaxIteration)
        {
        m_CurrentIteration = iteration ;
        if (this->CalculateDensities())


3)  Insert a cout inside the while loop, like


      while (iteration < m_MaxIteration)
        {
        std::cout << "Iteration : " << iteration << std::endl;
        m_CurrentIteration = iteration ;
        if (this->CalculateDensities())


Please run it with this change, and let us know
for how many iterations it runs.


    Thanks


       Luis



---------------------
Moti Freiman wrote:
> 
> Hi All,
> I'm trying to run the EM algorithm in ITK on my image.
> My image is a simple scalar 3D volume.
> I wrote the following code, based on the itkSoftwareGuide example, but 
> it seems that the estimator does not run at all.
> The output estimated values are exactly the same as the initialization.
> Thanks,
> Moti
> 
> 
> *********************************** Begining of code 
> ****************************************************
>     unsigned int numberOfClasses = 2;
>     typedef itk::Vector< PixelType, 1 > MeasurementVectorType;
> 
>     typedef itk::Statistics::ScalarImageToListAdaptor <ImageType> 
> itkScalarImageToListAdaptorType;
>     itkScalarImageToListAdaptorType::Pointer im2list = 
> itkScalarImageToListAdaptorType::New();
>     im2list->SetImage (sample_volume);
> 
> 
> 
>     typedef itkScalarImageToListAdaptorType SampleType;
>    
>    
>     typedef itk::Array< double > ParametersType;
>     ParametersType params( 2 );
> 
>     std::vector< ParametersType > initialParameters( numberOfClasses );
>     params[0] = 60;
>     params[1] = 50;
>     initialParameters[0] = params;
> 
>     params[0] = 250;
>     params[1] = 50;
>     initialParameters[1] = params;
> 
>     typedef itk::Statistics::GaussianMixtureModelComponent< SampleType 
>  >  ComponentType;
> 
>     std::vector< ComponentType::Pointer > components;
>     for ( unsigned int i = 0 ; i < numberOfClasses ; i++ )
>     {
>         components.push_back( ComponentType::New() );
>         (components[i])->SetSample( im2list );
>         (components[i])->SetParameters( initialParameters[i] );
>     }
> 
> 
> 
>     typedef 
> itk::Statistics::ExpectationMaximizationMixtureModelEstimator< 
> SampleType > EstimatorType;
>     EstimatorType::Pointer estimator = EstimatorType::New();
>     estimator->SetSample( im2list );
>     estimator->SetMaximumIteration( 200 );
> 
>     itk::Array< double > initialProportions(numberOfClasses);
>     initialProportions[0] = 0.5;
>     initialProportions[1] = 0.5;
> 
>     estimator->SetInitialProportions( initialProportions );
>      
>     for ( unsigned int i = 0 ; i < numberOfClasses ; i++)
>     {
>         estimator->AddComponent( (ComponentType::Superclass*)
>                                 (components[i]).GetPointer() );
>     }
>      
>     estimator->Update();
>     for ( unsigned int i = 0 ; i < numberOfClasses ; i++ )
>     {
>         std::cout << "Cluster[" << i << "]" << std::endl;
>         std::cout << "    Parameters:" << std::endl;
>         std::cout << "         " << (components[i])->GetFullParameters()
>                 << std::endl;
>         std::cout << "    Proportion: ";
>         std::cout << "         " << (*estimator->GetProportions())[i] << 
> std::endl;
>     }
> 
> ************************************ end of code 
> **********************************************************
> -- 
> __
> Moti Freiman, Ph.D Student.
> Medical Image Processing and Computer-Assisted Surgery Laboratory.
> School of Computer Science and Engineering.
> The Hebrew University of Jerusalem Givat Ram, Jerusalem 91904, Israel
> Phone: +(972)-2-658-5371 (laboratory)
> WWW site: http://www.cs.huji.ac.il/~freiman
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users


More information about the Insight-users mailing list