Brush C++ API
A flexible interpretable machine learning framework
Loading...
Searching...
No Matches
types.h
Go to the documentation of this file.
1/* Brush
2
3copyright 2020 William La Cava
4license: GNU/GPL v3
5*/
6#ifndef TYPES_H
7#define TYPES_H
8
9#include <variant>
10#include <ceres/jet.h>
11#include <concepts>
12
13namespace Brush {
14
18template<typename First, typename ... Next>
19struct all_same{
20 static constexpr bool value {(std::is_same_v<First,Next> && ...)};
21};
22template<typename First, typename ... Next>
23static constexpr bool all_same_v = all_same<First, Next...>::value;
24
28template<typename First, typename ... Next>
29struct is_one_of{
30 static constexpr bool value {(std::is_same_v<First,Next> || ...)};
31};
32template<typename First, typename ... Next>
33static constexpr bool is_one_of_v = is_one_of<First, Next...>::value;
34// // see https://en.cppreference.com/w/cpp/concepts/same_as
35template<typename T, typename ... U>
36concept IsAnyOf = (std::same_as<T, U> || ...);
38// Eigen types
39typedef Eigen::Array<bool,Eigen::Dynamic,1> ArrayXb;
40typedef Eigen::Array<int,Eigen::Dynamic,1> ArrayXi;
41typedef Eigen::Array<bool,Eigen::Dynamic,Eigen::Dynamic> ArrayXXb;
42typedef Eigen::Array<int,Eigen::Dynamic,Eigen::Dynamic> ArrayXXi;
43// Ceres types
44static constexpr int stride = 8;
45typedef ceres::Jet<float, stride> fJet;
46typedef ceres::Jet<int, stride> iJet;
47typedef ceres::Jet<bool, stride> bJet;
48
49typedef Eigen::Array<fJet,Eigen::Dynamic,1> ArrayXfJet;
50typedef Eigen::Array<iJet,Eigen::Dynamic,1> ArrayXiJet;
51typedef Eigen::Array<bJet,Eigen::Dynamic,1> ArrayXbJet;
52typedef Eigen::Array<fJet,Eigen::Dynamic,Eigen::Dynamic> ArrayXXfJet;
53typedef Eigen::Array<iJet,Eigen::Dynamic,Eigen::Dynamic> ArrayXXiJet;
54typedef Eigen::Array<bJet,Eigen::Dynamic,Eigen::Dynamic> ArrayXXbJet;
55
58template <typename T>
59struct WeightType {
60 typedef std::conditional_t<
62 fJet,
63 float
64 > type;
65};
66template<typename T>
69// Program
76using PT = ProgramType;
77template<PT T> struct Program;
82
84// Individual
85namespace Pop {
86 template<Brush::ProgramType T> class Individual;
87}
92
94// Engine
95using PT = ProgramType;
96template<PT T> class Engine;
101
103// Data
104namespace Data{
105 template<class T> struct TimeSeries;
116
119 typedef std::variant<
120 ArrayXb,
121 ArrayXi,
122 ArrayXf,
123 ArrayXXb,
124 ArrayXXi,
125 ArrayXXf,
129 // Jet types
139 >
141}
143enum class DataType : uint32_t {
144 ArrayB,
145 ArrayI,
146 ArrayF,
147 MatrixB,
148 MatrixI,
149 MatrixF,
153 ArrayBJet,
154 ArrayIJet,
155 ArrayFJet,
156 MatrixBJet,
157 MatrixIJet,
158 MatrixFJet,
162};
163
164#ifndef DOXYGEN_SKIP
165// map DataType values to JSON as strings
167 {DataType::ArrayB, "ArrayB"},
168 {DataType::ArrayI, "ArrayI"},
169 {DataType::ArrayF, "ArrayF"},
170 {DataType::MatrixB, "MatrixB"},
171 {DataType::MatrixI, "MatrixI"},
172 {DataType::MatrixF, "MatrixF"},
173 {DataType::TimeSeriesB, "TimeSeriesB"},
174 {DataType::TimeSeriesI,"TimeSeriesI"},
175 {DataType::TimeSeriesF,"TimeSeriesF"},
176 {DataType::ArrayBJet, "ArrayBJet"},
177 {DataType::ArrayIJet, "ArrayIJet"},
178 {DataType::ArrayFJet, "ArrayFJet"},
179 {DataType::MatrixBJet, "MatrixBJet"},
180 {DataType::MatrixIJet, "MatrixIJet"},
181 {DataType::MatrixFJet, "MatrixFJet"},
182 {DataType::TimeSeriesBJet, "TimeSeriesBJet"},
183 {DataType::TimeSeriesIJet,"TimeSeriesIJet"},
184 {DataType::TimeSeriesFJet, "TimeSeriesFJet"},
185})
186#endif
187
188using DT = DataType;
189
190template<DT D> struct DataEnumType;
191template<> struct DataEnumType<DT::ArrayB>{ using type = ArrayXb; };
192template<> struct DataEnumType<DT::ArrayI>{ using type = ArrayXi; };
193template<> struct DataEnumType<DT::ArrayF>{ using type = ArrayXf; };
194template<> struct DataEnumType<DT::MatrixB>{ using type = ArrayXXb; };
195template<> struct DataEnumType<DT::MatrixI>{ using type = ArrayXXi; };
196template<> struct DataEnumType<DT::MatrixF>{ using type = ArrayXXf; };
197template<> struct DataEnumType<DT::TimeSeriesB>{ using type = Data::TimeSeriesb; };
198template<> struct DataEnumType<DT::TimeSeriesI>{ using type = Data::TimeSeriesi; };
199template<> struct DataEnumType<DT::TimeSeriesF>{ using type = Data::TimeSeriesf; };
200template<> struct DataEnumType<DT::ArrayBJet>{ using type = ArrayXbJet; };
201template<> struct DataEnumType<DT::ArrayIJet>{ using type = ArrayXiJet; };
202template<> struct DataEnumType<DT::ArrayFJet>{ using type = ArrayXfJet; };
203template<> struct DataEnumType<DT::MatrixBJet>{ using type = ArrayXXbJet; };
204template<> struct DataEnumType<DT::MatrixIJet>{ using type = ArrayXXiJet; };
205template<> struct DataEnumType<DT::MatrixFJet>{ using type = ArrayXXfJet; };
206
207template<typename T> struct DataTypeEnum;
208template <> struct DataTypeEnum<ArrayXb> { static constexpr DT value = DT::ArrayB; };
209template <> struct DataTypeEnum<ArrayXi> { static constexpr DT value = DT::ArrayI; };
210template <> struct DataTypeEnum<ArrayXf> { static constexpr DT value = DT::ArrayF; };
211template <> struct DataTypeEnum<ArrayXXb> { static constexpr DT value = DT::MatrixB; };
212template <> struct DataTypeEnum<ArrayXXi> { static constexpr DT value = DT::MatrixI; };
213template <> struct DataTypeEnum<ArrayXXf> { static constexpr DT value = DT::MatrixF; };
214template <> struct DataTypeEnum<Data::TimeSeriesb> { static constexpr DT value = DT::TimeSeriesB; };
215template <> struct DataTypeEnum<Data::TimeSeriesi> { static constexpr DT value = DT::TimeSeriesI; };
216template <> struct DataTypeEnum<Data::TimeSeriesf> { static constexpr DT value = DT::TimeSeriesF; };
217template <> struct DataTypeEnum<ArrayXbJet> { static constexpr DT value = DT::ArrayBJet; };
218template <> struct DataTypeEnum<ArrayXiJet> { static constexpr DT value = DT::ArrayIJet; };
219template <> struct DataTypeEnum<ArrayXfJet> { static constexpr DT value = DT::ArrayFJet; };
220template <> struct DataTypeEnum<ArrayXXbJet> { static constexpr DT value = DT::MatrixBJet; };
221template <> struct DataTypeEnum<ArrayXXiJet> { static constexpr DT value = DT::MatrixIJet; };
222template <> struct DataTypeEnum<ArrayXXfJet> { static constexpr DT value = DT::MatrixFJet; };
223template <>
224struct DataTypeEnum<Data::TimeSeriesbJet>
225{
226 static constexpr DT value = DT::TimeSeriesBJet;
227};
228template <>
229struct DataTypeEnum<Data::TimeSeriesiJet>
230{
231 static constexpr DT value = DT::TimeSeriesIJet;
232};
233template <>
234struct DataTypeEnum<Data::TimeSeriesfJet>
235{
236 static constexpr DT value = DT::TimeSeriesFJet;
237};
238
239// check for std::array types
240template <typename T>
241struct is_std_array : std::false_type {};
242template <typename V, size_t n>
243struct is_std_array<std::array<V, n>> : std::true_type {};
244template <typename T>
246
247// check for Eigen::Array types
248template<typename T>
250 : std::is_base_of<Eigen::ArrayBase<std::decay_t<T> >, std::decay_t<T> > {};
251
252template<typename T>
254
255// check for tuple types
256template <typename> struct is_tuple: std::false_type {};
257template <typename ...T> struct is_tuple<std::tuple<T...>>: std::true_type {};
258template <typename T>
259static constexpr bool is_tuple_v = is_tuple<T>::value;
260} // Brush
261
262#endif
void bind_engine(py::module &m, string name)
The Engine class represents the core engine of the brush library.
Definition engine.h:43
TimeSeries< fJet > TimeSeriesfJet
Definition types.h:115
TimeSeries< iJet > TimeSeriesiJet
Definition types.h:114
TimeSeries< bool > TimeSeriesb
TimeSeries convenience typedefs.
Definition types.h:110
TimeSeries< float > TimeSeriesf
Definition types.h:112
TimeSeries< bJet > TimeSeriesbJet
Definition types.h:113
std::variant< ArrayXb, ArrayXi, ArrayXf, ArrayXXb, ArrayXXi, ArrayXXf, TimeSeriesb, TimeSeriesi, TimeSeriesf, ArrayXbJet, ArrayXiJet, ArrayXfJet, ArrayXXbJet, ArrayXXiJet, ArrayXXfJet, TimeSeriesbJet, TimeSeriesiJet, TimeSeriesfJet > State
defines the possible types of data flowing thru nodes.
Definition types.h:140
TimeSeries< int > TimeSeriesi
Definition types.h:111
< nsga2 selection operator for getting the front
Definition data.cpp:12
static constexpr bool is_tuple_v
Definition types.h:259
Program< PT::Representer > RepresenterProgram
Definition types.h:81
ceres::Jet< int, stride > iJet
Definition types.h:46
Eigen::Array< bool, Eigen::Dynamic, 1 > ArrayXb
Definition types.h:39
ceres::Jet< bool, stride > bJet
Definition types.h:47
Eigen::Array< int, Eigen::Dynamic, Eigen::Dynamic > ArrayXXi
Definition types.h:42
typename WeightType< T >::type WeightType_t
Definition types.h:67
Eigen::Array< bJet, Eigen::Dynamic, Eigen::Dynamic > ArrayXXbJet
Definition types.h:54
Program< PT::BinaryClassifier > ClassifierProgram
Definition types.h:79
DataType
data types.
Definition types.h:143
Engine< PT::MulticlassClassifier > MulticlassClassifierEngine
Definition types.h:99
Engine< PT::Regressor > RegressorEngine
Definition types.h:97
static constexpr bool is_eigen_array_v
Definition types.h:253
ProgramType PT
Definition program.h:40
static constexpr bool is_one_of_v
Definition types.h:33
static constexpr bool all_same_v
Definition types.h:23
Eigen::Array< bool, Eigen::Dynamic, Eigen::Dynamic > ArrayXXb
Definition types.h:41
Eigen::Array< fJet, Eigen::Dynamic, 1 > ArrayXfJet
Definition types.h:49
Pop::Individual< PT::MulticlassClassifier > MulticlassClassifierIndividual
Definition types.h:90
Engine< PT::BinaryClassifier > ClassifierEngine
Definition types.h:98
Eigen::Array< int, Eigen::Dynamic, 1 > ArrayXi
Definition types.h:40
Eigen::Array< bJet, Eigen::Dynamic, 1 > ArrayXbJet
Definition types.h:51
Pop::Individual< PT::Representer > RepresenterIndividual
Definition types.h:91
Eigen::Array< fJet, Eigen::Dynamic, Eigen::Dynamic > ArrayXXfJet
Definition types.h:52
Program< PT::Regressor > RegressorProgram
Definition types.h:78
Eigen::Array< iJet, Eigen::Dynamic, 1 > ArrayXiJet
Definition types.h:50
Pop::Individual< PT::BinaryClassifier > ClassifierIndividual
Definition types.h:89
ProgramType
Definition types.h:70
static constexpr int stride
Definition types.h:44
static constexpr bool is_std_array_v
Definition types.h:245
Eigen::Array< iJet, Eigen::Dynamic, Eigen::Dynamic > ArrayXXiJet
Definition types.h:53
Pop::Individual< PT::Regressor > RegressorIndividual
Definition types.h:88
Program< PT::MulticlassClassifier > MulticlassClassifierProgram
Definition types.h:80
Engine< PT::Representer > RepresenterEngine
Definition types.h:100
ceres::Jet< float, stride > fJet
Definition types.h:45
STL namespace.
Stores time series data and implements operators over it.
Definition timeseries.h:26
An individual program, a.k.a. model.
Definition program.h:50
Returns the weight type associated with the scalar type underlying T.
Definition types.h:59
std::conditional_t< is_one_of_v< typename T::Scalar, fJet, iJet, bJet >, fJet, float > type
Definition types.h:64
checks whether all the types match.
Definition types.h:19
static constexpr bool value
Definition types.h:20
checks whether any of the types match the first one.
Definition types.h:29
static constexpr bool value
Definition types.h:30