MLpp
ml::AbstractLogisticRegression Class Reference

Abstract implementation, sharing the common parameters and stopping criterion. More...

#include <LogisticRegression.hpp>

Inheritance diagram for ml::AbstractLogisticRegression:
Collaboration diagram for ml::AbstractLogisticRegression:

Public Member Functions

 AbstractLogisticRegression ()
 Constructor setting default parameter values.
 
double lam () const
 Returns the regularisation parameter. More...
 
double absolute_tolerance () const
 Returns absolute tolerance for fitted weights.
 
double relative_tolerance () const
 Returns relative tolerance for fitted weights.
 
unsigned int maximum_steps () const
 Returns maximum number of steps allowed.
 
void set_lam (double lam)
 Sets the regularisation parameter. More...
 
void set_absolute_tolerance (double absolute_tolerance)
 Sets absolute tolerance for weight convergence. More...
 
void set_relative_tolerance (double relative_tolerance)
 Sets relative tolerance for weight convergence. More...
 
void set_maximum_steps (unsigned int maximum_steps)
 Sets maximum number of steps.
 
- Public Member Functions inherited from ml::LogisticRegression
virtual ~LogisticRegression ()
 Virtual destructor.
 
virtual Result fit (Eigen::Ref< const Eigen::MatrixXd > X, Eigen::Ref< const Eigen::VectorXd > y) const =0
 Fits the model and returns the result. More...
 

Protected Member Functions

bool weights_converged (Eigen::Ref< const Eigen::VectorXd > old_weights, Eigen::Ref< const Eigen::VectorXd > new_weights) const
 Check if weight fitting converged. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from ml::LogisticRegression
static double probability (Eigen::Ref< const Eigen::VectorXd > x, double y, Eigen::Ref< const Eigen::VectorXd > w)
 Calculates the probability of label given model weights and feature vector. More...
 
static double log_likelihood (Eigen::Ref< const Eigen::MatrixXd > X, Eigen::Ref< const Eigen::VectorXd > y, Eigen::Ref< const Eigen::VectorXd > w, double lam)
 Calculates the posterior log-likelihood of data given model weights. More...
 
static void grad_log_likelihood (Eigen::Ref< const Eigen::MatrixXd > X, Eigen::Ref< const Eigen::VectorXd > y, Eigen::Ref< const Eigen::VectorXd > w, double lam, Eigen::Ref< Eigen::VectorXd > g)
 Calculates the gradient of the posterior log-likelihood of data given model weights, over those weights. More...
 
static void hessian_log_likelihood (Eigen::Ref< const Eigen::MatrixXd > X, Eigen::Ref< const Eigen::VectorXd > y, Eigen::Ref< const Eigen::VectorXd > w, double lam, Eigen::Ref< Eigen::MatrixXd > H)
 Calculates the Hessian of the posterior log-likelihood of data given model weights, over those weights. More...
 

Detailed Description

Abstract implementation, sharing the common parameters and stopping criterion.

The stopping criterion is ||old_weights - new_weights||_2 <= absolute_tolerance + relative_tolerance * max(||old_weights||_2, ||new_weights||_2).

Member Function Documentation

◆ lam()

double ml::AbstractLogisticRegression::lam ( ) const
inline

Returns the regularisation parameter.

Returns
Inverse variance of the Gaussian prior for w. Cannot be negative. Set it to 0 if you want to perform maximum likelihood estimation of w.

◆ set_lam()

void ml::AbstractLogisticRegression::set_lam ( double  lam)

Sets the regularisation parameter.

Parameters
lamInverse variance of the Gaussian prior for w. Cannot be negative. Set it to 0 if you want to perform maximum likelihood estimation of w.
Exceptions
std::domain_errorIf lam is negative.

◆ set_absolute_tolerance()

void ml::AbstractLogisticRegression::set_absolute_tolerance ( double  absolute_tolerance)

Sets absolute tolerance for weight convergence.

Parameters
absolute_toleranceCannot be negative.
Exceptions
std::domain_errorIf negative.

◆ set_relative_tolerance()

void ml::AbstractLogisticRegression::set_relative_tolerance ( double  relative_tolerance)

Sets relative tolerance for weight convergence.

Parameters
relative_toleranceCannot be negative.
Exceptions
std::domain_errorIf negative.

◆ weights_converged()

bool ml::AbstractLogisticRegression::weights_converged ( Eigen::Ref< const Eigen::VectorXd >  old_weights,
Eigen::Ref< const Eigen::VectorXd >  new_weights 
) const
protected

Check if weight fitting converged.

Parameters
old_weightsPrevious weight vector.
new_weightsNew weight vector.
Returns
True if converged, false otherwise.

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