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

TEST: fix test for FlexibleDistanceWithMissingValue

parent 35697825
No related branches found
No related tags found
No related merge requests found
...@@ -9,11 +9,11 @@ ...@@ -9,11 +9,11 @@
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details. See OTBCopyright.txt for details.
Copyright (c) Institut Telecom / Telecom Bretagne. All rights reserved. Copyright (c) Institut Telecom / Telecom Bretagne. All rights reserved.
See ITCopyright.txt for details. See ITCopyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information. PURPOSE. See the above copyright notices for more information.
=========================================================================*/ =========================================================================*/
...@@ -30,17 +30,17 @@ namespace Statistics { ...@@ -30,17 +30,17 @@ namespace Statistics {
/** \class FlexibleDistanceWithMissingValue /** \class FlexibleDistanceWithMissingValue
* \brief Non-Euclidean distance function facing missing value. * \brief Non-Euclidean distance function facing missing value.
* *
* This class is derived from EuclideanDistanceWithMissingValuePow2 class to * This class is derived from EuclideanDistanceWithMissingValuePow2 class to
* deal with missing data. In addition, the initial Evaluate method performs * deal with missing data. In addition, the initial Evaluate method performs
* a flexible calculation of distance when a component does contain data. * a flexible calculation of distance when a component does contain data.
* *
* The general formlation is defined as: * The general formulation is defined as:
* \f$ * \f$
d(x,y) = \sum_i | x_i^a - y_i^a |^b. d(x,y) = \sum_i | x_i^a - y_i^a |^b.
\f$ \f$
* *
* The class can be templated over any container that holds data elements, as * The class can be templated over any container that holds data elements, as
* for template of EuclideanDistance. * for template of EuclideanDistance.
* *
* The only restriction is that elements have to support '\code{NaN}'. * The only restriction is that elements have to support '\code{NaN}'.
* *
...@@ -54,7 +54,7 @@ class ITK_EXPORT FlexibleDistanceWithMissingValue : ...@@ -54,7 +54,7 @@ class ITK_EXPORT FlexibleDistanceWithMissingValue :
/** Standard "Self" typedef. */ /** Standard "Self" typedef. */
typedef FlexibleDistanceWithMissingValue Self; typedef FlexibleDistanceWithMissingValue Self;
typedef otb::Statistics::EuclideanDistanceWithMissingValuePow2< TVector > Superclass; typedef otb::Statistics::EuclideanDistanceWithMissingValuePow2< TVector > Superclass;
typedef itk::SmartPointer< Self > Pointer ; typedef itk::SmartPointer< Self > Pointer ;
typedef itk::SmartPointer<const Self> ConstPointer; typedef itk::SmartPointer<const Self> ConstPointer;
typedef typename Superclass::MeasurementVectorSizeType MeasurementVectorSizeType; typedef typename Superclass::MeasurementVectorSizeType MeasurementVectorSizeType;
...@@ -75,7 +75,7 @@ class ITK_EXPORT FlexibleDistanceWithMissingValue : ...@@ -75,7 +75,7 @@ class ITK_EXPORT FlexibleDistanceWithMissingValue :
double Evaluate(const TVector &x1, const TVector &x2) const ; double Evaluate(const TVector &x1, const TVector &x2) const ;
/** Gets the cooridnate distance between a and b. NOTE: a and b /** Gets the cooridnate distance between a and b. NOTE: a and b
* should be type of component */ * should be type of component */
double Evaluate(const ValueType &a, const ValueType &b) const ; double Evaluate(const ValueType &a, const ValueType &b) const ;
/** Returns true if the distance between x and the origin is less /** Returns true if the distance between x and the origin is less
...@@ -84,10 +84,10 @@ class ITK_EXPORT FlexibleDistanceWithMissingValue : ...@@ -84,10 +84,10 @@ class ITK_EXPORT FlexibleDistanceWithMissingValue :
return Superclass::IsWithinRange( x, radius ); } return Superclass::IsWithinRange( x, radius ); }
/** Set the value of the parameter a and b. /** Set the value of the parameter a and b.
* Those parameters are defined as static component in order to call it far * Those parameters are defined as static component in order to call it far
* away from the instanciation of the class (through the SOM training for instance) */ * away from the instanciation of the class (through the SOM training for instance) */
static double Alpha; static double Alpha;
static double Beta; static double Beta;
static void SetAlphaBeta( double a, double b); static void SetAlphaBeta( double a, double b);
/** test if it is ordinary Euclidean distance */ /** test if it is ordinary Euclidean distance */
...@@ -95,7 +95,7 @@ class ITK_EXPORT FlexibleDistanceWithMissingValue : ...@@ -95,7 +95,7 @@ class ITK_EXPORT FlexibleDistanceWithMissingValue :
protected: protected:
FlexibleDistanceWithMissingValue() {} FlexibleDistanceWithMissingValue() {}
virtual ~FlexibleDistanceWithMissingValue() {} virtual ~FlexibleDistanceWithMissingValue() {}
}; // end of class }; // end of class
/** Static variable instanciation */ /** Static variable instanciation */
......
...@@ -9,11 +9,11 @@ ...@@ -9,11 +9,11 @@
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details. See OTBCopyright.txt for details.
Copyright (c) Institut Telecom / Telecom Bretagne. All rights reserved. Copyright (c) Institut Telecom / Telecom Bretagne. All rights reserved.
See ITCopyright.txt for details. See ITCopyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information. PURPOSE. See the above copyright notices for more information.
=========================================================================*/ =========================================================================*/
...@@ -37,7 +37,7 @@ FlexibleDistanceWithMissingValue< TVector > ...@@ -37,7 +37,7 @@ FlexibleDistanceWithMissingValue< TVector >
if (IsEuclidean()) if (IsEuclidean())
return Superclass::Evaluate(x1,x2); return Superclass::Evaluate(x1,x2);
if( itk::MeasurementVectorTraits::GetLength( x1 ) != if( itk::MeasurementVectorTraits::GetLength( x1 ) !=
itk::MeasurementVectorTraits::GetLength( x2 ) ) itk::MeasurementVectorTraits::GetLength( x2 ) )
{ {
itkExceptionMacro( << "Vector lengths must be equal." ); itkExceptionMacro( << "Vector lengths must be equal." );
...@@ -49,7 +49,7 @@ FlexibleDistanceWithMissingValue< TVector > ...@@ -49,7 +49,7 @@ FlexibleDistanceWithMissingValue< TVector >
{ {
if ( !IsMissingValue( x1[i] ) && !IsMissingValue( x2[i] ) ) if ( !IsMissingValue( x1[i] ) && !IsMissingValue( x2[i] ) )
{ {
temp = pow( fabs( pow(x1[i],this->Alpha) - pow(x2[i],this->Alpha) ), this->Beta ); temp = vcl_pow( vcl_abs( vcl_pow(x1[i],this->Alpha) - vcl_pow(x2[i],this->Alpha) ), this->Beta );
distance += temp ; distance += temp ;
} }
} }
...@@ -65,15 +65,15 @@ FlexibleDistanceWithMissingValue< TVector > ...@@ -65,15 +65,15 @@ FlexibleDistanceWithMissingValue< TVector >
if ( IsEuclidean() ) if ( IsEuclidean() )
return Superclass::Evaluate(x); return Superclass::Evaluate(x);
MeasurementVectorSizeType MeasurementVectorSizeType
measurementVectorSize = this->GetMeasurementVectorSize(); measurementVectorSize = this->GetMeasurementVectorSize();
if(measurementVectorSize == 0) if(measurementVectorSize == 0)
{ {
itkExceptionMacro( << "Please set the MeasurementVectorSize first" ); itkExceptionMacro( << "Please set the MeasurementVectorSize first" );
} }
itk::MeasurementVectorTraits::Assert( this->m_Origin, measurementVectorSize, itk::MeasurementVectorTraits::Assert( this->m_Origin, measurementVectorSize,
"EuclideanDistance::Evaluate Origin and input vector have different lengths"); "EuclideanDistance::Evaluate Origin and input vector have different lengths");
double temp, distance = itk::NumericTraits< double >::Zero ; double temp, distance = itk::NumericTraits< double >::Zero ;
...@@ -82,7 +82,7 @@ FlexibleDistanceWithMissingValue< TVector > ...@@ -82,7 +82,7 @@ FlexibleDistanceWithMissingValue< TVector >
{ {
if ( !IsMissingValue( this->GetOrigin()[i] ) && !IsMissingValue( x[i] ) ) if ( !IsMissingValue( this->GetOrigin()[i] ) && !IsMissingValue( x[i] ) )
{ {
temp = pow( fabs( pow(this->GetOrigin()[i],this->Alpha) - pow(x[i],this->Alpha) ), this->Beta) ; temp = vcl_pow( vcl_abs( vcl_pow(this->GetOrigin()[i],this->Alpha) - vcl_pow(x[i],this->Alpha) ), this->Beta) ;
distance += temp ; distance += temp ;
} }
} }
...@@ -97,12 +97,12 @@ FlexibleDistanceWithMissingValue< TVector > ...@@ -97,12 +97,12 @@ FlexibleDistanceWithMissingValue< TVector >
{ {
if (IsEuclidean()) if (IsEuclidean())
return Superclass::Evaluate(a,b); return Superclass::Evaluate(a,b);
// FIXME throw NaN exception or not ?? // FIXME throw NaN exception or not ??
if ( IsMissingValue( a ) || IsMissingValue( b ) ) if ( IsMissingValue( a ) || IsMissingValue( b ) )
return 0.0; return 0.0;
double temp = pow(fabs(pow(a,this->Alpha) - pow(b,this->Alpha)), this->Beta) ; double temp = vcl_pow(vcl_abs(vcl_pow(a,this->Alpha) - vcl_pow(b,this->Alpha)), this->Beta) ;
return temp ; return temp ;
} }
template< class TVector > template< class TVector >
...@@ -124,7 +124,7 @@ FlexibleDistanceWithMissingValue< TVector > ...@@ -124,7 +124,7 @@ FlexibleDistanceWithMissingValue< TVector >
return true; return true;
} }
else else
{ {
return false; return false;
} }
} }
......
...@@ -30,6 +30,8 @@ int otbFlexibleDistanceWithMissingValue( int argc, char * argv[] ) ...@@ -30,6 +30,8 @@ int otbFlexibleDistanceWithMissingValue( int argc, char * argv[] )
typedef itk::VariableLengthVector< double > VectorType; typedef itk::VariableLengthVector< double > VectorType;
typedef otb::Statistics::FlexibleDistanceWithMissingValue< VectorType > DistanceType; typedef otb::Statistics::FlexibleDistanceWithMissingValue< VectorType > DistanceType;
const double epsilon = 0.00000001;
float a = 2.0; float a = 2.0;
float b = 0.5; float b = 0.5;
DistanceType::SetAlphaBeta(a,b); DistanceType::SetAlphaBeta(a,b);
...@@ -44,7 +46,7 @@ int otbFlexibleDistanceWithMissingValue( int argc, char * argv[] ) ...@@ -44,7 +46,7 @@ int otbFlexibleDistanceWithMissingValue( int argc, char * argv[] )
double distanceValue = dist->Evaluate( x, y ); double distanceValue = dist->Evaluate( x, y );
std::cout << "Distance: " << distanceValue << std::endl; std::cout << "Distance: " << distanceValue << std::endl;
if ( distanceValue == 3. ) if ( (distanceValue - 3.*vcl_pow(3,b)) < epsilon )
return EXIT_SUCCESS; return EXIT_SUCCESS;
else else
return EXIT_FAILURE; return EXIT_FAILURE;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment