Loading...
Searching...
No Matches
itkGenericConjugateGradientOptimizer.h
Go to the documentation of this file.
/*=========================================================================
*
* Copyright UMC Utrecht and contributors
*
* 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
*
* http://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 itkGenericConjugateGradientOptimizer_h
#define itkGenericConjugateGradientOptimizer_h
#include "itkScaledSingleValuedNonLinearOptimizer.h"
#include "itkLineSearchOptimizer.h"
#include <vector>
#include <map>
namespace itk
{
class GenericConjugateGradientOptimizer : public ScaledSingleValuedNonLinearOptimizer
{
public:
ITK_DISALLOW_COPY_AND_MOVE(GenericConjugateGradientOptimizer);
using Self = GenericConjugateGradientOptimizer;
using Superclass = ScaledSingleValuedNonLinearOptimizer;
using Pointer = SmartPointer<Self>;
using ConstPointer = SmartPointer<const Self>;
itkNewMacro(Self);
itkTypeMacro(GenericConjugateGradientOptimizer, ScaledSingleValuedNonLinearOptimizer);
using Superclass::ParametersType;
using Superclass::DerivativeType;
using Superclass::CostFunctionType;
using Superclass::ScaledCostFunctionType;
using Superclass::MeasureType;
using Superclass::ScalesType;
using LineSearchOptimizerType = LineSearchOptimizer;
using LineSearchOptimizerPointer = LineSearchOptimizerType::Pointer;
using ComputeBetaFunctionType = double (Self::*)(const DerivativeType &,
const DerivativeType &,
const ParametersType &);
using BetaDefinitionType = std::string;
using BetaDefinitionMapType = std::map<BetaDefinitionType, ComputeBetaFunctionType>;
enum class StopConditionType : unsigned int
{
MetricError,
LineSearchError,
MaximumNumberOfIterations,
GradientMagnitudeTolerance,
ValueTolerance,
InfiniteBeta,
Unknown
};
void
StartOptimization() override;
virtual void
ResumeOptimization();
virtual void
StopOptimization();
itkGetConstMacro(CurrentIteration, unsigned long);
itkGetConstMacro(CurrentValue, MeasureType);
itkGetConstReferenceMacro(CurrentGradient, DerivativeType);
itkGetConstMacro(InLineSearch, bool);
itkGetConstReferenceMacro(StopCondition, StopConditionType);
itkGetConstMacro(CurrentStepLength, double);
itkSetObjectMacro(LineSearchOptimizer, LineSearchOptimizerType);
itkGetModifiableObjectMacro(LineSearchOptimizer, LineSearchOptimizerType);
itkGetConstMacro(MaximumNumberOfIterations, unsigned long);
itkSetClampMacro(MaximumNumberOfIterations, unsigned long, 1, NumericTraits<unsigned long>::max());
itkGetConstMacro(GradientMagnitudeTolerance, double);
itkSetMacro(GradientMagnitudeTolerance, double)
itkGetConstMacro(ValueTolerance, double);
itkSetMacro(ValueTolerance, double);
virtual void
SetMaxNrOfItWithoutImprovement(unsigned long arg);
itkGetConstMacro(MaxNrOfItWithoutImprovement, unsigned long);
void
SetBetaDefinition(const BetaDefinitionType & arg);
itkGetConstReferenceMacro(BetaDefinition, BetaDefinitionType);
protected:
GenericConjugateGradientOptimizer();
~GenericConjugateGradientOptimizer() override = default;
void
PrintSelf(std::ostream & os, Indent indent) const override;
DerivativeType m_CurrentGradient{};
MeasureType m_CurrentValue{ 0.0 };
unsigned long m_CurrentIteration{ 0 };
StopConditionType m_StopCondition{ StopConditionType::Unknown };
bool m_Stop{ false };
double m_CurrentStepLength{ 0.0 };
bool m_UseDefaultMaxNrOfItWithoutImprovement{ true };
bool m_InLineSearch{ false };
itkSetMacro(InLineSearch, bool);
bool m_PreviousGradientAndSearchDirValid{ false };
BetaDefinitionType m_BetaDefinition{};
BetaDefinitionMapType m_BetaDefinitionMap{};
void
AddBetaDefinition(const BetaDefinitionType & name, ComputeBetaFunctionType function);
virtual void
ComputeSearchDirection(const DerivativeType & previousGradient,
const DerivativeType & gradient,
ParametersType & searchDir);
virtual void
LineSearch(const ParametersType searchDir, double & step, ParametersType & x, MeasureType & f, DerivativeType & g);
virtual bool
TestConvergence(bool firstLineSearchDone);
virtual double
ComputeBeta(const DerivativeType & previousGradient,
const DerivativeType & gradient,
const ParametersType & previousSearchDir);
double
ComputeBetaSD(const DerivativeType & previousGradient,
const DerivativeType & gradient,
const ParametersType & previousSearchDir);
double
ComputeBetaFR(const DerivativeType & previousGradient,
const DerivativeType & gradient,
const ParametersType & previousSearchDir);
double
ComputeBetaPR(const DerivativeType & previousGradient,
const DerivativeType & gradient,
const ParametersType & previousSearchDir);
double
ComputeBetaDY(const DerivativeType & previousGradient,
const DerivativeType & gradient,
const ParametersType & previousSearchDir);
double
ComputeBetaHS(const DerivativeType & previousGradient,
const DerivativeType & gradient,
const ParametersType & previousSearchDir);
double
ComputeBetaDYHS(const DerivativeType & previousGradient,
const DerivativeType & gradient,
const ParametersType & previousSearchDir);
private:
unsigned long m_MaximumNumberOfIterations{ 100 };
double m_ValueTolerance{ 1e-5 };
double m_GradientMagnitudeTolerance{ 1e-5 };
unsigned long m_MaxNrOfItWithoutImprovement{ 10 };
LineSearchOptimizerPointer m_LineSearchOptimizer{ nullptr };
};
} // end namespace itk
#endif //#ifndef itkGenericConjugateGradientOptimizer_h
double
itk::GenericConjugateGradientOptimizer::SetMaxNrOfItWithoutImprovement
virtual void SetMaxNrOfItWithoutImprovement(unsigned long arg)
itk::GenericConjugateGradientOptimizer::m_GradientMagnitudeTolerance
double m_GradientMagnitudeTolerance
Definition itkGenericConjugateGradientOptimizer.h:259
itk::GenericConjugateGradientOptimizer::ComputeBetaPR
double ComputeBetaPR(const DerivativeType &previousGradient, const DerivativeType &gradient, const ParametersType &previousSearchDir)
itk::GenericConjugateGradientOptimizer::PrintSelf
void PrintSelf(std::ostream &os, Indent indent) const override
itk::GenericConjugateGradientOptimizer::TestConvergence
virtual bool TestConvergence(bool firstLineSearchDone)
itk::GenericConjugateGradientOptimizer::Superclass
ScaledSingleValuedNonLinearOptimizer Superclass
Definition itkGenericConjugateGradientOptimizer.h:46
itk::GenericConjugateGradientOptimizer::m_StopCondition
StopConditionType m_StopCondition
Definition itkGenericConjugateGradientOptimizer.h:150
itk::GenericConjugateGradientOptimizer::m_BetaDefinition
BetaDefinitionType m_BetaDefinition
Definition itkGenericConjugateGradientOptimizer.h:169
itk::GenericConjugateGradientOptimizer::m_CurrentStepLength
double m_CurrentStepLength
Definition itkGenericConjugateGradientOptimizer.h:152
itk::GenericConjugateGradientOptimizer::ITK_DISALLOW_COPY_AND_MOVE
ITK_DISALLOW_COPY_AND_MOVE(GenericConjugateGradientOptimizer)
itk::GenericConjugateGradientOptimizer::m_UseDefaultMaxNrOfItWithoutImprovement
bool m_UseDefaultMaxNrOfItWithoutImprovement
Definition itkGenericConjugateGradientOptimizer.h:156
itk::GenericConjugateGradientOptimizer::BetaDefinitionType
std::string BetaDefinitionType
Definition itkGenericConjugateGradientOptimizer.h:68
itk::GenericConjugateGradientOptimizer::Pointer
SmartPointer< Self > Pointer
Definition itkGenericConjugateGradientOptimizer.h:47
itk::GenericConjugateGradientOptimizer::m_CurrentGradient
DerivativeType m_CurrentGradient
Definition itkGenericConjugateGradientOptimizer.h:147
itk::GenericConjugateGradientOptimizer::m_ValueTolerance
double m_ValueTolerance
Definition itkGenericConjugateGradientOptimizer.h:258
itk::GenericConjugateGradientOptimizer::LineSearchOptimizerPointer
LineSearchOptimizerType::Pointer LineSearchOptimizerPointer
Definition itkGenericConjugateGradientOptimizer.h:61
itk::GenericConjugateGradientOptimizer::BetaDefinitionMapType
std::map< BetaDefinitionType, ComputeBetaFunctionType > BetaDefinitionMapType
Definition itkGenericConjugateGradientOptimizer.h:69
itk::GenericConjugateGradientOptimizer::m_BetaDefinitionMap
BetaDefinitionMapType m_BetaDefinitionMap
Definition itkGenericConjugateGradientOptimizer.h:173
itk::GenericConjugateGradientOptimizer::ComputeBetaHS
double ComputeBetaHS(const DerivativeType &previousGradient, const DerivativeType &gradient, const ParametersType &previousSearchDir)
itk::GenericConjugateGradientOptimizer::m_Stop
bool m_Stop
Definition itkGenericConjugateGradientOptimizer.h:151
itk::GenericConjugateGradientOptimizer::StopConditionType
StopConditionType
Definition itkGenericConjugateGradientOptimizer.h:72
itk::GenericConjugateGradientOptimizer::StopConditionType::GradientMagnitudeTolerance
@ GradientMagnitudeTolerance
Definition itkGenericConjugateGradientOptimizer.h:76
itk::GenericConjugateGradientOptimizer::StopConditionType::MetricError
@ MetricError
Definition itkGenericConjugateGradientOptimizer.h:73
itk::GenericConjugateGradientOptimizer::StopConditionType::ValueTolerance
@ ValueTolerance
Definition itkGenericConjugateGradientOptimizer.h:77
itk::GenericConjugateGradientOptimizer::StopConditionType::InfiniteBeta
@ InfiniteBeta
Definition itkGenericConjugateGradientOptimizer.h:78
itk::GenericConjugateGradientOptimizer::StopConditionType::Unknown
@ Unknown
Definition itkGenericConjugateGradientOptimizer.h:79
itk::GenericConjugateGradientOptimizer::StopConditionType::LineSearchError
@ LineSearchError
Definition itkGenericConjugateGradientOptimizer.h:74
itk::GenericConjugateGradientOptimizer::StopConditionType::MaximumNumberOfIterations
@ MaximumNumberOfIterations
Definition itkGenericConjugateGradientOptimizer.h:75
itk::GenericConjugateGradientOptimizer::StartOptimization
void StartOptimization() override
itk::GenericConjugateGradientOptimizer::StopOptimization
virtual void StopOptimization()
itk::GenericConjugateGradientOptimizer::m_CurrentIteration
unsigned long m_CurrentIteration
Definition itkGenericConjugateGradientOptimizer.h:149
itk::GenericConjugateGradientOptimizer::GenericConjugateGradientOptimizer
GenericConjugateGradientOptimizer()
itk::GenericConjugateGradientOptimizer::m_InLineSearch
bool m_InLineSearch
Definition itkGenericConjugateGradientOptimizer.h:159
itk::GenericConjugateGradientOptimizer::SetBetaDefinition
void SetBetaDefinition(const BetaDefinitionType &arg)
itk::GenericConjugateGradientOptimizer::Self
GenericConjugateGradientOptimizer Self
Definition itkGenericConjugateGradientOptimizer.h:45
itk::GenericConjugateGradientOptimizer::m_LineSearchOptimizer
LineSearchOptimizerPointer m_LineSearchOptimizer
Definition itkGenericConjugateGradientOptimizer.h:262
itk::GenericConjugateGradientOptimizer::ComputeSearchDirection
virtual void ComputeSearchDirection(const DerivativeType &previousGradient, const DerivativeType &gradient, ParametersType &searchDir)
itk::GenericConjugateGradientOptimizer::ComputeBetaSD
double ComputeBetaSD(const DerivativeType &previousGradient, const DerivativeType &gradient, const ParametersType &previousSearchDir)
itk::GenericConjugateGradientOptimizer::m_PreviousGradientAndSearchDirValid
bool m_PreviousGradientAndSearchDirValid
Definition itkGenericConjugateGradientOptimizer.h:166
itk::GenericConjugateGradientOptimizer::LineSearch
virtual void LineSearch(const ParametersType searchDir, double &step, ParametersType &x, MeasureType &f, DerivativeType &g)
itk::GenericConjugateGradientOptimizer::ComputeBetaFR
double ComputeBetaFR(const DerivativeType &previousGradient, const DerivativeType &gradient, const ParametersType &previousSearchDir)
itk::GenericConjugateGradientOptimizer::ConstPointer
SmartPointer< const Self > ConstPointer
Definition itkGenericConjugateGradientOptimizer.h:48
itk::GenericConjugateGradientOptimizer::m_CurrentValue
MeasureType m_CurrentValue
Definition itkGenericConjugateGradientOptimizer.h:148
itk::GenericConjugateGradientOptimizer::m_MaxNrOfItWithoutImprovement
unsigned long m_MaxNrOfItWithoutImprovement
Definition itkGenericConjugateGradientOptimizer.h:260
itk::GenericConjugateGradientOptimizer::ResumeOptimization
virtual void ResumeOptimization()
itk::GenericConjugateGradientOptimizer::ComputeBeta
virtual double ComputeBeta(const DerivativeType &previousGradient, const DerivativeType &gradient, const ParametersType &previousSearchDir)
itk::GenericConjugateGradientOptimizer::LineSearchOptimizerType
LineSearchOptimizer LineSearchOptimizerType
Definition itkGenericConjugateGradientOptimizer.h:60
itk::GenericConjugateGradientOptimizer::m_MaximumNumberOfIterations
unsigned long m_MaximumNumberOfIterations
Definition itkGenericConjugateGradientOptimizer.h:257
itk::GenericConjugateGradientOptimizer::ComputeBetaFunctionType
double(Self::*)(const DerivativeType &, const DerivativeType &, const ParametersType &) ComputeBetaFunctionType
Definition itkGenericConjugateGradientOptimizer.h:65
itk::GenericConjugateGradientOptimizer::AddBetaDefinition
void AddBetaDefinition(const BetaDefinitionType &name, ComputeBetaFunctionType function)
itk::GenericConjugateGradientOptimizer::ComputeBetaDY
double ComputeBetaDY(const DerivativeType &previousGradient, const DerivativeType &gradient, const ParametersType &previousSearchDir)
itk::GenericConjugateGradientOptimizer::ComputeBetaDYHS
double ComputeBetaDYHS(const DerivativeType &previousGradient, const DerivativeType &gradient, const ParametersType &previousSearchDir)
itk::GenericConjugateGradientOptimizer::itkGetModifiableObjectMacro
itkGetModifiableObjectMacro(LineSearchOptimizer, LineSearchOptimizerType)
itk::LineSearchOptimizer
A base class for LineSearch optimizers.
Definition itkLineSearchOptimizer.h:38
itk::LineSearchOptimizer::Pointer
SmartPointer< Self > Pointer
Definition itkLineSearchOptimizer.h:44
itk::ScaledSingleValuedNonLinearOptimizer::ScaledSingleValuedNonLinearOptimizer
ScaledSingleValuedNonLinearOptimizer()
itk::ScaledSingleValuedNonLinearOptimizer::ScalesType
NonLinearOptimizer::ScalesType ScalesType
Definition itkScaledSingleValuedNonLinearOptimizer.h:85
itk::ScaledSingleValuedNonLinearOptimizer::ScaledCostFunctionType
ScaledSingleValuedCostFunction ScaledCostFunctionType
Definition itkScaledSingleValuedNonLinearOptimizer.h:86
itkLineSearchOptimizer.h
itkScaledSingleValuedNonLinearOptimizer.h
itk
Definition itkAdvancedImageToImageMetric.h:43

Generated on 1768596610 for elastix by 1.15.0 |