htfa.fit

htfa.fit(data, K=50, coords=None, mask=None, stack=False, channels='gray', spacing=None, groups=None, subject_ids=None, **model_kwargs)[source]

Load data and fit TFA (one subject) or HTFA (several).

Parameters:
data, coords, mask, stack, channels, spacing

As in htfa.io.load.

Kint

Number of factors.

groups, subject_idsoptional

Nested groups of subjects and subject identifiers, passed to htfa.HTFA.fit (several subjects only); groups needs template_update='fixed' or 'empirical'. With groups=None, nested folders supply group paths automatically and the template update defaults to 'fixed'. Explicit groups override folder metadata; groups=False disables inference. A single subject still fits TFA. A GroupTree.from_paths tree supports unequal hierarchy depths.

**model_kwargs

Passed to htfa.TFA or htfa.HTFA; an unknown key raises TypeError. One subject fits a TFA and several fit an HTFA, so HTFA-only kwargs (e.g. max_global_iter) fail for a single subject. Both take kernel and n_components (factor shapes and mixtures).

Returns:
HTFAResults

Examples

>>> import numpy as np
>>> from htfa import fit
>>> img = np.random.default_rng(0).random((6, 6, 6, 8)) + 1
>>> res = fit(img, K=2, standardize=False, init="power", max_iter=5)
>>> res.connectivity().shape
(2, 2)