mixle.models.dirichlet_process_mixture moduleΒΆ
Dirichlet-process mixture experiment helpers.
This module keeps nonparametric-mixture logic in the model layer. It exposes
small stick-breaking utilities and a dependency-free truncated variational
mixture loop over ordinary mixle.stats component estimators.
- class TruncatedDirichletProcessMixtureFitResult(model, responsibilities, history)[source]
Bases:
objectFitted truncated DPM plus variational responsibilities and history.
- Parameters:
- model: TruncatedDirichletProcessMixtureModel
- responsibilities: ndarray
- class TruncatedDirichletProcessMixtureModel(components, alpha=1.0, gamma=None, weights=None, name=None)[source]
Bases:
objectTruncated stick-breaking mixture over existing mixle component models.
- Parameters:
- property expected_log_weights: ndarray
Return E_q[log pi_k] under the variational stick posteriors.
- component_log_density(x)[source]
Return component log densities for one observation.
- log_density(x)[source]
Return the finite-truncation mixture log density for one observation.
- density(x)[source]
Return the finite-truncation mixture density for one observation.
- responsibilities(data, expected=True)[source]
Return posterior component probabilities for observations.
- effective_components(threshold=0.01)[source]
Count components with posterior mean stick weight above
threshold.
- stick_breaking_weights(stick_fractions, residual=True)[source]
Convert stick fractions into mixture weights.
When
residualis true, the returned vector has one extra final entry containing the remaining stick mass. This is the usual finite truncation.
- expected_log_stick_weights(gamma)[source]
Return E_q[log pi_k] for truncated Beta stick posteriors.
- mean_stick_weights(gamma)[source]
Return E_q[pi_k] under independent Beta stick posteriors.
- sample_crp_assignments(num_obs, alpha, seed=None)[source]
Sample Chinese-restaurant-process assignments and table counts.
- fit_truncated_dpm(data, initial_components, component_estimator, alpha=1.0, max_its=50, tol=1.0e-8, sort_components=True, name=None)[source]
Fit a truncated DP mixture by coordinate-ascent variational updates.
The component M-steps are delegated to ordinary
mixle.statsestimators. This keeps component likelihood math and sufficient statistics in their distribution modules.- Parameters:
- Return type:
TruncatedDirichletProcessMixtureFitResult