13 #ifndef XACC_MLPACK_OPTIMIZER_HPP_ 14 #define XACC_MLPACK_OPTIMIZER_HPP_ 16 #include <type_traits> 19 #include "Optimizer.hpp" 21 #include <ensmallen.hpp> 27 std::vector<double> grad;
32 : opt_function(optF), grad(std::vector<double>(optF.dimensions())) {}
33 std::size_t NumFunctions()
const {
return 1; }
38 double Evaluate(
const arma::mat &x) {
39 auto x_vec = arma::conv_to<std::vector<double>>::from(x);
40 return opt_function(x_vec, grad);
43 double Evaluate(
const arma::mat &coordinates,
const size_t begin,
44 const size_t batchSize) {
45 return Evaluate(coordinates);
47 double EvaluateWithGradient(
const arma::mat &coordinates,
48 arma::mat &gradient) {
49 auto val = Evaluate(coordinates);
50 Gradient(coordinates, gradient);
53 double EvaluateWithGradient(
const arma::mat &coordinates, std::size_t bb,
54 arma::mat &gradient, std::size_t b) {
55 auto val = Evaluate(coordinates);
56 Gradient(coordinates, gradient);
61 void Gradient(
const arma::mat &x, arma::mat &gradient) {
72 const std::string
name()
const override {
return "mlpack"; }
Definition: mlpack_optimizer.hpp:25
Definition: Accelerator.hpp:25
Definition: Optimizer.hpp:48
const std::string description() const override
Definition: mlpack_optimizer.hpp:73
const std::string name() const override
Definition: mlpack_optimizer.hpp:72
Definition: Optimizer.hpp:31
Definition: mlpack_optimizer.hpp:67