pymc-modeling

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

PyMC modeling

PyMC 建模

Choose a useful starting point: a simple scaffold, an established subject-matter model, or a decomposition of a larger target model. Expand, simplify or branch as the question, data and checks warrant. Use the consuming project's data and Python environment; check installed APIs and package compatibility.
选择一个有用的起点:简单脚手架、成熟的领域模型,或对大型目标模型的分解。根据问题、数据和检查需要进行扩展、简化或分支调整。使用调用方项目的数据和 Python 环境;检查已安装的 API 和包兼容性。

Choose the primary task

选择主要任务

  • Construct, fit or initialize a model: use
    pymc-modeling
    .
  • Elicit prior assumptions or check prior-predictive plausibility: use
    prior-elicitation
    when available.
  • Diagnose an existing completed fit or evaluate its predictions: use
    arviz-diagnostics
    when available.
  • Repair symbolic computation, broadcasting, gradients or compilation: use
    pytensor-workflows
    when available.
Multipart requests can use more than one skill. The references below support modeling when specialist skills are not installed.
  • 构建、拟合或初始化模型:使用
    pymc-modeling
    。
  • 设定先验假设或检查先验预测的合理性:如果已安装,使用
    prior-elicitation
    。
  • 诊断已有且已完成的拟合或评估其预测:如果已安装,使用
    arviz-diagnostics
    。
  • 修复符号计算、广播、梯度或编译问题:如果已安装,使用
    pytensor-workflows
    。
多部分请求可以使用多个 skill。如果未安装专业 skill,以下参考资料仍可用于支持建模工作。

Workflow

工作流

  1. Formulate. State the estimand or prediction target, observation units, outcome support, grouping/time structure, selection and missingness, and what information is available at prediction time. Separate predictive, inferential and causal claims; respect data authorization and retain source identities.
  2. Specify and inspect. Match the likelihood to the observation process; choose identifiable parameterizations and priors in declared units. Check row alignment, shapes, support and finite initial log density. Ordinary
    dims
    label positional tensors; they do not join coordinates. Use known-parameter simulated cases to probe new implementations and their failure modes; use scoped SBC when repeated inference checks are warranted.
  3. Check prior predictions. Simulate before fitting and compare support, scales and decision-relevant features to domain knowledge. Do not tune priors solely to the realized extrema.
  4. Explore, then fit for inference. Prefer nutpie when compatible and installed. Short preliminary fits can reveal bugs, difficult geometry or gross misfit; label them exploratory, not reliable posterior inference. For reportable results, allocate warmup and draws from adaptation and required ESS/MCSE. Save results before diagnostics or plotting.
  5. Diagnose, then criticize. Inspect divergences, rank R-hat, bulk/tail ESS, MCSE and chain/rank plots. Diagnose every divergence. Unreliable computation leaves posterior conclusions unresolved; it does not disprove a likelihood. Use posterior predictive discrepancies to check the observation model. In-sample PPCs are not held-out validation.
  6. Predict, decide and revise. Preserve training identities and align new inputs; distinguish latent means from noisy observations. For recommendations, propagate uncertainty through stated consequences, utilities and constraints, or hand off the inference without inventing the decision maker's values. Retain relevant model variants and explain how changed assumptions affect estimands, predictions and decisions—not just which has the best score. Adaptive PPC/CV-driven search can overfit; do not present its winner as uniquely confirmed or change seeds/criteria merely to obtain a favorable result.
PyMC 6 returns
xarray.DataTree
: use
idata["posterior"]
, not attribute group access. Call
pm.compute_log_likelihood(idata, model=model)
explicitly before LOO or other pointwise-likelihood workflows. ArviZ 1.0 uses LOO, not removed WAIC; state interval probability and type (the default is 89% ETI). Similar stacking weights do not imply model equivalence. Sampler preferences, warmup starting points and interval defaults are implementation conventions, not universal Bayesian workflow requirements. Choose them for the task.
  1. 构建问题。 陈述估计目标(estimand)或预测目标、观测单位、 结果支持域、分组或时间结构、选择与缺失机制,以及预测时有哪些 信息可用。区分预测性、推断性和因果性主张;遵守数据使用授权, 并保留来源身份。
  2. 指定并检查。 使似然函数与观测过程相匹配;以声明的单位选择 可识别的参数化和先验。检查行对齐、形状、支持域以及初始对数密度 是否为有限值。普通
    dims
    为位置张量添加标签;它们不会连接坐标。 使用已知参数的模拟案例探测新实现及其故障模式;在需要反复进行 推断检查时,使用限定范围的 SBC。
  3. 检查先验预测。 在拟合前进行模拟,并将支持域、尺度和与决策 相关的特征同领域知识进行比较。不要仅依据实际出现的极值调整先验。
  4. 探索,然后执行推断拟合。 如果兼容且已安装,优先使用 nutpie。 简短的初步拟合可以暴露 bug、困难几何或严重失配;应将其标记为 探索性结果,而非可靠的后验推断。对于可报告的结果,为拟合分配 足够的 warmup 和 draws,以完成自适应并达到所需的 ESS/MCSE。 在诊断或绘图之前保存结果。
  5. 诊断,然后批判性检验。 检查 divergence、rank R-hat、bulk/tail ESS、 MCSE 以及链或秩图。诊断每一个 divergence。计算结果不可靠意味着 后验结论尚无定论;这并不能否定似然函数。使用后验预测不一致性 检查观测模型。样本内 PPC 不能替代留出验证。
  6. 预测、决策与修订。 保留训练数据身份并对齐新输入;区分潜在 均值与含噪观测。对于建议,应通过明确说明的后果、效用和约束传播 不确定性,或者移交推断结果,而不要臆造决策者的价值偏好。 保留相关的模型变体,并解释假设变化如何影响估计目标、预测和决策, 而不只是说明哪个模型得分最佳。自适应 PPC 或 CV 驱动的搜索可能 过拟合;不要将其胜出模型表述为得到唯一确认,也不要仅为获得有利 结果而更换种子或评判标准。
PyMC 6 返回
xarray.DataTree
:使用
idata["posterior"]
,不要使用属性形式的 group 访问。在 LOO 或其他逐点似然工作流之前,显式调用
pm.compute_log_likelihood(idata, model=model)
。ArviZ 1.0 使用 LOO,而不是已移除的 WAIC;应明确说明区间概率及其类型(默认为 89% ETI)。相似的 stacking 权重并不意味着模型等价。
采样器偏好、warmup 起点和区间默认值都是实现约定,而不是通用贝叶斯工作流的必要条件。应根据任务进行选择。

Read only what the task needs

只阅读任务所需内容

When working onReference
End-to-end fitting, diagnostics and scientific checksWorkflow
Model construction, data containers and dimensionsModel and data
Failed initialization, shape errors, stuck sampling or warningsTroubleshooting
Group effects, pooling and parameterizationHierarchical models
Outcome support, censoring, multivariate families and JacobiansLikelihoods
Algorithms, backends, budgets and persistenceSampling
Variational, Laplace and Pathfinder approximationsApproximate inference
Covariance models and finite-basis errorGaussian processes
Temporal dependence, differential equations and forecastingTime series
Label invariance and discrete eliminationMixtures
External densities, simulators and predictive callbacksCustom likelihoods
Conditioning, interventions and graph transformationsTransformations
In-sample criticism and new-input predictionPredictive checks
Tree ensembles and prediction stateBART
Basis penalties and distributional predictorsSplines
Simulated-data experiments, SBC, numerical oracles and mocksModel testing
Advanced numerical and extension interfacesInterface boundaries
For version-specific APIs, use
help()
or
inspect.signature()
on the installed object in the consuming environment, then consult version-matched official documentation or source.
处理以下工作时参考资料
端到端拟合、诊断和科学检验工作流
模型构建、数据容器和维度模型与数据
初始化失败、形状错误、采样停滞或警告故障排除
组效应、池化和参数化层级模型
结果支持域、删失、多元分布族和 Jacobian似然函数
算法、后端、预算和持久化采样
变分、Laplace 和 Pathfinder 近似近似推断
协方差模型和有限基误差Gaussian processes
时间依赖、微分方程和预测时间序列
标签不变性和离散消除混合模型
外部密度、模拟器和预测回调自定义似然函数
条件化、干预和图变换变换
样本内批判性检验和新输入预测预测检验
树集成和预测状态BART
基函数惩罚和分布型预测器样条与分布预测器
模拟数据实验、SBC、数值 oracle 和 mock模型测试
高级数值接口和扩展接口接口边界
对于特定版本的 API,请在调用方环境中对已安装的对象使用
help()
或
inspect.signature()
,然后查阅版本匹配的官方文档或源代码。