ITK  5.2.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  * http://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 
25 namespace itk
26 {
37 class ITKOptimizers_EXPORT MultipleValuedVnlCostFunctionAdaptor : public vnl_least_squares_function
38 {
39 public:
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
88  compute(const InternalParametersType & x, InternalMeasureType * ff, InternalDerivativeType * g);
89 
91  void
92  ConvertExternalToInternalGradient(const DerivativeType & input, InternalDerivativeType & output);
93 
95  void
96  ConvertExternalToInternalMeasures(const MeasureType & input, InternalMeasureType & output);
97 
101  void
102  SetUseGradient(bool);
103 
104  void
106  {
107  this->SetUseGradient(true);
108  }
109  void
111  {
112  this->SetUseGradient(false);
113  }
114  bool
115  GetUseGradient() const;
116 
118  void
119  SetScales(const ScalesType & scales);
120 
125  unsigned long
126  AddObserver(const EventObject & event, Command *) const;
127 
132  const MeasureType &
133  GetCachedValue() const;
134 
135  const DerivativeType &
136  GetCachedDerivative() const;
137 
138  const ParametersType &
139  GetCachedCurrentParameters() const;
140 
141 protected:
144  void
145  ReportIteration(const EventObject & event) const;
146 
147 private:
149  itkGetConstReferenceMacro(InverseScales, ScalesType);
150 
152 
156 
160 }; // end of Class CostFunction
161 } // end namespace itk
162 
163 #endif
itk::MultipleValuedCostFunction
This class is a base for the CostFunctions returning a multiple values.
Definition: itkMultipleValuedCostFunction.h:35
itk::MultipleValuedVnlCostFunctionAdaptor::GetCostFunction
const MultipleValuedCostFunction * GetCostFunction() const
Definition: itkMultipleValuedVnlCostFunctionAdaptor.h:73
itk::OptimizerParameters< TInternalComputationValueType >
itk::MultipleValuedVnlCostFunctionAdaptor::UseGradientOff
void UseGradientOff()
Definition: itkMultipleValuedVnlCostFunctionAdaptor.h:110
itk::MultipleValuedVnlCostFunctionAdaptor::InternalParametersType
vnl_vector< double > InternalParametersType
Definition: itkMultipleValuedVnlCostFunctionAdaptor.h:41
itk::MultipleValuedVnlCostFunctionAdaptor::m_CachedValue
MeasureType m_CachedValue
Definition: itkMultipleValuedVnlCostFunctionAdaptor.h:157
itk::SmartPointer< Self >
itk::MultipleValuedCostFunction::ParametersType
Superclass::ParametersType ParametersType
Definition: itkMultipleValuedCostFunction.h:51
itk::Command
Superclass for callback/observer methods.
Definition: itkCommand.h:45
itk::MultipleValuedVnlCostFunctionAdaptor::m_CachedCurrentParameters
ParametersType m_CachedCurrentParameters
Definition: itkMultipleValuedVnlCostFunctionAdaptor.h:159
itk::MultipleValuedVnlCostFunctionAdaptor::SetCostFunction
void SetCostFunction(MultipleValuedCostFunction *costFunction)
Definition: itkMultipleValuedVnlCostFunctionAdaptor.h:66
itk::MultipleValuedVnlCostFunctionAdaptor::InternalDerivativeType
vnl_matrix< double > InternalDerivativeType
Definition: itkMultipleValuedVnlCostFunctionAdaptor.h:47
itk::MultipleValuedCostFunction::MeasureType
Array< double > MeasureType
Definition: itkMultipleValuedCostFunction.h:55
itk::MultipleValuedVnlCostFunctionAdaptor
This class is an Adaptor that allows to pass itk::MultipleValuedCostFunctions to vnl_optimizers expec...
Definition: itkMultipleValuedVnlCostFunctionAdaptor.h:37
itk::MultipleValuedVnlCostFunctionAdaptor::InternalMeasureType
vnl_vector< double > InternalMeasureType
Definition: itkMultipleValuedVnlCostFunctionAdaptor.h:44
itk::MultipleValuedVnlCostFunctionAdaptor::m_Reporter
Object::Pointer m_Reporter
Definition: itkMultipleValuedVnlCostFunctionAdaptor.h:155
itk::MultipleValuedVnlCostFunctionAdaptor::UseGradientOn
void UseGradientOn()
Definition: itkMultipleValuedVnlCostFunctionAdaptor.h:105
itk::MultipleValuedVnlCostFunctionAdaptor::m_InverseScales
ScalesType m_InverseScales
Definition: itkMultipleValuedVnlCostFunctionAdaptor.h:154
itkMultipleValuedCostFunction.h
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::MultipleValuedCostFunction::DerivativeType
Array2D< double > DerivativeType
Definition: itkMultipleValuedCostFunction.h:59
itk::MultipleValuedVnlCostFunctionAdaptor::m_ScalesInitialized
bool m_ScalesInitialized
Definition: itkMultipleValuedVnlCostFunctionAdaptor.h:153
itk::Array< double >
itk::EventObject
Abstraction of the Events used to communicating among filters and with GUIs.
Definition: itkEventObject.h:57
itk::Array2D
Array2D class representing a 2D array with size defined at construction time.
Definition: itkArray2D.h:45
itk::MultipleValuedVnlCostFunctionAdaptor::m_CostFunction
MultipleValuedCostFunction::Pointer m_CostFunction
Definition: itkMultipleValuedVnlCostFunctionAdaptor.h:149
itk::MultipleValuedVnlCostFunctionAdaptor::m_CachedDerivative
DerivativeType m_CachedDerivative
Definition: itkMultipleValuedVnlCostFunctionAdaptor.h:158