movedby 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
movedby-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 nnfuzzy
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
movedby-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,230 @@
1
+ Metadata-Version: 2.4
2
+ Name: movedby
3
+ Version: 0.1.0
4
+ Summary: What moved the decision: SHAP- and LIME-style attribution for typed decision models (Jev, OpenAI Decisions, Kairos), with a noise floor, a budget and a ledger
5
+ Keywords: explainability,interpretability,attribution,shapley,shap,lime,decision-model,system-one,llm
6
+ Author: nnfuzzy
7
+ License-Expression: MIT
8
+ License-File: LICENSE
9
+ Classifier: Development Status :: 3 - Alpha
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: Intended Audience :: Science/Research
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Classifier: Programming Language :: Python :: 3.13
16
+ Classifier: Programming Language :: Python :: 3.14
17
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
18
+ Classifier: Typing :: Typed
19
+ Requires-Dist: httpx>=0.27
20
+ Requires-Dist: numpy>=1.26
21
+ Requires-Dist: matplotlib>=3.8 ; extra == 'plot'
22
+ Requires-Python: >=3.12
23
+ Project-URL: Homepage, https://github.com/nnfuzzy/movedby
24
+ Project-URL: Repository, https://github.com/nnfuzzy/movedby
25
+ Project-URL: Issues, https://github.com/nnfuzzy/movedby/issues
26
+ Project-URL: Changelog, https://github.com/nnfuzzy/movedby/blob/main/CHANGELOG.md
27
+ Provides-Extra: plot
28
+ Description-Content-Type: text/markdown
29
+
30
+ # movedby
31
+
32
+ **What moved the decision.** SHAP- and LIME-style attribution for typed decision models: Jev (TypeSafe), Kairos (DMind), OpenAI's Decisions API, or any Python function that answers with a probability.
33
+
34
+ ```bash
35
+ pip install movedby # or: uv add movedby
36
+ pip install "movedby[plot]" # with the two charts
37
+ ```
38
+
39
+ Python 3.12 or newer. Two dependencies: httpx and numpy.
40
+
41
+ A decision model reads one state and answers typed questions (yes/no, choice, score) with probabilities and no reason. movedby asks it again with facts taken out and reduces the answers to attributions, as SHAP does for a tabular model. A paid, remote, noisy judge needs more than that, and movedby adds it:
42
+ - a noise line and an order floor, so nothing is named below what chance or reordering does;
43
+ - a quote before anything is paid, and a ledger that never pays twice;
44
+ - planted cases with known answers, to check the method before trusting a reading.
45
+
46
+ | SHAP / LIME | movedby |
47
+ |---|---|
48
+ | features | **facts**: the parts of the state you declare as players (a headline, a field) |
49
+ | masker / background | **a removal rule per fact**: `Delete` a list item, or `Replace` a field with a neutral value |
50
+ | the output explained | **a target**: `P`, `Choice`, `Expected` (a score's mean level), `Gap` (distance to a reference), `Loss` (against an outcome), `Policy` |
51
+ | exact / permutation SHAP | `Exact` (every coalition, up to 10 facts), `Orders` (sampled orders of arrival, each walked both ways), `LeaveOneOut`, `Stories` |
52
+ | efficiency axiom | values add up to `v(all) − v(∅)`; both ends are in every plan |
53
+ | (not needed: the model is local, free and deterministic) | repeats and shuffles of the full state, a quote, a ledger keyed by the bytes sent, planted controls |
54
+
55
+ ### Where it sits
56
+
57
+ Libraries such as llmSHAP attribute the text a chat model generates to parts of its prompt, and have to score how alike two generated texts are. A decision model states a probability, so movedby attributes that number directly, in probability points. What it adds is what a paid, remote judge makes necessary: floors that say when a value is noise or an effect of order, planted cases with known answers, and a quote and a ledger so that a reading is priced before it is paid and never paid twice.
58
+
59
+ ## A first run, without a key
60
+
61
+ ```python
62
+ from pathlib import Path
63
+
64
+ from movedby import Case, Delete, Exact, Fact, Function, NoulAnswer, P, explain
65
+ from movedby.report import text
66
+
67
+ heads = ["Yields rise", "Fed holds", "Bonds slide", "Tech rallies"]
68
+ case = Case({"headlines": heads},
69
+ tuple(Fact(f"h{i}", ("headlines", i), Delete()) for i in range(len(heads))),
70
+ {"against": {"type": "noul", "instructions": "Does at least one headline push the trade the other way?"}})
71
+
72
+ def judge(state, questions): # "at least one": the strongest headline counts
73
+ weight = {"Yields rise": 0.35, "Fed holds": -0.05, "Bonds slide": 0.25, "Tech rallies": 0.0}
74
+ return {"against": NoulAnswer(0.1 + max((weight[h] for h in state["headlines"]), default=0.0))}
75
+
76
+ ex = explain(Function(judge), case, P("against"), Exact(), ledger=Path("first.jsonl"), line=0.05,
77
+ pay=True, monotone=True).value
78
+ print(text(ex, case))
79
+ ```
80
+
81
+ "Bonds slide" carries 0.13 by Shapley value and 0.00 by leave-one-out: "Yields rise" covers for it. That is the blind spot of a one-at-a-time probe, and the first thing movedby is for.
82
+
83
+ `explain` returns `Ok(...)` or `Err(...)`; `.value` above is short for a `match` on the two.
84
+
85
+ ## On a real judge
86
+
87
+ ```python
88
+ from movedby import Orders, TypeSafe # Jev, pinned to jev-1.14.0; TYPESAFE_API_KEY in the environment
89
+
90
+ judge = TypeSafe()
91
+ quote = explain(judge, case, P("against"), Orders(pairs=10), ledger=Path("real.jsonl"), line=0.05).value
92
+ print(quote) # calls, cached calls, the upper cost; nothing was called
93
+ ex = explain(judge, case, P("against"), Orders(pairs=10), ledger=Path("real.jsonl"), line=0.05,
94
+ pay=True).value # asks what the ledger lacks; a second run pays nothing
95
+ ```
96
+
97
+ `Kairos()` (DMind's model behind the Minara gateway, `KAIROS_API_KEY`) speaks Jev's endpoint and takes the same questions unchanged. No price was measured for it, so a run on Kairos takes a call cap (`budget=Budget(usd=None, calls=200)`) or a `price` you pass. Its answers are read as recorded on 2026-11-21; `pytest -m live -k kairos` asks it for real.
98
+
99
+ `Decisions()` (OpenAI, `OPENAI_API_KEY`) takes the same questions: they are declared once, in TypeSafe's form, and translated. Without `pay=True` you get the quote. With every answer already in the ledger you get the explanation, and pay nothing.
100
+
101
+ A `Function` judge is not a pinned model: its code can change while its name stays. So each new `Function` is asked afresh. Give it a `version` and its answers are reused from the ledger like a pinned model's.
102
+
103
+ ## Keys
104
+
105
+ A judge needs its provider's key only when it sends a request. The first run above, a quote (no `pay`) and the tutorial need none.
106
+
107
+ | judge | variable | the key comes from |
108
+ |---|---|---|
109
+ | `TypeSafe()` (Jev) | `TYPESAFE_API_KEY` | TypeSafe |
110
+ | `Kairos()` | `KAIROS_API_KEY` | Minara, the gateway that serves DMind's Kairos |
111
+ | `Decisions()` | `OPENAI_API_KEY` | OpenAI |
112
+
113
+ Set only the ones for the judges you ask. movedby reads the process environment and never opens a `.env` file, so a key kept in a file has to be loaded first. `.env.example` lists the three names:
114
+
115
+ ```bash
116
+ cp .env.example .env # fill in the keys you have; git ignores .env
117
+ set -a; . ./.env; set +a # this shell now has them
118
+ uv run --env-file .env movedby run case.json --pay # or hand the file to one command
119
+ ```
120
+
121
+ In code a key can be passed instead, `TypeSafe(api_key=...)`; it is left out of the judge's `repr`. A key is sent to its provider as a bearer header and nowhere else: a ledger row holds the answers under a hash of the request, never a key.
122
+
123
+ Without a key a paid run sends nothing and comes back as `Err(NoAccess('TYPESAFE_API_KEY is not set'))`; no ledger row is written.
124
+
125
+ ## The reading
126
+
127
+ Every explanation carries its floors and one reading.
128
+
129
+ **The line** a value must clear is the largest of three:
130
+ - the line you state;
131
+ - the order floor: how far the answer moves when the same facts come in another order (five shuffles);
132
+ - the noise line: what the largest of n values crosses 5 times in 100 by chance.
133
+
134
+ **The noise line is sized for the estimate it is held against:**
135
+ - A leave-one-out effect is one difference of two answers.
136
+ - An exact Shapley value is a weighted mean over every coalition, so it is quieter.
137
+ - A value from sampled orders takes the answers' noise carried through those orders, or the spread between the two halves of the orders if that is larger.
138
+
139
+ The answers' noise comes from repeats of the full state (five by default), with Student's t for so few. A noise sd you measured elsewhere on many repeats can be passed as `noise_sd` and is taken as known. One repeat measures no noise, and the report says so.
140
+
141
+ **What gets named:**
142
+ - **Carries / holds back:** the answer falls / rises without the fact, at or past the line. They are listed apart, never by the size of the effect alone.
143
+ - **Unsettled:** a named fact whose two halves of the sampled orders disagree by more than the line. More orders would settle it.
144
+ - **Hidden from leave-one-out:** facts Shapley credits past the line that leave-one-out misses.
145
+ - **Violations:** for a question you declare monotone ("at least one headline ..."), deletions that raise the answer past the line.
146
+
147
+ **The word:**
148
+ - `moved`: a fact clears the line;
149
+ - `saturated`: both ends at the same edge of the scale;
150
+ - `flat`: nothing moves;
151
+ - `below the order floor`: reordering moves the answer as much as everything together does;
152
+ - `hidden`: the move clears every floor, and no single fact does.
153
+
154
+ `movedby.report` prints it as text or JSON. `movedby.plot` (the `plot` extra) draws the values against the line, with leave-one-out as a ring, and the walk from no fact to every fact.
155
+
156
+ ### How well the line holds
157
+
158
+ Measured on a noisy judge (sd 0.02) with six facts, two of which do nothing; `tests/test_noise.py` pins it.
159
+
160
+ | | a do-nothing fact named | a +0.30 effect found | a +0.10 effect found |
161
+ |---|---|---|---|
162
+ | leave-one-out, 3 repeats | 1.5% of runs | 64% | 17% |
163
+ | leave-one-out, 5 repeats (the default) | 0.2% | 99% | 34% |
164
+ | exact Shapley, 5 repeats | 0.8% | 100% | 100% |
165
+ | sampled orders (10 pairs), 5 repeats | 0.8% | 100% | 96% |
166
+
167
+ Three repeats are too few to pin a judge's noise, which is why five is the default.
168
+
169
+ ## Case files and the command line
170
+
171
+ ```bash
172
+ movedby plan case.json # the quote; calls nothing
173
+ movedby run case.json --pay # the explanation; --json for machines
174
+ movedby control --judge jev --pay # the three planted cases and their gates (48 calls); exit 1 on a failed gate
175
+ ```
176
+
177
+ A case file names the judge, the state, the facts (`list_facts` makes every item of a list a fact), the questions, the target, the estimator and the line. The format is in `movedby/casefile.py`. A malformed file comes back as a list of its problems.
178
+
179
+ A case file is trusted input: a `function` judge names a Python module, and loading the file imports it.
180
+
181
+ ## What a paid run guards against
182
+
183
+ - **No access** (no key, 401, 403). The first call goes out alone. If it is refused, nothing is recorded and nothing else is asked, so fixing the key and running again asks everything.
184
+ - **A ledger that cannot be written.** What is still queued is cancelled, and the error says how many answers were asked and lost.
185
+ - **A failed call** (a timeout, a 500, an answer that cannot be read). It becomes a row with its error and is asked again only with `retry_failed=True` (`--retry-failed`).
186
+ - **A judge dearer than quoted.** After the first 20 calls a per-token judge's tokens per character are measured, and the rest is gated against what is left of the budget.
187
+ - **A write that was cut off.** A last ledger line without its newline holds no row; it is skipped on reading and removed by the next write.
188
+
189
+ ## Rules it keeps (each one learned on a real judge)
190
+
191
+ 1. **One renderer, canonical bytes.** Every state is built by `render`; the request is sent as the exact bytes its cache key hashes, with JSON keys sorted. Key order alone moved Decisions by two points. With sorted keys, movedby rebuilt betlab101's requests byte for byte, and Decisions gave its stored answers back exactly.
192
+ 2. **Both ends, always.** No fact and every fact are in every plan: a flat answer and a hidden one look alike to the probe.
193
+ 3. **Floors before attribution.** A judge that answers the same request identically can still move by 0.30 when the same facts come in another order (Decisions on desk101's states and on the NVIDIA case).
194
+ 4. **Signed naming, and a monotone check** where the question allows it.
195
+ 5. **A failed call is a row, never a number.** A refusal is a `Refusal` answer; another model behind a pinned name is `ModelMoved`.
196
+ 6. **Nothing is paid without saying so.** `pay=False` is the default, a quote is an upper bound, and the default budget is one dollar.
197
+
198
+ ## What the method does not show
199
+
200
+ - How the answer responds to its input, not what happens inside the model; a vendor can change the model behind a pinned name.
201
+ - "Removed" means what the removal rule says; another rule gives other numbers.
202
+ - A per-fact number averages over how facts work together.
203
+ - **`Gap` is not additive across the reference:** a fact that alone carries the judge across the reference, and with others pulls it back, gets credited both ways, near zero.
204
+ - Scored by an outcome (`Loss`), a fact can be sound evidence and still point away from what happened.
205
+ - Planted cases test the estimators and the renderer; they do not prove faithfulness on real states.
206
+ - Two runs on one ledger at the same time both pay: there is no lock.
207
+
208
+ ## Tutorial
209
+
210
+ `tutorial/nvidia.ipynb`: NVIDIA in the fortnight to 2026-11-25 (Huang resigns, results, reinstatement, the 31.5% day and the two after), Jev and Decisions on "where does NVDA close on Dec 3", from a ledger shipped with it, so it runs without a key:
211
+
212
+ ```bash
213
+ uv sync --group tutorial
214
+ uv run --group tutorial jupyter lab tutorial/nvidia.ipynb
215
+ ```
216
+
217
+ ## Development
218
+
219
+ ```bash
220
+ uv sync
221
+ uv run pytest # sockets disabled: no test can call a provider
222
+ uv run mypy src/movedby # the package ships py.typed
223
+ uv run pytest -m live # opt-in and paid: the planted `single` case on Jev, Kairos and Decisions; a judge without its key is skipped
224
+ ```
225
+
226
+ `tests/golden/` holds three planted cases about invented places and the 96 answers Jev and Decisions gave to every subset of them (betlab101, 2026-11-21); the golden test reproduces betlab101's numbers from those rows.
227
+
228
+ Tested on Python 3.12, 3.13 and 3.14, and with the lowest versions `pyproject.toml` allows. `RELEASING.md` has the steps of a release.
229
+
230
+ MIT licence. movedby is an independent project: it is not affiliated with or endorsed by TypeSafe, DMind or OpenAI, whose names are used here only to say which models it can ask.
@@ -0,0 +1,201 @@
1
+ # movedby
2
+
3
+ **What moved the decision.** SHAP- and LIME-style attribution for typed decision models: Jev (TypeSafe), Kairos (DMind), OpenAI's Decisions API, or any Python function that answers with a probability.
4
+
5
+ ```bash
6
+ pip install movedby # or: uv add movedby
7
+ pip install "movedby[plot]" # with the two charts
8
+ ```
9
+
10
+ Python 3.12 or newer. Two dependencies: httpx and numpy.
11
+
12
+ A decision model reads one state and answers typed questions (yes/no, choice, score) with probabilities and no reason. movedby asks it again with facts taken out and reduces the answers to attributions, as SHAP does for a tabular model. A paid, remote, noisy judge needs more than that, and movedby adds it:
13
+ - a noise line and an order floor, so nothing is named below what chance or reordering does;
14
+ - a quote before anything is paid, and a ledger that never pays twice;
15
+ - planted cases with known answers, to check the method before trusting a reading.
16
+
17
+ | SHAP / LIME | movedby |
18
+ |---|---|
19
+ | features | **facts**: the parts of the state you declare as players (a headline, a field) |
20
+ | masker / background | **a removal rule per fact**: `Delete` a list item, or `Replace` a field with a neutral value |
21
+ | the output explained | **a target**: `P`, `Choice`, `Expected` (a score's mean level), `Gap` (distance to a reference), `Loss` (against an outcome), `Policy` |
22
+ | exact / permutation SHAP | `Exact` (every coalition, up to 10 facts), `Orders` (sampled orders of arrival, each walked both ways), `LeaveOneOut`, `Stories` |
23
+ | efficiency axiom | values add up to `v(all) − v(∅)`; both ends are in every plan |
24
+ | (not needed: the model is local, free and deterministic) | repeats and shuffles of the full state, a quote, a ledger keyed by the bytes sent, planted controls |
25
+
26
+ ### Where it sits
27
+
28
+ Libraries such as llmSHAP attribute the text a chat model generates to parts of its prompt, and have to score how alike two generated texts are. A decision model states a probability, so movedby attributes that number directly, in probability points. What it adds is what a paid, remote judge makes necessary: floors that say when a value is noise or an effect of order, planted cases with known answers, and a quote and a ledger so that a reading is priced before it is paid and never paid twice.
29
+
30
+ ## A first run, without a key
31
+
32
+ ```python
33
+ from pathlib import Path
34
+
35
+ from movedby import Case, Delete, Exact, Fact, Function, NoulAnswer, P, explain
36
+ from movedby.report import text
37
+
38
+ heads = ["Yields rise", "Fed holds", "Bonds slide", "Tech rallies"]
39
+ case = Case({"headlines": heads},
40
+ tuple(Fact(f"h{i}", ("headlines", i), Delete()) for i in range(len(heads))),
41
+ {"against": {"type": "noul", "instructions": "Does at least one headline push the trade the other way?"}})
42
+
43
+ def judge(state, questions): # "at least one": the strongest headline counts
44
+ weight = {"Yields rise": 0.35, "Fed holds": -0.05, "Bonds slide": 0.25, "Tech rallies": 0.0}
45
+ return {"against": NoulAnswer(0.1 + max((weight[h] for h in state["headlines"]), default=0.0))}
46
+
47
+ ex = explain(Function(judge), case, P("against"), Exact(), ledger=Path("first.jsonl"), line=0.05,
48
+ pay=True, monotone=True).value
49
+ print(text(ex, case))
50
+ ```
51
+
52
+ "Bonds slide" carries 0.13 by Shapley value and 0.00 by leave-one-out: "Yields rise" covers for it. That is the blind spot of a one-at-a-time probe, and the first thing movedby is for.
53
+
54
+ `explain` returns `Ok(...)` or `Err(...)`; `.value` above is short for a `match` on the two.
55
+
56
+ ## On a real judge
57
+
58
+ ```python
59
+ from movedby import Orders, TypeSafe # Jev, pinned to jev-1.14.0; TYPESAFE_API_KEY in the environment
60
+
61
+ judge = TypeSafe()
62
+ quote = explain(judge, case, P("against"), Orders(pairs=10), ledger=Path("real.jsonl"), line=0.05).value
63
+ print(quote) # calls, cached calls, the upper cost; nothing was called
64
+ ex = explain(judge, case, P("against"), Orders(pairs=10), ledger=Path("real.jsonl"), line=0.05,
65
+ pay=True).value # asks what the ledger lacks; a second run pays nothing
66
+ ```
67
+
68
+ `Kairos()` (DMind's model behind the Minara gateway, `KAIROS_API_KEY`) speaks Jev's endpoint and takes the same questions unchanged. No price was measured for it, so a run on Kairos takes a call cap (`budget=Budget(usd=None, calls=200)`) or a `price` you pass. Its answers are read as recorded on 2026-11-21; `pytest -m live -k kairos` asks it for real.
69
+
70
+ `Decisions()` (OpenAI, `OPENAI_API_KEY`) takes the same questions: they are declared once, in TypeSafe's form, and translated. Without `pay=True` you get the quote. With every answer already in the ledger you get the explanation, and pay nothing.
71
+
72
+ A `Function` judge is not a pinned model: its code can change while its name stays. So each new `Function` is asked afresh. Give it a `version` and its answers are reused from the ledger like a pinned model's.
73
+
74
+ ## Keys
75
+
76
+ A judge needs its provider's key only when it sends a request. The first run above, a quote (no `pay`) and the tutorial need none.
77
+
78
+ | judge | variable | the key comes from |
79
+ |---|---|---|
80
+ | `TypeSafe()` (Jev) | `TYPESAFE_API_KEY` | TypeSafe |
81
+ | `Kairos()` | `KAIROS_API_KEY` | Minara, the gateway that serves DMind's Kairos |
82
+ | `Decisions()` | `OPENAI_API_KEY` | OpenAI |
83
+
84
+ Set only the ones for the judges you ask. movedby reads the process environment and never opens a `.env` file, so a key kept in a file has to be loaded first. `.env.example` lists the three names:
85
+
86
+ ```bash
87
+ cp .env.example .env # fill in the keys you have; git ignores .env
88
+ set -a; . ./.env; set +a # this shell now has them
89
+ uv run --env-file .env movedby run case.json --pay # or hand the file to one command
90
+ ```
91
+
92
+ In code a key can be passed instead, `TypeSafe(api_key=...)`; it is left out of the judge's `repr`. A key is sent to its provider as a bearer header and nowhere else: a ledger row holds the answers under a hash of the request, never a key.
93
+
94
+ Without a key a paid run sends nothing and comes back as `Err(NoAccess('TYPESAFE_API_KEY is not set'))`; no ledger row is written.
95
+
96
+ ## The reading
97
+
98
+ Every explanation carries its floors and one reading.
99
+
100
+ **The line** a value must clear is the largest of three:
101
+ - the line you state;
102
+ - the order floor: how far the answer moves when the same facts come in another order (five shuffles);
103
+ - the noise line: what the largest of n values crosses 5 times in 100 by chance.
104
+
105
+ **The noise line is sized for the estimate it is held against:**
106
+ - A leave-one-out effect is one difference of two answers.
107
+ - An exact Shapley value is a weighted mean over every coalition, so it is quieter.
108
+ - A value from sampled orders takes the answers' noise carried through those orders, or the spread between the two halves of the orders if that is larger.
109
+
110
+ The answers' noise comes from repeats of the full state (five by default), with Student's t for so few. A noise sd you measured elsewhere on many repeats can be passed as `noise_sd` and is taken as known. One repeat measures no noise, and the report says so.
111
+
112
+ **What gets named:**
113
+ - **Carries / holds back:** the answer falls / rises without the fact, at or past the line. They are listed apart, never by the size of the effect alone.
114
+ - **Unsettled:** a named fact whose two halves of the sampled orders disagree by more than the line. More orders would settle it.
115
+ - **Hidden from leave-one-out:** facts Shapley credits past the line that leave-one-out misses.
116
+ - **Violations:** for a question you declare monotone ("at least one headline ..."), deletions that raise the answer past the line.
117
+
118
+ **The word:**
119
+ - `moved`: a fact clears the line;
120
+ - `saturated`: both ends at the same edge of the scale;
121
+ - `flat`: nothing moves;
122
+ - `below the order floor`: reordering moves the answer as much as everything together does;
123
+ - `hidden`: the move clears every floor, and no single fact does.
124
+
125
+ `movedby.report` prints it as text or JSON. `movedby.plot` (the `plot` extra) draws the values against the line, with leave-one-out as a ring, and the walk from no fact to every fact.
126
+
127
+ ### How well the line holds
128
+
129
+ Measured on a noisy judge (sd 0.02) with six facts, two of which do nothing; `tests/test_noise.py` pins it.
130
+
131
+ | | a do-nothing fact named | a +0.30 effect found | a +0.10 effect found |
132
+ |---|---|---|---|
133
+ | leave-one-out, 3 repeats | 1.5% of runs | 64% | 17% |
134
+ | leave-one-out, 5 repeats (the default) | 0.2% | 99% | 34% |
135
+ | exact Shapley, 5 repeats | 0.8% | 100% | 100% |
136
+ | sampled orders (10 pairs), 5 repeats | 0.8% | 100% | 96% |
137
+
138
+ Three repeats are too few to pin a judge's noise, which is why five is the default.
139
+
140
+ ## Case files and the command line
141
+
142
+ ```bash
143
+ movedby plan case.json # the quote; calls nothing
144
+ movedby run case.json --pay # the explanation; --json for machines
145
+ movedby control --judge jev --pay # the three planted cases and their gates (48 calls); exit 1 on a failed gate
146
+ ```
147
+
148
+ A case file names the judge, the state, the facts (`list_facts` makes every item of a list a fact), the questions, the target, the estimator and the line. The format is in `movedby/casefile.py`. A malformed file comes back as a list of its problems.
149
+
150
+ A case file is trusted input: a `function` judge names a Python module, and loading the file imports it.
151
+
152
+ ## What a paid run guards against
153
+
154
+ - **No access** (no key, 401, 403). The first call goes out alone. If it is refused, nothing is recorded and nothing else is asked, so fixing the key and running again asks everything.
155
+ - **A ledger that cannot be written.** What is still queued is cancelled, and the error says how many answers were asked and lost.
156
+ - **A failed call** (a timeout, a 500, an answer that cannot be read). It becomes a row with its error and is asked again only with `retry_failed=True` (`--retry-failed`).
157
+ - **A judge dearer than quoted.** After the first 20 calls a per-token judge's tokens per character are measured, and the rest is gated against what is left of the budget.
158
+ - **A write that was cut off.** A last ledger line without its newline holds no row; it is skipped on reading and removed by the next write.
159
+
160
+ ## Rules it keeps (each one learned on a real judge)
161
+
162
+ 1. **One renderer, canonical bytes.** Every state is built by `render`; the request is sent as the exact bytes its cache key hashes, with JSON keys sorted. Key order alone moved Decisions by two points. With sorted keys, movedby rebuilt betlab101's requests byte for byte, and Decisions gave its stored answers back exactly.
163
+ 2. **Both ends, always.** No fact and every fact are in every plan: a flat answer and a hidden one look alike to the probe.
164
+ 3. **Floors before attribution.** A judge that answers the same request identically can still move by 0.30 when the same facts come in another order (Decisions on desk101's states and on the NVIDIA case).
165
+ 4. **Signed naming, and a monotone check** where the question allows it.
166
+ 5. **A failed call is a row, never a number.** A refusal is a `Refusal` answer; another model behind a pinned name is `ModelMoved`.
167
+ 6. **Nothing is paid without saying so.** `pay=False` is the default, a quote is an upper bound, and the default budget is one dollar.
168
+
169
+ ## What the method does not show
170
+
171
+ - How the answer responds to its input, not what happens inside the model; a vendor can change the model behind a pinned name.
172
+ - "Removed" means what the removal rule says; another rule gives other numbers.
173
+ - A per-fact number averages over how facts work together.
174
+ - **`Gap` is not additive across the reference:** a fact that alone carries the judge across the reference, and with others pulls it back, gets credited both ways, near zero.
175
+ - Scored by an outcome (`Loss`), a fact can be sound evidence and still point away from what happened.
176
+ - Planted cases test the estimators and the renderer; they do not prove faithfulness on real states.
177
+ - Two runs on one ledger at the same time both pay: there is no lock.
178
+
179
+ ## Tutorial
180
+
181
+ `tutorial/nvidia.ipynb`: NVIDIA in the fortnight to 2026-11-25 (Huang resigns, results, reinstatement, the 31.5% day and the two after), Jev and Decisions on "where does NVDA close on Dec 3", from a ledger shipped with it, so it runs without a key:
182
+
183
+ ```bash
184
+ uv sync --group tutorial
185
+ uv run --group tutorial jupyter lab tutorial/nvidia.ipynb
186
+ ```
187
+
188
+ ## Development
189
+
190
+ ```bash
191
+ uv sync
192
+ uv run pytest # sockets disabled: no test can call a provider
193
+ uv run mypy src/movedby # the package ships py.typed
194
+ uv run pytest -m live # opt-in and paid: the planted `single` case on Jev, Kairos and Decisions; a judge without its key is skipped
195
+ ```
196
+
197
+ `tests/golden/` holds three planted cases about invented places and the 96 answers Jev and Decisions gave to every subset of them (betlab101, 2026-11-21); the golden test reproduces betlab101's numbers from those rows.
198
+
199
+ Tested on Python 3.12, 3.13 and 3.14, and with the lowest versions `pyproject.toml` allows. `RELEASING.md` has the steps of a release.
200
+
201
+ MIT licence. movedby is an independent project: it is not affiliated with or endorsed by TypeSafe, DMind or OpenAI, whose names are used here only to say which models it can ask.
@@ -0,0 +1,75 @@
1
+ [project]
2
+ name = "movedby"
3
+ version = "0.1.0"
4
+ description = "What moved the decision: SHAP- and LIME-style attribution for typed decision models (Jev, OpenAI Decisions, Kairos), with a noise floor, a budget and a ledger"
5
+ readme = "README.md"
6
+ license = "MIT"
7
+ license-files = ["LICENSE"]
8
+ requires-python = ">=3.12"
9
+ keywords = [
10
+ "explainability",
11
+ "interpretability",
12
+ "attribution",
13
+ "shapley",
14
+ "shap",
15
+ "lime",
16
+ "decision-model",
17
+ "system-one",
18
+ "llm",
19
+ ]
20
+ classifiers = [
21
+ "Development Status :: 3 - Alpha",
22
+ "Intended Audience :: Developers",
23
+ "Intended Audience :: Science/Research",
24
+ "Operating System :: OS Independent",
25
+ "Programming Language :: Python :: 3",
26
+ "Programming Language :: Python :: 3.12",
27
+ "Programming Language :: Python :: 3.13",
28
+ "Programming Language :: Python :: 3.14",
29
+ "Topic :: Scientific/Engineering :: Artificial Intelligence",
30
+ "Typing :: Typed",
31
+ ]
32
+ dependencies = [
33
+ "httpx>=0.27",
34
+ "numpy>=1.26",
35
+ ]
36
+
37
+ [[project.authors]]
38
+ name = "nnfuzzy"
39
+
40
+ [project.urls]
41
+ Homepage = "https://github.com/nnfuzzy/movedby"
42
+ Repository = "https://github.com/nnfuzzy/movedby"
43
+ Issues = "https://github.com/nnfuzzy/movedby/issues"
44
+ Changelog = "https://github.com/nnfuzzy/movedby/blob/main/CHANGELOG.md"
45
+
46
+ [project.scripts]
47
+ movedby = "movedby.cli:main"
48
+
49
+ [project.optional-dependencies]
50
+ plot = ["matplotlib>=3.8"]
51
+
52
+ [build-system]
53
+ requires = ["uv_build>=0.9.0,<0.10.0"]
54
+ build-backend = "uv_build"
55
+
56
+ [dependency-groups]
57
+ dev = [
58
+ "hypothesis>=6.170.17",
59
+ "matplotlib>=3.8",
60
+ "mypy>=2.4.1",
61
+ "pytest>=9.2.0",
62
+ "pytest-socket>=0.8.1",
63
+ "ruff>=0.17.6",
64
+ ]
65
+ tutorial = [
66
+ "ipykernel>=7.4.0",
67
+ "jupyterlab>=4.6.6",
68
+ "nbconvert>=7.17.2",
69
+ "nbformat>=5.11.1",
70
+ ]
71
+
72
+ [tool.pytest.ini_options]
73
+ testpaths = ["tests"]
74
+ addopts = "--disable-socket -m 'not live'"
75
+ markers = ["live: calls a paid provider; opt-in with -m live"]
@@ -0,0 +1,75 @@
1
+ [project]
2
+ name = "movedby"
3
+ version = "0.1.0"
4
+ description = "What moved the decision: SHAP- and LIME-style attribution for typed decision models (Jev, OpenAI Decisions, Kairos), with a noise floor, a budget and a ledger"
5
+ readme = "README.md"
6
+ license = "MIT"
7
+ license-files = ["LICENSE"]
8
+ authors = [{ name = "nnfuzzy" }]
9
+ requires-python = ">=3.12"
10
+ keywords = [
11
+ "explainability",
12
+ "interpretability",
13
+ "attribution",
14
+ "shapley",
15
+ "shap",
16
+ "lime",
17
+ "decision-model",
18
+ "system-one",
19
+ "llm",
20
+ ]
21
+ classifiers = [
22
+ "Development Status :: 3 - Alpha",
23
+ "Intended Audience :: Developers",
24
+ "Intended Audience :: Science/Research",
25
+ "Operating System :: OS Independent",
26
+ "Programming Language :: Python :: 3",
27
+ "Programming Language :: Python :: 3.12",
28
+ "Programming Language :: Python :: 3.13",
29
+ "Programming Language :: Python :: 3.14",
30
+ "Topic :: Scientific/Engineering :: Artificial Intelligence",
31
+ "Typing :: Typed",
32
+ ]
33
+ dependencies = [
34
+ "httpx>=0.27",
35
+ "numpy>=1.26",
36
+ ]
37
+
38
+ [project.urls]
39
+ Homepage = "https://github.com/nnfuzzy/movedby"
40
+ Repository = "https://github.com/nnfuzzy/movedby"
41
+ Issues = "https://github.com/nnfuzzy/movedby/issues"
42
+ Changelog = "https://github.com/nnfuzzy/movedby/blob/main/CHANGELOG.md"
43
+
44
+ [project.scripts]
45
+ movedby = "movedby.cli:main"
46
+
47
+ [project.optional-dependencies]
48
+ plot = [
49
+ "matplotlib>=3.8",
50
+ ]
51
+
52
+ [build-system]
53
+ requires = ["uv_build>=0.9.0,<0.10.0"]
54
+ build-backend = "uv_build"
55
+
56
+ [dependency-groups]
57
+ dev = [
58
+ "hypothesis>=6.170.17",
59
+ "matplotlib>=3.8",
60
+ "mypy>=2.4.1",
61
+ "pytest>=9.2.0",
62
+ "pytest-socket>=0.8.1",
63
+ "ruff>=0.17.6",
64
+ ]
65
+ tutorial = [
66
+ "ipykernel>=7.4.0",
67
+ "jupyterlab>=4.6.6",
68
+ "nbconvert>=7.17.2",
69
+ "nbformat>=5.11.1",
70
+ ]
71
+
72
+ [tool.pytest.ini_options]
73
+ testpaths = ["tests"]
74
+ addopts = "--disable-socket -m 'not live'"
75
+ markers = ["live: calls a paid provider; opt-in with -m live"]
@@ -0,0 +1,64 @@
1
+ """movedby: which facts moved a typed decision model's answer, measured from outside.
2
+
3
+ A decision model (Jev, OpenAI's Decisions API, Kairos) reads one state and answers typed
4
+ questions with probabilities and no reason. movedby asks it again with facts removed and
5
+ reduces the answers to attributions, as SHAP does for a tabular model, with what a paid,
6
+ remote, noisy judge needs on top: a noise floor, a quote before paying, a ledger that never
7
+ pays twice, and planted cases with known answers.
8
+
9
+ The names a run needs are here; the report (`movedby.report`), the charts (`movedby.plot`,
10
+ which needs the `plot` extra), the planted controls (`movedby.controls`) and case files
11
+ (`movedby.casefile`) are imported from their modules.
12
+ """
13
+
14
+ from importlib.metadata import PackageNotFoundError, version
15
+
16
+ from movedby.answers import ChoiceAnswer, NoulAnswer, Refusal, ScoreAnswer
17
+ from movedby.case import BadCase, Case, Delete, Fact, Replace, validate
18
+ from movedby.estimators import Exact, LeaveOneOut, Orders, Stories
19
+ from movedby.judges import Decisions, Function, Judge, Kairos, Price, TypeSafe
20
+ from movedby.result import Err, Ok, Result
21
+ from movedby.run import Budget, Explanation, Quote, explain
22
+ from movedby.target import Choice, Expected, Gap, Loss, P, Policy
23
+
24
+ try:
25
+ __version__ = version("movedby")
26
+ except PackageNotFoundError: # a source tree that was never installed
27
+ __version__ = "0+unknown"
28
+
29
+ __all__ = [
30
+ "BadCase",
31
+ "Budget",
32
+ "Case",
33
+ "Choice",
34
+ "ChoiceAnswer",
35
+ "Decisions",
36
+ "Delete",
37
+ "Err",
38
+ "Exact",
39
+ "Expected",
40
+ "Explanation",
41
+ "Fact",
42
+ "Function",
43
+ "Gap",
44
+ "Judge",
45
+ "Kairos",
46
+ "LeaveOneOut",
47
+ "Loss",
48
+ "NoulAnswer",
49
+ "Ok",
50
+ "Orders",
51
+ "P",
52
+ "Policy",
53
+ "Price",
54
+ "Quote",
55
+ "Refusal",
56
+ "Replace",
57
+ "Result",
58
+ "ScoreAnswer",
59
+ "Stories",
60
+ "TypeSafe",
61
+ "__version__",
62
+ "explain",
63
+ "validate",
64
+ ]