belief_model
agentevac.agents.belief_model
Bayesian belief-update pipeline for wildfire hazard assessment.
Each agent maintains a probability distribution over three hazard states
p_safe: fire is far enough that the agent's current position is safe.p_risky: fire is close enough to warrant caution but not immediate danger.p_danger: fire is imminent; departure is likely warranted.
The update pipeline (exposed via update_agent_belief) runs once per decision period:
1. Map the observed margin (meters from fire edge) to a prior triplet
(categorize_hazard_state).
2. If social messages are present, fuse the environment-derived prior with a
social-signal belief weighted by theta_trust (fuse_env_and_social_beliefs).
3. Apply temporal smoothing using a fixed inertia factor to avoid belief whiplash
(smooth_belief).
4. Compute Shannon entropy to quantify uncertainty (compute_belief_entropy).
5. Normalize entropy to [0, 1] and bucket it into Low / Medium / High
(normalize_entropy, bucket_uncertainty).
bucket_uncertainty(entropy_norm)
Discretize normalized entropy into a human-readable uncertainty label.
Thresholds
- "Low" : entropy_norm ≤ 0.33 (agent is fairly confident)
- "Medium" : entropy_norm ≤ 0.67 (moderate uncertainty)
- "High" : entropy_norm > 0.67 (agent is highly uncertain)
The label is included in the LLM prompt so the model can reason about its own epistemic state without having to interpret raw entropy values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entropy_norm
|
float
|
Normalized entropy ∈ [0, 1]. |
required |
Returns:
| Type | Description |
|---|---|
str
|
One of "Low", "Medium", or "High". |
Source code in agentevac/agents/belief_model.py
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 | |
categorize_hazard_state(signal)
Map an observed margin (meters from fire edge) to a hazard-state prior.
Uses observed_margin_m if available, falling back to base_margin_m.
If neither is present (e.g., no fire active), returns a uniform prior.
Threshold rationale
- ≤ 0 m : fire has reached / overtaken the edge → near-certain danger.
- ≤ 1200 m : within ember-attack range → high danger.
- ≤ 2500 m : smoke / radiant-heat proximity → risky (watch closely).
- ≤ 5000 m : fire visible but with buffer → elevated but manageable.
-
5000 m : fire is well clear of the route → predominantly safe.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
signal
|
Dict[str, Any]
|
Environment signal dict, typically from |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, float]
|
A normalized {p_safe, p_risky, p_danger} dict representing the categorical prior. |
Source code in agentevac/agents/belief_model.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | |
compute_belief_entropy(belief)
Compute the Shannon entropy of a {p_safe, p_risky, p_danger} belief distribution.
Entropy H = -Σ p_i * log(p_i) over the three states. The maximum possible value for a 3-state uniform distribution is log(3) ≈ 1.099 nats. A floor of 1e-12 is applied to each probability to avoid log(0) singularities.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
belief
|
Dict[str, float]
|
The belief distribution dict (will be normalized internally). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Shannon entropy in nats (≥ 0). |
Source code in agentevac/agents/belief_model.py
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | |
compute_signal_conflict(env_belief, social_belief)
Measure disagreement between env and social beliefs via Jensen-Shannon divergence.
JSD is symmetric, bounded [0, ln 2], and information-theoretic — consistent with the entropy framework used elsewhere in this module. The raw JSD is normalized by ln(2) so the return value lies in [0, 1]:
0 = sources perfectly agree
1 = sources maximally disagree (e.g., one says safe, the other says danger)
This score is recorded for post-hoc RQ1 analysis and surfaced in the LLM prompt so the agent can reason about contradictions between its own observation and neighbor messages.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
env_belief
|
Dict[str, float]
|
Belief derived from the agent's own hazard observation. |
required |
social_belief
|
Dict[str, float]
|
Belief inferred from neighbor inbox messages. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Normalized JSD ∈ [0, 1]. |
Source code in agentevac/agents/belief_model.py
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 | |
fuse_env_and_social_beliefs(env_belief, social_belief, theta_trust)
Fuse an environmental belief with a social-signal belief via weighted average.
The agent's trust parameter theta_trust ∈ [0, 1] determines how much weight
is given to peer messages relative to its own observations:
fused = (1 - theta_trust) * env_belief + theta_trust * social_belief
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
env_belief
|
Dict[str, float]
|
Belief derived from the agent's own hazard observations. |
required |
social_belief
|
Dict[str, float]
|
Belief inferred from neighbor inbox messages. |
required |
theta_trust
|
float
|
Weight given to social signals; 0 = ignore peers, 1 = ignore self. |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, float]
|
A normalized {p_safe, p_risky, p_danger} dict representing the fused belief. |
Source code in agentevac/agents/belief_model.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | |
normalize_entropy(entropy)
Normalize Shannon entropy to the range [0, 1] relative to the 3-state maximum.
Divides raw entropy by log(3) so that a uniform distribution maps to 1.0 and a fully confident belief maps to 0.0.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entropy
|
float
|
Raw Shannon entropy in nats. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Normalized entropy ∈ [0, 1]. |
Source code in agentevac/agents/belief_model.py
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 | |
smooth_belief(prev_belief, new_belief, inertia=0.35)
Blend the previous belief with a newly computed belief using exponential smoothing.
Prevents erratic belief flips between decision rounds by retaining a fraction
(inertia) of the prior state:
smoothed = inertia * prev + (1 - inertia) * new
A higher inertia value means the agent is slower to update beliefs (more conservative). The default of 0.35 balances responsiveness with stability.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prev_belief
|
Dict[str, float]
|
The agent's belief from the previous decision round. |
required |
new_belief
|
Dict[str, float]
|
The freshly computed belief for the current round. |
required |
inertia
|
float
|
Mixing weight for the previous belief ∈ [0, 0.999]. |
0.35
|
Returns:
| Type | Description |
|---|---|
Dict[str, float]
|
A normalized {p_safe, p_risky, p_danger} dict representing the smoothed belief. |
Source code in agentevac/agents/belief_model.py
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | |
update_agent_belief(prev_belief, env_signal, social_signal, theta_trust, inertia=0.35)
Run the full Bayesian belief-update pipeline for one decision round.
Steps
- Convert environment signal margin to a categorical prior (
categorize_hazard_state). - If peer messages exist, fuse env prior with social belief via
theta_trust(fuse_env_and_social_beliefs); otherwise use env prior directly. - Apply temporal smoothing against the previous belief (
smooth_belief). - Compute and normalize Shannon entropy; bucket into Low / Medium / High.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prev_belief
|
Dict[str, float]
|
The agent's belief dict from the previous decision round. |
required |
env_signal
|
Dict[str, Any]
|
Environment signal produced by |
required |
social_signal
|
Dict[str, Any]
|
Social signal produced by |
required |
theta_trust
|
float
|
Social-signal trust weight ∈ [0, 1] (from agent profile). |
required |
inertia
|
float
|
Temporal smoothing factor ∈ [0, 0.999]. |
0.35
|
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
An enriched belief dict containing: - p_safe, p_risky, p_danger : smoothed posterior probabilities - entropy, entropy_norm : Shannon entropy (raw and normalized) - uncertainty_bucket : "Low", "Medium", or "High" - signal_conflict : JSD between env and social beliefs [0, 1] - env_weight, social_weight : fusion weights applied this round - env_belief, social_belief : component beliefs before fusion |
Source code in agentevac/agents/belief_model.py
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 | |