22 m_ValueTolerance(1e-5), m_Iterations(1000), m_DerivativeStepLength(1e-5),
23 m_ActivateFailureThreshold(true)
35 names.push_back(
"sum_diff^2");
46 metric->SetModel(model);
47 metric->SetSample(sample);
50 result[0] = metric->GetValue(parameters);
60 metric->SetModel(model);
61 metric->SetSample(value);
62 metric->SetDerivativeStepLength(m_DerivativeStepLength);
66 if (m_ConstraintChecker.IsNotNull())
70 decorator->SetConstraintChecker(m_ConstraintChecker);
71 decorator->SetWrappedCostFunction(metric);
72 decorator->SetFailureThreshold(m_ConstraintChecker->GetFailedConstraintValue());
74 decorator->SetModel(model);
75 decorator->SetSample(value);
76 decorator->SetActivateFailureThreshold(m_ActivateFailureThreshold);
87 result.push_back(
"optimization_time");
88 result.push_back(
"nr_of_iterations");
89 result.push_back(
"stop_condition");
90 if (m_ConstraintChecker.IsNotNull())
92 result.push_back(
"constraint_penalty_ratio");
93 result.push_back(
"constraint_failure_ratio");
94 result.push_back(
"constraint_last_failed_parameter");
105 std::chrono::time_point<std::chrono::system_clock> startTime;
106 startTime = std::chrono::system_clock::now();
107 ::itk::LevenbergMarquardtOptimizer::ParametersType internalInitParam = initialParameters;
108 ::itk::LevenbergMarquardtOptimizer::ScalesType scales = m_Scales;
113 "Size of initial parameters of fit functor optimizer do not match number of model parameters. Renitialize parameters with 0.0.";
115 internalInitParam.Fill(0.0);
121 "Size of scales of fit functor optimizer do not match number of model parameters. Reinitialize scales with 1.0.";
128 ::itk::LevenbergMarquardtOptimizer::Pointer optimizer = ::itk::LevenbergMarquardtOptimizer::New();
130 optimizer->SetCostFunction(metric);
131 optimizer->SetEpsilonFunction(m_Epsilon);
132 optimizer->SetGradientTolerance(m_GradientTolerance);
133 optimizer->SetNumberOfIterations(m_Iterations);
134 optimizer->SetScales(scales);
135 optimizer->SetInitialPosition(internalInitParam);
137 optimizer->StartOptimization();
139 itk::Optimizer::ParametersType position = optimizer->GetCurrentPosition();
141 std::chrono::time_point<std::chrono::system_clock> stopTime;
142 stopTime = std::chrono::system_clock::now();
143 debugParameters.clear();
146 const auto timeDiff = std::chrono::duration_cast<std::chrono::milliseconds>(stopTime - startTime).count();
147 debugParameters.insert(std::make_pair(
"optimization_time", timeDiff));
150 debugParameters.insert(std::make_pair(
"nr_of_iterations", value));
151 value = optimizer->GetOptimizer()->get_failure_code();
152 debugParameters.insert(std::make_pair(
"stop_condition", value));
159 debugParameters.insert(std::make_pair(
"constraint_penalty_ratio", value));
160 value = decorator->GetFailureRatio();
161 debugParameters.insert(std::make_pair(
"constraint_failure_ratio", value));
162 value = decorator->GetFailedParameter();
163 debugParameters.insert(std::make_pair(
"constraint_last_failed_parameter", value));
167 if (m_ConstraintChecker.IsNotNull())
169 mitkThrow() <<
"Fit functor has invalid state/wrong implementation. Constraint checker is set, but used metric seems to be no MVContstrainedCostFunctionDecorator.";
double GetPenaltyRatio() const
virtual MVModelFitCostFunction::Pointer GenerateCostFunction(const SignalType &value, const ModelBase *model) const
Base class for (dynamic) models. A model can be used to calculate its signal given the discrete time ...
ModelTraitsInterface::ParametersType ParametersType
Superclass::ParametersType ParametersType
std::map< std::string, ParameterImagePixelType > DebugParameterMapType
ModelBase::ParameterNamesType ParameterNamesType
virtual bool GetDebugParameterMaps() const
virtual ParametersSizeType GetNumberOfParameters() const =0
Superclass::SignalType SignalType
This class is used to add constraints to any multi valued model fit cost function.
Superclass::OutputPixelArrayType OutputPixelArrayType
ParameterNamesType DefineDebugParameterNames() const override
ParametersType DoModelFit(const SignalType &value, const ModelBase *model, const ModelBase::ParametersType &initialParameters, DebugParameterMapType &debugParameters) const override
ParameterNamesType GetCriterionNames() const override
OutputPixelArrayType GetCriteria(const ModelBase *model, const ParametersType ¶meters, const SignalType &sample) const override
ScalarType ParameterImagePixelType
~LevenbergMarquardtModelFitFunctor() override
LevenbergMarquardtModelFitFunctor()