MLPACK  1.0.11
sa.hpp
Go to the documentation of this file.
1 
22 #ifndef __MLPACK_CORE_OPTIMIZERS_SA_SA_HPP
23 #define __MLPACK_CORE_OPTIMIZERS_SA_SA_HPP
24 
25 #include <mlpack/prereqs.hpp>
26 
27 #include "exponential_schedule.hpp"
28 
29 namespace mlpack {
30 namespace optimization {
31 
71 template<
72  typename FunctionType,
73  typename CoolingScheduleType = ExponentialSchedule
74 >
75 class SA
76 {
77  public:
94  SA(FunctionType& function,
95  CoolingScheduleType& coolingSchedule,
96  const size_t maxIterations = 1000000,
97  const double initT = 10000.,
98  const size_t initMoves = 1000,
99  const size_t moveCtrlSweep = 100,
100  const double tolerance = 1e-5,
101  const size_t maxToleranceSweep = 3,
102  const double maxMoveCoef = 20,
103  const double initMoveCoef = 0.3,
104  const double gain = 0.3);
105 
114  double Optimize(arma::mat& iterate);
115 
117  const FunctionType& Function() const { return function; }
119  FunctionType& Function() { return function; }
120 
122  double Temperature() const { return temperature; }
124  double& Temperature() { return temperature; }
125 
127  size_t InitMoves() const { return initMoves; }
129  size_t& InitMoves() { return initMoves; }
130 
132  size_t MoveCtrlSweep() const { return moveCtrlSweep; }
134  size_t& MoveCtrlSweep() { return moveCtrlSweep; }
135 
137  double Tolerance() const { return tolerance; }
139  double& Tolerance() { return tolerance; }
140 
142  size_t MaxToleranceSweep() const { return maxToleranceSweep; }
144  size_t& MaxToleranceSweep() { return maxToleranceSweep; }
145 
147  double Gain() const { return gain; }
149  double& Gain() { return gain; }
150 
152  size_t MaxIterations() const { return maxIterations; }
154  size_t& MaxIterations() { return maxIterations; }
155 
157  arma::mat MaxMove() const { return maxMove; }
159  arma::mat& MaxMove() { return maxMove; }
160 
162  arma::mat MoveSize() const { return moveSize; }
164  arma::mat& MoveSize() { return moveSize; }
165 
167  std::string ToString() const;
168  private:
170  FunctionType& function;
172  CoolingScheduleType& coolingSchedule;
176  double temperature;
178  size_t initMoves;
182  double tolerance;
186  double gain;
187 
189  arma::mat maxMove;
191  arma::mat moveSize;
192 
208  void GenerateMove(arma::mat& iterate,
209  arma::mat& accept,
210  double& energy,
211  size_t& idx,
212  size_t& sweepCounter);
213 
232  void MoveControl(const size_t nMoves, arma::mat& accept);
233 };
234 
235 }; // namespace optimization
236 }; // namespace mlpack
237 
238 #include "sa_impl.hpp"
239 
240 #endif