[mlpack-git] master,mlpack-1.0.x: Rename parameters, clean up documentation; very minor tweaks. No functionality changes. (b2a0826)

gitdub at big.cc.gt.atl.ga.us gitdub at big.cc.gt.atl.ga.us
Thu Mar 5 21:50:42 EST 2015


Repository : https://github.com/mlpack/mlpack

On branches: master,mlpack-1.0.x
Link       : https://github.com/mlpack/mlpack/compare/904762495c039e345beba14c1142fd719b3bd50e...f94823c800ad6f7266995c700b1b630d5ffdcf40

>---------------------------------------------------------------

commit b2a0826e550d2fe73c53983a76a9573100cbb2f8
Author: Ryan Curtin <ryan at ratml.org>
Date:   Wed Jul 2 21:04:59 2014 +0000

    Rename parameters, clean up documentation; very minor tweaks.  No functionality changes.


>---------------------------------------------------------------

b2a0826e550d2fe73c53983a76a9573100cbb2f8
 src/mlpack/core/optimizers/sa/sa.hpp      | 71 ++++++++++++++++++-------------
 src/mlpack/core/optimizers/sa/sa_impl.hpp |  8 ++--
 2 files changed, 46 insertions(+), 33 deletions(-)

diff --git a/src/mlpack/core/optimizers/sa/sa.hpp b/src/mlpack/core/optimizers/sa/sa.hpp
index cecf86c..57e2734 100644
--- a/src/mlpack/core/optimizers/sa/sa.hpp
+++ b/src/mlpack/core/optimizers/sa/sa.hpp
@@ -93,67 +93,80 @@ class SA
   double Optimize(arma::mat& iterate);
 
   //! Get the instantiated function to be optimized.
-  const FunctionType& Function() const {return function;}
+  const FunctionType& Function() const { return function; }
   //! Modify the instantiated function.
-  FunctionType& Function() {return function;}
+  FunctionType& Function() { return function; }
 
   //! Get the temperature.
-  double Temperature() const {return T;}
+  double Temperature() const { return temperature; }
   //! Modify the temperature.
-  double& Temperature() {return T;}
+  double& Temperature() { return temperature; }
 
   //! Get the initial moves.
-  size_t InitMoves() const {return initMoves;}
+  size_t InitMoves() const { return initMoves; }
   //! Modify the initial moves.
-  size_t& InitMoves() {return initMoves;}
+  size_t& InitMoves() { return initMoves; }
 
   //! Get sweeps per move control.
-  size_t MoveCtrlSweep() const {return moveCtrlSweep;}
+  size_t MoveCtrlSweep() const { return moveCtrlSweep; }
   //! Modify sweeps per move control.
-  size_t& MoveCtrlSweep() {return moveCtrlSweep;}
+  size_t& MoveCtrlSweep() { return moveCtrlSweep; }
 
   //! Get the tolerance.
-  double Tolerance() const {return tolerance;}
+  double Tolerance() const { return tolerance; }
   //! Modify the tolerance.
-  double& Tolerance() {return tolerance;}
+  double& Tolerance() { return tolerance; }
 
   //! Get the maxToleranceSweep.
-  size_t MaxToleranceSweep() const {return maxToleranceSweep;}
+  size_t MaxToleranceSweep() const { return maxToleranceSweep; }
   //! Modify the maxToleranceSweep.
-  size_t& MaxToleranceSweep() {return maxToleranceSweep;}
+  size_t& MaxToleranceSweep() { return maxToleranceSweep; }
 
   //! Get the gain.
-  double Gain() const {return gain;}
+  double Gain() const { return gain; }
   //! Modify the gain.
-  double& Gain() {return gain;}
+  double& Gain() { return gain; }
 
-  //! Get the maxIterations.
-  size_t MaxIterations() const {return maxIterations;}
-  //! Modify the maxIterations.
-  size_t& MaxIterations() {return maxIterations;}
+  //! Get the maximum number of iterations.
+  size_t MaxIterations() const { return maxIterations; }
+  //! Modify the maximum number of iterations.
+  size_t& MaxIterations() { return maxIterations; }
 
-  //! Get Maximum move size of each parameter
-  arma::mat MaxMove() const {return maxMove;}
-  //! Modify maximum move size of each parameter
-  arma::mat& MaxMove() {return maxMove;}
+  //! Get the maximum move size of each parameter.
+  arma::mat MaxMove() const { return maxMove; }
+  //! Modify the maximum move size of each parameter.
+  arma::mat& MaxMove() { return maxMove; }
 
-  //! Get move size of each parameter
-  arma::mat MoveSize() const {return moveSize;}
-  //! Modify  move size of each parameter
-  arma::mat& MoveSize() {return moveSize;}
+  //! Get move size of each parameter.
+  arma::mat MoveSize() const { return moveSize; }
+  //! Modify move size of each parameter.
+  arma::mat& MoveSize() { return moveSize; }
 
+  //! Return a string representation of this object.
   std::string ToString() const;
  private:
-  FunctionType&function;
-  CoolingScheduleType &coolingSchedule;
+  //! The function to be optimized.
+  FunctionType& function;
+  //! The cooling schedule being used.
+  CoolingScheduleType& coolingSchedule;
+  //! The maximum number of iterations.
   size_t maxIterations;
-  double T;
+  //! The current temperature.
+  double temperature;
+  //! The number of initial moves before reducing the temperature.
   size_t initMoves;
+  //! The number of sweeps before a MoveControl() call.
   size_t moveCtrlSweep;
+  //! Tolerance for convergence.
   double tolerance;
+  //! Number of sweeps in tolerance before system is considered frozen.
   size_t maxToleranceSweep;
+  //! Proportional control in feedback move control.
   double gain;
+
+  //! Maximum move size of each parameter.
   arma::mat maxMove;
+  //! Move size of each parameter.
   arma::mat moveSize;
 
 
diff --git a/src/mlpack/core/optimizers/sa/sa_impl.hpp b/src/mlpack/core/optimizers/sa/sa_impl.hpp
index d1833b8..fc2ac5c 100644
--- a/src/mlpack/core/optimizers/sa/sa_impl.hpp
+++ b/src/mlpack/core/optimizers/sa/sa_impl.hpp
@@ -31,7 +31,7 @@ SA<FunctionType, CoolingScheduleType>::SA(
     function(function),
     coolingSchedule(coolingSchedule),
     maxIterations(maxIterations),
-    T(initT),
+    temperature(initT),
     initMoves(initMoves),
     moveCtrlSweep(moveCtrlSweep),
     tolerance(tolerance),
@@ -78,7 +78,7 @@ double SA<FunctionType, CoolingScheduleType>::Optimize(arma::mat &iterate)
   {
     oldEnergy = energy;
     GenerateMove(iterate);
-    T = coolingSchedule.nextTemperature(T, energy);
+    temperature = coolingSchedule.nextTemperature(temperature, energy);
 
     // Determine if the optimization has entered (or continues to be in) a
     // frozen state.
@@ -135,7 +135,7 @@ void SA<FunctionType, CoolingScheduleType>::GenerateMove(
   // min{1, exp(-(E_new - E_old) / T)}.
   double xi = math::Random();
   double delta = energy - prevEnergy;
-  double criterion = std::exp(-delta / T);
+  double criterion = std::exp(-delta / temperature);
   if (delta <= 0. || criterion > xi)
   {
     accept(idx) += 1.;
@@ -209,7 +209,7 @@ ToString() const
   convert << util::Indent(function.ToString(), 2);
   convert << "  Cooling Schedule:" << std::endl;
   convert << util::Indent(coolingSchedule.ToString(), 2);
-  convert << "  Temperature: " << T << std::endl;
+  convert << "  Temperature: " << temperature << std::endl;
   convert << "  Initial moves: " << initMoves << std::endl;
   convert << "  Sweeps per move control: " << moveCtrlSweep << std::endl;
   convert << "  Tolerance: " << tolerance << std::endl;



More information about the mlpack-git mailing list