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
22 class IDataProvider {
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)
64 VIRTUAL_VOID;
65
71 virtual std::shared_ptr<const std::vector<float>> get_weights() const
72 VIRTUAL_PTR;
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;
119 size_t annot_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_
forpy::IDataProvider::feat_vec_dim
size_t feat_vec_dim
The dimension of one feature vector.
Definition: idataprovider.h:114
forpy::IDataProvider::get_weights
virtual std::shared_ptr< const std::vector< float > > get_weights() const VIRTUAL_PTR
Get a pointer to the sample weights.
VIRTUAL_VOID
#define VIRTUAL_VOID
Definition: global.h:32
forpy::IDataProvider::set_annotations
virtual void set_annotations(const DataStore< Mat > &new_annotations) VIRTUAL_VOID
Replace the annotations.
forpy::IDataProvider
A data provider for the training of one tree.
Definition: idataprovider.h:22
std
STL namespace.
forpy::id_t
size_t id_t
Element id type.
Definition: types.h:106
forpy::IDataProvider::~IDataProvider
virtual ~IDataProvider()
Definition: idataprovider.h:24
forpy::IDataProvider::get_feature
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
forpy::usage_map_t
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
forpy::Data
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
forpy::DataStore
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
VIRTUAL_PTR
#define VIRTUAL_PTR
Definition: global.h:33
VIRTUAL
#define VIRTUAL(type)
Definition: global.h:31
forpy::IDataProvider::get_annotations
virtual Data< MatCRef > get_annotations() const
Get the full annotation data (must have inner stride 1).
Definition: idataprovider.h:49
forpy::IDataProvider::get_annot_vec_dim
size_t get_annot_vec_dim() const
Get the annotation vector dimension.
Definition: idataprovider.h:82
forpy::IDataProvider::IDataProvider
IDataProvider()
Constructor solely for deserialization.
Definition: idataprovider.h:114
forpy::IDataProvider::annot_vec_dim
size_t annot_vec_dim
The dimension of one annotation vector.
Definition: idataprovider.h:119
forpy::IDataProvider::get_feat_vec_dim
size_t get_feat_vec_dim() const
Get the feature vector dimension.
Definition: idataprovider.h:77
forpy::IDataProvider::access
friend class cereal::access
Definition: idataprovider.h:122
forpy::IDataProvider::serialize
void serialize(Archive &ar, const uint &)
Definition: idataprovider.h:124
forpy::IDataProvider::operator==
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.
Definition: idataprovider.h:101
forpy
Definition: fastdprov.h:13
forpy::VecCMap
Eigen::Map< const Eigen::Matrix< DT, 1, Eigen::Dynamic, Eigen::RowMajor >, Eigen::Unaligned, Eigen::InnerStride<> > VecCMap
Definition: types.h:90
forpy::ForpyException
Definition: global.h:91
forpy::uint
unsigned int uint
Convenience typedef for unsigned int.
Definition: types.h:113