Turi Create
4.0
|
#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 |
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.
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
[in] | _data | ML Data containing everything |
turi::supervised::linear_svm_scaled_logistic_opt_interface::~linear_svm_scaled_logistic_opt_interface | ( | ) |
Default destructor
|
virtual |
Compute first order statistics at the given point. (Gradient & Function value)
[in] | point | Point at which we are computing the stats. |
[out] | gradient | Dense gradient |
[out] | function_value | Function value |
[in] | mbStart | Minibatch start index |
[in] | mbSize | Minibatch size (-1 implies all) |
Implements turi::optimization::first_order_opt_interface.
|
virtualinherited |
Compute the function value at a given point.
[in] | point | Point at which we are computing the gradient. |
[in] | mbStart | Minibatch start index |
[in] | mbSize | Minibatch size (-1 implies all) |
|
virtualinherited |
Compute a gradient at the given point.
[in] | point | Point at which we are computing the gradient. |
[out] | gradient | Dense gradient |
[in] | mbStart | Minibatch start index |
[in] | mbSize | Minibatch size (-1 implies all) |
|
virtual |
Get strings needed to print a row of the progress table.
[in] | a | vector of model coefficients. |
[in] | a | vector of stats to print at the beginning of each row |
Reimplemented from turi::optimization::first_order_opt_interface.
|
virtual |
Get strings needed to print the header for the progress table.
[in] | a | vector of strings to print at the beginning of the header. |
Reimplemented from turi::optimization::first_order_opt_interface.
void turi::supervised::linear_svm_scaled_logistic_opt_interface::init_feature_rescaling | ( | ) |
Set feature scaling
size_t turi::supervised::linear_svm_scaled_logistic_opt_interface::num_classes | ( | ) | const |
Get the number of classes in the model
|
virtual |
Get the number of examples for the model
Implements turi::optimization::first_order_opt_interface.
size_t turi::supervised::linear_svm_scaled_logistic_opt_interface::num_validation_examples | ( | ) | const |
Get the number of validation-set examples for the model
|
virtual |
Get the number of variables in the model
Implements turi::optimization::first_order_opt_interface.
void turi::supervised::linear_svm_scaled_logistic_opt_interface::rescale_solution | ( | DenseVector & | coefs | ) |
Transform the final solution back to the original scale.
[in,out] | coefs | Solution vector |
|
virtualinherited |
Reset the state of the model's "randomness" source.
[in] | seed | Seed that is the source of randomness. |
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)
[in] | class_weights | Validated flex_dict Key : Index of the class in the target_metadata Value : Weights on the class |
void turi::supervised::linear_svm_scaled_logistic_opt_interface::set_gamma | ( | const double | _gamma | ) |
Set the scale for the scaled logistic loss.
[in] | _gamma | Set the Gamma |
void turi::supervised::linear_svm_scaled_logistic_opt_interface::set_threads | ( | size_t | _n_threads | ) |
Set the number of threads
[in] | _n_threads | Number of threads |
|
protected |
Number of classes
Definition at line 59 of file linear_svm_opt_interface.hpp.
|
protected |
Num examples
Definition at line 57 of file linear_svm_opt_interface.hpp.
|
protected |
<Scale features
Definition at line 65 of file linear_svm_opt_interface.hpp.
|
protected |
Num features
Definition at line 56 of file linear_svm_opt_interface.hpp.
|
protected |
Feature rescaling
Definition at line 66 of file linear_svm_opt_interface.hpp.
|
protected |
Primal variables
Definition at line 58 of file linear_svm_opt_interface.hpp.