Evidence¶
Evidence-based reasoning for architecture decisions.
Overview¶
The evidence system supports confidence-weighted reasoning about architectural properties.
Class Documentation¶
upir.core.evidence.Evidence
dataclass
¶
A piece of evidence supporting or refuting an architectural decision.
Evidence can come from various sources (benchmarks, tests, production data, formal proofs) and carries a Bayesian confidence level that can be updated as new observations arrive.
Based on the TD Commons disclosure, UPIR tracks evidence with confidence levels that propagate through reasoning graphs. The Bayesian update implements a simple beta-binomial conjugate prior approach.
Attributes:
| Name | Type | Description |
|---|---|---|
source |
str
|
Where the evidence came from (e.g., "load_test_2024-01", "formal_verification", "production_metrics") |
type |
str
|
Type of evidence - one of: benchmark, test, production, formal_proof |
data |
Dict[str, Any]
|
The actual evidence data (metrics, test results, proof artifacts) |
confidence |
float
|
Bayesian confidence level in [0, 1] |
timestamp |
datetime
|
When the evidence was collected (UTC) |
Example
evidence = Evidence( ... source="load_test_2024-01", ... type="benchmark", ... data={"latency_p99": 95, "throughput": 10000}, ... confidence=0.8, ... timestamp=datetime.utcnow() ... ) evidence.update_confidence(new_observation=True) evidence.confidence > 0.8 # Confidence increased True
References: - TD Commons: Evidence tracking structure - Bayesian inference: Beta-binomial conjugate prior
Source code in upir/core/evidence.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 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 99 100 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 128 129 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 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 | |
Functions¶
__post_init__()
¶
Validate evidence fields.
Source code in upir/core/evidence.py
update_confidence(new_observation, prior_weight=0.1)
¶
Update confidence using Bayesian update based on new observation.
This implements a simple Bayesian update using a beta-binomial conjugate prior. The prior_weight controls how much the new observation affects the current confidence.
Update rules: - Positive observation: confidence += prior_weight * (1 - confidence) - Negative observation: confidence *= (1 - prior_weight)
These rules ensure: 1. Confidence stays in [0, 1] 2. Positive observations increase confidence (asymptotically to 1) 3. Negative observations decrease confidence (multiplicatively) 4. Higher current confidence is harder to change (conservative)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
new_observation
|
bool
|
True if observation supports the evidence, False if it contradicts it |
required |
prior_weight
|
float
|
Weight of the prior in [0, 1]. Higher values mean new observations have more impact. Default 0.1. |
0.1
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If prior_weight not in [0, 1] |
Example
evidence = Evidence( ... source="test", ... type="benchmark", ... data={}, ... confidence=0.5 ... ) evidence.update_confidence(new_observation=True) evidence.confidence 0.55 evidence.update_confidence(new_observation=False) evidence.confidence 0.495
References: - Beta-binomial conjugate prior: Standard Bayesian approach for binary observations - Murphy (2006): Bayesian inference for Bernoulli distribution
Source code in upir/core/evidence.py
to_dict()
¶
Serialize evidence to JSON-compatible dictionary.
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dictionary with all evidence fields |
Example
evidence = Evidence( ... source="test", ... type="benchmark", ... data={"metric": 100}, ... confidence=0.8, ... timestamp=datetime(2024, 1, 1, 12, 0, 0) ... ) d = evidence.to_dict() d["source"] 'test'
Source code in upir/core/evidence.py
from_dict(data)
classmethod
¶
Deserialize evidence from dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Dict[str, Any]
|
Dictionary containing evidence fields |
required |
Returns:
| Type | Description |
|---|---|
Evidence
|
Evidence instance |
Example
data = { ... "source": "test", ... "type": "benchmark", ... "data": {"metric": 100}, ... "confidence": 0.8, ... "timestamp": "2024-01-01T12:00:00" ... } evidence = Evidence.from_dict(data) evidence.source 'test'
Source code in upir/core/evidence.py
upir.core.evidence.ReasoningNode
dataclass
¶
A node in the reasoning graph representing an architectural decision.
Reasoning nodes form a directed acyclic graph (DAG) where each node represents a decision or conclusion, supported by evidence and potentially dependent on other decisions (parent nodes).
Based on the TD Commons disclosure, UPIR maintains a reasoning graph to track decision provenance and propagate confidence through the architecture.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
str
|
Unique identifier (UUID) |
decision |
str
|
The decision or conclusion made |
rationale |
str
|
Explanation of why this decision was made |
evidence_ids |
List[str]
|
IDs of Evidence objects supporting this decision |
parent_ids |
List[str]
|
IDs of other ReasoningNodes this depends on (for DAG) |
alternatives |
List[Dict[str, Any]]
|
Other options that were considered but not chosen |
confidence |
float
|
Computed confidence in this decision [0, 1] |
Example
node = ReasoningNode( ... id=str(uuid.uuid4()), ... decision="Use PostgreSQL for primary database", ... rationale="Strong consistency needed for financial transactions", ... evidence_ids=["evidence-1", "evidence-2"], ... parent_ids=["node-consistency-requirement"], ... alternatives=[ ... {"option": "MongoDB", "rejected_because": "eventual consistency"} ... ], ... confidence=0.0 # Will be computed from evidence ... )
References: - TD Commons: Reasoning graph structure - DAG: Directed acyclic graph for decision dependencies
Source code in upir/core/evidence.py
218 219 220 221 222 223 224 225 226 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 264 265 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 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 | |
Functions¶
__post_init__()
¶
Validate reasoning node fields.
Source code in upir/core/evidence.py
generate_id()
staticmethod
¶
Generate a unique ID for a reasoning node.
Returns:
| Type | Description |
|---|---|
str
|
UUID string |
Example
node_id = ReasoningNode.generate_id() len(node_id) == 36 # UUID format True
Source code in upir/core/evidence.py
compute_confidence(evidence_map)
¶
Compute aggregate confidence from supporting evidence using geometric mean.
The geometric mean is more conservative than arithmetic mean - a single piece of low-confidence evidence significantly reduces overall confidence. This matches how engineers actually reason: one weak piece of evidence can't be compensated by many strong pieces.
Formula: exp(mean(log(c_i))) for confidences c_i
If no evidence is available, returns 0.0 (no confidence). If any evidence has confidence 0, returns 0.0 (geometric mean property).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
evidence_map
|
Dict[str, Evidence]
|
Mapping from evidence IDs to Evidence objects |
required |
Returns:
| Type | Description |
|---|---|
float
|
Computed confidence in [0, 1] |
Example
evidence_map = { ... "e1": Evidence("src1", "test", {}, 0.8, datetime.utcnow()), ... "e2": Evidence("src2", "test", {}, 0.9, datetime.utcnow()) ... } node = ReasoningNode( ... id="node-1", ... decision="test", ... rationale="test", ... evidence_ids=["e1", "e2"] ... ) conf = node.compute_confidence(evidence_map) 0.84 < conf < 0.85 # sqrt(0.8 * 0.9) ≈ 0.8485 True
References: - Geometric mean: https://en.wikipedia.org/wiki/Geometric_mean - More conservative than arithmetic mean for combining confidences
Source code in upir/core/evidence.py
to_dict()
¶
Serialize reasoning node to JSON-compatible dictionary.
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dictionary with all node fields |
Example
node = ReasoningNode( ... id="node-1", ... decision="Use caching", ... rationale="Reduce latency", ... evidence_ids=["e1"], ... parent_ids=[], ... alternatives=[{"option": "No cache"}], ... confidence=0.8 ... ) d = node.to_dict() d["decision"] 'Use caching'
Source code in upir/core/evidence.py
from_dict(data)
classmethod
¶
Deserialize reasoning node from dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Dict[str, Any]
|
Dictionary containing node fields |
required |
Returns:
| Type | Description |
|---|---|
ReasoningNode
|
ReasoningNode instance |
Example
data = { ... "id": "node-1", ... "decision": "Use caching", ... "rationale": "Reduce latency", ... "evidence_ids": ["e1"], ... "parent_ids": [], ... "alternatives": [], ... "confidence": 0.8 ... } node = ReasoningNode.from_dict(data) node.decision 'Use caching'
Source code in upir/core/evidence.py
__str__()
¶
__repr__()
¶
Developer-friendly representation.
Source code in upir/core/evidence.py
See Also¶
- UPIR - Main UPIR class