Turi Create  4.0
turi::supervised::logistic_regression_opt_interface Class Reference

#include <toolkits/supervised_learning/logistic_regression_opt_interface.hpp>

Public Member Functions

 logistic_regression_opt_interface (const ml_data &_data, const ml_data &_valid_data, logistic_regression &_model)
 
 ~logistic_regression_opt_interface ()
 
void init_feature_rescaling ()
 
void rescale_solution (DenseVector &coefs)
 
void set_threads (size_t _n_threads)
 
void set_class_weights (const flexible_type &class_weights)
 
size_t num_examples () const
 
size_t num_validation_examples () const
 
size_t num_variables () const
 
size_t num_classes () const
 
std::vector< std::pair< std::string, size_t > > get_status_header (const std::vector< std::string > &stat_names)
 
std::vector< std::string > get_status (const DenseVector &coefs, const std::vector< std::string > &stats)
 
void compute_first_order_statistics (const DenseVector &point, DenseVector &gradient, double &function_value, const size_t mbStart=0, const size_t mbSize=-1)
 
void compute_second_order_statistics (const DenseVector &point, DenseMatrix &hessian, DenseVector &gradient, double &function_value)
 
void compute_validation_first_order_statistics (const DenseVector &point, DenseVector &gradient, double &function_value)
 
virtual void compute_hessian (const DenseVector &point, DenseMatrix &hessian)
 
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)
 

Protected Attributes

bool feature_rescaling = false
 
bool is_dense = false
 

Detailed Description

Solver interface for logistic regression.

Let J denote the number of classes, K the number of features, and N the number of examples.

coefs = [coef_1 ... coef_{J-1}] := (K * (J-1)) x 1 column vector where each coef_j for j = 1 .. J-1 is a K x 1 column vector representing coefficients for the class j.

Definition at line 43 of file logistic_regression_opt_interface.hpp.

Constructor & Destructor Documentation

◆ logistic_regression_opt_interface()

turi::supervised::logistic_regression_opt_interface::logistic_regression_opt_interface ( const ml_data _data,
const ml_data _valid_data,
logistic_regression _model 
)

Is the data dense? Default constructor

Parameters
[in]_dataML Data containing everything
Note
Default options are used when the interface is called from the logistic regression class.

◆ ~logistic_regression_opt_interface()

turi::supervised::logistic_regression_opt_interface::~logistic_regression_opt_interface ( )

Default destructor

Member Function Documentation

◆ compute_first_order_statistics()

void turi::supervised::logistic_regression_opt_interface::compute_first_order_statistics ( const DenseVector &  point,
DenseVector &  gradient,
double &  function_value,
const size_t  mbStart = 0,
const size_t  mbSize = -1 
)
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)

Implements turi::optimization::first_order_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 
)
virtualinherited

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

void turi::supervised::logistic_regression_opt_interface::compute_second_order_statistics ( const DenseVector &  point,
DenseMatrix &  hessian,
DenseVector &  gradient,
double &  function_value 
)
virtual

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

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

Implements turi::optimization::second_order_opt_interface.

◆ compute_validation_first_order_statistics()

void turi::supervised::logistic_regression_opt_interface::compute_validation_first_order_statistics ( const DenseVector &  point,
DenseVector &  gradient,
double &  function_value 
)

Compute first order statistics at the given point with respect to the validation data. (Gradient & Function value)

Parameters
[in]pointPoint at which we are computing the stats.
[out]gradientDense gradient
[out]function_valueFunction value

◆ get_status()

std::vector<std::string> turi::supervised::logistic_regression_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 from turi::optimization::first_order_opt_interface.

◆ get_status_header()

std::vector<std::pair<std::string, size_t> > turi::supervised::logistic_regression_opt_interface::get_status_header ( const std::vector< std::string > &  stat_names)
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 from turi::optimization::first_order_opt_interface.

◆ init_feature_rescaling()

void turi::supervised::logistic_regression_opt_interface::init_feature_rescaling ( )

Set feature scaling

◆ num_classes()

size_t turi::supervised::logistic_regression_opt_interface::num_classes ( ) const

Get the number of classes in the model

Returns
Number of classes

◆ num_examples()

size_t turi::supervised::logistic_regression_opt_interface::num_examples ( ) const
virtual

Get the number of examples for the model

Returns
Number of examples

Implements turi::optimization::first_order_opt_interface.

◆ num_validation_examples()

size_t turi::supervised::logistic_regression_opt_interface::num_validation_examples ( ) const

Get the number of validation-set examples for the model

Returns
Number of examples

◆ num_variables()

size_t turi::supervised::logistic_regression_opt_interface::num_variables ( ) const
virtual

Get the number of variables in the model

Returns
Number of variables

Implements turi::optimization::first_order_opt_interface.

◆ rescale_solution()

void turi::supervised::logistic_regression_opt_interface::rescale_solution ( DenseVector &  coefs)

Transform the final solution back to the original scale.

Parameters
[in,out]coefsSolution vector

◆ 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.

◆ set_class_weights()

void turi::supervised::logistic_regression_opt_interface::set_class_weights ( const flexible_type class_weights)

Set the class weights (as a flex_dict which is already validated)

Parameters
[in]class_weightsValidated flex_dict Key : Index of the class in the target_metadata Value : Weights on the class

◆ set_threads()

void turi::supervised::logistic_regression_opt_interface::set_threads ( size_t  _n_threads)

Set the number of threads

Parameters
[in]_n_threadsNumber of threads

Member Data Documentation

◆ feature_rescaling

bool turi::supervised::logistic_regression_opt_interface::feature_rescaling = false
protected

<Scale features

Definition at line 62 of file logistic_regression_opt_interface.hpp.

◆ is_dense

bool turi::supervised::logistic_regression_opt_interface::is_dense = false
protected

Feature rescaling

Definition at line 63 of file logistic_regression_opt_interface.hpp.


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