7 #include "spdlog/spdlog.h"
20 throw std::invalid_argument(error_msg);
31 m_Weights(
check_positive(partial.label_count,
"Number of weight must be positive!")),
32 m_NumFeatures(num_features) {
45 PredictVisitor(
const Eigen::Ref<PredictionMatrix>& target,
const std::vector<SparseRealVector>* weights) :
46 Target(target), Weights(weights) {
50 for(
int i = 0; i <
ssize(*Weights); ++i) {
51 Target.col(i) = instances * (*Weights)[i];
56 for(
int i = 0; i <
ssize(*Weights); ++i) {
57 Target.col(i) = instances * (*Weights)[i];
62 for(
int i = 0; i <
ssize(*Weights); ++i) {
63 Target.col(i) = instances * (*Weights)[i];
68 types::SparseColMajor<real_t> copy = instances;
69 for(
int i = 0; i <
ssize(*Weights); ++i) {
70 Target.col(i) = copy * (*Weights)[i];
75 const std::vector<SparseRealVector>*
Weights;
80 PredictVisitor visitor(target, &
m_Weights);
81 visit(visitor, instances);
91 Label(label), Target(target) {
97 for(
long i = 0; i < source.size(); ++i) {
98 if(abs(source.coeff(i)) > 0) {
99 Target->insert(i) = source.coeff(i);
115 visit(visitor, weights);
Strong typedef for an int to signify a label id.
A model combines a set of weight with some meta-information about these weights.
Eigen::Ref< PredictionMatrix > PredictionMatrixOut
SparseModel(long num_features, long num_labels)
long num_features() const override
How many weights are in each weight vector, i.e. how many features should the input have.
void predict_scores_unchecked(const FeatureMatrixIn &instances, PredictionMatrixOut target) const override
Unchecked version of predict_scores().
void set_weights_for_label_unchecked(label_id_t label, const WeightVectorIn &weights) override
Unchecked version of set_weights_for_label().
std::vector< SparseRealVector > m_Weights
void get_weights_for_label_unchecked(label_id_t label, Eigen::Ref< DenseRealVector > target) const override
Unchecked version of get_weights_for_label().
constexpr T to_index() const
! Explicitly convert to an integer.
Eigen::Ref< SparseColMajor< T > > SparseColMajorRef
Eigen::Ref< SparseRowMajor< T > > SparseRowMajorRef
Eigen::Ref< DenseColMajor< T > > DenseColMajorRef
Eigen::Ref< DenseRowMajor< T > > DenseRowMajorRef
Eigen::Ref< DenseVector< T > > DenseRef
Eigen::Ref< SparseVector< T > > SparseRef
long check_positive(long v, const char *error_msg)
auto visit(F &&f, Variants &&... variants)
Main namespace in which all types, classes, and functions are defined.
constexpr auto ssize(const C &c) -> std::common_type_t< std::ptrdiff_t, std::make_signed_t< decltype(c.size())>>
signed size free function. Taken from https://en.cppreference.com/w/cpp/iterator/size
Eigen::Ref< PredictionMatrix > Target
void operator()(const GenericInMatrix::SparseColMajorRef &instances)
void operator()(const GenericInMatrix::DenseRowMajorRef &instances)
void operator()(const GenericInMatrix::DenseColMajorRef &instances)
void operator()(const GenericInMatrix::SparseRowMajorRef &instances)
PredictVisitor(const Eigen::Ref< PredictionMatrix > &target, const std::vector< SparseRealVector > *weights)
const std::vector< SparseRealVector > * Weights
void operator()(const GenericInVector::SparseRef &source)
void operator()(const GenericInVector::DenseRef &source)
SetWeightsVisitor(label_id_t label, Eigen::SparseVector< real_t > *target)
Eigen::SparseVector< real_t > * Target
Specifies how to interpret a weight matrix for a partial model.