DiSMEC++
|
A utility class template that, when instatiated with a MarginFunction
, produces the corresponding linear classifier loss.
More...
#include <generic_linear.h>
Public Member Functions | |
GenericMarginClassifier (std::shared_ptr< const GenericFeatureMatrix > X, std::unique_ptr< Objective > regularizer, MarginFunction phi) | |
void | calculate_loss (const DenseRealVector &scores, const BinaryLabelVector &labels, DenseRealVector &out) const override |
Calculates the loss for each instance. More... | |
void | calculate_derivative (const DenseRealVector &scores, const BinaryLabelVector &labels, DenseRealVector &out) const override |
Calculates the derivative of the loss with respect to the scores for each instance. More... | |
void | calculate_2nd_derivative (const DenseRealVector &scores, const BinaryLabelVector &labels, DenseRealVector &out) const override |
Calculates the 2nd derivative of the loss with respect to the scores for each instance. More... | |
Public Member Functions inherited from dismec::objective::GenericLinearClassifier | |
GenericLinearClassifier (std::shared_ptr< const GenericFeatureMatrix > X, std::unique_ptr< Objective > regularizer) | |
Public Member Functions inherited from dismec::objective::LinearClassifierBase | |
LinearClassifierBase (std::shared_ptr< const GenericFeatureMatrix > X) | |
long | num_instances () const noexcept |
long | num_variables () const noexcept override |
BinaryLabelVector & | get_label_ref () |
void | update_costs (real_t positive, real_t negative) |
Public Member Functions inherited from dismec::objective::Objective | |
Objective () | |
virtual | ~Objective () noexcept=default |
real_t | value (const HashVector &location) |
Evaluate the objective at the given location . More... | |
void | diag_preconditioner (const HashVector &location, Eigen::Ref< DenseRealVector > target) |
Get precondition to be used in CG optimization. More... | |
void | project_to_line (const HashVector &location, const DenseRealVector &direction) |
creates a function g such that g(a) = objective(location + a * direction) Use lookup_on_line() to evaluate g . More... | |
void | gradient_at_zero (Eigen::Ref< DenseRealVector > target) |
Gets the gradient for location zero. More... | |
void | gradient (const HashVector &location, Eigen::Ref< DenseRealVector > target) |
Evaluate the gradient at location . More... | |
void | hessian_times_direction (const HashVector &location, const DenseRealVector &direction, Eigen::Ref< DenseRealVector > target) |
Calculates the product of the Hessian matrix at location with direction . More... | |
void | gradient_and_pre_conditioner (const HashVector &location, Eigen::Ref< DenseRealVector > gradient, Eigen::Ref< DenseRealVector > pre) |
Combines the calculation of gradient and pre-conditioner, which may be more efficient in some cases. More... | |
Public Member Functions inherited from dismec::stats::Tracked | |
Tracked () | |
Default constructor, creates the internal stats::StatisticsCollection . More... | |
void | register_stat (const std::string &name, std::unique_ptr< Statistics > stat) |
Registers a tracker for the statistics name . More... | |
std::shared_ptr< StatisticsCollection > | get_stats () const |
Gets an ownership-sharing reference to the StatisticsCollection . More... | |
Public Attributes | |
MarginFunction | Phi |
Additional Inherited Members | |
Protected Member Functions inherited from dismec::objective::LinearClassifierBase | |
const DenseRealVector & | x_times_w (const HashVector &w) |
Calculates the vector of feature matrix times weights w More... | |
template<class Derived > | |
void | update_xtw_cache (const HashVector &new_weight, const Eigen::MatrixBase< Derived > &new_result) |
Updates the cached value for x_times_w. More... | |
void | project_linear_to_line (const HashVector &location, const DenseRealVector &direction) |
Prepares the cache variables for line projection. More... | |
auto | line_interpolation (real_t t) const |
void | declare_vector_on_last_line (const HashVector &location, real_t t) override |
State that the given vector corresponds to a certain position on the line of the last line search. More... | |
const GenericFeatureMatrix & | generic_features () const |
const DenseFeatures & | dense_features () const |
const SparseFeatures & | sparse_features () const |
const DenseRealVector & | costs () const |
const BinaryLabelVector & | labels () const |
Protected Member Functions inherited from dismec::stats::Tracked | |
~Tracked () | |
Non-virtual destructor. Declared protected, so we don't accidentally try to do a polymorphic delete. More... | |
template<class T > | |
void | record (stat_id_t stat, T &&value) |
Record statistics. This function just forwards all its arguments to the internal StatisticsCollection . More... | |
void | declare_stat (stat_id_t index, StatisticMetaData meta) |
Declares a new statistics. This function just forwards all its arguments to the internal StatisticsCollection . More... | |
void | declare_tag (tag_id_t index, std::string name) |
Declares a new tag. This function just forwards all its arguments to the internal StatisticsCollection . More... | |
template<class... Args> | |
void | set_tag (tag_id_t tag, long value) |
Set value of tag. This function just forwards all its arguments to the internal StatisticsCollection . More... | |
template<class... Args> | |
auto | make_timer (stat_id_t id, Args... args) |
Creates a new ScopeTimer using stats::record_scope_time . More... | |
A utility class template that, when instatiated with a MarginFunction
, produces the corresponding linear classifier loss.
MarginFunction | A class that needs to provide three scalar functions: value , grad , and quad that give the value, first order, and second order approximation to the function at the given point. |
Definition at line 120 of file generic_linear.h.
|
inline |
Definition at line 121 of file generic_linear.h.
|
inlineoverridevirtual |
Calculates the 2nd derivative of the loss with respect to the scores for each instance.
[in] | scores | The scores, i.e. the product weights times features, for each instance. |
[in] | labels | The binary labels as a vector of plus and minus ones. |
[out] | out | This vector will be filled with the instance-wise loss 2nd derivatives. |
Implements dismec::objective::GenericLinearClassifier.
Definition at line 149 of file generic_linear.h.
References dismec::objective::LinearClassifierBase::labels(), and dismec::objective::GenericMarginClassifier< MarginFunction >::Phi.
|
inlineoverridevirtual |
Calculates the derivative of the loss with respect to the scores for each instance.
[in] | scores | The scores, i.e. the product weights times features, for each instance. |
[in] | labels | The binary labels as a vector of plus and minus ones. |
[out] | out | This vector will be filled with the instance-wise loss derivatives. |
Implements dismec::objective::GenericLinearClassifier.
Definition at line 138 of file generic_linear.h.
References dismec::objective::LinearClassifierBase::labels(), and dismec::objective::GenericMarginClassifier< MarginFunction >::Phi.
|
inlineoverridevirtual |
Calculates the loss for each instance.
[in] | scores | The scores, i.e. the product weights times features, for each instance. |
[in] | labels | The binary labels as a vector of plus and minus ones. |
[out] | out | This vector will be filled with the instance-wise loss value. |
Implements dismec::objective::GenericLinearClassifier.
Definition at line 128 of file generic_linear.h.
References dismec::objective::LinearClassifierBase::labels(), and dismec::objective::GenericMarginClassifier< MarginFunction >::Phi.
MarginFunction dismec::objective::GenericMarginClassifier< MarginFunction >::Phi |
Definition at line 159 of file generic_linear.h.
Referenced by dismec::objective::GenericMarginClassifier< MarginFunction >::calculate_2nd_derivative(), dismec::objective::GenericMarginClassifier< MarginFunction >::calculate_derivative(), and dismec::objective::GenericMarginClassifier< MarginFunction >::calculate_loss().