stratifier

stratifier

Stratification of datasets using GAD.

Classes

Name Description
Clusterer Protocol for sklearn clusterer objects.
Stratifier Stratifier class for determining stratifications of data.

Clusterer

stratifier.Clusterer()

Protocol for sklearn clusterer objects.

Methods

Name Description
fit_predict Fit the clusterer and predict cluster labels.
fit_predict
stratifier.Clusterer.fit_predict(X)

Fit the clusterer and predict cluster labels.

Stratifier

stratifier.Stratifier(clusterer, max_dim=1, n_jobs=1)

Stratifier class for determining stratifications of data.

This class relies on the GAD algorithm implemented in dimmer to construct stratifications.

Parameters

Name Type Description Default
clusterer Clusterer A scikit-learn style clusterer such as DBSCAN. required
max_dim int The maximal dimension to run GAD. 1
n_jobs int The number of processors to use. 1

Note

This class is experimental and has not yet been fully tested. It is written in the style of a scikit-learn transformer.

Methods

Name Description
fit_predict Compute stratification labels across all dimensions.
fit_predict_dw Compute stratification labels in a specified dimension.
fit_predict
stratifier.Stratifier.fit_predict(X, ids, max_dim, y=None)

Compute stratification labels across all dimensions.

This method iteratively applies fit_predict_dw from max_dim down to dimension 1, then clusters all remaining points at dimension <= 1.

Parameters
Name Type Description Default
X np.ndarray[tuple[int, int], np.dtype[np.float64]] Array containing n_samples points within ambient Euclidean space of dimension n_features. required
ids np.ndarray[tuple[int], np.dtype[np.float64]] Dimension estimates for each point in X. required
max_dim int Maximum dimension up to which stratification is computed. required
y np.ndarray[tuple[int], np.dtype[np.float64]] | None Ignored. (Default value = None) None

Returns: Cluster labels

fit_predict_dw
stratifier.Stratifier.fit_predict_dw(X, ids, dim, cluster_labels=None, y=None)

Compute stratification labels in a specified dimension.

This model takes dimension estimates as input in ids (e.g., the output of fit_predict and computes a stratification within a single dimension specified by dim using self.clusterer.

Parameters
Name Type Description Default
X np.ndarray[tuple[int, int], np.dtype[np.float64]] Array containing n_samples points within ambient Euclidean space of dimension n_features. required
ids np.ndarray[tuple[int], np.dtype[np.float64]] Dimension estimates for each point in X. required
dim int Dimension in which to compute stratification. required
cluster_labels np.ndarray[tuple[int], np.dtype[np.float64]] | None Already computed labels, usually from a previous degree. None
y np.ndarray | None Ignored. None
Returns
Name Type Description
np.ndarray Cluster labels

Functions

Name Description
construct_region_labels Construct the Hasse diagram for a stratification.

construct_region_labels

stratifier.construct_region_labels(X, ids, grid_sep=1.0)

Construct the Hasse diagram for a stratification.

This method labels each top-dimensional region with a unique integer, the region id. Points which are not classified as top dimensional are then assigned a label by looking at the closest two top-dimensional points. If both of those points have the same region id, that id is assigned to the point in question. If they have a different region id, both region ids are assigned to the point in question.

Parameters

Name Type Description Default
X np.ndarray[tuple[int, int], np.dtype[np.float64]] np.ndarray: required
ids np.ndarray[tuple[int], np.dtype[np.float64]] np.ndarray: required
grid_sep float float: (Default value = 1.0) 1.0

Returns

Name Type Description
dict[int, list[int]] A dictionary of region ids.

Note

This method is specifically for gridded data. It can certainly be modified for other projects, but this algorithm assumes the data lies on a grid.