func_sq.hpp
Go to the documentation of this file.
1 
12 #ifndef MLPACK_CORE_OPTIMIZERS_FW_FUNC_SQ_HPP
13 #define MLPACK_CORE_OPTIMIZERS_FW_FUNC_SQ_HPP
14 
15 #include <mlpack/prereqs.hpp>
16 
17 namespace mlpack {
18 namespace optimization {
19 
25 class FuncSq
26 {
27  public:
34  FuncSq(const arma::mat& A, const arma::vec& b) : A(A), b(b)
35  {/* Nothing to do. */}
36 
44  double Evaluate(const arma::mat& coords)
45  {
46  arma::vec r = A * coords - b;
47  return arma::dot(r, r) * 0.5;
48  }
49 
57  void Gradient(const arma::mat& coords, arma::mat& gradient)
58  {
59  arma::vec r = A * coords - b;
60  gradient = A.t() * r;
61  }
62 
64  arma::mat MatrixA() const {return A;}
66  arma::mat& MatrixA() {return A;}
67 
69  arma::vec Vectorb() const { return b; }
71  arma::vec& Vectorb() { return b; }
72 
73  private:
75  arma::mat A;
76 
78  arma::vec b;
79 };
80 
81 } // namespace optimization
82 } // namespace mlpack
83 
84 #endif
double Evaluate(const arma::mat &coords)
Evaluation of the function.
Definition: func_sq.hpp:44
arma::mat MatrixA() const
Get the matrix A.
Definition: func_sq.hpp:64
void Gradient(const arma::mat &coords, arma::mat &gradient)
Gradient of square loss function.
Definition: func_sq.hpp:57
Square loss function .
Definition: func_sq.hpp:25
.hpp
Definition: add_to_po.hpp:21
arma::mat & MatrixA()
Modify the matrix A.
Definition: func_sq.hpp:66
The core includes that mlpack expects; standard C++ includes and Armadillo.
arma::vec & Vectorb()
Modify the vector b.
Definition: func_sq.hpp:71
FuncSq(const arma::mat &A, const arma::vec &b)
Construct the square loss function.
Definition: func_sq.hpp:34
arma::vec Vectorb() const
Get the vector b.
Definition: func_sq.hpp:69