sa.hpp
Go to the documentation of this file.
1 
12 #ifndef MLPACK_CORE_OPTIMIZERS_SA_SA_HPP
13 #define MLPACK_CORE_OPTIMIZERS_SA_SA_HPP
14 
15 #include <mlpack/prereqs.hpp>
16 
17 #include "exponential_schedule.hpp"
18 
19 namespace mlpack {
20 namespace optimization {
21 
60 template<typename CoolingScheduleType = ExponentialSchedule>
61 class SA
62 {
63  public:
80  SA(CoolingScheduleType& coolingSchedule,
81  const size_t maxIterations = 1000000,
82  const double initT = 10000.,
83  const size_t initMoves = 1000,
84  const size_t moveCtrlSweep = 100,
85  const double tolerance = 1e-5,
86  const size_t maxToleranceSweep = 3,
87  const double maxMoveCoef = 20,
88  const double initMoveCoef = 0.3,
89  const double gain = 0.3);
90 
101  template<typename FunctionType>
102  double Optimize(FunctionType& function, arma::mat& iterate);
103 
105  double Temperature() const { return temperature; }
107  double& Temperature() { return temperature; }
108 
110  size_t InitMoves() const { return initMoves; }
112  size_t& InitMoves() { return initMoves; }
113 
115  size_t MoveCtrlSweep() const { return moveCtrlSweep; }
117  size_t& MoveCtrlSweep() { return moveCtrlSweep; }
118 
120  double Tolerance() const { return tolerance; }
122  double& Tolerance() { return tolerance; }
123 
125  size_t MaxToleranceSweep() const { return maxToleranceSweep; }
127  size_t& MaxToleranceSweep() { return maxToleranceSweep; }
128 
130  double Gain() const { return gain; }
132  double& Gain() { return gain; }
133 
135  size_t MaxIterations() const { return maxIterations; }
137  size_t& MaxIterations() { return maxIterations; }
138 
139  private:
141  CoolingScheduleType& coolingSchedule;
143  size_t maxIterations;
145  double temperature;
147  size_t initMoves;
149  size_t moveCtrlSweep;
151  double tolerance;
153  size_t maxToleranceSweep;
155  double maxMoveCoef;
157  double initMoveCoef;
159  double gain;
160 
177  template<typename FunctionType>
178  void GenerateMove(FunctionType& function,
179  arma::mat& iterate,
180  arma::mat& accept,
181  arma::mat& moveSize,
182  double& energy,
183  size_t& idx,
184  size_t& sweepCounter);
185 
204  void MoveControl(const size_t nMoves, arma::mat& accept, arma::mat& moveSize);
205 };
206 
207 } // namespace optimization
208 } // namespace mlpack
209 
210 #include "sa_impl.hpp"
211 
212 #endif
size_t MaxIterations() const
Get the maximum number of iterations.
Definition: sa.hpp:135
size_t & MaxIterations()
Modify the maximum number of iterations.
Definition: sa.hpp:137
.hpp
Definition: add_to_po.hpp:21
double Temperature() const
Get the temperature.
Definition: sa.hpp:105
double Gain() const
Get the gain.
Definition: sa.hpp:130
Simulated Annealing is an stochastic optimization algorithm which is able to deliver near-optimal res...
Definition: sa.hpp:61
double & Gain()
Modify the gain.
Definition: sa.hpp:132
SA(CoolingScheduleType &coolingSchedule, const size_t maxIterations=1000000, const double initT=10000., const size_t initMoves=1000, const size_t moveCtrlSweep=100, const double tolerance=1e-5, const size_t maxToleranceSweep=3, const double maxMoveCoef=20, const double initMoveCoef=0.3, const double gain=0.3)
Construct the SA optimizer with the given parameters.
The core includes that mlpack expects; standard C++ includes and Armadillo.
double Tolerance() const
Get the tolerance.
Definition: sa.hpp:120
size_t & MoveCtrlSweep()
Modify sweeps per move control.
Definition: sa.hpp:117
double Optimize(FunctionType &function, arma::mat &iterate)
Optimize the given function using simulated annealing.
size_t InitMoves() const
Get the initial moves.
Definition: sa.hpp:110
size_t MaxToleranceSweep() const
Get the maxToleranceSweep.
Definition: sa.hpp:125
double & Tolerance()
Modify the tolerance.
Definition: sa.hpp:122
size_t & InitMoves()
Modify the initial moves.
Definition: sa.hpp:112
size_t & MaxToleranceSweep()
Modify the maxToleranceSweep.
Definition: sa.hpp:127
double & Temperature()
Modify the temperature.
Definition: sa.hpp:107
size_t MoveCtrlSweep() const
Get sweeps per move control.
Definition: sa.hpp:115