mlpack  3.0.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
parallel_sgd.hpp
Go to the documentation of this file.
1 
12 #ifndef MLPACK_CORE_OPTIMIZERS_PARALLEL_SGD_HPP
13 #define MLPACK_CORE_OPTIMIZERS_PARALLEL_SGD_HPP
14 
15 #include <mlpack/prereqs.hpp>
18 
19 namespace mlpack {
20 namespace optimization {
21 
59 template <typename DecayPolicyType = ConstantStep>
61 {
62  public:
80  ParallelSGD(const size_t maxIterations,
81  const size_t threadShareSize,
82  const double tolerance = 1e-5,
83  const bool shuffle = true,
84  const DecayPolicyType& decayPolicy = DecayPolicyType());
85 
97  template <typename SparseFunctionType>
98  double Optimize(SparseFunctionType& function, arma::mat& iterate);
99 
101  size_t MaxIterations() const { return maxIterations; }
103  size_t& MaxIterations() { return maxIterations; }
104 
107  size_t ThreadShareSize() const { return threadShareSize; }
110  size_t& ThreadShareSize() { return threadShareSize; }
111 
113  double Tolerance() const { return tolerance; }
115  double& Tolerance() { return tolerance; }
116 
118  bool Shuffle() const { return shuffle; }
120  bool& Shuffle() { return shuffle; }
121 
123  DecayPolicyType& DecayPolicy() const { return decayPolicy; }
125  DecayPolicyType& DecayPolicy() { return decayPolicy; }
126 
127  private:
129  size_t maxIterations;
130 
132  size_t threadShareSize;
133 
135  double tolerance;
136 
139  bool shuffle;
140 
142  DecayPolicyType decayPolicy;
143 };
144 
145 } // namespace optimization
146 } // namespace mlpack
147 
148 // Include implementation.
149 #include "parallel_sgd_impl.hpp"
150 
151 #endif
ParallelSGD(const size_t maxIterations, const size_t threadShareSize, const double tolerance=1e-5, const bool shuffle=true, const DecayPolicyType &decayPolicy=DecayPolicyType())
Construct the parallel SGD optimizer to optimize the given function with the given parameters...
double Optimize(SparseFunctionType &function, arma::mat &iterate)
Optimize the given function using the parallel SGD algorithm.
The core includes that mlpack expects; standard C++ includes and Armadillo.
size_t & ThreadShareSize()
Modify the number of datapoints to be processed in one iteration by each thread.
bool Shuffle() const
Get whether or not the individual functions are shuffled.
size_t MaxIterations() const
Get the maximum number of iterations (0 indicates no limits).
size_t ThreadShareSize() const
Get the number of datapoints to be processed in one iteration by each thread.
double Tolerance() const
Get the tolerance for termination.
DecayPolicyType & DecayPolicy()
Modify the step size decay policy.
double & Tolerance()
Modify the tolerance for termination.
Miscellaneous math random-related routines.
An implementation of parallel stochastic gradient descent using the lock-free HOGWILD! approach...
bool & Shuffle()
Modify whether or not the individual functions are shuffled.
size_t & MaxIterations()
Modify the maximum number of iterations (0 indicates no limits).
DecayPolicyType & DecayPolicy() const
Get the step size decay policy.