Turi Create  4.0
turi::optimization::first_order_opt_interface Class Referenceabstract

#include <ml/optimization/optimization_interface.hpp>

Public Member Functions

virtual ~first_order_opt_interface ()
 
virtual size_t num_examples () const =0
 
virtual size_t num_variables () const =0
 
virtual void compute_first_order_statistics (const DenseVector &point, DenseVector &gradient, double &function_value, const size_t mbStart=0, const size_t mbSize=-1)=0
 
virtual double compute_function_value (const DenseVector &point, const size_t mbStart=0, const size_t mbSize=-1)
 
virtual void compute_gradient (const DenseVector &point, DenseVector &gradient, const size_t mbStart=0, const size_t mbSize=-1)
 
virtual void reset (int seed)
 
virtual std::vector< std::pair< std::string, size_t > > get_status_header (const std::vector< std::string > &stats)
 
virtual std::vector< std::string > get_status (const DenseVector &coefs, const std::vector< std::string > &stats)
 

Detailed Description

The interface to inherit from to describe a first order optimization model.

This model must implement methods to compute mini-batch gradient, and function value.

Definition at line 141 of file optimization_interface.hpp.

Constructor & Destructor Documentation

◆ ~first_order_opt_interface()

virtual turi::optimization::first_order_opt_interface::~first_order_opt_interface ( )
virtual

Default desctuctor.

Member Function Documentation

◆ compute_first_order_statistics()

virtual void turi::optimization::first_order_opt_interface::compute_first_order_statistics ( const DenseVector &  point,
DenseVector &  gradient,
double &  function_value,
const size_t  mbStart = 0,
const size_t  mbSize = -1 
)
pure virtual

Compute first order statistics at the given point. (Gradient & Function value)

Parameters
[in]pointPoint at which we are computing the stats.
[out]gradientDense gradient
[out]function_valueFunction value
[in]mbStartMinibatch start index
[in]mbSizeMinibatch size (-1 implies all)
Warning
DO NOT USE this if your model is truly sparse.

Implemented in turi::supervised::linear_svm_scaled_logistic_opt_interface, turi::supervised::logistic_regression_opt_interface, and turi::supervised::linear_regression_opt_interface.

◆ compute_function_value()

virtual double turi::optimization::first_order_opt_interface::compute_function_value ( const DenseVector &  point,
const size_t  mbStart = 0,
const size_t  mbSize = -1 
)
virtual

Optimizations for performance reasons.

Compute the function value at a given point.

Parameters
[in]pointPoint at which we are computing the gradient.
[in]mbStartMinibatch start index
[in]mbSizeMinibatch size (-1 implies all)
Returns
Function value at "point"

◆ compute_gradient()

virtual void turi::optimization::first_order_opt_interface::compute_gradient ( const DenseVector &  point,
DenseVector &  gradient,
const size_t  mbStart = 0,
const size_t  mbSize = -1 
)
virtual

Compute a gradient at the given point.

Parameters
[in]pointPoint at which we are computing the gradient.
[out]gradientDense gradient
[in]mbStartMinibatch start index
[in]mbSizeMinibatch size (-1 implies all)
Warning
See warning on "sparse" compute_gradient to see a potential danger of an infinite loop if you don't imeplement at least one of "dense" or "sparse" versions of compute_gradient.
DO NOT USE this if your model is truly sparse.

◆ get_status()

virtual std::vector<std::string> turi::optimization::first_order_opt_interface::get_status ( const DenseVector &  coefs,
const std::vector< std::string > &  stats 
)
virtual

Get strings needed to print a row of the progress table.

Parameters
[in]avector of model coefficients.
[in]avector of stats to print at the beginning of each row

Reimplemented in turi::supervised::logistic_regression_opt_interface, turi::supervised::linear_svm_scaled_logistic_opt_interface, and turi::supervised::linear_regression_opt_interface.

◆ get_status_header()

virtual std::vector<std::pair<std::string,size_t> > turi::optimization::first_order_opt_interface::get_status_header ( const std::vector< std::string > &  stats)
virtual

Get strings needed to print the header for the progress table.

Parameters
[in]avector of strings to print at the beginning of the header.

Reimplemented in turi::supervised::logistic_regression_opt_interface, turi::supervised::linear_svm_scaled_logistic_opt_interface, and turi::supervised::linear_regression_opt_interface.

◆ num_examples()

virtual size_t turi::optimization::first_order_opt_interface::num_examples ( ) const
pure virtual

Get the number of examples in the dataset (Required for SGD).

Returns
Number of examples in the data.

Implemented in turi::supervised::linear_svm_scaled_logistic_opt_interface, turi::supervised::logistic_regression_opt_interface, and turi::supervised::linear_regression_opt_interface.

◆ num_variables()

virtual size_t turi::optimization::first_order_opt_interface::num_variables ( ) const
pure virtual

Get the number of variables in the optimization problem.

Returns
Number of variables (features) in the optimization.
Note
Statisticians beware. Bias terms are variables in the optimization problem.

Implemented in turi::supervised::linear_svm_scaled_logistic_opt_interface, turi::supervised::logistic_regression_opt_interface, and turi::supervised::linear_regression_opt_interface.

◆ reset()

virtual void turi::optimization::first_order_opt_interface::reset ( int  seed)
virtual

Reset the state of the model's "randomness" source.

Parameters
[in]seedSeed that is the source of randomness.

The documentation for this class was generated from the following file: