11 #ifndef MLPACK_CORE_OPTIMIZERS_FW_ATOMS_HPP 12 #define MLPACK_CORE_OPTIMIZERS_FW_ATOMS_HPP 19 namespace optimization {
38 if (currentAtoms.is_empty())
43 atomSqTerm.set_size(1);
44 atomSqTerm(0) = std::pow(norm(
function.MatrixA() * v, 2), 2);
48 currentAtoms.insert_cols(0, v);
51 currentCoeffs.insert_rows(0, cVec);
52 double tmp = std::pow(norm(
function.MatrixA() * v, 2), 2);
55 atomSqTerm.insert_rows(0, tmpVec);
63 x = currentAtoms * currentCoeffs;
87 arma::vec sqTerm = 0.5 * atomSqTerm % square(currentCoeffs);
89 while (currentAtoms.n_cols > 1)
94 arma::mat gradient(size(x));
95 function.Gradient(x, gradient);
98 arma::vec gap = sqTerm -
99 currentCoeffs % trans(gradient.t() * currentAtoms);
104 arma::mat newAtoms(currentAtoms.n_rows, currentAtoms.n_cols - 1);
106 newAtoms.cols(0, ind - 1) = currentAtoms.cols(0, ind - 1);
107 if (ind < (currentAtoms.n_cols - 1))
109 newAtoms.cols(ind, newAtoms.n_cols - 1) =
110 currentAtoms.cols(ind + 1, currentAtoms.n_cols - 1);
117 arma::vec newCoeffs =
118 solve(
function.MatrixA() * newAtoms,
function.Vectorb());
121 double Fnew =
function.Evaluate(newAtoms * newCoeffs);
129 currentAtoms = newAtoms;
130 currentCoeffs = newCoeffs;
131 atomSqTerm.shed_row(ind);
132 sqTerm.shed_row(ind);
168 size_t maxIteration = 100,
169 double tolerance = 1e-3)
173 double value =
function.Evaluate(x);
175 for (
size_t iter = 1; iter<maxIteration; iter++)
179 function.Gradient(x, g);
180 g = currentAtoms.t() * g;
181 currentCoeffs = currentCoeffs - stepSize * g;
187 double valueNew =
function.Evaluate(x);
189 if ((value - valueNew) < tolerance)
209 arma::vec currentCoeffs;
212 arma::mat currentAtoms;
216 arma::vec atomSqTerm;
arma::vec & CurrentCoeffs()
Modify the current atom coefficients.
Class to hold the information and operations of current atoms in the soluton space.
The core includes that mlpack expects; standard C++ includes and Armadillo.
const arma::vec & CurrentCoeffs() const
Get the current atom coefficients.
void RecoverVector(arma::mat &x)
Recover the solution coordinate from the coefficients of current atoms.
void ProjectedGradientEnhancement(FuncSq &function, double tau, double stepSize, size_t maxIteration=100, double tolerance=1e-3)
Enhance the solution in the convex hull of current atoms with atom norm constraint tau...
void PruneSupport(const double F, FuncSq &function)
Prune the support, delete previous atoms if they don't contribute much.
static void ProjectToL1Ball(arma::vec &v, double tau)
Project the vector onto the l1 ball with norm tau.
void AddAtom(const arma::vec &v, FuncSq &function, const double c=0)
Add atom into the solution space.
const arma::mat & CurrentAtoms() const
Get the current atoms.
arma::mat & CurrentAtoms()
Modify the current atoms.