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

#include <ml/optimization/optimization_interface.hpp>

Public Member Functions

virtual ~second_order_opt_interface ()
 
virtual void compute_second_order_statistics (const DenseVector &point, DenseMatrix &Hessian, DenseVector &gradient, double &function_value)=0
 
virtual void compute_hessian (const DenseVector &point, DenseMatrix &hessian)
 
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 second order optimization model.

This model must implement methods to compute hessian as well as gradient.

Definition at line 253 of file optimization_interface.hpp.

Constructor & Destructor Documentation

◆ ~second_order_opt_interface()

virtual turi::optimization::second_order_opt_interface::~second_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 virtualinherited

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 
)
virtualinherited

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 
)
virtualinherited

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.

◆ compute_hessian()

virtual void turi::optimization::second_order_opt_interface::compute_hessian ( const DenseVector &  point,
DenseMatrix &  hessian 
)
virtual

Optimizations for performance reasons.

Compute the hessian at the given point

Parameters
[in]pointPoint at which we are computing the function value.
[out]hessianReturns a dense hessian matrix.
Note
Hessians are always dense matrices. Even if they are sparse, it is still really hard to factorize them by make sure the factors stay sparse.

◆ compute_second_order_statistics()

virtual void turi::optimization::second_order_opt_interface::compute_second_order_statistics ( const DenseVector &  point,
DenseMatrix &  Hessian,
DenseVector &  gradient,
double &  function_value 
)
pure virtual

Compute second order statistics at the given point. (Hessian, Gradient & Function value)

Parameters
[in]pointPoint at which we are computing the stats.
[out]hessianHessian computation (dense)
[out]gradientDense gradient
[out]function_valueFunction value

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

◆ get_status()

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

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)
virtualinherited

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 virtualinherited

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 virtualinherited

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)
virtualinherited

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: