9 #include "spdlog/spdlog.h"
15 m_Data(data), m_A(a), m_B(b)
18 throw std::invalid_argument(
"data must not be nullptr");
26 return 1.0 / (1.0 + d);
38 m_PositiveCost(positive_cost), m_NegativeCost(negative_cost) {
39 if(positive_cost < 0 || negative_cost < 0) {
40 throw std::invalid_argument(
"Negative cost");
71 m_PositiveWeights(std::move(positive_weights)), m_NegativeWeights(std::move(negative_weights)) {
74 throw std::logic_error(fmt::format(
"Mismatched number of entries: {} in positive and {} in negative weights",
83 throw std::logic_error(fmt::format(
"Trying to get positive weight for label {}, but only {} weights are known.",
92 throw std::logic_error(fmt::format(
"Trying to get positive weight for label {}, but only {} weights are known.",
103 auto labels = std::make_shared<BinaryLabelVector>(BinaryLabelVector::Zero(50));
104 labels->coeffRef(0) = 1;
110 CHECK(prop == doctest::Approx(0.25562221863533147));
112 for(
int i = 0; i < 25; ++i) {
113 labels->coeffRef(i) = 1;
118 CHECK(prop == doctest::Approx(0.5571545100089221));
134 auto labels = std::make_shared<BinaryLabelVector>(BinaryLabelVector::Zero(50));
135 labels->coeffRef(0) = 1;
138 CHECK(pw.get_positive_weight(
label_id_t{0}) == doctest::Approx(2.0 / 0.25562221863533147 - 1.0));
139 CHECK(pw.get_negative_weight(
label_id_t{0}) == doctest::Approx(1.0));
Collects the data related to a single optimization problem.
Simple weighting scheme that assigns the same weighting to all label_ids.
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.
ConstantWeighting(double positive_cost, double negative_cost)
double m_NegativeCost
Cost to use if the label is absent, independent of the label_id.
double m_PositiveCost
Cost to use if the label is present, independent of the label_id.
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.
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.
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.
DenseRealVector m_NegativeWeights
DenseRealVector m_PositiveWeights
CustomWeighting(DenseRealVector positive_weights, DenseRealVector negative_weights)
long num_examples() const noexcept
Get the total number of instances, i.e. the number of rows in the feature matrix.
virtual long num_positives(label_id_t id) const
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.
PropensityModel m_Propensity
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.
PropensityDownWeighting(PropensityModel model)
const DatasetBase * m_Data
PropensityModel(const DatasetBase *data, double a=0.55, double b=1.5)
double get_propensity(label_id_t label_id) const
PropensityModel m_Propensity
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.
PropensityWeighting(PropensityModel model)
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.
Strong typedef for an int to signify a label id.
constexpr T to_index() const
! Explicitly convert to an integer.
Main namespace in which all types, classes, and functions are defined.
types::DenseVector< real_t > DenseRealVector
Any dense, real values vector.
types::SparseRowMajor< real_t > SparseFeatures
Sparse Feature Matrix in Row Major format.
TEST_CASE("propensity calculation")