File size: 1,752 Bytes
d517dc9 | 1 2 3 4 5 | {"type": "session", "harness": "opencode", "id": "reason-0045", "name": "abductive"}
{"type": "message", "message": {"role": "system", "content": "You are an expert software engineer and technical assistant. You provide accurate, detailed, and practical answers. When writing code, use best practices, proper error handling, and clear variable names. When analyzing code, identify bugs, security issues, and performance problems. You have deep knowledge of C/C++, Windows API, Python, and many other technologies."}}
{"type": "message", "message": {"role": "user", "content": "What is abductive reasoning (inference to best explanation)? Show Bayesian scoring with correct posteriors and falsifiability pitfalls. Include code examples."}}
{"type": "message", "message": {"role": "assistant", "content": "**Abductive: observation -> best hypothesis -> predict -> test.**\n\n```python\ndef abductive(observations: dict, hypotheses: list[dict]) -> dict[str, float]:\n scores = {h[\"name\"]: h[\"prior\"] * h[\"likelihood_fn\"](observations) for h in hypotheses}\n total = sum(scores.values())\n return {k: v / total for k, v in scores.items()}\n\nhypotheses = [\n {\"name\": \"Flu\", \"prior\": 0.3, \"likelihood_fn\": lambda x: 0.8 if x[\"fever\"] else 0.1},\n {\"name\": \"Cold\", \"prior\": 0.5, \"likelihood_fn\": lambda x: 0.4 if x[\"fever\"] else 0.6},\n {\"name\": \"COVID\", \"prior\": 0.2, \"likelihood_fn\": lambda x: 0.9 if x[\"fever\"] else 0.2},\n]\nresult = abductive({\"fever\": True, \"cough\": True}, hypotheses)\nprint(sorted(result.items(), key=lambda x: -x[1]))\n# Flu 0.24/0.62=0.387, Cold 0.20/0.62=0.323, COVID 0.18/0.62=0.290\n```\n\n**Pitfalls:** confirmation bias, overfitting, unfalsifiable hypotheses."}}
|