1 #ifndef __STAN__MCMC__DUALAVERAGE_H__
2 #define __STAN__MCMC__DUALAVERAGE_H__
53 void update(
const std::vector<double>& g, std::vector<double>&
xk) {
56 double avgeta = 1.0 / (
_k + 10);
57 double xbar_avgeta =
pow(
_k, -0.75);
59 for (
size_t i = 0; i <
_gbar.size(); ++i) {
60 _gbar[i] = avgeta * g[i] + (1 - avgeta) *
_gbar[i];
65 _xbar[i] = xbar_avgeta *
xk[i] + (1 - xbar_avgeta) *
_xbar[i];
75 inline void setx0(
const std::vector<double>&
x0) {
76 _x0.assign(
x0.begin(),
x0.end());
102 inline void xk(std::vector<double>&
xk) {
111 inline void x0(std::vector<double>&
x0) {
119 inline int k() {
return _k; }
Implements Nesterov's dual average algorithm.
double gamma()
Return the regularization parameter gamma.
void x0(std::vector< double > &x0)
Get the point towards which we're shrinking the iterates.
std::vector< double > _gbar
std::vector< double > _xbar
int k()
Return how many iterations we've run for.
DualAverage(double gamma, const std::vector< double > &x0)
Constructor.
std::vector< double > _lastx
void setx0(const std::vector< double > &x0)
Set the point towards which each iterate is shrunk.
void update(const std::vector< double > &g, std::vector< double > &xk)
Produces the next iterate xk given the current gradient g.
void xbar(std::vector< double > &xbar)
Get the exponentially weighted moving average of all previous iterates.
void xk(std::vector< double > &xk)
Get the current iterate.
void gbar(std::vector< double > &gbar)
Get the average of all previous gradients.
std::vector< double > _x0
var sqrt(const var &a)
Return the square root of the specified variable (cmath).
var pow(const var &base, const var &exponent)
Return the base raised to the power of the exponent (cmath).
Probability, optimization and sampling library.