modeling-and-factors
Builds and validates pgmpy graph, model, CPD, factor, and backend objects for causal and probabilistic graphical models.
- License 许可
- MIT
- 最近更新
- 2026-09-03
- Stars
- ★ 351
- Forks
- 27
01 前言 Front Matter
- name
- modeling-and-factors
- license
- MIT
- metadata
- { "disco-role": "operating" }
- description
- Builds and validates pgmpy graph, model, CPD, factor, and backend objects for causal and probabilistic graphical models.
- disable-model-invocation
- true
02 资源文件 4
- 参考文档references/model-and-factor-api.md10.8 KB
- 参考文档references/modeling-workflows.md10.6 KB
- 参考文档references/troubleshooting.md9.7 KB
- 脚本scripts/check_modeling_smoke.py5.0 KB
03 SKILL.md 正文
Modeling and Factors
Use this sub-skill when the task is to construct, validate, inspect, or debug pgmpy graph/model/factor objects before learning, inference, simulation, causal effects, or file I/O.
Route here
- Build graph-only objects:
DAG,PDAG,MAG,ADMG,SimpleCausalModel, andUndirectedGraph, including causal roles such as exposures, outcomes, latents, confounders, mediators, and instruments. - Build probabilistic model containers:
DiscreteBayesianNetwork,LinearGaussianBayesianNetwork,FunctionalBayesianNetwork,DynamicBayesianNetwork,DiscreteMarkovNetwork,FactorGraph,JunctionTree,ClusterGraph, andMarkovChain. - Define and validate CPDs/factors:
TabularCPD,LinearGaussianCPD,FunctionalCPD,DiscreteFactor,JointProbabilityDistribution, andNoisyORCPD. - Diagnose
add_cpds,get_cpds,get_factors,check_model, cardinality, state-name, evidence-order, graph-role, factor-scope, and backend-configuration errors.
Reroute elsewhere
- Parameter fitting, structure learning, CI tests, and scores: route to
learning-structure-and-parameters. - Posterior queries, MAP, simulation, and sampling beyond a tiny validation smoke: route to
inference-sampling-and-simulation. - Adjustment/frontdoor identification, do-calculus, ATE, IV, and effect-regressor workflows: route to
causal-identification-and-effects. - Model serialization formats, datasets/example models, graph metrics, and evaluation: route to
data-io-and-evaluation. - Adding or modifying pgmpy source APIs/templates: route to
extending-pgmpy.
Read next
- Model and factor API reference for class-selection tables, CPD/factor shape rules, role methods, backend config, and validation semantics.
- Modeling workflows for self-contained recipes adapted from pgmpy's discrete BN, linear Gaussian BN, CPD, dynamic BN, functional BN, and factor-graph examples.
- Troubleshooting for
check_model()failures, CPD evidence/cardinality mismatches, state-name confusion, optional torch/Pyro errors, and graph-only-vs-model decisions. - Smoke script to verify that an installed pgmpy package can build and validate a tiny discrete BN from any working directory.
Minimal operating checklist
- Choose the lightest object that matches the task: graph-only roles if no CPDs are needed; a BN/Markov/factor container if parameters are needed; a dynamic or functional model only when its extra structure is essential.
- Add all nodes/edges before adding CPDs or factors. CPD/factor variables must already exist in the graph/model.
- For
TabularCPD, makevaluesa 2-D array with shape(variable_card, product(evidence_card)); every column is a conditional distribution and must sum to 1 beforecheck_model()passes. - Keep parent/evidence names, cardinalities, and
state_namesconsistent across parent CPDs and child CPDs. Use the same labels in inference/evidence later. - Call
model.check_model()before handing the model to learning, inference, simulation, causal, or I/O workflows. - Treat
FunctionalBayesianNetworkandFunctionalCPDas optional: they require the torch backend pluspyro-ppl; they were not installed in the minimum CPU environment used for the core skill.
Safe validation command
From any directory with pgmpy installed, run:
python path/to/check_modeling_smoke.py
The script builds a tiny discrete Bayesian network, validates CPDs, runs one small exact query as a smoke check, and reports whether optional torch/Pyro packages are importable without requiring them.
04 同仓库更多 Skills
passnet-triton-opt
Make a single PassNet Triton kernel fast AND numerically faithful: performance model (when a replacement can win at all), block/grid/warp tuning, autotune policy, launch overhead, and per-op numeric recipes to pass the dtype baseline tolerances. Use when a pass matches and is correct but speedup below expected, or when correctness fails by small numeric margins.
passnet-solve
END-TO-END playbook for solving one PassNet sample: analyze the computation graphs, decide the optimization strategy (what to fuse, what to replace, what to leave alone), drive the iteration loop, and maximize the sample score. This is the ENTRY skill — invoke it first for any PassNet optimization task; it tells you when to use passnet-pattern-fusion, passnet-triton-opt and passnet-feedback.
passnet-skill
PassNet GPU kernel optimization via compiler passes. Design and implement Triton-based optimization passes, create pass files under ./pass_dir/, self-evaluate with pass_evaluator, and iterate to maximize GPU speedup.
passnet-pattern-fusion
Author PassNet pass files: write patterns that actually MATCH the FX graph, pick fusion regions (which ops to absorb into one Triton kernel), and structure multi-pass submissions with the mandatory shared-dispatch architecture. Use when creating or fixing pattern()/replacement_args()/replacement_func() files, when a pass "failed to match", or when deciding how to fuse multiple kernels/ops.
passnet-orchestrate
Round/batch planning and decision support for PassNet graph optimization. Use for multi-sample triage, worker allocation, eval-budget policy, and post-eval keep/revert decisions. For solving one concrete sample end to end, use passnet-solve as the entry skill; consult this skill only when you need broader planning or a specific decision gate.
passnet-feedback
Fast, deterministic feedback for PassNet work: pre-flight pattern/match verification WITHOUT burning a GPU evaluation, per-node bottleneck analysis of a sample's graphs, and eval-log parsing into per-variant status + estimated score + failure classification. Use BEFORE every GPU evaluation (check_pattern), at the START of a sample (analyze_graph), and AFTER every evaluation (parse_eval_log).