ppforest2 v0.1.3
Projection Pursuit Decision Trees and Random Forests
Loading...
Searching...
No Matches
Types.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "utils/UserError.hpp"
4
5#include <Eigen/Dense>
6#include <string>
7#include <string_view>
8#include <vector>
9
10// ppforest2 targets Eigen 3.4.x — the version pinned for the standalone C++
11// build (see core/Dependencies.cmake) and the range RcppEigen ships for the R
12// package. This is a *floor* guard: newer Eigen is allowed, but if an
13// incompatible version ever appears (e.g. via an RcppEigen bump), the build
14// fails here with a clear message instead of a deep template error. If a
15// future Eigen release breaks the API, adjust this after validating.
16#if defined(EIGEN_VERSION_AT_LEAST) && !EIGEN_VERSION_AT_LEAST(3, 4, 0)
17#error "ppforest2 requires Eigen >= 3.4.0. Update Eigen (or RcppEigen for the R package)."
18#endif
19
34 using Feature = float;
35
37 using GroupId = int;
38
41
43 using FeatureMatrix = Eigen::Matrix<Feature, Eigen::Dynamic, Eigen::Dynamic>;
44
46 using FeatureVector = Eigen::Matrix<Feature, Eigen::Dynamic, 1>;
47
49 using GroupIdVector = Eigen::Matrix<GroupId, Eigen::Dynamic, 1>;
50
52 using OutcomeVector = Eigen::Matrix<Outcome, Eigen::Dynamic, 1>;
53
59 using Names = std::vector<std::string>;
60
62 template<typename T> using Matrix = Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>;
63
65 template<typename T> using Vector = Eigen::Matrix<T, Eigen::Dynamic, 1>;
66
68 enum class Mode : uint8_t { Classification, Regression };
69
71 inline bool is_classification(Mode mode) {
72 return mode == Mode::Classification;
73 }
74
76 inline bool is_regression(Mode mode) {
77 return mode == Mode::Regression;
78 }
79
83 inline std::string to_string(Mode mode) {
84 return is_regression(mode) ? "regression" : "classification";
85 }
86
90 inline Mode mode_from_string(std::string_view s) {
91 if (s == "classification") {
93 }
94
95 if (s == "regression") {
96 return Mode::Regression;
97 }
98
99 throw UserError("Invalid mode '" + std::string(s) + "'. Expected 'classification' or 'regression'.");
100 }
101
102}
Exception type for user-facing input validation errors.
Exception for user-facing input validation errors.
Definition UserError.hpp:25
Core numeric type aliases for the ppforest2 library.
Definition Types.hpp:32
std::vector< std::string > Names
Vector of name strings — used uniformly for class labels (group_names[i] is the label for GroupId == ...
Definition Types.hpp:59
bool is_classification(Mode mode)
Whether mode is Classification.
Definition Types.hpp:71
std::string to_string(Mode mode)
Canonical string form of a training mode.
Definition Types.hpp:83
Eigen::Matrix< Feature, Eigen::Dynamic, Eigen::Dynamic > FeatureMatrix
Dynamic-size matrix of feature values.
Definition Types.hpp:43
Eigen::Matrix< Outcome, Eigen::Dynamic, 1 > OutcomeVector
Dynamic-size column vector of predictions.
Definition Types.hpp:52
bool is_regression(Mode mode)
Whether mode is Regression.
Definition Types.hpp:76
Eigen::Matrix< GroupId, Eigen::Dynamic, 1 > GroupIdVector
Dynamic-size column vector of internal group labels.
Definition Types.hpp:49
Eigen::Matrix< Feature, Eigen::Dynamic, 1 > FeatureVector
Dynamic-size column vector of feature values.
Definition Types.hpp:46
Mode mode_from_string(std::string_view s)
Training mode from string.
Definition Types.hpp:90
Feature Outcome
Scalar type for predictions (float for both classification and regression).
Definition Types.hpp:40
Eigen::Matrix< T, Eigen::Dynamic, 1 > Vector
Generic dynamic-size column vector.
Definition Types.hpp:65
int GroupId
Scalar type for internal group labels (integer). Used as map keys, set elements, and partition indice...
Definition Types.hpp:37
Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > Matrix
Generic dynamic-size matrix.
Definition Types.hpp:62
Mode
Training mode.
Definition Types.hpp:68
@ Classification
Definition Types.hpp:68
@ Regression
Definition Types.hpp:68
float Feature
Scalar type for feature values.
Definition Types.hpp:34