Loading...
Searching...
No Matches
itkStochasticGradientDescentOptimizer.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 itkStochasticGradientDescentOptimizer_h
#define itkStochasticGradientDescentOptimizer_h
#include "itkScaledSingleValuedNonLinearOptimizer.h"
#include "itkMultiThreaderBase.h"
namespace itk
{
class StochasticGradientDescentOptimizer : public ScaledSingleValuedNonLinearOptimizer
{
public:
ITK_DISALLOW_COPY_AND_MOVE(StochasticGradientDescentOptimizer);
using Self = StochasticGradientDescentOptimizer;
using Superclass = ScaledSingleValuedNonLinearOptimizer;
using Pointer = SmartPointer<Self>;
using ConstPointer = SmartPointer<const Self>;
itkNewMacro(Self);
itkTypeMacro(StochasticGradientDescentOptimizer, ScaledSingleValuedNonLinearOptimizer);
using Superclass::MeasureType;
using Superclass::ParametersType;
using Superclass::DerivativeType;
using Superclass::CostFunctionType;
using Superclass::ScalesType;
using Superclass::ScaledCostFunctionType;
using Superclass::ScaledCostFunctionPointer;
enum StopConditionType
{
MaximumNumberOfIterations,
MetricError,
MinimumStepSize,
InvalidDiagonalMatrix,
GradientMagnitudeTolerance,
LineSearchError,
};
virtual void
AdvanceOneStep();
void
StartOptimization() override;
virtual void
ResumeOptimization();
virtual void
MetricErrorResponse(ExceptionObject & err);
virtual void
StopOptimization();
itkSetMacro(LearningRate, double);
itkGetConstReferenceMacro(LearningRate, double);
itkSetMacro(NumberOfIterations, unsigned long);
itkGetConstMacro(LBFGSMemory, unsigned int);
itkGetConstReferenceMacro(NumberOfIterations, unsigned long);
itkGetConstReferenceMacro(NumberOfInnerIterations, unsigned long);
itkGetConstMacro(CurrentIteration, unsigned int);
itkGetConstMacro(CurrentInnerIteration, unsigned int);
itkGetConstReferenceMacro(Value, double);
itkGetConstReferenceMacro(StopCondition, StopConditionType);
itkGetConstReferenceMacro(Gradient, DerivativeType);
itkGetConstReferenceMacro(SearchDir, DerivativeType);
itkSetMacro(PreviousPosition, ParametersType);
itkGetConstReferenceMacro(PreviousPosition, ParametersType);
itkSetMacro(PreviousGradient, DerivativeType);
itkGetConstReferenceMacro(PreviousGradient, DerivativeType);
void
SetNumberOfWorkUnits(ThreadIdType numberOfThreads)
{
this->m_Threader->SetNumberOfWorkUnits(numberOfThreads);
}
// itkGetConstReferenceMacro( NumberOfThreads, ThreadIdType );
itkSetMacro(UseMultiThread, bool);
itkSetMacro(UseEigen, bool);
protected:
StochasticGradientDescentOptimizer();
~StochasticGradientDescentOptimizer() override = default;
void
PrintSelf(std::ostream & os, Indent indent) const override;
using ThreadInfoType = MultiThreaderBase::WorkUnitInfo;
// made protected so subclass can access
double m_Value{ 0.0 };
DerivativeType m_Gradient{};
ParametersType m_SearchDir{};
ParametersType m_PreviousSearchDir{};
ParametersType m_PrePreviousSearchDir{};
ParametersType m_MeanSearchDir{};
double m_LearningRate{ 1.0 };
StopConditionType m_StopCondition{ MaximumNumberOfIterations };
DerivativeType m_PreviousGradient{};
DerivativeType m_PrePreviousGradient{};
ParametersType m_PreviousPosition{};
MultiThreaderBase::Pointer m_Threader{ MultiThreaderBase::New() };
bool m_Stop{ false };
unsigned long m_NumberOfIterations{ 100 };
unsigned long m_NumberOfInnerIterations{};
unsigned long m_CurrentIteration{ 0 };
unsigned long m_CurrentInnerIteration{};
unsigned long m_LBFGSMemory{ 0 };
private:
// multi-threaded AdvanceOneStep:
bool m_UseMultiThread{ false };
struct MultiThreaderParameterType
{
ParametersType * t_NewPosition;
Self * t_Optimizer;
};
bool m_UseEigen{ false };
static ITK_THREAD_RETURN_FUNCTION_CALL_CONVENTION
AdvanceOneStepThreaderCallback(void * arg);
inline void
ThreadedAdvanceOneStep(ThreadIdType threadId, ParametersType & newPosition);
};
} // end namespace itk
#endif
itk::ScaledSingleValuedNonLinearOptimizer::ScaledSingleValuedNonLinearOptimizer
ScaledSingleValuedNonLinearOptimizer()
itk::ScaledSingleValuedNonLinearOptimizer::ScaledCostFunctionPointer
ScaledCostFunctionType::Pointer ScaledCostFunctionPointer
Definition itkScaledSingleValuedNonLinearOptimizer.h:87
itk::ScaledSingleValuedNonLinearOptimizer::ScalesType
NonLinearOptimizer::ScalesType ScalesType
Definition itkScaledSingleValuedNonLinearOptimizer.h:85
itk::ScaledSingleValuedNonLinearOptimizer::ScaledCostFunctionType
ScaledSingleValuedCostFunction ScaledCostFunctionType
Definition itkScaledSingleValuedNonLinearOptimizer.h:86
itk::StochasticGradientDescentOptimizer::ConstPointer
SmartPointer< const Self > ConstPointer
Definition itkStochasticGradientDescentOptimizer.h:62
itk::StochasticGradientDescentOptimizer::m_PreviousSearchDir
ParametersType m_PreviousSearchDir
Definition itkStochasticGradientDescentOptimizer.h:185
itk::StochasticGradientDescentOptimizer::AdvanceOneStepThreaderCallback
static ITK_THREAD_RETURN_FUNCTION_CALL_CONVENTION AdvanceOneStepThreaderCallback(void *arg)
itk::StochasticGradientDescentOptimizer::StopConditionType
StopConditionType
Definition itkStochasticGradientDescentOptimizer.h:83
itk::StochasticGradientDescentOptimizer::MaximumNumberOfIterations
@ MaximumNumberOfIterations
Definition itkStochasticGradientDescentOptimizer.h:84
itk::StochasticGradientDescentOptimizer::MetricError
@ MetricError
Definition itkStochasticGradientDescentOptimizer.h:85
itk::StochasticGradientDescentOptimizer::MinimumStepSize
@ MinimumStepSize
Definition itkStochasticGradientDescentOptimizer.h:86
itk::StochasticGradientDescentOptimizer::LineSearchError
@ LineSearchError
Definition itkStochasticGradientDescentOptimizer.h:89
itk::StochasticGradientDescentOptimizer::GradientMagnitudeTolerance
@ GradientMagnitudeTolerance
Definition itkStochasticGradientDescentOptimizer.h:88
itk::StochasticGradientDescentOptimizer::InvalidDiagonalMatrix
@ InvalidDiagonalMatrix
Definition itkStochasticGradientDescentOptimizer.h:87
itk::StochasticGradientDescentOptimizer::ResumeOptimization
virtual void ResumeOptimization()
itk::StochasticGradientDescentOptimizer::m_SearchDir
ParametersType m_SearchDir
Definition itkStochasticGradientDescentOptimizer.h:184
itk::StochasticGradientDescentOptimizer::Self
StochasticGradientDescentOptimizer Self
Definition itkStochasticGradientDescentOptimizer.h:59
itk::StochasticGradientDescentOptimizer::StochasticGradientDescentOptimizer
StochasticGradientDescentOptimizer()
itk::StochasticGradientDescentOptimizer::Pointer
SmartPointer< Self > Pointer
Definition itkStochasticGradientDescentOptimizer.h:61
itk::StochasticGradientDescentOptimizer::PrintSelf
void PrintSelf(std::ostream &os, Indent indent) const override
itk::StochasticGradientDescentOptimizer::MetricErrorResponse
virtual void MetricErrorResponse(ExceptionObject &err)
itk::StochasticGradientDescentOptimizer::AdvanceOneStep
virtual void AdvanceOneStep()
itk::StochasticGradientDescentOptimizer::m_PreviousGradient
DerivativeType m_PreviousGradient
Definition itkStochasticGradientDescentOptimizer.h:190
itk::StochasticGradientDescentOptimizer::m_Stop
bool m_Stop
Definition itkStochasticGradientDescentOptimizer.h:195
itk::StochasticGradientDescentOptimizer::m_StopCondition
StopConditionType m_StopCondition
Definition itkStochasticGradientDescentOptimizer.h:189
itk::StochasticGradientDescentOptimizer::m_MeanSearchDir
ParametersType m_MeanSearchDir
Definition itkStochasticGradientDescentOptimizer.h:187
itk::StochasticGradientDescentOptimizer::StopOptimization
virtual void StopOptimization()
itk::StochasticGradientDescentOptimizer::m_LBFGSMemory
unsigned long m_LBFGSMemory
Definition itkStochasticGradientDescentOptimizer.h:200
itk::StochasticGradientDescentOptimizer::Superclass
ScaledSingleValuedNonLinearOptimizer Superclass
Definition itkStochasticGradientDescentOptimizer.h:60
itk::StochasticGradientDescentOptimizer::StartOptimization
void StartOptimization() override
itk::StochasticGradientDescentOptimizer::m_CurrentIteration
unsigned long m_CurrentIteration
Definition itkStochasticGradientDescentOptimizer.h:198
itk::StochasticGradientDescentOptimizer::SetNumberOfWorkUnits
void SetNumberOfWorkUnits(ThreadIdType numberOfThreads)
Definition itkStochasticGradientDescentOptimizer.h:164
itk::StochasticGradientDescentOptimizer::m_PreviousPosition
ParametersType m_PreviousPosition
Definition itkStochasticGradientDescentOptimizer.h:192
itk::StochasticGradientDescentOptimizer::m_UseMultiThread
bool m_UseMultiThread
Definition itkStochasticGradientDescentOptimizer.h:204
itk::StochasticGradientDescentOptimizer::m_PrePreviousGradient
DerivativeType m_PrePreviousGradient
Definition itkStochasticGradientDescentOptimizer.h:191
itk::StochasticGradientDescentOptimizer::m_UseEigen
bool m_UseEigen
Definition itkStochasticGradientDescentOptimizer.h:211
itk::StochasticGradientDescentOptimizer::ThreadInfoType
MultiThreaderBase::WorkUnitInfo ThreadInfoType
Definition itkStochasticGradientDescentOptimizer.h:179
itk::StochasticGradientDescentOptimizer::~StochasticGradientDescentOptimizer
~StochasticGradientDescentOptimizer() override=default
itk::StochasticGradientDescentOptimizer::m_NumberOfInnerIterations
unsigned long m_NumberOfInnerIterations
Definition itkStochasticGradientDescentOptimizer.h:197
itk::StochasticGradientDescentOptimizer::m_LearningRate
double m_LearningRate
Definition itkStochasticGradientDescentOptimizer.h:188
itk::StochasticGradientDescentOptimizer::m_Threader
MultiThreaderBase::Pointer m_Threader
Definition itkStochasticGradientDescentOptimizer.h:193
itk::StochasticGradientDescentOptimizer::m_NumberOfIterations
unsigned long m_NumberOfIterations
Definition itkStochasticGradientDescentOptimizer.h:196
itk::StochasticGradientDescentOptimizer::m_PrePreviousSearchDir
ParametersType m_PrePreviousSearchDir
Definition itkStochasticGradientDescentOptimizer.h:186
itk::StochasticGradientDescentOptimizer::ITK_DISALLOW_COPY_AND_MOVE
ITK_DISALLOW_COPY_AND_MOVE(StochasticGradientDescentOptimizer)
itk::StochasticGradientDescentOptimizer::ThreadedAdvanceOneStep
void ThreadedAdvanceOneStep(ThreadIdType threadId, ParametersType &newPosition)
itk::StochasticGradientDescentOptimizer::m_Value
double m_Value
Definition itkStochasticGradientDescentOptimizer.h:182
itk::StochasticGradientDescentOptimizer::m_CurrentInnerIteration
unsigned long m_CurrentInnerIteration
Definition itkStochasticGradientDescentOptimizer.h:199
itk::StochasticGradientDescentOptimizer::m_Gradient
DerivativeType m_Gradient
Definition itkStochasticGradientDescentOptimizer.h:183
itkScaledSingleValuedNonLinearOptimizer.h
itk
Definition itkAdvancedImageToImageMetric.h:43
itk::StochasticGradientDescentOptimizer::MultiThreaderParameterType
Definition itkStochasticGradientDescentOptimizer.h:206
itk::StochasticGradientDescentOptimizer::MultiThreaderParameterType::t_Optimizer
Self * t_Optimizer
Definition itkStochasticGradientDescentOptimizer.h:208
itk::StochasticGradientDescentOptimizer::MultiThreaderParameterType::t_NewPosition
ParametersType * t_NewPosition
Definition itkStochasticGradientDescentOptimizer.h:207

Generated on 1768596610 for elastix by 1.15.0 |