ITK  6.0.0
Insight Toolkit
itkMultipleValuedVnlCostFunctionAdaptor.h
Go to the documentation of this file.
1/*=========================================================================
2 *
3 * Copyright NumFOCUS
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * https://www.apache.org/licenses/LICENSE-2.0.txt
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 *=========================================================================*/
18#ifndef itkMultipleValuedVnlCostFunctionAdaptor_h
19#define itkMultipleValuedVnlCostFunctionAdaptor_h
20
22#include "vnl/vnl_least_squares_function.h"
23#include "ITKOptimizersExport.h"
24
25namespace itk
26{
37class ITKOptimizers_EXPORT MultipleValuedVnlCostFunctionAdaptor : public vnl_least_squares_function
38{
39public:
41 using InternalParametersType = vnl_vector<double>;
42
44 using InternalMeasureType = vnl_vector<double>;
45
47 using InternalDerivativeType = vnl_matrix<double>;
48
51
54
57
60
62 MultipleValuedVnlCostFunctionAdaptor(unsigned int spaceDimension, unsigned int numberOfValues);
63
65 void
67 {
68 m_CostFunction = costFunction;
69 }
70
74 {
75 return m_CostFunction;
76 }
77
79 void
80 f(const InternalParametersType & inparameters, InternalMeasureType & measures) override;
81
83 void
84 gradf(const InternalParametersType & inparameters, InternalDerivativeType & gradient) override;
85
87 virtual void
89
91 void
93
95 void
97
101 void
103
104 void
106 {
107 this->SetUseGradient(true);
108 }
109 void
111 {
112 this->SetUseGradient(false);
113 }
114 bool
116
118 void
119 SetScales(const ScalesType & scales);
120
125 unsigned long
126 AddObserver(const EventObject & event, Command *) const;
127
132 const MeasureType &
134
135 const DerivativeType &
137
138 const ParametersType &
140
141protected:
144 void
145 ReportIteration(const EventObject & event) const;
146
147private:
149 itkGetConstReferenceMacro(InverseScales, ScalesType);
150
152
153 bool m_ScalesInitialized{};
154 ScalesType m_InverseScales{};
155 Object::Pointer m_Reporter{};
156
157 mutable MeasureType m_CachedValue{};
158 mutable DerivativeType m_CachedDerivative{};
159 mutable ParametersType m_CachedCurrentParameters{};
160}; // end of Class CostFunction
161} // end namespace itk
162
163#endif
Array2D class representing a 2D array.
Definition: itkArray2D.h:43
Superclass for callback/observer methods.
Definition: itkCommand.h:46
Abstraction of the Events used to communicating among filters and with GUIs.
This class is a base for the CostFunctions returning a multiple values.
This class is an Adaptor that allows to pass itk::MultipleValuedCostFunctions to vnl_optimizers expec...
const MeasureType & GetCachedValue() const
void ConvertExternalToInternalMeasures(const MeasureType &input, InternalMeasureType &output)
void ReportIteration(const EventObject &event) const
virtual void compute(const InternalParametersType &x, InternalMeasureType *ff, InternalDerivativeType *g)
MultipleValuedCostFunction::ParametersType ParametersType
MultipleValuedVnlCostFunctionAdaptor(unsigned int spaceDimension, unsigned int numberOfValues)
const DerivativeType & GetCachedDerivative() const
void SetScales(const ScalesType &scales)
void ConvertExternalToInternalGradient(const DerivativeType &input, InternalDerivativeType &output)
void gradf(const InternalParametersType &inparameters, InternalDerivativeType &gradient) override
void SetCostFunction(MultipleValuedCostFunction *costFunction)
const MultipleValuedCostFunction * GetCostFunction() const
unsigned long AddObserver(const EventObject &event, Command *) const
const ParametersType & GetCachedCurrentParameters() const
void f(const InternalParametersType &inparameters, InternalMeasureType &measures) override
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....