Mantid
Loading...
Searching...
No Matches
FABADAMinimizer.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2014 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7#pragma once
8
13#include "MantidKernel/System.h"
14
15namespace Mantid {
16namespace CurveFitting {
17namespace CostFunctions {
19class CostFuncLeastSquares;
20} // namespace CostFunctions
21} // namespace CurveFitting
22} // namespace Mantid
23
24namespace Mantid {
25namespace CurveFitting {
26namespace FuncMinimisers {
27
32class MANTID_CURVEFITTING_DLL FABADAMinimizer : public API::IFuncMinimizer {
33public:
37 std::string name() const override { return "FABADA"; }
39 void initialize(API::ICostFunction_sptr function, size_t maxIterations) override;
41 bool iterate(size_t iter) override;
43 double costFunctionVal() override;
45 void finalize() override;
46
48
51 void boundApplication(const size_t &parameterIndex, double &newValue, double &step);
52
53private:
55 double gaussianStep(const double &jump);
58 void tieApplication(const size_t &parameterIndex, EigenVector &newParameters, double &newValue);
61 void algorithmDisplacement(const size_t &parameterIndex, const double &chi2New, const EigenVector &newParameters);
63 void jumpUpdate(const size_t &parameterIndex);
66 void convergenceCheck();
68 void simAnnealingRefrigeration();
70 bool iterationContinuation();
72 void outputChains();
74 void outputConvergedChains(size_t convLength, int nSteps);
76 void outputCostFunctionTable(size_t convLength, double mostProbableChi2);
78 double outputPDF(std::size_t const &convLength, std::vector<std::vector<double>> &reducedChain);
79 void outputPDF(std::vector<double> &xValues, std::vector<double> &yValues,
80 std::vector<std::vector<double>> &reducedChain, std::size_t const &convLength, int const &pdfLength);
82 double getMostProbableChiSquared(std::size_t const &convLength, std::vector<std::vector<double>> &reducedChain,
83 int const &pdfLength, std::vector<double> &xValues, std::vector<double> &yValues,
84 std::vector<double> &PDFYAxis, double const &start, double const &bin);
86 void setParameterXAndYValuesForPDF(std::vector<double> &xValues, std::vector<double> &yValues,
87 std::vector<std::vector<double>> &reducedChain, std::size_t const &convLength,
88 int const &pdfLength);
90 void outputParameterTable(const std::vector<double> &bestParameters, const std::vector<double> &errorsLeft,
91 const std::vector<double> &errorsRight);
93 void calculateConvChainAndBestParameters(size_t convLength, int nSteps,
94 std::vector<std::vector<double>> &reducedChain,
95 std::vector<double> &bestParameters, std::vector<double> &errorLeft,
96 std::vector<double> &errorRight);
98 void initChainsAndParameters();
100 void initSimulatedAnnealing();
101
102 // Variables declarations
104 // Intentar encontrar una manera de sacar aqui el numero de parametros que
105 // no sea necesaria la cost function
106 std::shared_ptr<CostFunctions::CostFuncLeastSquares> m_leastSquares;
110 size_t m_counter;
114 std::vector<int> m_changes;
116 std::vector<double> m_jump;
120 std::vector<std::vector<double>> m_chain;
122 double m_chi2;
128 std::vector<bool> m_parConverged;
130 std::vector<double> m_criteria;
132 size_t m_maxIter;
134 std::vector<bool> m_parChanged;
149 size_t m_nParams;
151 std::vector<size_t> m_numInactiveRegenerations;
153 std::vector<int> m_changesOld;
154};
155
158public:
161};
162
163} // namespace FuncMinimisers
164} // namespace CurveFitting
165} // namespace Mantid
An interface for function minimizers.
A wrapper around Eigen::Vector.
Definition: EigenVector.h:27
FABADA : Implements the FABADA Algorithm, based on a Adaptive Metropolis Algorithm extended with Gibb...
size_t m_nParams
Number of parameters of the FittingFunction (not necessarily the CostFunction)
size_t m_counter
The number of iterations done (restarted at each phase).
std::shared_ptr< CostFunctions::CostFuncLeastSquares > m_leastSquares
Pointer to the cost function. Must be the least squares.
std::vector< int > m_changes
The number of changes done on each parameter.
double m_tempStep
Temperature step between different Simulated Annealing phases.
std::vector< double > m_jump
The jump for each parameter.
size_t m_maxIter
Maximum number of iterations.
double m_temperature
Simulated Annealing temperature.
double m_chi2
The chi square result of previous iteration;.
size_t m_counterGlobal
The global number of iterations done.
std::string name() const override
Name of the minimizer.
std::vector< double > m_criteria
Convergence criteria for each parameter.
std::vector< size_t > m_numInactiveRegenerations
Number of consecutive regenerations without changes.
size_t m_simAnnealingItStep
Number of iterations between Simulated Annealing refrigeration points.
std::vector< std::vector< double > > m_chain
Markov chain.
size_t m_convPoint
The point when convergence has been reached.
std::vector< bool > m_parChanged
Bool that idicates if a varible has changed at some self iteration.
std::vector< bool > m_parConverged
Convergence of each parameter.
std::vector< int > m_changesOld
To track convergence through immobility.
size_t m_leftRefrPoints
The number of refrigeration points left.
size_t m_chainIterations
The number of chain iterations.
API::IFunction_sptr m_fitFunction
Pointer to the Fitting Function (IFunction) inside the cost function.
bool m_converged
Boolean that indicates global convergence.
Used to access the setDirty() protected member.
void setDirtyInherited()
To inform the main class of changes through the IFunction.
std::shared_ptr< IFunction > IFunction_sptr
shared pointer to the function base class
Definition: IFunction.h:732
std::shared_ptr< ICostFunction > ICostFunction_sptr
define a shared pointer to a cost function
Definition: ICostFunction.h:60
Helper class which provides the Collimation Length for SANS instruments.