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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
|
/*=========================================================================
*
* Copyright NumFOCUS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*=========================================================================*/
#ifndef itkCumulativeGaussianCostFunction_h
#define itkCumulativeGaussianCostFunction_h
#include "itkMultipleValuedCostFunction.h"
#include "ITKOptimizersExport.h"
namespace itk
{
/** \class CumulativeGaussianCostFunction
* \brief Cost function for the Cumulative Gaussian Optimizer.
*
* The Cumulative Gaussian is defined as the integral of
* a normalized Gaussian over the domain \f$ [-\infty, \infty] \f$.
*
* \par Let G(x) be the normalized Gaussian defined as
* \f$ G(x) = \frac{1}{{\sigma \sqrt {2\pi } }}e^{ - \frac{{\left( {x -
* \mu } \right)^2 }}{{2\sigma ^2 }}} \f$.
* The Cumulative Gaussian, is acquired by integrating G(x) then scaling and
* offsetting it by the lower asymptotes \f$ I_1 \f$ and upper \f$ I_2 \f$:
* \f$ C\left( x \right) = I_1 + \frac{{I_2 - I_1 }}{2}\left( {1 +
* erf\left( {\frac{{x - \mu }}{{\sigma \sqrt 2 }}} \right)} \right) \f$, where
* \f$ C\left( { - \infty } \right) = I_1 \f$ and
* \f$ C\left( \infty \right) = I_2 \f$.
*
* \par C(x) can only be tabulated since it's a variation of the
* error function. It is included in this class
* as the function EvaluateCumulativeGaussian, where the argument
* of the function is \f$ {\frac{{x - \mu }}{{\sigma \sqrt 2 }}} \f$.
*
* \ingroup Numerics Cost Functions
* \ingroup ITKOptimizers
*/
class ITKOptimizers_EXPORT CumulativeGaussianCostFunction : public MultipleValuedCostFunction
{
public:
/** Standard type alias. */
using Self = CumulativeGaussianCostFunction;
using Superclass = MultipleValuedCostFunction;
using Pointer = SmartPointer<Self>;
using ConstPointer = SmartPointer<const Self>;
/** \see LightObject::GetNameOfClass() */
itkOverrideGetNameOfClassMacro(CumulativeGaussianCostFunction);
/** Method for creation through the object factory. */
itkNewMacro(Self);
/** Array Typedefs. */
using ParametersType = Superclass::ParametersType;
using MeasureType = Superclass::MeasureType;
using DerivativeType = Superclass::DerivativeType;
/** The dimensions of parameter space; mean, standard deviation, lower and
upper asymptotes. */
enum
{
SpaceDimension = 4
};
/** Not necessary for this optimizer. */
void
GetDerivative(const ParametersType & itkNotUsed(parameters), DerivativeType & itkNotUsed(derivative)) const override
{}
/** Return the values evaluated for the given parameters. */
MeasureType
GetValue(const ParametersType & parameters) const override;
/** Return a pointer of values evaluated for the given parameters. */
MeasureType *
GetValuePointer(ParametersType & parameters);
/** Calculate a fit error between the data and the fit curve. */
double
CalculateFitError(MeasureType * setTestArray);
/** Given the argument of a Cumulative Gaussian, return its value. */
double
EvaluateCumulativeGaussian(double argument) const;
/** Get the SpaceDimension. */
unsigned int
GetNumberOfParameters() const override;
/** Get the number Range Dimension. */
unsigned int
GetNumberOfValues() const override;
/** Initialize the arrays. */
void
Initialize(unsigned int rangeDimension);
/** Set the original data array. */
void
SetOriginalDataArray(MeasureType * setOriginalDataArray);
protected:
CumulativeGaussianCostFunction();
~CumulativeGaussianCostFunction() override;
void
PrintSelf(std::ostream & os, Indent indent) const override;
private:
/** The original data array. */
MeasureType m_OriginalDataArray{};
/** Number of data samples. */
unsigned int m_RangeDimension{ 0 };
/** Different arrays. */
mutable MeasureType m_Measure{};
mutable MeasureType m_MeasurePointer{};
mutable ParametersType m_Parameters{};
};
} // end namespace itk
#endif
|