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
|
/*=========================================================================
Program: Insight Segmentation & Registration Toolkit
Module: $RCSfile: itkLogLikelihoodGoodnessOfFitFunction.txx,v $
Language: C++
Date: $Date: 2009-03-04 15:23:56 $
Version: $Revision: 1.12 $
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 __itkLogLikelihoodGoodnessOfFitFunction_txx
#define __itkLogLikelihoodGoodnessOfFitFunction_txx
#include "itkLogLikelihoodGoodnessOfFitFunction.h"
namespace itk {
namespace Statistics {
template< class TInputHistogram >
LogLikelihoodGoodnessOfFitFunction< TInputHistogram >
::LogLikelihoodGoodnessOfFitFunction()
{
this->SetUseExpectedHistogram(true);
m_Initialized = false;
}
template< class TInputHistogram >
void
LogLikelihoodGoodnessOfFitFunction< TInputHistogram >
::GenerateData()
{
const TInputHistogram* observedHistogram = this->GetObservedHistogram();
const TInputHistogram* expectedHistogram = this->GetExpectedHistogram();
float p, px, sum = 0.0f;
double ratio;
typename TInputHistogram::ConstIterator e_iter = expectedHistogram->Begin();
typename TInputHistogram::ConstIterator e_last = expectedHistogram->End();
typename TInputHistogram::ConstIterator o_iter = observedHistogram->Begin();
while ( e_iter != e_last )
{
p = e_iter.GetFrequency();
px = o_iter.GetFrequency();
ratio = px / p;
if ( ratio > this->GetEpsilon() && px > 0 )
{
sum += px * vcl_log(ratio);
}
else
{
sum += px * this->GetLogEpsilon();
}
++e_iter;
++o_iter;
}
sum *= 2.0;
this->GetOutput() = sum;
}
} // end of namespace Statistics
} // end of namespace itk
#endif
|