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

#include <toolkits/supervised_learning/linear_svm_opt_interface.hpp>

Public Member Functions

 linear_svm_scaled_logistic_opt_interface (const ml_data &_data, const ml_data &_valid_data, linear_svm &model)
 
void set_gamma (const double _gamma)
 
 ~linear_svm_scaled_logistic_opt_interface ()
 
void init_feature_rescaling ()
 
void rescale_solution (DenseVector &coefs)
 
void set_threads (size_t _n_threads)
 
size_t num_examples () const
 
size_t num_validation_examples () const
 
size_t num_variables () 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 set_class_weights (const flexible_type &class_weights)
 
size_t num_classes () const
 
void compute_first_order_statistics (const DenseVector &point, DenseVector &gradient, double &function_value, const size_t mbStart=0, const size_t mbSize=-1)
 
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

size_t features
 
size_t examples
 
size_t primal_variables
 
size_t classes = 2
 
bool feature_rescaling = false
 
double gamma = 30
 

Detailed Description

Scaled Logistic Loss function

SVM is trained using LBFGS on the Modifified logistic function described in [1]. It is much simpler to optimize and very close to the hinge loss.

References:

[1] Modified Logistic Regression: An Approximation to SVM and Its Applications in Large-Scale Text Categorization - Zhang et al ICML 2003

Definition at line 46 of file linear_svm_opt_interface.hpp.

Constructor & Destructor Documentation

◆ linear_svm_scaled_logistic_opt_interface()

turi::supervised::linear_svm_scaled_logistic_opt_interface::linear_svm_scaled_logistic_opt_interface ( const ml_data _data,
const ml_data _valid_data,
linear_svm model 
)

Is the data dense? Default constructor

Parameters
[in]_dataML Data containing everything

◆ ~linear_svm_scaled_logistic_opt_interface()

turi::supervised::linear_svm_scaled_logistic_opt_interface::~linear_svm_scaled_logistic_opt_interface ( )

Default destructor

Member Function Documentation

◆ compute_first_order_statistics()

void turi::supervised::linear_svm_scaled_logistic_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.

◆ get_status()

std::vector<std::string> turi::supervised::linear_svm_scaled_logistic_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::linear_svm_scaled_logistic_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::linear_svm_scaled_logistic_opt_interface::init_feature_rescaling ( )

Set feature scaling

◆ num_classes()

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

Get the number of classes in the model

Returns
Number of classes

◆ num_examples()

size_t turi::supervised::linear_svm_scaled_logistic_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::linear_svm_scaled_logistic_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::linear_svm_scaled_logistic_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::linear_svm_scaled_logistic_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::linear_svm_scaled_logistic_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_gamma()

void turi::supervised::linear_svm_scaled_logistic_opt_interface::set_gamma ( const double  _gamma)

Set the scale for the scaled logistic loss.

Parameters
[in]_gammaSet the Gamma

◆ set_threads()

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

Set the number of threads

Parameters
[in]_n_threadsNumber of threads

Member Data Documentation

◆ classes

size_t turi::supervised::linear_svm_scaled_logistic_opt_interface::classes = 2
protected

Number of classes

Definition at line 59 of file linear_svm_opt_interface.hpp.

◆ examples

size_t turi::supervised::linear_svm_scaled_logistic_opt_interface::examples
protected

Num examples

Definition at line 57 of file linear_svm_opt_interface.hpp.

◆ feature_rescaling

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

<Scale features

Definition at line 65 of file linear_svm_opt_interface.hpp.

◆ features

size_t turi::supervised::linear_svm_scaled_logistic_opt_interface::features
protected

Num features

Definition at line 56 of file linear_svm_opt_interface.hpp.

◆ gamma

double turi::supervised::linear_svm_scaled_logistic_opt_interface::gamma = 30
protected

Feature rescaling

Definition at line 66 of file linear_svm_opt_interface.hpp.

◆ primal_variables

size_t turi::supervised::linear_svm_scaled_logistic_opt_interface::primal_variables
protected

Primal variables

Definition at line 58 of file linear_svm_opt_interface.hpp.


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