12 #ifndef MLPACK_CORE_OPTIMIZERS_PARALLEL_SGD_SPARSE_TEST_FUNCTION_HPP 13 #define MLPACK_CORE_OPTIMIZERS_PARALLEL_SGD_SPARSE_TEST_FUNCTION_HPP 18 namespace optimization {
32 intercepts = arma::vec(
"20 12 15 100");
33 bi = arma::vec(
"-4 -2 -3 -8");
48 const size_t batchSize = 1)
const 51 for (
size_t j = i; j < i + batchSize; ++j)
53 result += coordinates[j] * coordinates[j] + bi[j] * coordinates[j] +
61 double Evaluate(
const arma::mat& coordinates)
const 63 double objective = 0.0;
66 objective += coordinates[i] * coordinates[i] + bi[i] * coordinates[i] +
76 arma::sp_mat& gradient,
77 const size_t batchSize = 1)
const 79 gradient.zeros(arma::size(coordinates));
80 for (
size_t j = i; j < i + batchSize; ++j)
81 gradient[j] = 2 * coordinates[j] + bi[j];
87 arma::sp_mat& gradient)
const 89 gradient.zeros(arma::size(coordinates));
90 gradient[j] = 2 * coordinates[j] + bi[j];
void PartialGradient(const arma::mat &coordinates, const size_t j, arma::sp_mat &gradient) const
Evaluate the gradient of a feature function.
SparseTestFunction()
Set members in the default constructor.
The core includes that mlpack expects; standard C++ includes and Armadillo.
double Evaluate(const arma::mat &coordinates, const size_t i, const size_t batchSize=1) const
Evaluate a function.
size_t NumFunctions() const
Return 4 (the number of functions).
double Evaluate(const arma::mat &coordinates) const
Evaluate all the functions.
arma::mat GetInitialPoint() const
Get the starting point.
size_t NumFeatures() const
Return 4 (the number of features).
void Gradient(const arma::mat &coordinates, const size_t i, arma::sp_mat &gradient, const size_t batchSize=1) const
Evaluate the gradient of a function.