Commit fc85dd70 authored by Emmanuel Christophe's avatar Emmanuel Christophe

TEST: fix test for FlexibleDistanceWithMissingValue

parent 35697825
......@@ -9,11 +9,11 @@
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
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.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
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.
=========================================================================*/
......@@ -30,17 +30,17 @@ namespace Statistics {
/** \class FlexibleDistanceWithMissingValue
* \brief Non-Euclidean distance function facing missing value.
*
* This class is derived from EuclideanDistanceWithMissingValuePow2 class to
* deal with missing data. In addition, the initial Evaluate method performs
* This class is derived from EuclideanDistanceWithMissingValuePow2 class to
* deal with missing data. In addition, the initial Evaluate method performs
* a flexible calculation of distance when a component does contain data.
*
* The general formlation is defined as:
* The general formulation is defined as:
* \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$
*
*
* 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}'.
*
......@@ -54,7 +54,7 @@ class ITK_EXPORT FlexibleDistanceWithMissingValue :
/** Standard "Self" typedef. */
typedef FlexibleDistanceWithMissingValue Self;
typedef otb::Statistics::EuclideanDistanceWithMissingValuePow2< TVector > Superclass;
typedef itk::SmartPointer< Self > Pointer ;
typedef itk::SmartPointer< Self > Pointer ;
typedef itk::SmartPointer<const Self> ConstPointer;
typedef typename Superclass::MeasurementVectorSizeType MeasurementVectorSizeType;
......@@ -75,7 +75,7 @@ class ITK_EXPORT FlexibleDistanceWithMissingValue :
double Evaluate(const TVector &x1, const TVector &x2) const ;
/** 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 ;
/** Returns true if the distance between x and the origin is less
......@@ -84,10 +84,10 @@ class ITK_EXPORT FlexibleDistanceWithMissingValue :
return Superclass::IsWithinRange( x, radius ); }
/** 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) */
static double Alpha;
static double Beta;
static double Beta;
static void SetAlphaBeta( double a, double b);
/** test if it is ordinary Euclidean distance */
......@@ -95,7 +95,7 @@ class ITK_EXPORT FlexibleDistanceWithMissingValue :
protected:
FlexibleDistanceWithMissingValue() {}
virtual ~FlexibleDistanceWithMissingValue() {}
virtual ~FlexibleDistanceWithMissingValue() {}
}; // end of class
/** Static variable instanciation */
......
......@@ -9,11 +9,11 @@
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
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.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
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.
=========================================================================*/
......@@ -37,7 +37,7 @@ FlexibleDistanceWithMissingValue< TVector >
if (IsEuclidean())
return Superclass::Evaluate(x1,x2);
if( itk::MeasurementVectorTraits::GetLength( x1 ) !=
if( itk::MeasurementVectorTraits::GetLength( x1 ) !=
itk::MeasurementVectorTraits::GetLength( x2 ) )
{
itkExceptionMacro( << "Vector lengths must be equal." );
......@@ -49,7 +49,7 @@ FlexibleDistanceWithMissingValue< TVector >
{
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 ;
}
}
......@@ -65,15 +65,15 @@ FlexibleDistanceWithMissingValue< TVector >
if ( IsEuclidean() )
return Superclass::Evaluate(x);
MeasurementVectorSizeType
MeasurementVectorSizeType
measurementVectorSize = this->GetMeasurementVectorSize();
if(measurementVectorSize == 0)
if(measurementVectorSize == 0)
{
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");
double temp, distance = itk::NumericTraits< double >::Zero ;
......@@ -82,7 +82,7 @@ FlexibleDistanceWithMissingValue< TVector >
{
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 ;
}
}
......@@ -97,12 +97,12 @@ FlexibleDistanceWithMissingValue< TVector >
{
if (IsEuclidean())
return Superclass::Evaluate(a,b);
// FIXME throw NaN exception or not ??
if ( IsMissingValue( a ) || IsMissingValue( b ) )
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 ;
}
template< class TVector >
......@@ -124,7 +124,7 @@ FlexibleDistanceWithMissingValue< TVector >
return true;
}
else
{
{
return false;
}
}
......
......@@ -30,6 +30,8 @@ int otbFlexibleDistanceWithMissingValue( int argc, char * argv[] )
typedef itk::VariableLengthVector< double > VectorType;
typedef otb::Statistics::FlexibleDistanceWithMissingValue< VectorType > DistanceType;
const double epsilon = 0.00000001;
float a = 2.0;
float b = 0.5;
DistanceType::SetAlphaBeta(a,b);
......@@ -44,7 +46,7 @@ int otbFlexibleDistanceWithMissingValue( int argc, char * argv[] )
double distanceValue = dist->Evaluate( x, y );
std::cout << "Distance: " << distanceValue << std::endl;
if ( distanceValue == 3. )
if ( (distanceValue - 3.*vcl_pow(3,b)) < epsilon )
return EXIT_SUCCESS;
else
return EXIT_FAILURE;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment