HabitatPrototypeAlignment

Note

This page is a reference documentation. It only explains the class signature, and not how to use it. Please refer to the Habitat Guide and Python API guide (v2.0) for usage.

class HabitatPrototypeAlignment(habitat_maps: Tuple[HabitatMap, ...], prototypes: ndarray, feature_names: Tuple[str, ...], source: str, assignments: DataFrame, objective: float, n_iter: int, converged: bool, seed_subject_id: str, metric: str, standardize: str, reduction: str, location: ndarray | None, scale: ndarray | None, match_prototypes: ndarray, model_id: str)[source]

Bases: object

Cohort habitat maps renamed onto shared prototypes.

Returned by align_habitat_maps_to_prototypes().

Pass it back as prototypes= to name new subjects with the same definition (same prototypes, same scaler, same metric, same model_id).

habitat_maps

Aligned maps, input order. Prototype k is habitat id k + 1 in every map, so the same id means the same habitat across subjects. No subject loses or merges a habitat. A habitat stays unnamed only when max_distance is set (or when a subject has more habitats than frozen prototypes); it then keeps a subject-local id above K that is not comparable across subjects.

Type:

Tuple[habit.contracts.habitat.HabitatMap, …]

prototypes

Shape (K, n_features) in the units of the input summaries (row k is habitat id k + 1): the mean (median for metric="manhattan") of every subject summary assigned to that prototype. Descriptive; matching uses match_prototypes. For frozen runs these are the reference’s.

Type:

numpy.ndarray

feature_names

Column names of prototypes: the models’ or feature fields’ names when available, else f0, f1, ....

Type:

Tuple[str, …]

source

Where the habitat summaries came from: "models" (fitted clustering centroids), "features" (per-habitat means of a supplied voxel feature volume / field), or "centroids" (caller-supplied matrices).

Type:

str

assignments

One row per input habitat with columns subject_id, habitat_id (original id), prototype_id (new id, NA when left unnamed), and distance to the prototype in the matching space (see metric).

Type:

pandas.core.frame.DataFrame

objective

Sum of matched metric costs plus the unmatched penalty, in the matching space.

Type:

float

n_iter

Assign / update rounds of the winning start (1 when frozen).

Type:

int

converged

False when max_iter stopped the search first.

Type:

bool

seed_subject_id

Subject whose summaries seeded the winning start, empty for frozen runs.

Type:

str

metric

Matching distance (see PROTOTYPE_METRICS).

Type:

str

standardize

"none" or "zscore".

Type:

str

reduction

Per-habitat reduction used for features= sources.

Type:

str

location

Column means of the z-score (None without z-score).

Type:

numpy.ndarray | None

scale

Column standard deviations of the z-score, or None.

Type:

numpy.ndarray | None

match_prototypes

Prototypes in the matching space (after z-score; unit rows for cosine / correlation). Reused by frozen runs.

Type:

numpy.ndarray

model_id

Shared model_id written into every aligned map.

Type:

str

__init__(habitat_maps: Tuple[HabitatMap, ...], prototypes: ndarray, feature_names: Tuple[str, ...], source: str, assignments: DataFrame, objective: float, n_iter: int, converged: bool, seed_subject_id: str, metric: str, standardize: str, reduction: str, location: ndarray | None, scale: ndarray | None, match_prototypes: ndarray, model_id: str) → None

Examples using habit.precision.HabitatPrototypeAlignment

Graph features

Graph features

Prototype matching step by step

Prototype matching step by step

Naming a new cohort with frozen prototypes

Naming a new cohort with frozen prototypes

What matching changes in a cohort feature table

What matching changes in a cohort feature table

Matching habitat labels across subjects

Matching habitat labels across subjects