mlpack  master
minibatch_sgd.hpp
Go to the documentation of this file.
1 
12 #ifndef MLPACK_CORE_OPTIMIZERS_MINIBATCH_SGD_MINIBATCH_SGD_HPP
13 #define MLPACK_CORE_OPTIMIZERS_MINIBATCH_SGD_MINIBATCH_SGD_HPP
14 
15 #include <mlpack/prereqs.hpp>
16 
17 namespace mlpack {
18 namespace optimization {
19 
73 template<typename DecomposableFunctionType>
75 {
76  public:
93  MiniBatchSGD(DecomposableFunctionType& function,
94  const size_t batchSize = 1000,
95  const double stepSize = 0.01,
96  const size_t maxIterations = 100000,
97  const double tolerance = 1e-5,
98  const bool shuffle = true);
99 
108  double Optimize(arma::mat& iterate);
109 
111  const DecomposableFunctionType& Function() const { return function; }
113  DecomposableFunctionType& Function() { return function; }
114 
116  size_t BatchSize() const { return batchSize; }
118  size_t& BatchSize() { return batchSize; }
119 
121  double StepSize() const { return stepSize; }
123  double& StepSize() { return stepSize; }
124 
126  size_t MaxIterations() const { return maxIterations; }
128  size_t& MaxIterations() { return maxIterations; }
129 
131  double Tolerance() const { return tolerance; }
133  double& Tolerance() { return tolerance; }
134 
136  bool Shuffle() const { return shuffle; }
138  bool& Shuffle() { return shuffle; }
139 
140  private:
142  DecomposableFunctionType& function;
143 
145  size_t batchSize;
146 
148  double stepSize;
149 
152 
154  double tolerance;
155 
158  bool shuffle;
159 };
160 
161 } // namespace optimization
162 } // namespace mlpack
163 
164 // Include implementation.
165 #include "minibatch_sgd_impl.hpp"
166 
167 #endif
size_t batchSize
The size of each mini-batch.
bool & Shuffle()
Modify whether or not the individual functions are shuffled.
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: binarize.hpp:18
double & Tolerance()
Modify the tolerance for termination.
const DecomposableFunctionType & Function() const
Get the instantiated function to be optimized.
The core includes that mlpack expects; standard C++ includes and Armadillo.
MiniBatchSGD(DecomposableFunctionType &function, const size_t batchSize=1000, const double stepSize=0.01, const size_t maxIterations=100000, const double tolerance=1e-5, const bool shuffle=true)
Construct the MiniBatchSGD optimizer with the given function and parameters.
Mini-batch Stochastic Gradient Descent is a technique for minimizing a function which can be expresse...
size_t MaxIterations() const
Get the maximum number of iterations (0 indicates no limit).
double Tolerance() const
Get the tolerance for termination.
size_t & MaxIterations()
Modify the maximum number of iterations (0 indicates no limit).
DecomposableFunctionType & Function()
Modify the instantiated function.
double tolerance
The tolerance for termination.
double stepSize
The step size for each example.
double & StepSize()
Modify the step size.
double Optimize(arma::mat &iterate)
Optimize the given function using mini-batch SGD.
bool shuffle
Controls whether or not the individual functions are shuffled when iterating.
size_t & BatchSize()
Modify the batch size.
size_t BatchSize() const
Get the batch size.
double StepSize() const
Get the step size.
size_t maxIterations
The maximum number of allowed iterations.
bool Shuffle() const
Get whether or not the individual functions are shuffled.