File size: 9,195 Bytes
6f74f8b e2c3c1c 434ba34 e2c3c1c 6f74f8b e2c3c1c 434ba34 e2c3c1c 434ba34 e2c3c1c 434ba34 e2c3c1c 434ba34 e2c3c1c 434ba34 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 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 | ---
language:
- en
license: other
license_name: undecided
license_link: LICENSE
pretty_name: Causal Graph
size_categories:
- 1K<n<10K
task_categories:
- question-answering
- text-retrieval
tags:
- knowledge-base
- knowledge-graph
- formulas
- symbolic-ai
- explainable-ai
- rule-based
- question-answering
- calculator
- physics
- chemistry
- finance
- statistics
- engineering
- ecology
- machine-learning
- reliability
- no-training
- json
- python
---
# Causal Graph
This is a hand-written knowledge base of quantitative formulas, concepts, processes and rules, together with a small, dependency-free Python engine that answers practical numerical questions from it.
Nothing is trained. Every formula, concept, variable, rule and worked example was written by hand. Each answer shows the numbers it read from the question, the formulas it ran, the assumptions it made and the reasoning it used, so every result can be checked.
```text
$ python3 -m symmix "What is the monthly payment on a 300000 loan at 5% over 20 years?"
Read from your question:
- Principal (loan or deposit amount) = 300,000.00 (from '300000')
- Annual interest or return rate = 5% (from '5%')
- Time in years = 20 years (from '20 years')
Fixed-rate loan payment (amortisation):
...
Result: Periodic payment (monthly by default) = 1,979.87, Total interest paid over the term = 175,168.13
```
## Highlights
- **Explainable by construction.** Every number is traced to a named variable, every formula shows its steps, and every answer lists its assumptions.
- **Fully inspectable.** The knowledge base is plain JSON. The full graph is exported as one JSON file of typed nodes and edges.
- **No training, no dependencies.** The engine uses only the Python standard library. It runs offline and is deterministic.
- **Abstains instead of guessing.** Questions with no good match below a fixed threshold return no answer.
- **Checked.** The knowledge base is validated by `python3 -m symmix --check`, and every formula carries worked examples that the test suite verifies.
## Key numbers
| Component | Count |
|---|---:|
| Formulas | 401 |
| Worked examples (checked by the tests) | 1,003 |
| Concepts | 377 |
| Variables | 1,285 |
| Processes | 23 |
| Rules | 56 |
| Lexicon feature atoms | 335 |
| Graph nodes | 2,616 |
| Graph edges | 4,831 |
| Vocabulary terms | 54,107 |
| Unit tests | 206 |
## Coverage
Formulas by domain (largest 17 of 44 domains):
| Domain | Formulas | Domain | Formulas |
|---|---:|---|---:|
| finance | 34 | chemistry | 27 |
| mechanics | 30 | electrical | 22 |
| physics | 29 | geometry | 21 |
| statistics | 28 | software | 19 |
| optics | 14 | fluids | 14 |
| thermal | 13 | construction | 13 |
| everyday | 11 | math | 10 |
| transport | 9 | ml | 8 |
| energy | 8 | | |
Other domains include earth science, reliability, acoustics, project management, manufacturing, weather, ecology, queueing, inventory, genetics, logistics, growth, space and quality.
## Quick start
Causal Graph needs Python 3 and nothing else. Clone or download this repository, then run from its root:
```bash
python3 -m symmix "How much will 2000 be worth after 8 years at 4%?"
python3 -m symmix --debug "..." # retrieval scores for the question
python3 -m symmix --check # validate the knowledge base
python3 -m symmix --export DIR # write the graph, vocabulary and vectors to DIR
python3 -m symmix --kb PATH "..." # use another knowledge-base folder
python3 -m symmix # interactive mode; a blank line quits
python3 -m unittest # run the test suite
```
From Python:
```python
from symmix.model import Model
model = Model()
print(model.render(model.answer("How much will 2000 be worth after 8 years at 4%?")))
```
Output (abridged):
```text
Future value with compound interest:
future_value = principal * (1 + annual_rate / periods_per_year) ^ (periods_per_year * years) -> 2000 * (1 + 0.04 / 1) ^ (1 * 8) = 2737.14
Result: Future value = 2,737.14, Interest earned = 737.14
Assumes: fixed rate; equal compounding periods; no deposits, withdrawals or fees.
```
## How an answer is produced
1. **Extract.** Numbers in the question are linked to named variables by nearby labels and compatible units. Links are one-to-one. Explicit `name=value` pairs always take precedence, so they are the most reliable way to state inputs.
2. **Retrieve.** Formulas, concepts and processes are scored on alias phrases, word and character n-grams, lexicon features, a two-hop graph spread and input availability. Weights live in `kb/config.json`.
3. **Choose.** A formula is used only if it scores at least 0.8 of the best match. Anything below an absolute threshold of 0.12 is not shown, and the engine abstains.
4. **Re-read.** Inputs are extracted again with the chosen formula in view. If an output is given and one input is missing, the formula is solved for that input and the answer says so.
5. **Compute.** Formulas run through a whitelisted evaluator with guards. Producers run before consumers. Values that disagree by more than 1% with stated figures are flagged.
6. **Report.** The answer lists what was read, each formula's steps and assumptions, plans for formulas that cannot run ("To use X, I still need ..."), applicable rules, and the matching concept with a pitfall.
## Knowledge base format
All knowledge is JSON under `kb/`, loaded strictly: unknown keys and duplicate IDs are errors.
| Folder | Item | Key fields |
|---|---|---|
| `kb/variables/` | Quantity | `id`, `name`, `kind`, `unit`, `base`, `aliases`, `weak`, `unit_only_ok`, `phrases` |
| `kb/formulas/` | Formula | `id`, `name`, `domain`, `aliases`, `concepts`, `features`, `inputs`, `defaults`, `steps`, `outputs`, `guards`, `decisions`, `assumptions`, `examples` |
| `kb/concepts/` | Concept | `id`, `name`, `domain`, `aliases`, `features`, `statements`, `pitfalls`, `actions`, `causes`, `uses`, `related`, `contrast` |
| `kb/processes.json` | Process | `id`, `name`, `domain`, `aliases`, `features`, `when`, `steps`, `checks` |
| `kb/rules.json` | Rule | `id`, `if_atoms`, `if_expr`, `then`, `text` |
| `kb/lexicon.json` | Feature atoms | context, domain and intent cues used by retrieval |
| `kb/config.json` | Settings | retrieval weights, graph decay and hops, thresholds |
A formula example, from `kb/formulas/` (abridged):
```json
{
"id": "finance.future_value",
"inputs": ["principal", "annual_rate", "years", "periods_per_year"],
"steps": [["future_value", "principal * (1 + annual_rate / periods_per_year) ** (periods_per_year * years)"],
["interest_earned", "future_value - principal"]],
"outputs": ["future_value", "interest_earned"],
"examples": [{"inputs": {"principal": 1000, "annual_rate": 0.05, "periods_per_year": 12, "years": 10},
"expect": {"future_value": 1647.0095}}]
}
```
## Graph export
`python3 -m symmix --export DIR` writes four files, computed from the knowledge base alone. A pre-built export is in `export/`.
| File | Contents |
|---|---|
| `graph.json` | The full typed graph: 2,616 nodes and 4,831 edges, pretty-printed JSON |
| `vocabulary.json` | 54,107 n-gram terms (word, character and feature) |
| `vectors.json` | Sparse TF-IDF vectors for 2,477 items in word, character and feature spaces |
| `manifest.json` | Counts, retrieval settings and a statement of what the files are |
`graph.json` has the shape `{"format": "symmix-export/1", "nodes": [...], "edges": [...]}`.
Node types: `variable` (1,285), `atom` (474), `formula` (401), `concept` (377), `rule` (56), `process` (23).
A variable node and an edge:
```json
{"id": "var:hourly_wage", "type": "variable", "name": "Hourly wage", "kind": "money", "unit": "currency per hour"}
{"source": "chem.titration_endpoint", "target": "var:analyte_concentration", "relation": "input"}
```
Edge relations and counts: `feature` 2,001, `input` 1,084, `output` 523, `explains` 403, `asserts` 143, `related` 272, `uses` 122, `requires` 60, `feeds` 59, `contrast` 49, `cites` 47, `suggests` 35, `causes` 33.
The vectors are sparse lexical weights over written terms. They are not learned embeddings, and two items are similar only when they share words, character sequences or features. The graph is hand-built and has not been checked against an independent reference.
## Adding knowledge
1. Add or edit JSON in `kb/`. Every new formula needs worked examples.
2. Run `python3 -m symmix --check`. It checks references, cycles, lexicon coverage, weight sums and formula examples.
3. Run `python3 -m unittest`.
4. Regenerate the export with `python3 -m symmix --export export`.
## Repository layout
```text
symmix/ engine: model.py (pipeline), extract.py (number linking), index.py, graph.py,
formulas.py and safe_eval.py (formula engine), rules.py, units.py, kb.py, check.py, export.py, cli.py
kb/ the knowledge base (variables, formulas, concepts, processes, rules, lexicon, config)
export/ the pre-built graph, vocabulary, vectors and manifest
tests/ 206 tests in 14 modules
evaluation/ question-set scripts used during development
```
## License
Apache 2.0 |