24#ifndef HYBRIDSIMULATEDANNEALINGFUNCTORS_H
25#define HYBRIDSIMULATEDANNEALINGFUNCTORS_H
27#include <ql/math/array.hpp>
28#include <ql/math/randomnumbers/seedgenerator.hpp>
29#include <ql/math/optimization/problem.hpp>
50 QL_REQUIRE(newPoint.
size() == currentPoint.
size(),
"Incompatible input");
51 QL_REQUIRE(newPoint.
size() == temp.
size(),
"Incompatible input");
52 for (
Size i = 0; i < currentPoint.
size(); i++)
71 QL_REQUIRE(newPoint.
size() == currentPoint.
size(),
"Incompatible input");
72 QL_REQUIRE(newPoint.
size() == temp.
size(),
"Incompatible input");
73 for (
Size i = 0; i < currentPoint.
size(); i++)
96 QL_REQUIRE(newPoint.
size() == currentPoint.
size(),
"Incompatible input");
97 QL_REQUIRE(newPoint.
size() == temp.
size(),
"Incompatible input");
98 for (
Size i = 0; i < currentPoint.
size(); i++){
100 while(newPoint[i] <
lower_[i] || newPoint[i] >
upper_[i]){
101 if(newPoint[i] <
lower_[i]){
130 QL_REQUIRE(newPoint.
size() == currentPoint.
size(),
"Incompatible input");
131 QL_REQUIRE(newPoint.
size() == temp.
size(),
"Incompatible input");
132 for (
Size i = 0; i < currentPoint.
size(); i++){
134 while(newPoint[i] <
lower_[i] || newPoint[i] >
upper_[i]){
135 if(newPoint[i] <
lower_[i]){
162 QL_REQUIRE(newPoint.
size() == currentPoint.
size(),
"Incompatible input");
163 QL_REQUIRE(newPoint.
size() == temp.
size(),
"Incompatible input");
164 for (
Size i = 0; i < currentPoint.
size(); i++)
187 QL_REQUIRE(newPoint.
size() == currentPoint.
size(),
"Incompatible input");
188 QL_REQUIRE(newPoint.
size() ==
lower_.
size(),
"Incompatible input");
189 QL_REQUIRE(newPoint.
size() == temp.
size(),
"Incompatible input");
190 for (
Size i = 0; i < currentPoint.
size(); i++) {
191 newPoint[i] =
lower_[i] - 1.0;
192 while (newPoint[i] <
lower_[i] || newPoint[i] >
upper_[i]) {
194 Real sign =
static_cast<int>(0.5 < draw) -
static_cast<int>(draw < 0.5);
195 Real y = sign*temp[i] * (std::pow(1.0 + 1.0 / temp[i],
196 std::abs(2 * draw - 1.0)) - 1.0);
197 newPoint[i] = currentPoint[i] + y*(
upper_[i] -
lower_[i]);
214 return currentValue > newValue;
228 Real temperature = *std::max_element(temp.
begin(), temp.
end());
245 if (newValue < currentValue)
247 Real mTemperature = *std::max_element(temp.
begin(), temp.
end());
263 QL_REQUIRE(currTemp.
size() == newTemp.
size(),
"Incompatible input");
279 QL_REQUIRE(currTemp.
size() == newTemp.
size(),
"Incompatible input");
294 QL_REQUIRE(currTemp.
size() == newTemp.
size(),
"Incompatible input");
309 QL_REQUIRE(currTemp.
size() == newTemp.
size(),
"Incompatible input");
331 QL_REQUIRE(currTemp.
size() == newTemp.
size(),
"Incompatible input");
347 Real aCurrentValue,
const Array & currTemp) {};
363 Real stepSize = 1e-7,
364 Real minSize = 1e-10,
365 Real functionTol = 1e-10)
370 QL_REQUIRE(lower.
size() ==
N_,
"Incompatible input");
371 QL_REQUIRE(upper.
size() ==
N_,
"Incompatible input");
373 for (
Size i = 0; i <
N_; i++) {
380 Real currentValue,
const Array & currTemp) {
381 QL_REQUIRE(currTemp.
size() ==
N_,
"Incompatible input");
382 QL_REQUIRE(steps.
size() ==
N_,
"Incompatible input");
385 Real finiteDiffMax = 0.0;
386 Array ofssetPoint(currentPoint);
387 for (
Size i = 0; i <
N_; i++) {
393 if (finiteDiffs[i] > finiteDiffMax)
394 finiteDiffMax = finiteDiffs[i];
396 for (
Size i = 0; i <
N_; i++) {
398 Real sRatio = finiteDiffMax / finiteDiffs[i];
403 steps[i] = std::pow(std::fabs(std::log(sRatio*tRatio)),
1-D array used in linear algebra.
bool empty() const
whether the array is empty
const_iterator end() const
Size size() const
dimension of the array
const_iterator begin() const
Boltzmann Downhill Probability.
std::uniform_real_distribution< Real > distribution_
bool operator()(Real currentValue, Real newValue, const Array &temp)
ProbabilityBoltzmannDownhill(unsigned long seed=SeedGenerator::instance().get())
std::uniform_real_distribution< Real > distribution_
bool operator()(Real currentValue, Real newValue, const Array &temp)
ProbabilityBoltzmann(unsigned long seed=SeedGenerator::instance().get())
Constrained optimization problem.
Real value(const Array &x)
call cost function computation and increment evaluation counter
Reannealing Finite Difference.
ReannealingFiniteDifferences(Real initialTemp, Size dimension, const Array &lower=Array(), const Array &upper=Array(), Real stepSize=1e-7, Real minSize=1e-10, Real functionTol=1e-10)
void operator()(Array &steps, const Array ¤tPoint, Real currentValue, const Array &currTemp)
void setProblem(Problem &P)
SamplerCauchy(unsigned long seed=SeedGenerator::instance().get())
void operator()(Array &newPoint, const Array ¤tPoint, const Array &temp)
std::cauchy_distribution< Real > distribution_
std::normal_distribution< Real > distribution_
void operator()(Array &newPoint, const Array ¤tPoint, const Array &temp)
SamplerGaussian(unsigned long seed=SeedGenerator::instance().get())
SamplerLogNormal(unsigned long seed=SeedGenerator::instance().get())
std::normal_distribution< Real > distribution_
void operator()(Array &newPoint, const Array ¤tPoint, const Array &temp)
SamplerMirrorGaussian(Array lower, Array upper, unsigned long seed=SeedGenerator::instance().get())
std::normal_distribution< Real > distribution_
void operator()(Array &newPoint, const Array ¤tPoint, const Array &temp)
std::normal_distribution< Real > distribution_
SamplerRingGaussian(Array lower, Array upper, unsigned long seed=SeedGenerator::instance().get())
void operator()(Array &newPoint, const Array ¤tPoint, const Array &temp)
Very Fast Annealing Sampler.
std::uniform_real_distribution< Real > distribution_
SamplerVeryFastAnnealing(Array lower, Array upper, unsigned long seed=SeedGenerator::instance().get())
void operator()(Array &newPoint, const Array ¤tPoint, const Array &temp)
static SeedGenerator & instance()
access to the unique instance
void operator()(Array &newTemp, const Array &currTemp, const Array &steps)
TemperatureBoltzmann(Real initialTemp, Size dimension)
void operator()(Array &newTemp, const Array &currTemp, const Array &steps)
TemperatureCauchy1D(Real initialTemp, Size dimension)
void operator()(Array &newTemp, const Array &currTemp, const Array &steps)
TemperatureCauchy(Real initialTemp, Size dimension)
void operator()(Array &newTemp, const Array &currTemp, const Array &steps)
TemperatureExponential(Real initialTemp, Size dimension, Real power=0.95)
Temperature Very Fast Annealing.
void operator()(Array &newTemp, const Array &currTemp, const Array &steps)
TemperatureVeryFastAnnealing(Real initialTemp, Real finalTemp, Real maxSteps, Size dimension)
QL_INTEGER Integer
integer number
std::size_t Size
size of a container
Always Downhill Probability.
bool operator()(Real currentValue, Real newValue, const Array &temp)
void operator()(Array &steps, const Array ¤tPoint, Real aCurrentValue, const Array &currTemp)
ReannealingTrivial()=default
void setProblem(Problem &P)