SuPReMo  0.1.1
Loading...
Searching...
No Matches
Optimiser.h
1// ====================================================================================================
2//
3// SuPReMo: Surrogate Parameterised Respiratory Motion Model
4// An implementation of the generalised motion modelling and image registration framework
5//
6// Copyright (c) University College London (UCL). All rights reserved.
7//
8// This software is distributed WITHOUT ANY WARRANTY; without even
9// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
10// PURPOSE.
11//
12// See LICENSE.txt in the top level directory for details.
13//
14// ====================================================================================================
15
16
17
18
19#pragma once
20
21#include <memory>
22#include <iostream>
23
24// forward declarations
26
27
31{
32public:
33 typedef float PrecisionType;
34
37 Optimiser();
38
41 virtual ~Optimiser();
42
46 void SetObjectiveFunction( std::shared_ptr<ObjectiveFunction>& objectiveFunctionIn );
47
51 virtual void Optimise( PrecisionType* startingPoint ) = 0;
52
55 virtual void Initialise() = 0;
56
60
64
68
72
76 inline void SetMaxIterations( unsigned int maxIterations )
77 {
78 this->maxNumberOfIterations = maxIterations;
79 }
80
86
87
88 void SetOutputIntermediateGradientFolder( const std::string & outputFolderIn, const std::string & outPrefix )
89 {
90 this->outputIntermediateGradientFolder = outputFolderIn;
91 this->outputIntermediateGradientPrefix = outPrefix;
92 }
93
94
95protected:
96
100 void inline MoveCurrentPointAlongGradient( PrecisionType stepSize );
101
110 void PerformLineSearch( PrecisionType maxLength, PrecisionType smallLength, PrecisionType& startLength );
111
117 const unsigned int maxNumberOfLineIterations;
121 unsigned int numberOfDOFs;
122 std::shared_ptr<ObjectiveFunction> objectiveFunction;
130};
Definition: ObjectiveFunction.h:43
Definition: Optimiser.h:31
std::shared_ptr< ObjectiveFunction > objectiveFunction
Shared pointer to the objective function.
Definition: Optimiser.h:122
PrecisionType * GetBestPoint()
Definition: Optimiser.cpp:105
std::string outputIntermediateGradientFolder
Folder to which the intermediated objective function gradients will be saved.
Definition: Optimiser.h:128
const unsigned int maxNumberOfLineIterations
The maximum number of iterations used for the line-serach along the gradient.
Definition: Optimiser.h:117
void MoveCurrentPointAlongGradient(PrecisionType stepSize)
Definition: Optimiser.cpp:140
unsigned int numberOfDOFs
The number of degrees of freedom.
Definition: Optimiser.h:121
PrecisionType * currentPoint
The current point, p in numerical recipes.
Definition: Optimiser.h:124
float PrecisionType
Definition: Optimiser.h:33
unsigned int currentIterationNumber
Tracker of the current iteration number.
Definition: Optimiser.h:115
PrecisionType currentObjectiveFunctionValue
The current objective function value corresponding to the current iteration.
Definition: Optimiser.h:112
PrecisionType * gradient
The array xi in numerical recipes.
Definition: Optimiser.h:123
PrecisionType * bestPoint
The best point achieved, p in numerical recipes.
Definition: Optimiser.h:125
PrecisionType bestObjectiveFunctionValue
The best objective function value achieved.
Definition: Optimiser.h:113
unsigned int maxNumberOfIterations
The maximum number of allowed iterations.
Definition: Optimiser.h:116
PrecisionType GetBestObjectiveFunctionValue()
Definition: Optimiser.cpp:83
PrecisionType maxLineSearchStepSize
The maximum step size used for the line-search. Has to be initialised in derived class.
Definition: Optimiser.h:118
void SetObjectiveFunction(std::shared_ptr< ObjectiveFunction > &objectiveFunctionIn)
Definition: Optimiser.cpp:72
PrecisionType initialObjectiveFunctionValue
The objective function value at the starting point of the optimisation.
Definition: Optimiser.h:114
bool usePreEvaluatedEvaluatedObjectiveFunctionValue
Indicator if the first objective function value calculation can be skipped.
Definition: Optimiser.h:127
PrecisionType minLineSearchStepSize
The minimum step size used for the line-search. Has to be initialised in derived class.
Definition: Optimiser.h:119
void SetOutputIntermediateGradientFolder(const std::string &outputFolderIn, const std::string &outPrefix)
Definition: Optimiser.h:88
virtual ~Optimiser()
Definition: Optimiser.cpp:59
void SetPreviouslyEvaluatedObjectiveFunctionValue(PrecisionType objectiveFunctionValue)
Definition: Optimiser.cpp:128
unsigned int numberOfIterationsPerformed
The total number of iterations performed.
Definition: Optimiser.h:120
void SetMaxIterations(unsigned int maxIterations)
Definition: Optimiser.h:76
virtual void Initialise()=0
virtual void Optimise(PrecisionType *startingPoint)=0
void PerformLineSearch(PrecisionType maxLength, PrecisionType smallLength, PrecisionType &startLength)
Definition: Optimiser.cpp:157
PrecisionType preEvaluatedObjectiveFunctionValue
A pre-calculated objective function value that will be used during the optimisation if usePreEvaluate...
Definition: Optimiser.h:126
PrecisionType GetInitialObjectiveFunctionValue()
Definition: Optimiser.cpp:95
void ResetCurrentIterationNumber()
Definition: Optimiser.cpp:116
std::string outputIntermediateGradientPrefix
String holding additional information to differentiate the output from different levels.
Definition: Optimiser.h:129
Optimiser()
Definition: Optimiser.cpp:32