ppforest2 v0.1.0
Projection Pursuit Decision Trees and Random Forests
Loading...
Searching...
No Matches
ppforest2::stats::GroupPartition Class Reference

Contiguous-block representation of grouped observations. More...

#include <GroupPartition.hpp>

Public Member Functions

 GroupPartition (types::ResponseVector const &y)
 Construct from a sorted response vector.
 
types::FeatureMatrix bgss (types::FeatureMatrix const &x) const
 Between-group sum of squares matrix (p × p).
 
GroupPartition collapse () const
 Collapse all groups into a single supergroup.
 
auto data (types::FeatureMatrix const &x) const
 Extract all rows across all groups.
 
auto group (types::FeatureMatrix const &x, Group const &group) const
 Extract rows belonging to a group (or supergroup).
 
int group_end (Group const &group) const
 Last row index (inclusive) of the block for group.
 
int group_size (Group const &group) const
 Number of observations in group.
 
int group_start (Group const &group) const
 First row index of the block for group.
 
types::FeatureVector mean (types::FeatureMatrix const &x) const
 Overall mean of all grouped rows (p).
 
GroupPartition remap (GroupMap const &mapping) const
 Merge groups according to a mapping.
 
GroupPartition subset (GroupSet groups) const
 Create a partition containing only the given groups.
 
types::FeatureMatrix wgss (types::FeatureMatrix const &x) const
 Within-group sum of squares matrix (p × p).
 

Static Public Member Functions

static bool is_contiguous (GroupVector const &y)
 Check whether all equal values in y form a single contiguous block.
 

Public Attributes

GroupSet const groups
 Set of all group labels in this partition.
 
GroupInvMap const subgroups
 Maps each group to its set of subgroups.
 
GroupMap const supergroups
 Maps each group to its supergroup (identity if no merge).
 

Detailed Description

Contiguous-block representation of grouped observations.

Assumes the response vector is sorted so that observations of the same group are contiguous. Stores the start/end row indices of each group block and provides efficient extraction, subsetting, and computation of between- and within-group statistics.

Groups can be hierarchically merged via remap(), which assigns supergroup labels while tracking the original subgroups.

// y must be sorted so equal values are contiguous.
// Extract rows belonging to group 0:
auto x_group0 = gp.group(x, 0);
// Between- and within-group statistics:
auto B = gp.bgss(x); // between-group sum of squares (p × p)
auto W = gp.wgss(x); // within-group sum of squares (p × p)
// Restrict to a subset of groups:
GroupPartition sub = gp.subset({0, 2});
GroupPartition(types::ResponseVector const &y)
Construct from a sorted response vector.

Constructor & Destructor Documentation

◆ GroupPartition()

ppforest2::stats::GroupPartition::GroupPartition ( types::ResponseVector const & y)

Construct from a sorted response vector.

Parameters
yResponse vector (n) with contiguous group blocks.

Member Function Documentation

◆ bgss()

types::FeatureMatrix ppforest2::stats::GroupPartition::bgss ( types::FeatureMatrix const & x) const

Between-group sum of squares matrix (p × p).

◆ collapse()

GroupPartition ppforest2::stats::GroupPartition::collapse ( ) const

Collapse all groups into a single supergroup.

Returns
New GroupPartition with one supergroup containing all groups.

◆ data()

auto ppforest2::stats::GroupPartition::data ( types::FeatureMatrix const & x) const
inline

Extract all rows across all groups.

Parameters
xFeature matrix (n × p).
Returns
Sub-matrix with all grouped rows.

◆ group()

auto ppforest2::stats::GroupPartition::group ( types::FeatureMatrix const & x,
Group const & group ) const
inline

Extract rows belonging to a group (or supergroup).

Parameters
xFeature matrix (n × p).
groupGroup label.
Returns
Sub-matrix of rows belonging to group.

◆ group_end()

int ppforest2::stats::GroupPartition::group_end ( Group const & group) const

Last row index (inclusive) of the block for group.

◆ group_size()

int ppforest2::stats::GroupPartition::group_size ( Group const & group) const

Number of observations in group.

◆ group_start()

int ppforest2::stats::GroupPartition::group_start ( Group const & group) const

First row index of the block for group.

◆ is_contiguous()

static bool ppforest2::stats::GroupPartition::is_contiguous ( GroupVector const & y)
static

Check whether all equal values in y form a single contiguous block.

◆ mean()

types::FeatureVector ppforest2::stats::GroupPartition::mean ( types::FeatureMatrix const & x) const

Overall mean of all grouped rows (p).

◆ remap()

GroupPartition ppforest2::stats::GroupPartition::remap ( GroupMap const & mapping) const

Merge groups according to a mapping.

Parameters
mappingMaps original group labels to supergroup labels.
Returns
New GroupPartition with merged groups.

◆ subset()

GroupPartition ppforest2::stats::GroupPartition::subset ( GroupSet groups) const

Create a partition containing only the given groups.

Parameters
groupsSet of group labels to keep.
Returns
New GroupPartition restricted to groups.

◆ wgss()

types::FeatureMatrix ppforest2::stats::GroupPartition::wgss ( types::FeatureMatrix const & x) const

Within-group sum of squares matrix (p × p).

Member Data Documentation

◆ groups

GroupSet const ppforest2::stats::GroupPartition::groups

Set of all group labels in this partition.

◆ subgroups

GroupInvMap const ppforest2::stats::GroupPartition::subgroups

Maps each group to its set of subgroups.

◆ supergroups

GroupMap const ppforest2::stats::GroupPartition::supergroups

Maps each group to its supergroup (identity if no merge).


The documentation for this class was generated from the following file: