Skip to content
Snippets Groups Projects
Commit 8c71a0e7 authored by Emmanuel Christophe's avatar Emmanuel Christophe
Browse files

STYLE: and fix test for gamma

parent 99100bc7
No related branches found
No related tags found
No related merge requests found
...@@ -27,62 +27,65 @@ ...@@ -27,62 +27,65 @@
namespace otb namespace otb
{ {
/* /**
\* class MRFEnergyFisherClassification * \class MRFEnergyFisherClassification
\* This is the implementation of the Fisher model for Markov classification * \brief Fisher model for Markov classification
\* to be used for the fidelity (likelihood) term for the classification. *
\* * This is the implementation of the Fisher model for Markov classification
\* This class is meant to be used in the MRF framework with the otb:: MarkovRandomFieldFilter * to be used for the fidelity (likelihood) term for the classification.
*
* This class is meant to be used in the MRF framework with the
* otb::MarkovRandomFieldFilter
*
*/ */
template< class TInput1, class TInput2> template< class TInput1, class TInput2>
class ITK_EXPORT MRFEnergyFisherClassification:public MRFEnergy< TInput1, TInput2> class ITK_EXPORT MRFEnergyFisherClassification: public MRFEnergy< TInput1, TInput2>
{ {
public: public:
typedef MRFEnergyFisherClassification Self; typedef MRFEnergyFisherClassification Self;
typedef MRFEnergy< TInput1, TInput2> Superclass; typedef MRFEnergy< TInput1, TInput2> Superclass;
typedef itk::SmartPointer<Self> Pointer; typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer; typedef itk::SmartPointer<const Self> ConstPointer;
typedef TInput1 InputImageType; typedef TInput1 InputImageType;
typedef TInput2 LabelledImageType; typedef TInput2 LabelledImageType;
typedef typename InputImageType::PixelType InputImagePixelType; typedef typename InputImageType::PixelType InputImagePixelType;
typedef typename LabelledImageType::PixelType LabelledImagePixelType; typedef typename LabelledImageType::PixelType LabelledImagePixelType;
typedef itk::Array < double > ParametersType; typedef itk::Array < double > ParametersType;
itkNewMacro(Self); itkNewMacro(Self);
itkTypeMacro(MRFEnergyFisherClassification, MRFEnergy); itkTypeMacro(MRFEnergyFisherClassification, MRFEnergy);
Gamma g; Gamma g;
void SetNumberOfParameters(const unsigned int nParameters) void SetNumberOfParameters(const unsigned int nParameters)
{ {
Superclass::SetNumberOfParameters(nParameters); Superclass::SetNumberOfParameters(nParameters);
this->m_Parameters.SetSize(nParameters); this->m_Parameters.SetSize(nParameters);
this->Modified(); this->Modified();
} }
double GetSingleValue(const InputImagePixelType & value1, const LabelledImagePixelType & value2) double GetSingleValue(const InputImagePixelType & value1, const LabelledImagePixelType & value2)
{ {
if ((unsigned int)value2 >= this->GetNumberOfParameters()/3) if ((unsigned int)value2 >= this->GetNumberOfParameters()/3)
{ {
itkExceptionMacro(<<"Number of parameters does not correspond to number of classes" ); itkExceptionMacro(<<"Number of parameters does not correspond to number of classes" );
} }
double val1 = static_cast<double>(value1); double val1 = static_cast<double>(value1);
double mu = this->m_Parameters[3*static_cast<double>(value2)]; double mu = this->m_Parameters[3*static_cast<double>(value2)];
double l = this->m_Parameters[3*static_cast<double>(value2)+1]; double l = this->m_Parameters[3*static_cast<double>(value2)+1];
double m = this->m_Parameters[3*static_cast<double>(value2)+2]; double m = this->m_Parameters[3*static_cast<double>(value2)+2];
double result = -vcl_log((g.gamma(l+m)/(g.gamma(l)*g.gamma(m))) * (2/(mu)) * (vcl_sqrt(l/m)) * double result = -vcl_log((g.gamma(l+m)/(g.gamma(l)*g.gamma(m))) * (2/(mu)) * (vcl_sqrt(l/m)) *
((pow((vcl_sqrt(l/m)*(val1/mu)), ((2*l)-1))) / ((pow((vcl_sqrt(l/m)*(val1/mu)), ((2*l)-1))) /
(pow(1+(vcl_sqrt(l/m)*(val1/mu)*vcl_sqrt(l/m)*(val1/mu)), (l+m))))); (pow(1+(vcl_sqrt(l/m)*(val1/mu)*vcl_sqrt(l/m)*(val1/mu)), (l+m)))));
return static_cast<double>( result ); return static_cast<double>( result );
} }
protected: protected:
// The constructor and destructor. // The constructor and destructor.
MRFEnergyFisherClassification() {}; MRFEnergyFisherClassification() {};
virtual ~MRFEnergyFisherClassification() {}; virtual ~MRFEnergyFisherClassification() {};
}; };
} }
#endif #endif
...@@ -28,10 +28,13 @@ int otbGammaTest(int argc, char * argv[]) ...@@ -28,10 +28,13 @@ int otbGammaTest(int argc, char * argv[])
//Instantiation //Instantiation
GammaFunctionType * gam = new GammaFunctionType(); GammaFunctionType * gam = new GammaFunctionType();
const double epsilon = 0.0000000001; const double epsilon = 0.0000000001;
int output = EXIT_SUCCESS;
if ( vcl_abs(gam->gamma(1) - 1) > epsilon ) return EXIT_FAILURE; if ( vcl_abs(gam->gamma(1) - 1) > epsilon ) output = EXIT_FAILURE;
if ( vcl_abs(gam->gamma(0.5) - 1.77245385091) > epsilon ) return EXIT_FAILURE; if ( vcl_abs(gam->gamma(0.5) - 1.77245385091) > epsilon ) output = EXIT_FAILURE;
if ( vcl_abs(gam->gamma(4) - 6) > epsilon ) return EXIT_FAILURE; if ( vcl_abs(gam->gamma(4) - 6) > epsilon ) output = EXIT_FAILURE;
return EXIT_SUCCESS; delete gam;
return output;
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment