@pikaa-ai/pikaa 0.3.22 → 0.3.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/brand/orbit-logo-option4-whale.jpg +0 -0
- package/assets/brand/orbit-logo.jpg +0 -0
- package/assets/brand/orbit-logo.png +0 -0
- package/assets/brand/orbit-logo.svg +3 -0
- package/dist/cli.js +448 -181
- package/dist/index.js +22 -2
- package/package.json +1 -2
- package/skills/adaptyv/SKILL.md +0 -240
- package/skills/aeon/SKILL.md +0 -402
- package/skills/analytical-method-validation/SKILL.md +0 -299
- package/skills/anndata/SKILL.md +0 -431
- package/skills/arbor/SKILL.md +0 -152
- package/skills/arboreto/SKILL.md +0 -267
- package/skills/astropy/SKILL.md +0 -353
- package/skills/autoskill/SKILL.md +0 -233
- package/skills/benchling-integration/SKILL.md +0 -229
- package/skills/bgpt-paper-search/SKILL.md +0 -75
- package/skills/bids/SKILL.md +0 -237
- package/skills/biopython/SKILL.md +0 -472
- package/skills/bioservices/SKILL.md +0 -399
- package/skills/bulk-rnaseq/SKILL.md +0 -198
- package/skills/cellxgene-census/SKILL.md +0 -283
- package/skills/cirq/SKILL.md +0 -370
- package/skills/citation-management/SKILL.md +0 -329
- package/skills/clinical-decision-support/SKILL.md +0 -238
- package/skills/clinical-decision-support/references/README.md +0 -62
- package/skills/clinical-reports/SKILL.md +0 -248
- package/skills/clinical-reports/references/README.md +0 -34
- package/skills/cobrapy/SKILL.md +0 -496
- package/skills/consciousness-council/SKILL.md +0 -151
- package/skills/dask/SKILL.md +0 -482
- package/skills/database-lookup/SKILL.md +0 -386
- package/skills/datamol/SKILL.md +0 -200
- package/skills/deepchem/SKILL.md +0 -244
- package/skills/deepspot-m/SKILL.md +0 -175
- package/skills/deeptools/SKILL.md +0 -412
- package/skills/depmap/SKILL.md +0 -301
- package/skills/dhdna-profiler/SKILL.md +0 -184
- package/skills/diffdock/SKILL.md +0 -488
- package/skills/dnanexus-integration/SKILL.md +0 -325
- package/skills/docx/SKILL.md +0 -99
- package/skills/esm/SKILL.md +0 -334
- package/skills/etetoolkit/SKILL.md +0 -327
- package/skills/exa-search/SKILL.md +0 -102
- package/skills/executing-plans/SKILL.md +0 -14
- package/skills/experimental-design/SKILL.md +0 -234
- package/skills/exploratory-data-analysis/SKILL.md +0 -280
- package/skills/flowio/SKILL.md +0 -310
- package/skills/fluidsim/SKILL.md +0 -279
- package/skills/frontend-design/SKILL.md +0 -100
- package/skills/generate-image/SKILL.md +0 -304
- package/skills/geniml/SKILL.md +0 -310
- package/skills/genomic-coordinates/SKILL.md +0 -189
- package/skills/genomic-intelligence/SKILL.md +0 -243
- package/skills/geomaster/README.md +0 -105
- package/skills/geomaster/SKILL.md +0 -366
- package/skills/geopandas/SKILL.md +0 -250
- package/skills/get-available-resources/SKILL.md +0 -260
- package/skills/gget/SKILL.md +0 -153
- package/skills/ginkgo-cloud-lab/SKILL.md +0 -106
- package/skills/glycoengineering/SKILL.md +0 -339
- package/skills/gtars/SKILL.md +0 -282
- package/skills/guardian-rails/SKILL.md +0 -54
- package/skills/histolab/SKILL.md +0 -243
- package/skills/hugging-science/SKILL.md +0 -132
- package/skills/hypogenic/SKILL.md +0 -290
- package/skills/hypothesis-generation/SKILL.md +0 -264
- package/skills/imaging-data-commons/SKILL.md +0 -496
- package/skills/infographics/SKILL.md +0 -315
- package/skills/iso-standards-readiness/SKILL.md +0 -352
- package/skills/lab-hardware-cad/SKILL.md +0 -372
- package/skills/labarchive-integration/SKILL.md +0 -216
- package/skills/lamindb/SKILL.md +0 -408
- package/skills/latchbio-integration/SKILL.md +0 -227
- package/skills/latex-posters/SKILL.md +0 -369
- package/skills/latex-posters/references/README.md +0 -439
- package/skills/liteparse/SKILL.md +0 -295
- package/skills/literature-review/SKILL.md +0 -263
- package/skills/markdown-mermaid-writing/SKILL.md +0 -322
- package/skills/market-research-reports/SKILL.md +0 -337
- package/skills/markitdown/SKILL.md +0 -264
- package/skills/matchms/SKILL.md +0 -276
- package/skills/matlab/SKILL.md +0 -274
- package/skills/matplotlib/SKILL.md +0 -378
- package/skills/medchem/SKILL.md +0 -321
- package/skills/modal/SKILL.md +0 -468
- package/skills/molecular-dynamics/SKILL.md +0 -458
- package/skills/molfeat/SKILL.md +0 -348
- package/skills/ncats-arax/SKILL.md +0 -178
- package/skills/networkx/SKILL.md +0 -440
- package/skills/neurokit2/SKILL.md +0 -323
- package/skills/neuropixels-analysis/SKILL.md +0 -412
- package/skills/nextflow/SKILL.md +0 -195
- package/skills/omero-integration/SKILL.md +0 -222
- package/skills/onekgpd/SKILL.md +0 -371
- package/skills/ontology-term-resolution/SKILL.md +0 -147
- package/skills/open-notebook/SKILL.md +0 -297
- package/skills/openpiv/SKILL.md +0 -469
- package/skills/opentrons-integration/SKILL.md +0 -322
- package/skills/optimize-for-gpu/SKILL.md +0 -176
- package/skills/owasp-top10/SKILL.md +0 -48
- package/skills/pacsomatic/LICENSE +0 -21
- package/skills/pacsomatic/SKILL.md +0 -150
- package/skills/paper-lookup/SKILL.md +0 -263
- package/skills/paperclip/SKILL.md +0 -413
- package/skills/paperzilla/SKILL.md +0 -159
- package/skills/parallel-web/SKILL.md +0 -128
- package/skills/pathml/SKILL.md +0 -222
- package/skills/pathogen-variant-surveillance/SKILL.md +0 -208
- package/skills/pathway-enrichment/SKILL.md +0 -194
- package/skills/pdf/SKILL.md +0 -322
- package/skills/peer-review/SKILL.md +0 -288
- package/skills/penetration-testing/SKILL.md +0 -31
- package/skills/pennylane/SKILL.md +0 -240
- package/skills/phylogenetics/SKILL.md +0 -409
- package/skills/pi-agent/SKILL.md +0 -83
- package/skills/pkpd-modeling/SKILL.md +0 -381
- package/skills/polars/SKILL.md +0 -393
- package/skills/polars-bio/SKILL.md +0 -379
- package/skills/ponytail/SKILL.md +0 -31
- package/skills/ponytail-audit/SKILL.md +0 -18
- package/skills/pptx/SKILL.md +0 -246
- package/skills/pptx-posters/SKILL.md +0 -258
- package/skills/primekg/SKILL.md +0 -99
- package/skills/protocolsio-integration/SKILL.md +0 -236
- package/skills/pufferlib/SKILL.md +0 -328
- package/skills/pydeseq2/SKILL.md +0 -369
- package/skills/pydicom/SKILL.md +0 -381
- package/skills/pyhealth/SKILL.md +0 -124
- package/skills/pylabrobot/SKILL.md +0 -216
- package/skills/pymatgen/SKILL.md +0 -404
- package/skills/pymc/SKILL.md +0 -310
- package/skills/pymoo/SKILL.md +0 -276
- package/skills/pyopenms/SKILL.md +0 -179
- package/skills/pysam/SKILL.md +0 -330
- package/skills/pytdc/SKILL.md +0 -297
- package/skills/pytorch-lightning/SKILL.md +0 -191
- package/skills/pyzotero/SKILL.md +0 -137
- package/skills/qiskit/SKILL.md +0 -259
- package/skills/qutip/SKILL.md +0 -317
- package/skills/rdkit/SKILL.md +0 -94
- package/skills/relsa-severity-assessment/SKILL.md +0 -354
- package/skills/research-grants/SKILL.md +0 -296
- package/skills/research-grants/references/README.md +0 -287
- package/skills/research-lookup/README.md +0 -106
- package/skills/research-lookup/SKILL.md +0 -338
- package/skills/rowan/SKILL.md +0 -398
- package/skills/scanpy/SKILL.md +0 -303
- package/skills/scholar-evaluation/SKILL.md +0 -296
- package/skills/scientific-brainstorming/SKILL.md +0 -282
- package/skills/scientific-critical-thinking/SKILL.md +0 -180
- package/skills/scientific-schematics/SKILL.md +0 -370
- package/skills/scientific-slides/SKILL.md +0 -379
- package/skills/scientific-visualization/SKILL.md +0 -285
- package/skills/scientific-writing/SKILL.md +0 -356
- package/skills/scikit-bio/SKILL.md +0 -470
- package/skills/scikit-learn/SKILL.md +0 -324
- package/skills/scikit-survival/SKILL.md +0 -313
- package/skills/scvelo/SKILL.md +0 -328
- package/skills/scvi-tools/SKILL.md +0 -201
- package/skills/seaborn/SKILL.md +0 -254
- package/skills/security-auditor/SKILL.md +0 -37
- package/skills/shap/SKILL.md +0 -282
- package/skills/simpy/SKILL.md +0 -283
- package/skills/stable-baselines3/SKILL.md +0 -325
- package/skills/statistical-analysis/SKILL.md +0 -446
- package/skills/statistical-power/SKILL.md +0 -200
- package/skills/statsmodels/SKILL.md +0 -238
- package/skills/sympy/SKILL.md +0 -354
- package/skills/systematic-debugging/SKILL.md +0 -35
- package/skills/tamarind/SKILL.md +0 -285
- package/skills/tdd/SKILL.md +0 -26
- package/skills/tiledbvcf/SKILL.md +0 -456
- package/skills/timesfm-forecasting/SKILL.md +0 -408
- package/skills/timesfm-forecasting/examples/global-temperature/README.md +0 -178
- package/skills/torch-geometric/SKILL.md +0 -458
- package/skills/torchdrug/SKILL.md +0 -241
- package/skills/transformers/SKILL.md +0 -195
- package/skills/treatment-plans/SKILL.md +0 -174
- package/skills/treatment-plans/references/README.md +0 -19
- package/skills/umap-learn/SKILL.md +0 -488
- package/skills/uncertainty-and-units/SKILL.md +0 -384
- package/skills/usfiscaldata/SKILL.md +0 -171
- package/skills/vaex/SKILL.md +0 -204
- package/skills/venue-templates/SKILL.md +0 -269
- package/skills/verification-before-completion/SKILL.md +0 -22
- package/skills/waypoint-bio/SKILL.md +0 -273
- package/skills/what-if-oracle/SKILL.md +0 -184
- package/skills/writing-plans/SKILL.md +0 -15
- package/skills/xlsx/SKILL.md +0 -110
- package/skills/zarr-python/SKILL.md +0 -241
package/skills/pymc/SKILL.md
DELETED
|
@@ -1,310 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: pymc
|
|
3
|
-
description: Bayesian modeling with PyMC. Build hierarchical models, MCMC (NUTS), variational inference, LOO/WAIC comparison, posterior checks, for probabilistic programming and inference.
|
|
4
|
-
allowed-tools: Read Write Edit Bash
|
|
5
|
-
compatibility: Requires Python 3.12+ and PyMC 6.0.1-compatible dependencies. Install reproducible environments with `uv pip install "pymc[nutpie]==6.0.1"`; optional NumPyro or BlackJAX samplers require separately pinned JAX-compatible dependencies.
|
|
6
|
-
license: Apache License, Version 2.0
|
|
7
|
-
metadata:
|
|
8
|
-
version: "1.3"
|
|
9
|
-
skill-author: K-Dense Inc.
|
|
10
|
-
---
|
|
11
|
-
|
|
12
|
-
# PyMC Bayesian Modeling
|
|
13
|
-
|
|
14
|
-
## Overview
|
|
15
|
-
|
|
16
|
-
PyMC is a Python library for Bayesian modeling and probabilistic programming. Build, fit, validate, and compare Bayesian models using PyMC's modern API (version 6.x+), including hierarchical models, MCMC sampling (NUTS), variational inference, posterior predictive checks, and model comparison (LOO, WAIC).
|
|
17
|
-
|
|
18
|
-
## Current Version and Setup
|
|
19
|
-
|
|
20
|
-
PyMC 6.0.1 is the current stable release as of June 2026. It requires Python 3.12+, uses PyTensor 3 as the computational graph backend, and defaults to compiled backends such as Numba. For reproducible local environments, pin the version:
|
|
21
|
-
|
|
22
|
-
```bash
|
|
23
|
-
uv pip install "pymc[nutpie]==6.0.1"
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
The `nutpie` extra enables the faster Rust/Numba NUTS implementation. If using NumPyro or BlackJAX, install those optional sampler dependencies in the same environment and pin them in the project lockfile.
|
|
27
|
-
|
|
28
|
-
## When to Use This Skill
|
|
29
|
-
|
|
30
|
-
This skill should be used when:
|
|
31
|
-
- Building Bayesian models (linear/logistic regression, hierarchical models, time series, etc.)
|
|
32
|
-
- Performing MCMC sampling or variational inference
|
|
33
|
-
- Conducting prior/posterior predictive checks
|
|
34
|
-
- Diagnosing sampling issues (divergences, convergence, ESS)
|
|
35
|
-
- Comparing multiple models using information criteria (LOO, WAIC)
|
|
36
|
-
- Implementing uncertainty quantification through Bayesian methods
|
|
37
|
-
- Working with hierarchical/multilevel data structures
|
|
38
|
-
- Handling missing data or measurement error in a principled way
|
|
39
|
-
|
|
40
|
-
## Standard Bayesian Workflow
|
|
41
|
-
|
|
42
|
-
Never sample first and check later. The eight-step workflow — documented with code in
|
|
43
|
-
[references/standard_workflow.md](references/standard_workflow.md) — is:
|
|
44
|
-
|
|
45
|
-
1. **Data preparation** — including standardizing predictors so priors are interpretable.
|
|
46
|
-
2. **Model building** — priors and likelihood in a `pm.Model` context.
|
|
47
|
-
3. **Prior predictive check** — confirm the priors imply plausible data *before* fitting.
|
|
48
|
-
4. **Fit model** — `pm.sample()` with an explicit seed.
|
|
49
|
-
5. **Check diagnostics** — R-hat, ESS, divergences. Divergences invalidate the fit; fix
|
|
50
|
-
the model or reparameterize rather than raising `target_accept` and hoping.
|
|
51
|
-
6. **Posterior predictive check** — does the fitted model reproduce the observed data?
|
|
52
|
-
7. **Analyze results** — summaries and intervals from the posterior.
|
|
53
|
-
8. **Make predictions** — on new data via `pm.set_data` and posterior predictive sampling.
|
|
54
|
-
|
|
55
|
-
Reusable model structures and model comparison are in
|
|
56
|
-
[references/model_patterns.md](references/model_patterns.md).
|
|
57
|
-
|
|
58
|
-
## Distribution Selection Guide
|
|
59
|
-
|
|
60
|
-
### For Priors
|
|
61
|
-
|
|
62
|
-
**Scale parameters** (σ, τ):
|
|
63
|
-
- `pm.HalfNormal('sigma', sigma=1)` - Default choice
|
|
64
|
-
- `pm.Exponential('sigma', lam=1)` - Alternative
|
|
65
|
-
- `pm.Gamma('sigma', alpha=2, beta=1)` - More informative
|
|
66
|
-
|
|
67
|
-
**Unbounded parameters**:
|
|
68
|
-
- `pm.Normal('theta', mu=0, sigma=1)` - For standardized data
|
|
69
|
-
- `pm.StudentT('theta', nu=3, mu=0, sigma=1)` - Robust to outliers
|
|
70
|
-
|
|
71
|
-
**Positive parameters**:
|
|
72
|
-
- `pm.LogNormal('theta', mu=0, sigma=1)`
|
|
73
|
-
- `pm.Gamma('theta', alpha=2, beta=1)`
|
|
74
|
-
|
|
75
|
-
**Probabilities**:
|
|
76
|
-
- `pm.Beta('p', alpha=2, beta=2)` - Weakly informative
|
|
77
|
-
- `pm.Uniform('p', lower=0, upper=1)` - Non-informative (use sparingly)
|
|
78
|
-
|
|
79
|
-
**Correlation matrices**:
|
|
80
|
-
- `pm.LKJCholeskyCov('chol', n=n_vars, eta=2, sd_dist=pm.HalfNormal.dist(1))` - Preferred covariance prior
|
|
81
|
-
- `pm.LKJCorr('corr', n=n_vars, eta=2)` - Correlation-only prior; eta=1 uniform, eta>1 prefers identity
|
|
82
|
-
|
|
83
|
-
### For Likelihoods
|
|
84
|
-
|
|
85
|
-
**Continuous outcomes**:
|
|
86
|
-
- `pm.Normal('y', mu=mu, sigma=sigma)` - Default for continuous data
|
|
87
|
-
- `pm.StudentT('y', nu=nu, mu=mu, sigma=sigma)` - Robust to outliers
|
|
88
|
-
|
|
89
|
-
**Count data**:
|
|
90
|
-
- `pm.Poisson('y', mu=lambda)` - Equidispersed counts
|
|
91
|
-
- `pm.NegativeBinomial('y', mu=mu, alpha=alpha)` - Overdispersed counts
|
|
92
|
-
- `pm.ZeroInflatedPoisson('y', psi=psi, mu=mu)` - Excess zeros
|
|
93
|
-
- `pm.HurdleNegativeBinomial('y', psi=psi, mu=mu, alpha=alpha)` - Excess zeros plus overdispersion
|
|
94
|
-
|
|
95
|
-
**Binary outcomes**:
|
|
96
|
-
- `pm.Bernoulli('y', p=p)` or `pm.Bernoulli('y', logit_p=logit_p)`
|
|
97
|
-
|
|
98
|
-
**Categorical outcomes**:
|
|
99
|
-
- `pm.Categorical('y', p=probs)`
|
|
100
|
-
|
|
101
|
-
**See:** `references/distributions.md` for comprehensive distribution reference
|
|
102
|
-
|
|
103
|
-
## Sampling and Inference
|
|
104
|
-
|
|
105
|
-
### MCMC with NUTS
|
|
106
|
-
|
|
107
|
-
Default and recommended for most models:
|
|
108
|
-
|
|
109
|
-
```python
|
|
110
|
-
idata = pm.sample(
|
|
111
|
-
draws=2000,
|
|
112
|
-
tune=1000,
|
|
113
|
-
chains=4,
|
|
114
|
-
target_accept=0.9,
|
|
115
|
-
random_seed=42
|
|
116
|
-
)
|
|
117
|
-
```
|
|
118
|
-
|
|
119
|
-
**Adjust when needed:**
|
|
120
|
-
- Divergences → `target_accept=0.95` or higher
|
|
121
|
-
- Slow sampling → Use ADVI for initialization
|
|
122
|
-
- Discrete parameters → Use `pm.Metropolis()` for discrete vars
|
|
123
|
-
|
|
124
|
-
### Variational Inference
|
|
125
|
-
|
|
126
|
-
Fast approximation for exploration or initialization:
|
|
127
|
-
|
|
128
|
-
```python
|
|
129
|
-
with model:
|
|
130
|
-
approx = pm.fit(n=20000, method='advi')
|
|
131
|
-
|
|
132
|
-
# Use for initialization
|
|
133
|
-
initvals = approx.sample(return_inferencedata=False)[0]
|
|
134
|
-
idata = pm.sample(initvals=initvals)
|
|
135
|
-
```
|
|
136
|
-
|
|
137
|
-
**Trade-offs:**
|
|
138
|
-
- Much faster than MCMC
|
|
139
|
-
- Approximate (may underestimate uncertainty)
|
|
140
|
-
- Good for large models or quick exploration
|
|
141
|
-
|
|
142
|
-
**See:** `references/sampling_inference.md` for detailed sampling guide
|
|
143
|
-
|
|
144
|
-
## Diagnostic Scripts
|
|
145
|
-
|
|
146
|
-
### Comprehensive Diagnostics
|
|
147
|
-
|
|
148
|
-
```python
|
|
149
|
-
from scripts.model_diagnostics import create_diagnostic_report
|
|
150
|
-
|
|
151
|
-
create_diagnostic_report(
|
|
152
|
-
idata,
|
|
153
|
-
var_names=['alpha', 'beta', 'sigma'],
|
|
154
|
-
output_dir='diagnostics/'
|
|
155
|
-
)
|
|
156
|
-
```
|
|
157
|
-
|
|
158
|
-
Creates:
|
|
159
|
-
- Trace plots
|
|
160
|
-
- Rank plots (mixing check)
|
|
161
|
-
- Autocorrelation plots
|
|
162
|
-
- Energy plots
|
|
163
|
-
- Local ESS plots
|
|
164
|
-
- Summary statistics CSV
|
|
165
|
-
|
|
166
|
-
### Quick Diagnostic Check
|
|
167
|
-
|
|
168
|
-
```python
|
|
169
|
-
from scripts.model_diagnostics import check_diagnostics
|
|
170
|
-
|
|
171
|
-
results = check_diagnostics(idata)
|
|
172
|
-
```
|
|
173
|
-
|
|
174
|
-
Checks R-hat, ESS, divergences, and tree depth.
|
|
175
|
-
|
|
176
|
-
## Common Issues and Solutions
|
|
177
|
-
|
|
178
|
-
### Divergences
|
|
179
|
-
|
|
180
|
-
**Symptom:** `idata.sample_stats.diverging.sum() > 0`
|
|
181
|
-
|
|
182
|
-
**Solutions:**
|
|
183
|
-
1. Increase `target_accept=0.95` or `0.99`
|
|
184
|
-
2. Use non-centered parameterization (hierarchical models)
|
|
185
|
-
3. Add stronger priors to constrain parameters
|
|
186
|
-
4. Check for model misspecification
|
|
187
|
-
|
|
188
|
-
### Low Effective Sample Size
|
|
189
|
-
|
|
190
|
-
**Symptom:** `ESS < 400`
|
|
191
|
-
|
|
192
|
-
**Solutions:**
|
|
193
|
-
1. Sample more draws: `draws=5000`
|
|
194
|
-
2. Reparameterize to reduce posterior correlation
|
|
195
|
-
3. Use QR decomposition for regression with correlated predictors
|
|
196
|
-
|
|
197
|
-
### High R-hat
|
|
198
|
-
|
|
199
|
-
**Symptom:** `R-hat > 1.01`
|
|
200
|
-
|
|
201
|
-
**Solutions:**
|
|
202
|
-
1. Run longer chains: `tune=2000, draws=5000`
|
|
203
|
-
2. Check for multimodality
|
|
204
|
-
3. Improve initialization with ADVI
|
|
205
|
-
|
|
206
|
-
### Slow Sampling
|
|
207
|
-
|
|
208
|
-
**Solutions:**
|
|
209
|
-
1. Use ADVI initialization
|
|
210
|
-
2. Reduce model complexity
|
|
211
|
-
3. Increase parallelization: `cores=8, chains=8`
|
|
212
|
-
4. Use variational inference if appropriate
|
|
213
|
-
|
|
214
|
-
## Best Practices
|
|
215
|
-
|
|
216
|
-
### Model Building
|
|
217
|
-
|
|
218
|
-
1. **Always standardize predictors** for better sampling
|
|
219
|
-
2. **Use weakly informative priors** (not flat)
|
|
220
|
-
3. **Use named dimensions** (`dims`) for clarity
|
|
221
|
-
4. **Non-centered parameterization** for hierarchical models
|
|
222
|
-
5. **Check prior predictive** before fitting
|
|
223
|
-
|
|
224
|
-
### Sampling
|
|
225
|
-
|
|
226
|
-
1. **Run multiple chains** (at least 4) for convergence
|
|
227
|
-
2. **Use `target_accept=0.9`** as baseline (higher if needed)
|
|
228
|
-
3. **Include `log_likelihood=True`** for model comparison
|
|
229
|
-
4. **Set random seed** for reproducibility
|
|
230
|
-
|
|
231
|
-
### Validation
|
|
232
|
-
|
|
233
|
-
1. **Check diagnostics** before interpretation (R-hat, ESS, divergences)
|
|
234
|
-
2. **Posterior predictive check** for model validation
|
|
235
|
-
3. **Compare multiple models** when appropriate
|
|
236
|
-
4. **Report uncertainty** (HDI intervals, not just point estimates)
|
|
237
|
-
|
|
238
|
-
### Workflow
|
|
239
|
-
|
|
240
|
-
1. Start simple, add complexity gradually
|
|
241
|
-
2. Prior predictive check → Fit → Diagnostics → Posterior predictive check
|
|
242
|
-
3. Iterate on model specification based on checks
|
|
243
|
-
4. Document assumptions and prior choices
|
|
244
|
-
|
|
245
|
-
## Resources
|
|
246
|
-
|
|
247
|
-
This skill includes:
|
|
248
|
-
|
|
249
|
-
### References (`references/`)
|
|
250
|
-
|
|
251
|
-
- **`distributions.md`**: Comprehensive catalog of PyMC distributions organized by category (continuous, discrete, multivariate, mixture, time series). Use when selecting priors or likelihoods.
|
|
252
|
-
|
|
253
|
-
- **`sampling_inference.md`**: Detailed guide to sampling algorithms (NUTS, Metropolis, SMC), variational inference (ADVI, SVGD), and handling sampling issues. Use when encountering convergence problems or choosing inference methods.
|
|
254
|
-
|
|
255
|
-
- **`workflows.md`**: Complete workflow examples and code patterns for common model types, data preparation, prior selection, and model validation. Use as a cookbook for standard Bayesian analyses.
|
|
256
|
-
|
|
257
|
-
### Scripts (`scripts/`)
|
|
258
|
-
|
|
259
|
-
- **`model_diagnostics.py`**: Automated diagnostic checking and report generation. Functions: `check_diagnostics()` for quick checks, `create_diagnostic_report()` for comprehensive analysis with plots.
|
|
260
|
-
|
|
261
|
-
- **`model_comparison.py`**: Model comparison utilities built on PSIS-LOO ELPD, the only criterion ArviZ 1.x `compare()` ranks on. Functions: `compare_models()`, `check_loo_reliability()`, `model_averaging()`.
|
|
262
|
-
|
|
263
|
-
### Templates (`assets/`)
|
|
264
|
-
|
|
265
|
-
- **`linear_regression_template.py`**: Complete template for Bayesian linear regression with full workflow (data prep, prior checks, fitting, diagnostics, predictions).
|
|
266
|
-
|
|
267
|
-
- **`hierarchical_model_template.py`**: Complete template for hierarchical/multilevel models with non-centered parameterization and group-level analysis.
|
|
268
|
-
|
|
269
|
-
## Quick Reference
|
|
270
|
-
|
|
271
|
-
### Model Building
|
|
272
|
-
```python
|
|
273
|
-
with pm.Model(coords={'var': names}) as model:
|
|
274
|
-
# Priors
|
|
275
|
-
param = pm.Normal('param', mu=0, sigma=1, dims='var')
|
|
276
|
-
# Likelihood
|
|
277
|
-
y = pm.Normal('y', mu=..., sigma=..., observed=data)
|
|
278
|
-
```
|
|
279
|
-
|
|
280
|
-
### Sampling
|
|
281
|
-
```python
|
|
282
|
-
idata = pm.sample(draws=2000, tune=1000, chains=4, target_accept=0.9)
|
|
283
|
-
```
|
|
284
|
-
|
|
285
|
-
### Diagnostics
|
|
286
|
-
```python
|
|
287
|
-
from scripts.model_diagnostics import check_diagnostics
|
|
288
|
-
check_diagnostics(idata)
|
|
289
|
-
```
|
|
290
|
-
|
|
291
|
-
### Model Comparison
|
|
292
|
-
```python
|
|
293
|
-
from scripts.model_comparison import compare_models
|
|
294
|
-
compare_models({'m1': idata1, 'm2': idata2}, ic='loo')
|
|
295
|
-
```
|
|
296
|
-
|
|
297
|
-
### Predictions
|
|
298
|
-
```python
|
|
299
|
-
with model:
|
|
300
|
-
pm.set_data({'X_data': X_new})
|
|
301
|
-
pred = pm.sample_posterior_predictive(idata, predictions=True)
|
|
302
|
-
```
|
|
303
|
-
|
|
304
|
-
## Additional Notes
|
|
305
|
-
|
|
306
|
-
- PyMC integrates with ArviZ for visualization and diagnostics; PyMC 6 / ArviZ 1 use xarray `DataTree` while retaining familiar groups such as `.posterior` and `.posterior_predictive`
|
|
307
|
-
- Use `pm.model_to_graphviz(model)` to visualize model structure
|
|
308
|
-
- Save results with `idata.to_netcdf('results.nc')`
|
|
309
|
-
- Load with `az.from_netcdf('results.nc')`
|
|
310
|
-
- For very large models, consider minibatch ADVI or data subsampling
|
package/skills/pymoo/SKILL.md
DELETED
|
@@ -1,276 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: pymoo
|
|
3
|
-
description: Multi-objective optimization framework. NSGA-II, NSGA-III, MOEA/D, Pareto fronts, constraint handling, benchmarks (ZDT, DTLZ), for engineering design and optimization problems.
|
|
4
|
-
license: Apache-2.0 license
|
|
5
|
-
allowed-tools: Read Write Edit Bash
|
|
6
|
-
compatibility: Requires Python 3.10+ and pymoo (uv pip install). Optional matplotlib for visualization plots; optional autograd for gradient-based features; optional joblib for JoblibParallelization.
|
|
7
|
-
metadata:
|
|
8
|
-
version: "1.3"
|
|
9
|
-
skill-author: K-Dense Inc.
|
|
10
|
-
---
|
|
11
|
-
|
|
12
|
-
# Pymoo - Multi-Objective Optimization in Python
|
|
13
|
-
|
|
14
|
-
## Overview
|
|
15
|
-
|
|
16
|
-
Pymoo is a comprehensive Python framework for optimization with emphasis on multi-objective problems. Solve single and multi-objective optimization using state-of-the-art algorithms (NSGA-II/III, MOEA/D, SPEA2), benchmark problems (ZDT, DTLZ), customizable genetic operators, and multi-criteria decision making methods. Excels at finding trade-off solutions (Pareto fronts) for problems with conflicting objectives. Current stable release: **pymoo 0.6.1.6** (November 2025).
|
|
17
|
-
|
|
18
|
-
## Installation
|
|
19
|
-
|
|
20
|
-
```bash
|
|
21
|
-
uv pip install pymoo
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
For reproducible environments, pin a version: `uv pip install "pymoo==0.6.1.6"`.
|
|
25
|
-
|
|
26
|
-
**Dependencies:** NumPy (2.x compatible since 0.6.1.3), SciPy, matplotlib (visualization). Autograd is optional for gradient-based features (since 0.6.1.3).
|
|
27
|
-
|
|
28
|
-
**Documentation:** https://pymoo.org/ — LLM-friendly index: https://pymoo.org/llms.txt
|
|
29
|
-
|
|
30
|
-
## When to Use This Skill
|
|
31
|
-
|
|
32
|
-
This skill should be used when:
|
|
33
|
-
- Solving optimization problems with one or multiple objectives
|
|
34
|
-
- Finding Pareto-optimal solutions and analyzing trade-offs
|
|
35
|
-
- Implementing evolutionary algorithms (GA, DE, PSO, NSGA-II/III)
|
|
36
|
-
- Working with constrained optimization problems
|
|
37
|
-
- Benchmarking algorithms on standard test problems (ZDT, DTLZ, WFG)
|
|
38
|
-
- Customizing genetic operators (crossover, mutation, selection)
|
|
39
|
-
- Visualizing high-dimensional optimization results
|
|
40
|
-
- Making decisions from multiple competing solutions
|
|
41
|
-
- Handling binary, discrete, continuous, or mixed-variable problems
|
|
42
|
-
|
|
43
|
-
## Core Concepts
|
|
44
|
-
|
|
45
|
-
### The Unified Interface
|
|
46
|
-
|
|
47
|
-
Pymoo uses a consistent `minimize()` function for all optimization tasks:
|
|
48
|
-
|
|
49
|
-
```python
|
|
50
|
-
from pymoo.optimize import minimize
|
|
51
|
-
|
|
52
|
-
result = minimize(
|
|
53
|
-
problem, # What to optimize
|
|
54
|
-
algorithm, # How to optimize
|
|
55
|
-
termination, # When to stop
|
|
56
|
-
seed=1,
|
|
57
|
-
verbose=True
|
|
58
|
-
)
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
**Result object contains:**
|
|
62
|
-
- `result.X`: Decision variables of optimal solution(s)
|
|
63
|
-
- `result.F`: Objective values of optimal solution(s)
|
|
64
|
-
- `result.G`: Constraint violations (if constrained)
|
|
65
|
-
- `result.algorithm`: Algorithm object with history
|
|
66
|
-
|
|
67
|
-
### Problem Definition Styles
|
|
68
|
-
|
|
69
|
-
Pymoo supports three problem definition styles:
|
|
70
|
-
|
|
71
|
-
- **`Problem`**: Vectorized — `_evaluate` receives a batch of solutions (matrix)
|
|
72
|
-
- **`ElementwiseProblem`**: One solution per call — recommended for custom problems and parallel evaluation
|
|
73
|
-
- **`FunctionalProblem`**: Define objectives and constraints as separate functions without subclassing
|
|
74
|
-
|
|
75
|
-
### Problem Types
|
|
76
|
-
|
|
77
|
-
**Single-objective:** One objective to minimize/maximize
|
|
78
|
-
**Multi-objective:** 2-3 conflicting objectives → Pareto front
|
|
79
|
-
**Many-objective:** 4+ objectives → High-dimensional Pareto front
|
|
80
|
-
**Constrained:** Objectives + inequality/equality constraints
|
|
81
|
-
**Mixed-variable:** Continuous, integer, binary, and categorical variables in one problem
|
|
82
|
-
**Dynamic:** Time-varying objectives or constraints
|
|
83
|
-
|
|
84
|
-
## Quick Start Workflows
|
|
85
|
-
|
|
86
|
-
Nine runnable workflows are in
|
|
87
|
-
[references/quick_start_workflows.md](references/quick_start_workflows.md):
|
|
88
|
-
|
|
89
|
-
| # | Workflow | Use when |
|
|
90
|
-
| --- | --- | --- |
|
|
91
|
-
| 1 | Single-objective optimization | one objective, GA or DE |
|
|
92
|
-
| 2 | Multi-objective (2-3 objectives) | NSGA-II and a Pareto front |
|
|
93
|
-
| 3 | Many-objective (4+ objectives) | NSGA-III or reference-direction methods |
|
|
94
|
-
| 4 | Custom problem definition | subclassing `Problem` / `ElementwiseProblem` |
|
|
95
|
-
| 5 | Constraint handling | inequality and equality constraints |
|
|
96
|
-
| 6 | Decision making from a Pareto front | scalarization and MCDM selection |
|
|
97
|
-
| 7 | Visualization | scatter, PCP, radviz, and heatmap views |
|
|
98
|
-
| 8 | Parallel evaluation | threads, processes, or Dask for expensive objectives |
|
|
99
|
-
| 9 | Mixed-variable optimization | integer, binary, and categorical variables |
|
|
100
|
-
|
|
101
|
-
## Algorithm Selection Guide
|
|
102
|
-
|
|
103
|
-
### Single-Objective Problems
|
|
104
|
-
|
|
105
|
-
| Algorithm | Best For | Key Features |
|
|
106
|
-
|-----------|----------|--------------|
|
|
107
|
-
| **GA** | General-purpose | Flexible, customizable operators |
|
|
108
|
-
| **DE** | Continuous optimization | Good global search |
|
|
109
|
-
| **PSO** | Smooth landscapes | Fast convergence |
|
|
110
|
-
| **CMA-ES** | Difficult/noisy problems | Self-adapting |
|
|
111
|
-
|
|
112
|
-
### Multi-Objective Problems (2-3 objectives)
|
|
113
|
-
|
|
114
|
-
| Algorithm | Best For | Key Features |
|
|
115
|
-
|-----------|----------|--------------|
|
|
116
|
-
| **NSGA-II** | Standard benchmark | Fast, reliable, well-tested |
|
|
117
|
-
| **SPEA2** | Archive-based MOO | Strength-based fitness, external archive |
|
|
118
|
-
| **R-NSGA-II** | Preference regions | Reference point guidance |
|
|
119
|
-
| **MOEA/D** | Decomposable problems | Scalarization approach |
|
|
120
|
-
|
|
121
|
-
### Many-Objective Problems (4+ objectives)
|
|
122
|
-
|
|
123
|
-
| Algorithm | Best For | Key Features |
|
|
124
|
-
|-----------|----------|--------------|
|
|
125
|
-
| **NSGA-III** | 4-15 objectives | Reference direction-based |
|
|
126
|
-
| **RVEA** | Adaptive search | Reference vector evolution |
|
|
127
|
-
| **AGE-MOEA** | Complex landscapes | Adaptive geometry |
|
|
128
|
-
|
|
129
|
-
### Constrained Problems
|
|
130
|
-
|
|
131
|
-
| Approach | Algorithm | When to Use |
|
|
132
|
-
|----------|-----------|-------------|
|
|
133
|
-
| Feasibility-first | Any algorithm | Large feasible region |
|
|
134
|
-
| Specialized | SRES, ISRES | Heavy constraints |
|
|
135
|
-
| Penalty | GA + penalty | Algorithm compatibility |
|
|
136
|
-
|
|
137
|
-
**See:** `references/algorithms.md` for comprehensive algorithm reference
|
|
138
|
-
|
|
139
|
-
## Benchmark Problems
|
|
140
|
-
|
|
141
|
-
### Quick problem access:
|
|
142
|
-
```python
|
|
143
|
-
from pymoo.problems import get_problem
|
|
144
|
-
|
|
145
|
-
# Single-objective
|
|
146
|
-
problem = get_problem("rastrigin", n_var=10)
|
|
147
|
-
problem = get_problem("rosenbrock", n_var=10)
|
|
148
|
-
|
|
149
|
-
# Multi-objective
|
|
150
|
-
problem = get_problem("zdt1") # Convex front
|
|
151
|
-
problem = get_problem("zdt2") # Non-convex front
|
|
152
|
-
problem = get_problem("zdt3") # Disconnected front
|
|
153
|
-
|
|
154
|
-
# Many-objective
|
|
155
|
-
problem = get_problem("dtlz2", n_obj=5, n_var=12)
|
|
156
|
-
problem = get_problem("dtlz7", n_obj=4)
|
|
157
|
-
```
|
|
158
|
-
|
|
159
|
-
**See:** `references/problems.md` for complete test problem reference
|
|
160
|
-
|
|
161
|
-
## Genetic Operator Customization
|
|
162
|
-
|
|
163
|
-
### Standard operator configuration:
|
|
164
|
-
```python
|
|
165
|
-
from pymoo.algorithms.soo.nonconvex.ga import GA
|
|
166
|
-
from pymoo.operators.crossover.sbx import SBX
|
|
167
|
-
from pymoo.operators.mutation.pm import PM
|
|
168
|
-
|
|
169
|
-
algorithm = GA(
|
|
170
|
-
pop_size=100,
|
|
171
|
-
crossover=SBX(prob=0.9, eta=15),
|
|
172
|
-
mutation=PM(eta=20),
|
|
173
|
-
eliminate_duplicates=True
|
|
174
|
-
)
|
|
175
|
-
```
|
|
176
|
-
|
|
177
|
-
### Operator selection by variable type:
|
|
178
|
-
|
|
179
|
-
**Continuous variables:**
|
|
180
|
-
- Crossover: SBX (Simulated Binary Crossover)
|
|
181
|
-
- Mutation: PM (Polynomial Mutation)
|
|
182
|
-
|
|
183
|
-
**Binary variables:**
|
|
184
|
-
- Crossover: TwoPointCrossover, UniformCrossover
|
|
185
|
-
- Mutation: BitflipMutation
|
|
186
|
-
|
|
187
|
-
**Permutations (TSP, scheduling):**
|
|
188
|
-
- Crossover: OrderCrossover (OX)
|
|
189
|
-
- Mutation: InversionMutation
|
|
190
|
-
|
|
191
|
-
**See:** `references/operators.md` for comprehensive operator reference
|
|
192
|
-
|
|
193
|
-
## Performance and Troubleshooting
|
|
194
|
-
|
|
195
|
-
### Common issues and solutions:
|
|
196
|
-
|
|
197
|
-
**Problem: Algorithm not converging**
|
|
198
|
-
- Increase population size
|
|
199
|
-
- Increase number of generations
|
|
200
|
-
- Check if problem is multimodal (try different algorithms)
|
|
201
|
-
- Verify constraints are correctly formulated
|
|
202
|
-
|
|
203
|
-
**Problem: Poor Pareto front distribution**
|
|
204
|
-
- For NSGA-III: Adjust reference directions
|
|
205
|
-
- Increase population size
|
|
206
|
-
- Check for duplicate elimination
|
|
207
|
-
- Verify problem scaling
|
|
208
|
-
|
|
209
|
-
**Problem: Few feasible solutions**
|
|
210
|
-
- Use constraint-as-objective approach
|
|
211
|
-
- Apply repair operators
|
|
212
|
-
- Try SRES/ISRES for constrained problems
|
|
213
|
-
- Check constraint formulation (should be g <= 0)
|
|
214
|
-
|
|
215
|
-
**Problem: High computational cost**
|
|
216
|
-
- Reduce population size
|
|
217
|
-
- Decrease number of generations
|
|
218
|
-
- Use simpler operators
|
|
219
|
-
- Enable parallel evaluation via `elementwise_runner` (see Workflow 8)
|
|
220
|
-
|
|
221
|
-
### Best practices:
|
|
222
|
-
|
|
223
|
-
1. **Normalize objectives** when scales differ significantly
|
|
224
|
-
2. **Set random seed** for reproducibility
|
|
225
|
-
3. **Save history** to analyze convergence: `save_history=True`
|
|
226
|
-
4. **Visualize results** to understand solution quality
|
|
227
|
-
5. **Compare with true Pareto front** when available
|
|
228
|
-
6. **Use appropriate termination criteria** (generations, evaluations, tolerance)
|
|
229
|
-
7. **Tune operator parameters** for problem characteristics
|
|
230
|
-
|
|
231
|
-
## Resources
|
|
232
|
-
|
|
233
|
-
This skill includes comprehensive reference documentation and executable examples:
|
|
234
|
-
|
|
235
|
-
### references/
|
|
236
|
-
Detailed documentation for in-depth understanding:
|
|
237
|
-
|
|
238
|
-
- **algorithms.md**: Complete algorithm reference with parameters, usage, and selection guidelines
|
|
239
|
-
- **problems.md**: Benchmark test problems (ZDT, DTLZ, WFG) with characteristics
|
|
240
|
-
- **operators.md**: Genetic operators (sampling, selection, crossover, mutation) with configuration
|
|
241
|
-
- **visualization.md**: All visualization types with examples and selection guide
|
|
242
|
-
- **constraints_mcdm.md**: Constraint handling techniques and multi-criteria decision making methods
|
|
243
|
-
- **parallelization.md**: Parallel evaluation with StarmapParallelization and JoblibParallelization
|
|
244
|
-
|
|
245
|
-
**Search patterns for references:**
|
|
246
|
-
- Algorithm details: `grep -r "NSGA-II\|NSGA-III\|MOEA/D" references/`
|
|
247
|
-
- Constraint methods: `grep -r "Feasibility First\|Penalty\|Repair" references/`
|
|
248
|
-
- Visualization types: `grep -r "Scatter\|PCP\|Petal" references/`
|
|
249
|
-
|
|
250
|
-
### scripts/
|
|
251
|
-
Executable examples demonstrating common workflows:
|
|
252
|
-
|
|
253
|
-
- **single_objective_example.py**: Basic single-objective optimization with GA
|
|
254
|
-
- **multi_objective_example.py**: Multi-objective optimization with NSGA-II, visualization
|
|
255
|
-
- **many_objective_example.py**: Many-objective optimization with NSGA-III, reference directions
|
|
256
|
-
- **custom_problem_example.py**: Defining custom problems (constrained and unconstrained)
|
|
257
|
-
- **decision_making_example.py**: Multi-criteria decision making with different preferences
|
|
258
|
-
|
|
259
|
-
**Run examples:**
|
|
260
|
-
```bash
|
|
261
|
-
python3 scripts/single_objective_example.py
|
|
262
|
-
python3 scripts/multi_objective_example.py
|
|
263
|
-
python3 scripts/many_objective_example.py
|
|
264
|
-
python3 scripts/custom_problem_example.py
|
|
265
|
-
python3 scripts/decision_making_example.py
|
|
266
|
-
```
|
|
267
|
-
|
|
268
|
-
## Additional Notes
|
|
269
|
-
|
|
270
|
-
**Common patterns:**
|
|
271
|
-
- Use `ElementwiseProblem` for custom problems (or `FunctionalProblem` for function-based definitions)
|
|
272
|
-
- Use `vars` dict with typed variables for mixed-variable problems
|
|
273
|
-
- Constraints formulated as `g(x) <= 0` and `h(x) = 0`
|
|
274
|
-
- Reference directions required for NSGA-III
|
|
275
|
-
- Normalize objectives before MCDM
|
|
276
|
-
- Use appropriate termination: `('n_gen', N)` or `get_termination("f_tol", tol=0.001)`
|