44 using GroupSet = std::set<types::Response>;
45 using GroupMap = std::map<types::Response, types::Response>;
46 using GroupInvMap = std::map<types::Response, GroupSet>;
75 std::vector<int> indices;
79 for (
auto const& g : subs) {
81 invariant(i >= 0 && i < x.rows(),
"GroupPartition::group: index out of bounds");
86 return x(indices, Eigen::all);
96 std::vector<int> indices;
98 for (
auto const& kv : Blocks) {
99 auto const& g = kv.first;
101 indices.push_back(i);
105 return x(indices, Eigen::all);
150 std::optional<types::Response> next;
151 std::optional<types::Response> prev;
154 using BlockMap = std::map<types::Response, Block>;
155 BlockMap
const Blocks;
157 BlockMap init_Blocks(GroupVector
const& y);
158 GroupMap init_supergroups();
void invariant(bool condition, char const *message)
Runtime assertion that throws on failure.
GroupPartition remap(GroupMap const &mapping) const
Merge groups according to a mapping.
GroupPartition(types::ResponseVector const &y)
Construct from a sorted response vector.
GroupMap const supergroups
Maps each group to its supergroup (identity if no merge).
Definition GroupPartition.hpp:141
types::FeatureMatrix wgss(types::FeatureMatrix const &x) const
Within-group sum of squares matrix (p × p).
auto data(types::FeatureMatrix const &x) const
Extract all rows across all groups.
Definition GroupPartition.hpp:95
auto group(types::FeatureMatrix const &x, Group const &group) const
Extract rows belonging to a group (or supergroup).
Definition GroupPartition.hpp:74
types::FeatureVector mean(types::FeatureMatrix const &x) const
Overall mean of all grouped rows (p).
GroupSet const groups
Set of all group labels in this partition.
Definition GroupPartition.hpp:139
GroupPartition subset(GroupSet groups) const
Create a partition containing only the given groups.
types::FeatureMatrix bgss(types::FeatureMatrix const &x) const
Between-group sum of squares matrix (p × p).
int group_end(Group const &group) const
Last row index (inclusive) of the block for group.
static bool is_contiguous(GroupVector const &y)
Check whether all equal values in y form a single contiguous block.
int group_start(Group const &group) const
First row index of the block for group.
int group_size(Group const &group) const
Number of observations in group.
GroupPartition collapse() const
Collapse all groups into a single supergroup.
GroupInvMap const subgroups
Maps each group to its set of subgroups.
Definition GroupPartition.hpp:143
Statistical infrastructure for training and evaluation.
Definition ConfusionMatrix.hpp:11
Eigen::Matrix< Feature, Eigen::Dynamic, Eigen::Dynamic > FeatureMatrix
Dynamic-size matrix of feature values.
Definition Types.hpp:24
Eigen::Matrix< Feature, Eigen::Dynamic, 1 > FeatureVector
Dynamic-size column vector of feature values.
Definition Types.hpp:26
int Response
Scalar type for group labels (integer).
Definition Types.hpp:21
Eigen::Matrix< Response, Eigen::Dynamic, 1 > ResponseVector
Dynamic-size column vector of group labels.
Definition Types.hpp:29
Eigen::Matrix< T, Eigen::Dynamic, 1 > Vector
Generic dynamic-size column vector.
Definition Types.hpp:35