Template Class SummedGradientFunction

Inheritance Relationships

Derived Type

Class Documentation

template<typename T>
class SummedGradientFunction

The SummedGradientFunction class is an interface for cost functions and gradients that are a sum of functions evaluated on a number of data records. To be used e.g. for mini-batch optimization. Template parameter can be used for data indices or directly for data points.

Subclassed by parpe::SummedGradientFunctionGradientFunctionAdapter< T >

Public Functions

virtual FunctionEvaluationStatus evaluate(gsl::span<const double> parameters, T dataset, double &fval, gsl::span<double> gradient, Logger *logger, double *cpuTime) const = 0

Evaluate on single data point.

Parameters:
  • parameters – Parameter vector where the function is to be evaluated

  • dataset – The dataset on which to evaluate the function

  • fval – Output argument for f(x)

  • gradient – Preallocated space for the gradient of size dim(parameters). Or gsl::span<double>() for evaluation without gradient.

  • logger – Optional Logger instance used for output

  • cputime – Optional output argument to report cpuTime consumed by the the function

Returns:

Evaluation status

virtual FunctionEvaluationStatus evaluate(gsl::span<const double> parameters, std::vector<T> datasets, double &fval, gsl::span<double> gradient, Logger *logger, double *cpuTime) const = 0

Evaluate on vector of data points.

Parameters:
  • parameters – Parameter vector where the function is to be evaluated

  • datasets – The datasets on which to evaluate the function

  • fval – Output argument for f(x)

  • gradient – Preallocated space for the gradient of size dim(parameters). Or gsl::span<double>() for evaluation without gradient.

  • logger – Optional Logger instance used for output

  • cputime – Optional output argument to report cpuTime consumed by the the function

Returns:

Evaluation status

virtual int numParameters() const = 0

Get dimension of function parameter vector.

Returns:

Number of parameters

virtual std::vector<std::string> getParameterIds() const = 0
virtual ~SummedGradientFunction() = default