DiSMEC++
|
#include <submodel.h>
Public Member Functions | |
SubModelWrapper (T original, label_id_t begin, label_id_t end) | |
long | num_features () const override |
How many weights are in each weight vector, i.e. how many features should the input have. More... | |
bool | has_sparse_weights () const override |
whether this model stores the weights in a sparse format, or a dense format. More... | |
void | get_weights_for_label_unchecked (label_id_t label, Eigen::Ref< DenseRealVector > target) const override |
Unchecked version of get_weights_for_label(). More... | |
void | set_weights_for_label_unchecked (label_id_t label, const GenericInVector &weights) override |
Unchecked version of set_weights_for_label(). More... | |
void | predict_scores_unchecked (const GenericInMatrix &instances, PredictionMatrixOut target) const override |
Unchecked version of predict_scores(). More... | |
![]() | |
Model (PartialModelSpec spec) | |
virtual | ~Model ()=default |
long | num_labels () const noexcept |
How many labels are in the underlying dataset. More... | |
long | num_weights () const noexcept |
How many weights vectors are in this model. More... | |
bool | is_partial_model () const |
returns true if this instance only stores part of the weights of an entire model More... | |
label_id_t | labels_begin () const noexcept |
label_id_t | labels_end () const noexcept |
long | contained_labels () const noexcept |
How many labels are in this submodel. More... | |
void | get_weights_for_label (label_id_t label, Eigen::Ref< DenseRealVector > target) const |
Gets the weights for the given label as a dense vector. More... | |
void | set_weights_for_label (label_id_t label, const WeightVectorIn &weights) |
Sets the weights for a label. More... | |
void | predict_scores (const FeatureMatrixIn &instances, PredictionMatrixOut target) const |
Calculates the scores for all examples and all labels in this model. More... | |
Private Types | |
using | model_t = std::remove_reference_t< decltype(*std::declval< T >())> |
Private Attributes | |
T | m_Original |
Additional Inherited Members | |
![]() | |
using | PredictionMatrixOut = Eigen::Ref< PredictionMatrix > |
using | FeatureMatrixIn = GenericInMatrix |
using | WeightVectorIn = GenericInVector |
![]() | |
label_id_t | adjust_label (label_id_t label) const |
Definition at line 13 of file submodel.h.
|
private |
Definition at line 14 of file submodel.h.
|
inline |
Definition at line 17 of file submodel.h.
|
inlineoverridevirtual |
Unchecked version of get_weights_for_label().
Since we do not know whether the weights saved in the model are sparse or dense vectors, we cannot simply return a const reference here. Instead, the user is required to provide a pre-allocated buffer target
into which the weights will be copied.
If | target does not have the correct size, or if label is invalid. |
get_weights_for_label
and can assume label is a valid label index that has been corrected for partial models (i.e. such that the first label of the partial model will get the index 0
). Target can be assumed to be of correct size. Implements dismec::model::Model.
Definition at line 25 of file submodel.h.
References dismec::model::Model::labels_begin(), dismec::model::SubModelWrapper< T >::m_Original, and dismec::opaque_int_type< Tag, T >::to_index().
|
inlineoverridevirtual |
whether this model stores the weights in a sparse format, or a dense format.
Implements dismec::model::Model.
Definition at line 23 of file submodel.h.
References dismec::model::SubModelWrapper< T >::m_Original.
|
inlineoverridevirtual |
How many weights are in each weight vector, i.e. how many features should the input have.
Implements dismec::model::Model.
Definition at line 22 of file submodel.h.
References dismec::model::SubModelWrapper< T >::m_Original.
|
inlineoverridevirtual |
Unchecked version of predict_scores().
This is just the matrix multiplication of the input instances and the weight matrix. This function can be called safely from multiple threads. Note that Eigen::Ref requires that the passed submatrix has an inner stride of 1, i.e. that features for a single instance are provided as contiguous memory (in case of dense features), and the same for the pre-allocated buffer for the targets. This can be achieved e.g. by using rows of a row-major matrix.
instances | Feature vector of the instances for which we want to predict the scores. This is handled as a Eigen::Ref parameter so that subsets of a large dataset can be passed without needing data to be copied. Should have number of columns equal to the number of features. The GenericInMatrix allows different data formats to be passed – however, some data formats may be more efficient than others. |
target | This is the matrix to which the scores will be written. Has to have the correct size, i.e. the same number of rows as instances and number of columns equal to the number of labels. |
If | instances and target have different number of rows, or if the number of columns (rows) in instances (target ) does not match get_num_features() (get_num_labels() ). |
predict_scores
and can assume that the shapes of instances
and target
have been verified. Implements dismec::model::Model.
Definition at line 38 of file submodel.h.
|
inlineoverridevirtual |
Unchecked version of set_weights_for_label().
This assigns the given vector as weights for the label
th label. For non-overlapping label
parameters this function can safely be called concurrently from different threads. This function can be used for both dense and sparse internal weight representation. If the model internally uses a sparse representation, the zeros will be filtered out.
If | weights does not have the correct size, or if label is invalid. |
set_weights_for_label
and can assume label is a valid label index that has been corrected for partial models (i.e. such that the first label of the partial model will get the index 0
). weights
can be assumed to be of correct size. Implements dismec::model::Model.
Definition at line 29 of file submodel.h.
References dismec::model::Model::labels_begin(), dismec::model::SubModelWrapper< T >::m_Original, and dismec::opaque_int_type< Tag, T >::to_index().
|
private |
Definition at line 42 of file submodel.h.
Referenced by dismec::model::SubModelWrapper< T >::get_weights_for_label_unchecked(), dismec::model::SubModelWrapper< T >::has_sparse_weights(), dismec::model::SubModelWrapper< T >::num_features(), and dismec::model::SubModelWrapper< T >::set_weights_for_label_unchecked().