Dmx Local Modeling
Use this skill for implementation-heavy local modeling work after the problem
has already been scoped to a concrete local dmx-learn path.
This skill is narrow on purpose:
- it writes explicit estimators, fitting loops, and diagnostics
- it assumes the task is local and in scope for
dmx-learn
- it does not own broad intake, lightweight EDA, or high-level routing policy
When the problem framing is still ambiguous, hand that work to
dmx-expert-orchestrator first.
When To Use This Skill
Use this skill when at least one of these is already known:
- the observation structure is clear enough to code directly
- the model family has already been chosen upstream
- the user wants runnable fitting code, diagnostics, or post-fit usage
- the main question is about implementation details in
dmx.stats,
dmx.bstats, or dmx.utils
Do not use this skill as the main router for vague modeling requests. For:
- intake and lightweight local-data inspection
- structure-first routing across base, composite, mixture, sequence, joint, or
grouped models
- deciding when to fit one primary model plus one baseline
- deciding whether the task should stay broad and reusable instead of going
straight to a narrow conditional path
read ../dmx-expert-orchestrator/SKILL.md
and its
references/hierarchy-and-data-structure.md
first.
Default Workflow
1. Confirm The Implementation Target
Before coding, restate only the facts needed for implementation:
- what one observation is
- the intended estimator family or estimator tree
- the fitting objective or evaluation target
- any known validation split, restart budget, or scale constraint
If those facts are still uncertain, stop routing locally and defer back to the
orchestrator instead of improvising your own broad routing pass here.
2. Choose The Local Modeling Surface
- Prefer explicit
dmx.stats estimator construction for ordinary
non-Bayesian estimation when the model family is known.
- Use
dmx.bstats when the implementation needs explicit priors, expected
log-density calculations, local variational fitting, a truncated DPM, or an
automatic estimator that will participate in a Bayesian mixture workflow.
dmx.utils.automatic.get_estimator(data, use_bstats=True) is a valid
first-class route when automatic Bayesian structure inference is intentional.
Keep use_bstats=True explicit in generated code even though the current
helper default is True.
dmx.utils.automatic.get_dpm_mixture(data, ...) is the first-class local
automatic DPM route. It fits a truncated dmx.bstats DPM variationally,
removes components below its count threshold, and returns a finite
dmx.bstats.MixtureDistribution.
- Keep the hierarchy chosen upstream intact. Do not flatten a composite,
sequence, or grouped problem into a simpler estimator only because it is
quicker to code.
- Read
references/model-routing.md when you
need the concrete estimator family map after the structure is already known.
- Reuse the orchestrator's structure-first philosophy: hierarchy choice comes
first, field-level estimators second.
For advanced structure selection, grouped-sharing policy, or joint-model-first
reasoning, go back to the orchestrator reference instead of re-deriving that
logic in this skill.
3. Use Repo-Native Local Fitting Helpers
Read references/repo-entry-points.md for
the concrete repo paths.
Default non-Bayesian implementation path:
- Build an explicit estimator in
dmx.stats.
- Split data with
dmx.utils.estimation.partition_data when held-out
validation is needed.
- Fit with
dmx.utils.estimation.optimize.
- Upgrade to
dmx.utils.estimation.best_of when initialization sensitivity is
plausible, especially for mixtures or other latent-variable models.
- Use vectorized post-fit calls such as
seq_encode, seq_log_density,
seq_log_density_sum, or related posterior helpers instead of repeated
scalar scoring.
Bayesian and automatic implementation paths:
- Build explicit
dmx.bstats estimators and fit them with local helpers in
dmx.bstats.bestimation when priors or variational behavior must be
controlled directly.
- Use
get_estimator(..., use_bstats=True) for automatic Bayesian estimator
construction, including composite, optional, and sequence structures.
- Use
get_dpm_mixture for a concise local automatic mixture workflow.
prepare_mixture_model is a first-class automatic mixture route for
embedding flows; without a supplied model it delegates to the local
get_dpm_mixture path.
Keep the execution boundary explicit: these are local helpers. Do not route to
dmx.mpi4py.bstats, dmx.mpi4py.utils.bestimation, or
get_dpm_mixture_mpi; MPI workflows require separate distributed guidance.
4. Keep Shared-Structure Implementations Explicit
This skill should still be useful for coding and fitting advanced local models,
but not for deciding whether they are the right first abstraction.
Implementation defaults:
- for heterogeneous records, build field estimators explicitly and combine them
with
CompositeEstimator
- for latent subtypes over heterogeneous records, implement a
CompositeEstimator inside a MixtureEstimator
- for Bayesian latent subtypes over heterogeneous records, prefer a
dmx.bstats.CompositeEstimator as the base estimator for a truncated DPM;
this DPM-over-composite path is the primary high-value bstats workflow
- for many-label problems with shared latent structure, use keyed shared
components explicitly instead of hiding the structure inside many unrelated
conditional branches
Use references/model-routing.md and
references/repo-entry-points.md for the
keyed mixture and composite-mixture patterns. Use the orchestrator references
for the higher-level question of when those patterns should be preferred.
5. Code Diagnostics And Post-Fit Usage
Choose the success criterion before writing the final code path:
- held-out log likelihood or likelihood comparisons
- classification metrics or ranking depth
- posterior inspection or cluster structure
- embedding-oriented exploratory views
- parameter sanity and fit stability
Repo-native helpers:
src/dmx/utils/metrics.py for classification and ranking-style evaluation
src/dmx/utils/pvalues.py only for narrow approximate significance or rank
calculations, not as a generic testing framework
src/dmx/utils/htsne.py and src/dmx/utils/humap.py for embedding workflows
For cleaned bstats workflow evidence, use:
tests/bstats/dpm_test.py for deterministic DPM initialization, variational
updates, local optimization, and get_dpm_mixture conversion
tests/bstats/composite_test.py for a composite distribution inside finite
mixture and DPM containers
tests/bstats/structural_test.py and
tests/bstats/discrete_primitives_test.py for
get_estimator(..., use_bstats=True) routing
The MPI import smoke assertion in tests/bstats/dpm_test.py is compatibility
coverage only; it does not turn the local fitting recipe into an MPI workflow.
Example Reuse Policy
- Prefer adapting nearby runnable examples over inventing new scaffolding.
- Start with
examples/stats_examples/gaussian_example.py for the smallest
fit-and-score flow.
- Use
examples/utils_examples/detailed_estimation_example.py for validation and repeated-fit
loops.
- Use
examples/stats_examples/mixture_example.py for structured mixtures and
keyed shared-component implementations.
- Use
examples/stats_examples/spearman_rho_example.py for ranking workflows.
- For Bayesian and DPM behavior, prefer the focused
tests/bstats files above;
the current runnable examples primarily demonstrate dmx.stats models.
Output Expectations
- Restate the implementation assumptions briefly before coding.
- Produce runnable code, not only estimator advice.
- Include fitting, scoring, and model-use snippets when they are relevant.
- Show how to inspect the fitted model or compute the requested diagnostic.
- Cite the exact repo example, utility, or stats module that informed the code.
1---2name: dmx-local-modeling3description: Implementation-oriented local `dmx-learn` fitting skill for coding, fitting, diagnosing, and using models on local or in-memory data once the problem structure is known. Prefer explicit `dmx.stats` estimators for ordinary non-Bayesian work and use `dmx.bstats` for Bayesian, variational, DPM, and automatic mixture workflows. Do not use for Spark, MPI, or other distributed estimation workflows.4---56# Dmx Local Modeling78Use this skill for implementation-heavy local modeling work after the problem9has already been scoped to a concrete local `dmx-learn` path.1011This skill is narrow on purpose:1213- it writes explicit estimators, fitting loops, and diagnostics14- it assumes the task is local and in scope for `dmx-learn`15- it does not own broad intake, lightweight EDA, or high-level routing policy1617When the problem framing is still ambiguous, hand that work to18[`dmx-expert-orchestrator`](../dmx-expert-orchestrator/SKILL.md) first.1920## When To Use This Skill2122Use this skill when at least one of these is already known:2324- the observation structure is clear enough to code directly25- the model family has already been chosen upstream26- the user wants runnable fitting code, diagnostics, or post-fit usage27- the main question is about implementation details in `dmx.stats`,28 `dmx.bstats`, or `dmx.utils`2930Do not use this skill as the main router for vague modeling requests. For:3132- intake and lightweight local-data inspection33- structure-first routing across base, composite, mixture, sequence, joint, or34 grouped models35- deciding when to fit one primary model plus one baseline36- deciding whether the task should stay broad and reusable instead of going37 straight to a narrow conditional path3839read [`../dmx-expert-orchestrator/SKILL.md`](../dmx-expert-orchestrator/SKILL.md)40and its41[`references/hierarchy-and-data-structure.md`](../dmx-expert-orchestrator/references/hierarchy-and-data-structure.md)42first.4344## Default Workflow4546### 1. Confirm The Implementation Target4748Before coding, restate only the facts needed for implementation:4950- what one observation is51- the intended estimator family or estimator tree52- the fitting objective or evaluation target53- any known validation split, restart budget, or scale constraint5455If those facts are still uncertain, stop routing locally and defer back to the56orchestrator instead of improvising your own broad routing pass here.5758### 2. Choose The Local Modeling Surface5960- Prefer explicit `dmx.stats` estimator construction for ordinary61 non-Bayesian estimation when the model family is known.62- Use `dmx.bstats` when the implementation needs explicit priors, expected63 log-density calculations, local variational fitting, a truncated DPM, or an64 automatic estimator that will participate in a Bayesian mixture workflow.65- `dmx.utils.automatic.get_estimator(data, use_bstats=True)` is a valid66 first-class route when automatic Bayesian structure inference is intentional.67 Keep `use_bstats=True` explicit in generated code even though the current68 helper default is `True`.69- `dmx.utils.automatic.get_dpm_mixture(data, ...)` is the first-class local70 automatic DPM route. It fits a truncated `dmx.bstats` DPM variationally,71 removes components below its count threshold, and returns a finite72 `dmx.bstats.MixtureDistribution`.73- Keep the hierarchy chosen upstream intact. Do not flatten a composite,74 sequence, or grouped problem into a simpler estimator only because it is75 quicker to code.76- Read [`references/model-routing.md`](references/model-routing.md) when you77 need the concrete estimator family map after the structure is already known.78- Reuse the orchestrator's structure-first philosophy: hierarchy choice comes79 first, field-level estimators second.8081For advanced structure selection, grouped-sharing policy, or joint-model-first82reasoning, go back to the orchestrator reference instead of re-deriving that83logic in this skill.8485### 3. Use Repo-Native Local Fitting Helpers8687Read [`references/repo-entry-points.md`](references/repo-entry-points.md) for88the concrete repo paths.8990Default non-Bayesian implementation path:91921. Build an explicit estimator in `dmx.stats`.932. Split data with `dmx.utils.estimation.partition_data` when held-out94 validation is needed.953. Fit with `dmx.utils.estimation.optimize`.964. Upgrade to `dmx.utils.estimation.best_of` when initialization sensitivity is97 plausible, especially for mixtures or other latent-variable models.985. Use vectorized post-fit calls such as `seq_encode`, `seq_log_density`,99 `seq_log_density_sum`, or related posterior helpers instead of repeated100 scalar scoring.101102Bayesian and automatic implementation paths:103104- Build explicit `dmx.bstats` estimators and fit them with local helpers in105 `dmx.bstats.bestimation` when priors or variational behavior must be106 controlled directly.107- Use `get_estimator(..., use_bstats=True)` for automatic Bayesian estimator108 construction, including composite, optional, and sequence structures.109- Use `get_dpm_mixture` for a concise local automatic mixture workflow.110- `prepare_mixture_model` is a first-class automatic mixture route for111 embedding flows; without a supplied model it delegates to the local112 `get_dpm_mixture` path.113114Keep the execution boundary explicit: these are local helpers. Do not route to115`dmx.mpi4py.bstats`, `dmx.mpi4py.utils.bestimation`, or116`get_dpm_mixture_mpi`; MPI workflows require separate distributed guidance.117118### 4. Keep Shared-Structure Implementations Explicit119120This skill should still be useful for coding and fitting advanced local models,121but not for deciding whether they are the right first abstraction.122123Implementation defaults:124125- for heterogeneous records, build field estimators explicitly and combine them126 with `CompositeEstimator`127- for latent subtypes over heterogeneous records, implement a128 `CompositeEstimator` inside a `MixtureEstimator`129- for Bayesian latent subtypes over heterogeneous records, prefer a130 `dmx.bstats.CompositeEstimator` as the base estimator for a truncated DPM;131 this DPM-over-composite path is the primary high-value `bstats` workflow132- for many-label problems with shared latent structure, use keyed shared133 components explicitly instead of hiding the structure inside many unrelated134 conditional branches135136Use [`references/model-routing.md`](references/model-routing.md) and137[`references/repo-entry-points.md`](references/repo-entry-points.md) for the138keyed mixture and composite-mixture patterns. Use the orchestrator references139for the higher-level question of when those patterns should be preferred.140141### 5. Code Diagnostics And Post-Fit Usage142143Choose the success criterion before writing the final code path:144145- held-out log likelihood or likelihood comparisons146- classification metrics or ranking depth147- posterior inspection or cluster structure148- embedding-oriented exploratory views149- parameter sanity and fit stability150151Repo-native helpers:152153- `src/dmx/utils/metrics.py` for classification and ranking-style evaluation154- `src/dmx/utils/pvalues.py` only for narrow approximate significance or rank155 calculations, not as a generic testing framework156- `src/dmx/utils/htsne.py` and `src/dmx/utils/humap.py` for embedding workflows157158For cleaned `bstats` workflow evidence, use:159160- `tests/bstats/dpm_test.py` for deterministic DPM initialization, variational161 updates, local optimization, and `get_dpm_mixture` conversion162- `tests/bstats/composite_test.py` for a composite distribution inside finite163 mixture and DPM containers164- `tests/bstats/structural_test.py` and165 `tests/bstats/discrete_primitives_test.py` for166 `get_estimator(..., use_bstats=True)` routing167168The MPI import smoke assertion in `tests/bstats/dpm_test.py` is compatibility169coverage only; it does not turn the local fitting recipe into an MPI workflow.170171## Example Reuse Policy172173- Prefer adapting nearby runnable examples over inventing new scaffolding.174- Start with `examples/stats_examples/gaussian_example.py` for the smallest175 fit-and-score flow.176- Use `examples/utils_examples/detailed_estimation_example.py` for validation and repeated-fit177 loops.178- Use `examples/stats_examples/mixture_example.py` for structured mixtures and179 keyed shared-component implementations.180- Use `examples/stats_examples/spearman_rho_example.py` for ranking workflows.181- For Bayesian and DPM behavior, prefer the focused `tests/bstats` files above;182 the current runnable examples primarily demonstrate `dmx.stats` models.183184## Output Expectations185186- Restate the implementation assumptions briefly before coding.187- Produce runnable code, not only estimator advice.188- Include fitting, scoring, and model-use snippets when they are relevant.189- Show how to inspect the fitted model or compute the requested diagnostic.190- Cite the exact repo example, utility, or stats module that informed the code.