DiSMEC++
weighting.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_WEIGHTING_H
7 #define DISMEC_WEIGHTING_H
8 
9 #include "matrix_types.h"
10 #include "fwd.h"
11 
12 namespace dismec
13 {
15  public:
16  explicit PropensityModel(const DatasetBase* data, double a=0.55, double b=1.5);
17  [[nodiscard]] double get_propensity(label_id_t label_id) const;
18  private:
20  double m_A;
21  double m_B;
22  double m_C;
23  };
24 
33  public:
34  virtual ~WeightingScheme() = default;
36  [[nodiscard]] virtual double get_positive_weight(label_id_t label_id) const = 0;
38  [[nodiscard]] virtual double get_negative_weight(label_id_t label_id) const = 0;
39  };
40 
47  public:
48  ConstantWeighting(double positive_cost, double negative_cost);
49  [[nodiscard]] double get_positive_weight(label_id_t label_id) const override;
50  [[nodiscard]] double get_negative_weight(label_id_t label_id) const override;
51  private:
52  double m_PositiveCost;
53  double m_NegativeCost;
54  };
55 
57  public:
58  explicit PropensityWeighting(PropensityModel model);
59  [[nodiscard]] double get_positive_weight(label_id_t label_id) const override;
60  [[nodiscard]] double get_negative_weight(label_id_t label_id) const override;
61  private:
63  };
64 
66  public:
68  [[nodiscard]] double get_positive_weight(label_id_t label_id) const override;
69  [[nodiscard]] double get_negative_weight(label_id_t label_id) const override;
70  private:
72  };
73 
75  public:
76  explicit CustomWeighting(DenseRealVector positive_weights, DenseRealVector negative_weights);
77 
78  [[nodiscard]] double get_positive_weight(label_id_t label_id) const override;
79  [[nodiscard]] double get_negative_weight(label_id_t label_id) const override;
80  private:
83  };
84 }
85 
86 #endif //DISMEC_WEIGHTING_H
Simple weighting scheme that assigns the same weighting to all label_ids.
Definition: weighting.h:46
double get_positive_weight(label_id_t label_id) const override
Gets the weight to use for all examples where the label label_id is present.
Definition: weighting.cpp:29
ConstantWeighting(double positive_cost, double negative_cost)
Definition: weighting.cpp:37
double m_NegativeCost
Cost to use if the label is absent, independent of the label_id.
Definition: weighting.h:53
double m_PositiveCost
Cost to use if the label is present, independent of the label_id.
Definition: weighting.h:52
double get_negative_weight(label_id_t label_id) const override
Gets the weight to use for all examples where the label label_id is absent.
Definition: weighting.cpp:33
double get_positive_weight(label_id_t label_id) const override
Gets the weight to use for all examples where the label label_id is present.
Definition: weighting.cpp:80
double get_negative_weight(label_id_t label_id) const override
Gets the weight to use for all examples where the label label_id is absent.
Definition: weighting.cpp:89
DenseRealVector m_NegativeWeights
Definition: weighting.h:82
DenseRealVector m_PositiveWeights
Definition: weighting.h:81
CustomWeighting(DenseRealVector positive_weights, DenseRealVector negative_weights)
Definition: weighting.cpp:70
double get_positive_weight(label_id_t label_id) const override
Gets the weight to use for all examples where the label label_id is present.
Definition: weighting.cpp:60
PropensityModel m_Propensity
Definition: weighting.h:71
double get_negative_weight(label_id_t label_id) const override
Gets the weight to use for all examples where the label label_id is absent.
Definition: weighting.cpp:64
PropensityDownWeighting(PropensityModel model)
Definition: weighting.cpp:56
const DatasetBase * m_Data
Definition: weighting.h:19
PropensityModel(const DatasetBase *data, double a=0.55, double b=1.5)
Definition: weighting.cpp:14
double get_propensity(label_id_t label_id) const
Definition: weighting.cpp:23
PropensityModel m_Propensity
Definition: weighting.h:62
double get_negative_weight(label_id_t label_id) const override
Gets the weight to use for all examples where the label label_id is absent.
Definition: weighting.cpp:52
PropensityWeighting(PropensityModel model)
Definition: weighting.cpp:44
double get_positive_weight(label_id_t label_id) const override
Gets the weight to use for all examples where the label label_id is present.
Definition: weighting.cpp:48
Base class for label-based weighting schemes.
Definition: weighting.h:32
virtual ~WeightingScheme()=default
virtual double get_positive_weight(label_id_t label_id) const =0
Gets the weight to use for all examples where the label label_id is present.
virtual double get_negative_weight(label_id_t label_id) const =0
Gets the weight to use for all examples where the label label_id is absent.
Strong typedef for an int to signify a label id.
Definition: types.h:20
Forward-declares types.
Main namespace in which all types, classes, and functions are defined.
Definition: app.h:15
types::DenseVector< real_t > DenseRealVector
Any dense, real values vector.
Definition: matrix_types.h:40