InferenceResult
The object returned by GeoBayesianNetwork.infer().
Holds per-pixel probability distributions for one or more query nodes. The spatial
metadata (crs, transform) mirrors the reference grid used during inference.
Class reference
InferenceResult
dataclass
Holds per-pixel probability distributions for one or more query nodes.
Attributes
probabilities: Mapping from query node name to a (H, W, n_states) float32 array. NaN where an input the node depends on was NoData. state_names: Mapping from query node name to its ordered list of state labels. crs: CRS of the output grid as an EPSG string or WKT. transform: Affine pixel-to-world transform of the output grid.
expected_value
Probability-weighted mean of values: sum of P(state) * value(state).
Parameters
node:
Query node name.
values:
A number per state, either as a sequence in state order
([10, 50, 90]) or as a mapping from state name to number
({"low": 10, "medium": 50, "high": 90}) covering every state.
With consequence scores or costs this is the expected loss.
std
Standard deviation of values under the posterior.
values is given as for :meth:expected_value.
exceedance
P(node >= state): the probability of state plus every state after it in state order.
state is a state name or index. For a risk node ordered
low, medium, high, exceedance(node, "medium") is
P(medium) + P(high).
ignorance
Most probable state where its probability is at least threshold, NaN elsewhere (too uncertain to name a state).
threshold must be in (0, 1].
quantile
Index of the lowest state k with P(node <= k) >= q.
With states ordered from least to most severe, quantile(node, 0.95)
is the worst state at 95 % confidence: the node is no worse than it
with probability at least 0.95. q must be in (0, 1].
to_geotiff
Write one multi-band GeoTIFF per query node.
Band layout (1-indexed): Bands 1…N — P(state_i | evidence) for each state i Band N+1 — Shannon entropy
Band descriptions contain the state label or "entropy".
Parameters
output_dir:
Directory to write into (created if needed).
layers:
Optional extra (H, W) layers, e.g. from :meth:expected_value.
Each is written as a single-band {name}.tif on the same grid.
to_xarray
Return an xarray Dataset with spatial coordinates.
Each query node becomes a DataArray with dimensions
(state, y, x). Entropy is added as a separate variable
{node}_entropy with dimensions (y, x).
Parameters
layers:
Optional extra (H, W) layers, e.g. from :meth:expected_value,
added as (y, x) variables under their names.
show_map
show_map(output_dir='.', filename='map.html', overlay_opacity=0.65, open_browser=True, extra_layers=None, show_probability_bands=True, show_category=True, show_entropy=True)
Generate and optionally open an interactive Leaflet map.
Parameters
output_dir:
Directory to write the HTML file into.
filename:
Output filename (default map.html).
overlay_opacity:
Opacity of probability overlays (0–1).
open_browser:
If True (default), open the map in the default browser.
extra_layers:
Additional named (H, W) arrays to include as overlays
(e.g. {"Slope angle (°)": slope_deg}).
show_probability_bands:
If False, omit the individual P(state) layers (default True).
show_category:
If False, omit the argmax category layer (default True).
show_entropy:
If False, omit the entropy layer (default True).
Each layer is resampled (nearest neighbour) onto a Web Mercator grid
of about the same resolution before it is drawn, so that it lines up
with the base map for any grid CRS. The grid must lie within the
latitude range of Web Mercator (±85.05°); otherwise ValueError is
raised.
Returns
Path Path to the written HTML file.
Summary layers
Each method reduces the per-pixel distribution of one query node to a single
(H, W) float32 map. Pixels where the node's probabilities are NaN (NoData in an
input it depends on) are NaN. State indices follow the
order in state_names[node], so order the states from least to most severe for
exceedance and quantile to make sense.
For a pixel with P(low, medium, high) = (0.2, 0.5, 0.3):
| Method | Meaning | Example |
|---|---|---|
expected_value(node, values) |
Σ P(state) · value(state), e.g. expected loss | [10, 50, 90] → 54 |
std(node, values) |
Standard deviation of values |
≈ 28 |
mode(node) |
Index of the most probable state | 1 (medium) |
mode_probability(node) |
Probability of that state | 0.5 |
exceedance(node, state) |
P(node ≥ state) | "medium" → 0.8 |
ignorance(node, threshold) |
Mode where P(mode) ≥ threshold, else NaN | 0.6 → NaN |
quantile(node, q) |
Lowest state k with P(node ≤ k) ≥ q: the worst state at confidence q | 0.95 → 2 (high) |
values is either a list in state order or a dict keyed by state name
({"low": 10, "medium": 50, "high": 90}), which guards against order mistakes.
geobn does not choose these numbers; they are your consequence scores or costs.
Pass summary maps (or any other (H, W) array on the result grid) to the exporters:
score = result.expected_value("usv_risk", {"low": 10, "medium": 50, "high": 90})
result.to_geotiff("out/", layers={"risk_score": score}) # also writes out/risk_score.tif
ds = result.to_xarray(layers={"risk_score": score}) # adds a (y, x) variable
Band layout in GeoTIFF output
When calling to_geotiff(output_dir), one multi-band GeoTIFF is written per query
node:
| Band | Content |
|---|---|
| 1 … N | P(state_i | evidence) for each state i |
| N + 1 | Shannon entropy (bits) |
Band descriptions in the file metadata contain the state label or "entropy".
Each extra layer passed via layers= is written as a single-band {name}.tif
whose band description is the layer name.
Example
result = bn.infer(query=["avalanche_risk"])
# Inspect probabilities
probs = result.probabilities["avalanche_risk"] # (H, W, 3)
print(probs.shape) # (80, 240, 3) for an 80×240 grid with 3 states
# Entropy map
ent = result.entropy("avalanche_risk") # (H, W)
# P(avalanche_risk >= high)
p_high = result.exceedance("avalanche_risk", "high")
# Export
result.to_geotiff("output/") # writes avalanche_risk.tif
ds = result.to_xarray() # xarray Dataset with (state, y, x) dims
result.show_map() # opens browser