update_span.hpp
Go to the documentation of this file.
1 
13 #ifndef MLPACK_CORE_OPTIMIZERS_FW_UPDATE_SPAN_HPP
14 #define MLPACK_CORE_OPTIMIZERS_FW_UPDATE_SPAN_HPP
15 
16 #include <mlpack/prereqs.hpp>
17 #include "func_sq.hpp"
18 #include "atoms.hpp"
19 
20 namespace mlpack {
21 namespace optimization {
22 
30 {
31  public:
37  UpdateSpan(const bool isPrune = false) : isPrune(isPrune)
38  { /* Do nothing. */ }
39 
50  void Update(FuncSq& function,
51  const arma::mat& oldCoords,
52  const arma::mat& s,
53  arma::mat& newCoords,
54  const size_t /* numIter */)
55  {
56  // Add new atom into soluton space.
57  atoms.AddAtom(s, function);
58 
59  // Reoptimize the solution in the current space.
60  arma::vec b = function.Vectorb();
61  atoms.CurrentCoeffs() = solve(function.MatrixA() * atoms.CurrentAtoms(), b);
62 
63  // x has coords of only the current atoms, recover the solution
64  // to the original size.
65  atoms.RecoverVector(newCoords);
66 
67  // Prune the support.
68  if (isPrune)
69  {
70  double oldF = function.Evaluate(oldCoords);
71  double F = 0.25 * oldF + 0.75 * function.Evaluate(newCoords);
72  atoms.PruneSupport(F, function);
73  atoms.RecoverVector(newCoords);
74  }
75  }
76 
77  private:
79  Atoms atoms;
80 
82  bool isPrune;
83 }; // class UpdateSpan
84 
85 } // namespace optimization
86 } // namespace mlpack
87 
88 #endif
UpdateSpan(const bool isPrune=false)
Construct the span update rule.
Definition: update_span.hpp:37
Square loss function .
Definition: func_sq.hpp:25
Class to hold the information and operations of current atoms in the soluton space.
Definition: atoms.hpp:25
.hpp
Definition: add_to_po.hpp:21
The core includes that mlpack expects; standard C++ includes and Armadillo.
const arma::vec & CurrentCoeffs() const
Get the current atom coefficients.
Definition: atoms.hpp:198
void RecoverVector(arma::mat &x)
Recover the solution coordinate from the coefficients of current atoms.
Definition: atoms.hpp:61
void Update(FuncSq &function, const arma::mat &oldCoords, const arma::mat &s, arma::mat &newCoords, const size_t)
Update rule for FrankWolfe, reoptimize in the span of current solution space.
Definition: update_span.hpp:50
void PruneSupport(const double F, FuncSq &function)
Prune the support, delete previous atoms if they don&#39;t contribute much.
Definition: atoms.hpp:85
void AddAtom(const arma::vec &v, FuncSq &function, const double c=0)
Add atom into the solution space.
Definition: atoms.hpp:36
const arma::mat & CurrentAtoms() const
Get the current atoms.
Definition: atoms.hpp:203
Recalculate the optimal solution in the span of all previous solution space, used as update step for ...
Definition: update_span.hpp:29