forpy  2
idataprovider.h
Go to the documentation of this file.
1 /* Author: Christoph Lassner. */
2 #pragma once
3 #ifndef FORPY_DATA_PROVIDERS_IDATAPROVIDER_H_
4 #define FORPY_DATA_PROVIDERS_IDATAPROVIDER_H_
5 
6 #include "../global.h"
7 #include "../util/serialization/basics.h"
8 
9 #include <functional>
10 #include <vector>
11 
12 #include "../types.h"
13 #include "../util/storage.h"
14 
15 namespace forpy {
16 
23  public:
24  inline virtual ~IDataProvider(){};
25 
32  virtual std::vector<id_t> &get_initial_sample_list()
33  VIRTUAL(std::vector<id_t>);
34 
36  virtual size_t get_n_samples() const VIRTUAL_VOID;
37 
42  virtual Data<VecCMap> get_feature(const size_t & /*feat_idx*/) const {
43  throw ForpyException("`get_feature` not implemented!");
44  };
45 
49  virtual Data<MatCRef> get_annotations() const {
50  throw ForpyException("`get_annotations` not implemented!");
51  };
52 
63  virtual void set_annotations(const DataStore<Mat> &new_annotations)
65 
71  virtual std::shared_ptr<const std::vector<float>> get_weights() const
73 
77  inline size_t get_feat_vec_dim() const { return feat_vec_dim; };
78 
82  inline size_t get_annot_vec_dim() const { return annot_vec_dim; };
83 
97  virtual std::vector<std::shared_ptr<IDataProvider>> create_tree_providers(
98  usage_map_t &usage_map)
99  VIRTUAL(std::vector<std::shared_ptr<IDataProvider>>);
100 
101  virtual bool operator==(const IDataProvider &rhs) const VIRTUAL(bool);
102 
103  protected:
107  explicit IDataProvider(const size_t &feature_dimension,
108  const size_t &annotation_dimension);
109 
113  // cppcheck-suppress uninitVar
114  inline IDataProvider(){};
115 
117  size_t feat_vec_dim;
120 
121  private:
122  friend class cereal::access;
123  template <class Archive>
124  void serialize(Archive &ar, const uint &) {
125  ar(CEREAL_NVP(feat_vec_dim), CEREAL_NVP(annot_vec_dim));
126  }
127 };
128 } // namespace forpy
129 #endif // FORPY_DATA_PROVIDERS_IDATAPROVIDER_H_
size_t feat_vec_dim
The dimension of one feature vector.
virtual std::shared_ptr< const std::vector< float > > get_weights() const VIRTUAL_PTR
Get a pointer to the sample weights.
#define VIRTUAL_VOID
Definition: global.h:32
virtual void set_annotations(const DataStore< Mat > &new_annotations) VIRTUAL_VOID
Replace the annotations.
A data provider for the training of one tree.
Definition: idataprovider.h:22
STL namespace.
size_t id_t
Element id type.
Definition: types.h:106
virtual ~IDataProvider()
Definition: idataprovider.h:24
virtual Data< VecCMap > get_feature(const size_t &) const
Get the data for one feature from all samples, contiguously in memory (stride 1). ...
Definition: idataprovider.h:42
std::vector< std::pair< std::shared_ptr< std::vector< size_t > >, std::shared_ptr< std::vector< float > const > > > usage_map_t
Describes how each sample is used for each tree.
Definition: types.h:192
typename mu::variant< Empty, STOT< float >, STOT< double >, STOT< uint >, STOT< uint8_t > > Data
Storing a variant of the provided data container type.
Definition: storage.h:126
typename mu::variant< std::shared_ptr< const STOT< float > >, std::shared_ptr< const STOT< double > >, std::shared_ptr< const STOT< uint > >, std::shared_ptr< const STOT< uint8_t > >> DataStore
Variant for storing shared_ptrs to the stored data matrix type.
Definition: storage.h:119
#define VIRTUAL_PTR
Definition: global.h:33
#define VIRTUAL(type)
Definition: global.h:31
virtual Data< MatCRef > get_annotations() const
Get the full annotation data (must have inner stride 1).
Definition: idataprovider.h:49
size_t get_annot_vec_dim() const
Get the annotation vector dimension.
Definition: idataprovider.h:82
IDataProvider()
Constructor solely for deserialization.
size_t annot_vec_dim
The dimension of one annotation vector.
size_t get_feat_vec_dim() const
Get the feature vector dimension.
Definition: idataprovider.h:77
friend class cereal::access
void serialize(Archive &ar, const uint &)
virtual std::vector< std::shared_ptr< IDataProvider > > virtual create_tree_providers(usage_map_t &usage_map) VIRTUAL(std bool operator==(const IDataProvider &rhs) const VIRTUAL(bool)
Creates the data providers for each tree from the specified usage map.
Eigen::Map< const Eigen::Matrix< DT, 1, Eigen::Dynamic, Eigen::RowMajor >, Eigen::Unaligned, Eigen::InnerStride<> > VecCMap
Definition: types.h:90
unsigned int uint
Convenience typedef for unsigned int.
Definition: types.h:113