mescla.emma.model.EMMA¶
- class mescla.emma.model.EMMA(k=None, rule='one', standardize=True, variance_threshold=0.9)[source]¶
Bases:
objectEnd-Member Mixing Analysis.
- Parameters:
k (int, optional) – Force the rank. When
None(the default) it is chosen byrule.rule ({"one", "variance", "broken_stick", "parallel"}, default "one") – Retention criterion.
"one"is the classical rule of one (Kaiser); it is also the weakest, so checkrank_summary()and the residual diagnostics before accepting its answer.standardize (bool, default True) – Z-score the species first (correlation PCA). Turn off only when all species share units and you want large concentrations to dominate.
variance_threshold (float, default 0.9) – Target for
rule="variance".
- Variables:
result (EMMAResult)
standardizer (Standardizer)
k (int)
n_endmembers (int)
Examples
>>> from mescla import EMMA >>> model = EMMA().fit(samples) >>> model.n_endmembers 3 >>> model.diagnostics().to_frame() >>> model.project(candidates) # U-space coordinates
- fit(X)[source]¶
Fit on mixed water samples.
Candidate end-members are not part of the fit – they are projected in afterwards with
project(). Including them would let them influence the subspace they are supposed to be tested against.
- project(X)¶
Alias reading better when the argument is a set of candidate end-members.
- subspace_distance(X)[source]¶
Distance of each water from the mixing subspace, in standardised units.
- diagnostics(**kwargs)[source]¶
Per-species relative bias and RRMSE of the rank-k model (Hooper, 2003).
- Parameters:
kwargs (Any)
- Return type:
- residual_structure(alpha=0.05)[source]¶
Test each species’ residuals for structure – the real lack-of-fit check.
- Parameters:
alpha (float)
- Return type:
pd.DataFrame
- loadings_frame()[source]¶
Eigenvector loadings: which species drive which component.
- Return type:
pd.DataFrame
- screen_candidates(candidates)[source]¶
Score candidate end-members for extremeness and subspace membership.
- Parameters:
candidates (Any)
- Return type:
pd.DataFrame
- suggest_endmembers(candidates, n_endmembers=None)[source]¶
Rank combinations of candidates by how well they bound the samples.
- Parameters:
candidates (Any)
n_endmembers (int | None)
- Return type:
pd.DataFrame
- archetypes(n_archetypes=None, *, n_restarts=10, seed=0, max_iter=200, tol=1e-06)[source]¶
Propose end-member candidates by archetypal analysis in the fitted U-space.
suggest_endmembers()picks vertices from candidates you supply; this asks what the bestk+1vertices would be if the data chose them. Use it as a check on your candidates – do the algorithm’s vertices look like the sources your conceptual model named, before you looked? – and as a fallback when you have no candidate waters at all.Read
mescla.emma.archetypesbefore using the output. In short: the weights are not mixing ratios, the archetypes are still biased inward relative to the true sources, the method proposes rather than discovers, and the objective is non-convex so the answer depends onseed.- Parameters:
n_archetypes (int, optional) – Defaults to
n_endmembers(k + 1), the number the rank analysis called for.seed (int, default 0) – Recorded in the result. Check it matters with
archetype_stability().n_restarts (int)
max_iter (int)
tol (float)
- Returns:
ArchetypeResult
- Return type:
Examples
>>> model = EMMA().fit(samples) >>> arch = model.archetypes() >>> print(arch.summary()) # cautions included >>> arch.archetypes_frame() # candidate compositions >>> arch.support_frame() # how many samples support each