DiSMEC++
regularizers_imp.h
Go to the documentation of this file.
1 // Copyright (c) 2021, Aalto University, developed by Erik Schultheis
2 // All rights reserved.
3 //
4 // SPDX-License-Identifier: MIT
5 
6 #ifndef DISMEC_REGULARIZERS_IMP_H
7 #define DISMEC_REGULARIZERS_IMP_H
8 
9 #include "objective.h"
10 #include "utils/hash_vector.h"
11 #include "pointwise.h"
12 
19 namespace dismec::objective {
20 
30  class SquaredNormRegularizer : public PointWiseRegularizer<SquaredNormRegularizer> {
31  public:
32  explicit SquaredNormRegularizer(real_t scale = 1, bool ignore_bias=false);
33 
34  [[nodiscard]] static real_t point_wise_value(real_t x);
35  [[nodiscard]] static real_t point_wise_grad(real_t x);
36  [[nodiscard]] static real_t point_wise_quad(real_t x);
37 
38  [[nodiscard]] real_t value_unchecked(const HashVector& location) override;
39 
49  void project_to_line_unchecked(const HashVector& location, const DenseRealVector& direction) override;
50  real_t lookup_on_line(real_t a) override;
51 
52  private:
56  };
57 
70  class HuberRegularizer : public PointWiseRegularizer<HuberRegularizer> {
71  public:
77  explicit HuberRegularizer(real_t epsilon, real_t scale = 1.0, bool ignore_bias=false);
78 
79  [[nodiscard]] real_t point_wise_value(real_t x) const;
80  [[nodiscard]] real_t point_wise_grad(real_t x) const;
81  [[nodiscard]] real_t point_wise_quad(real_t x) const;
82  private:
84  };
85 
86  class ElasticNetRegularizer : public PointWiseRegularizer<ElasticNetRegularizer> {
87  public:
96  ElasticNetRegularizer(real_t epsilon, real_t scale, real_t interp, bool ignore_bias=false);
97 
98  [[nodiscard]] real_t point_wise_value(real_t x) const;
99  [[nodiscard]] real_t point_wise_grad(real_t x) const;
100  [[nodiscard]] real_t point_wise_quad(real_t x) const;
101  private:
105  };
106 }
107 
108 #endif //DISMEC_REGULARIZERS_IMP_H
An Eigen vector with versioning information, to implement simple caching of results.
Definition: hash_vector.h:43
ElasticNetRegularizer(real_t epsilon, real_t scale, real_t interp, bool ignore_bias=false)
Constructor for a ElasticNet regularizer objective.
This class implements a huber regularizer.
HuberRegularizer(real_t epsilon, real_t scale=1.0, bool ignore_bias=false)
Constructor for a Huber regularizer objective.
real_t point_wise_value(real_t x) const
real_t point_wise_quad(real_t x) const
real_t point_wise_grad(real_t x) const
Base class for pointwise regularization functions.
Definition: pointwise.h:39
real_t scale() const
Returns the common scale factor for the entire regularizer.
Definition: pointwise.h:69
This class implements a squared norm (L2) regularizer. Thus f(x) = 0.5 |x|^2.
real_t lookup_on_line(real_t a) override
Looks up the value of the objective on the line defined by the last call to project_to_line().
SquaredNormRegularizer(real_t scale=1, bool ignore_bias=false)
real_t value_unchecked(const HashVector &location) override
void project_to_line_unchecked(const HashVector &location, const DenseRealVector &direction) override
types::DenseVector< real_t > DenseRealVector
Any dense, real values vector.
Definition: matrix_types.h:40
float real_t
The default type for floating point values.
Definition: config.h:17