ppforest2 v0.1.0
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
24 using Feature = float;
25
27 using GroupId = int;
28
31
33 using FeatureMatrix = Eigen::Matrix<Feature, Eigen::Dynamic, Eigen::Dynamic>;
34
36 using FeatureVector = Eigen::Matrix<Feature, Eigen::Dynamic, 1>;
37
39 using GroupIdVector = Eigen::Matrix<GroupId, Eigen::Dynamic, 1>;
40
42 using OutcomeVector = Eigen::Matrix<Outcome, Eigen::Dynamic, 1>;
43
49 using Names = std::vector<std::string>;
50
52 template<typename T> using Matrix = Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>;
53
55 template<typename T> using Vector = Eigen::Matrix<T, Eigen::Dynamic, 1>;
56
58 enum class Mode : uint8_t { Classification, Regression };
59
61 inline bool is_classification(Mode mode) {
62 return mode == Mode::Classification;
63 }
64
66 inline bool is_regression(Mode mode) {
67 return mode == Mode::Regression;
68 }
69
73 inline std::string to_string(Mode mode) {
74 return is_regression(mode) ? "regression" : "classification";
75 }
76
80 inline Mode mode_from_string(std::string_view s) {
81 if (s == "classification") {
83 }
84
85 if (s == "regression") {
86 return Mode::Regression;
87 }
88
89 throw UserError("Invalid mode '" + std::string(s) + "'. Expected 'classification' or 'regression'.");
90 }
91
92}
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:22
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:49
bool is_classification(Mode mode)
Whether mode is Classification.
Definition Types.hpp:61
std::string to_string(Mode mode)
Canonical string form of a training mode.
Definition Types.hpp:73
Eigen::Matrix< Feature, Eigen::Dynamic, Eigen::Dynamic > FeatureMatrix
Dynamic-size matrix of feature values.
Definition Types.hpp:33
Eigen::Matrix< Outcome, Eigen::Dynamic, 1 > OutcomeVector
Dynamic-size column vector of predictions.
Definition Types.hpp:42
bool is_regression(Mode mode)
Whether mode is Regression.
Definition Types.hpp:66
Eigen::Matrix< GroupId, Eigen::Dynamic, 1 > GroupIdVector
Dynamic-size column vector of internal group labels.
Definition Types.hpp:39
Eigen::Matrix< Feature, Eigen::Dynamic, 1 > FeatureVector
Dynamic-size column vector of feature values.
Definition Types.hpp:36
Mode mode_from_string(std::string_view s)
Training mode from string.
Definition Types.hpp:80
Feature Outcome
Scalar type for predictions (float for both classification and regression).
Definition Types.hpp:30
Eigen::Matrix< T, Eigen::Dynamic, 1 > Vector
Generic dynamic-size column vector.
Definition Types.hpp:55
int GroupId
Scalar type for internal group labels (integer). Used as map keys, set elements, and partition indice...
Definition Types.hpp:27
Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > Matrix
Generic dynamic-size matrix.
Definition Types.hpp:52
Mode
Training mode.
Definition Types.hpp:58
@ Classification
Definition Types.hpp:58
@ Regression
Definition Types.hpp:58
float Feature
Scalar type for feature values.
Definition Types.hpp:24