15 #ifndef MLPACK_CORE_OPTIMIZERS_SPALERA_SGD_SPALERA_STEPSIZE_HPP 16 #define MLPACK_CORE_OPTIMIZERS_SPALERA_SGD_SPALERA_STEPSIZE_HPP 19 namespace optimization {
52 const double epsilon = 1e-6,
53 const double adaptRate = 3.10e-8) :
69 void Initialize(
const size_t rows,
const size_t cols,
const double lambda)
71 learningRates = arma::ones(rows, cols);
72 relaxedSums = arma::zeros(rows, cols);
74 this->lambda = lambda;
76 mu0 = un = mn = relaxedObjective = phCounter = eveCounter = 0;
92 const double objective,
93 const size_t batchSize,
94 const size_t numFunctions,
96 const arma::mat& gradient)
100 const double mbRatio = batchSize / (double) numFunctions;
104 if (phCounter > (1 / mbRatio))
106 relaxedObjective = (1 - mbRatio) * relaxedObjective + mbRatio * objective;
110 relaxedObjective = phCounter * relaxedObjective + objective;
111 relaxedObjective /= (phCounter + 1);
115 mu0 = phCounter * mu0 + relaxedObjective;
116 mu0 = mu0 / (phCounter + 1);
119 un += relaxedObjective - mu0;
126 if ((un - mn) > lambda)
129 iterate = previousIterate;
135 if (arma::any(arma::vectorise(learningRates) <= 1e-15))
142 mu0 = un = mn = relaxedObjective = phCounter = eveCounter = 0;
146 const double paramMean = (alpha / (2 - alpha) *
147 (1 - std::pow(1 - alpha, 2 * (eveCounter + 1)))) / iterate.n_elem;
149 const double paramStd = (alpha / std::sqrt(iterate.n_elem)) /
150 std::sqrt(iterate.n_elem);
152 const double normGradient = std::sqrt(arma::accu(arma::pow(gradient, 2)));
154 relaxedSums *= (1 - alpha);
155 if (normGradient > epsilon)
156 relaxedSums += gradient * (alpha / normGradient);
158 learningRates %= arma::exp((arma::pow(relaxedSums, 2) - paramMean) *
159 (adaptRate / paramStd));
161 previousIterate = iterate;
163 iterate -= stepSize * (learningRates % gradient);
174 double Alpha()
const {
return alpha; }
194 double relaxedObjective;
212 arma::mat learningRates;
215 arma::mat relaxedSums;
221 arma::mat previousIterate;
227 #endif // MLPACK_CORE_OPTIMIZERS_SPALERA_SGD_SPALERA_STEPSIZE_HPP double & AdaptRate()
Modify the agnostic learning rate update rate.
SPALeRAStepsize(const double alpha=0.001, const double epsilon=1e-6, const double adaptRate=3.10e-8)
Construct the SPALeRAStepsize object with the given parameters.
bool Update(const double stepSize, const double objective, const size_t batchSize, const size_t numFunctions, arma::mat &iterate, const arma::mat &gradient)
This function is called in each iteration.
Definition of the SPALeRA stepize technique, which implementes a change detection mechanism with an a...
double Alpha() const
Get the agnostic learning rate adaptation parameter.
double AdaptRate() const
Get the agnostic learning rate update rate.
void Initialize(const size_t rows, const size_t cols, const double lambda)
The Initialize method is called by SPALeRASGD Optimizer method before the start of the iteration upda...
double & Alpha()
Modify the agnostic learning rate adaptation parameter.