How it works¶
This page describes the steps that layerbn run performs to produce the report.
flowchart TD
F["settings.yml + variables.xlsx + data"] --> C["Check<br/><small>names, layers, rules, data</small>"]
C --> B["Bin<br/><small>continuous variables → categories</small>"]
B --> L["Learn<br/><small>structure within the layer order</small>"]
L --> R["Resample<br/><small>learn again on bootstrap samples</small>"]
L --> A["Analyse<br/><small>information, profiles, sweep</small>"]
R --> A
A --> O["Report, figures, tables, explorer"]
1 · Check¶
The settings, the variables table and the data are read and checked for consistency. Each name must exist, each layer must contain variables, and the rules must not conflict with each other or with the layer order. Missing values are handled as specified for each variable (see Missing values). If a problem is found, the run stops with a message that describes the correction.
2 · Bin¶
Continuous variables are divided into bins, by quantiles (the default) or by specified cut-off values. Categorical variables are used as they are. The bins are computed once, from the complete data, and are used in every bootstrap resample, so that all resamples use the same categories.
3 · Learn the structure¶
The network is learned by a score-based search with pyAgrum:
- Score: K2 (default), BDeu or BIC. For BIC, a small smoothing prior is added; K2 and BDeu include their own prior.
- Search: tabu search (default) or greedy hill climbing.
- Maximum of
max_parentsparents per variable.
The layer order is a hard constraint. Before the search, all arcs from a later layer to
an earlier layer are forbidden, as are all arcs within a layer with arcs_within: no. The
forbid rules are added to this list, and the require, no_parents and no_children
rules are passed to the learning algorithm. The search can only select from the remaining
arcs.
4 · Resample¶
Participants are drawn with replacement resamples times. For each sample, the structure
and the probability tables are learned again with the same bins and rules. Resample i uses
the seed seed + i, so the run is reproducible. The proportion of resamples that contain an
arc is its stability.
5 · Analyse¶
The following analyses use the network learned from the complete data:
- Mutual information of each arc and of each variable with each target, computed by exact inference in the fitted network, and the relation of each variable to the target.
- Profiles and sweeps: the specified values are set as evidence and the probabilities of the targets are computed in each bootstrap network. The result is a mean and a 2.5th to 97.5th percentile interval.
6 · Write the output¶
The run writes figures (PNG and PDF), tables (CSV and one Excel file), each network
(.bifxml, which can be read by other Bayesian network software), the interactive explorer,
copies of the input files with checksums, and the report with the methods paragraph.
Tests¶
The test suite runs on every change. Among other things, it checks that:
- no learned network and no bootstrap resample contains an arc that conflicts with the layer order;
- the structure of the simulated example is recovered;
- the same settings and seed result in the same network and the same frequencies;
- the bin edges for the example do not change after a dependency update;
- the inference in the explorer agrees with pyAgrum;
- the command-line interface works from
inittoreport.htmlin an installed package.