feat: native JSON model i/o and BinWM→CODA glue#46
Draft
corriander wants to merge 1 commit into
Draft
Conversation
Add stdlib-only JSON serialisation for CODA models and Binary Weighting
Matrices, plus glue to seed a CODA model from a BinWM.
- CODA.to_dict/from_dict/to_json/read_json using a flat, diff-friendly
schema (requirements, characteristics, relationships). Requirement raw
weights and the normalise flag are stored so self-normalising weights
replay faithfully on the target instance; only non-null relationships
are emitted.
- BinWM.to_dict/from_dict/to_json/read_json matching the existing test
fixture shape ({"requirements": [...], "binary_matrix": [[...]]}), so
the bundled fixtures are valid interchange files.
- CODA.add_requirements_from(binwm) adds one requirement per BinWM
requirement using its score as weight (normalise=True; BinWM.score
sums to unity by construction).
- Round-trip tests (dict + json string + file) for the bicycle-wheel
case study, optimise/unset-value handling, and pre-normalised weights.
- README JSON usage section.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds stdlib-only (
json) native serialisation for CODA models and Binary Weighting Matrices, and glue to seed a CODA model directly from a BinWM. No new dependencies.CODA JSON
Flat, human-readable, git-diff-friendly schema:
{ "requirements": [{"name": "...", "weight": 0.2, "normalise": true}], "characteristics": [{"name": "...", "limits": [lo, hi], "value": 24}], "relationships": [ {"requirement": "...", "characteristic": "...", "type": "min|max|opt", "correlation": 0.9, "target": 0.5, "tolerance": null} ] }CODA.to_dict()/from_dict()— dict form.CODA.to_json(path=None)— returns a string whenpathis omitted, else writes the file.CODA.read_json(path)— classmethod mirroringread_excel.limits/valuemay beNone;toleranceisNonefor non-optimising relationships.base_weightfor self-normalising requirements, otherwise the pre-normalised weight) plus anormaliseflag, sofrom_dictreplays normalisation on the target instance via the publicadd_*API — no element objects are copied across instances (their weights are context-dependent).BinWM JSON
BinWM.to_dict()/from_dict()/to_json()/read_json()using the exact shape of the existing test fixtures:{"requirements": ["..."], "binary_matrix": [[0, 0, 1], ...]}The bundled
case__*.jsonfixtures are therefore valid interchange files (a test loads one directly throughread_json).BinWM → CODA glue
CODA.add_requirements_from(binwm)adds one requirement per BinWM requirement, using its score as the weight.BinWM.scoresums to unity by construction, so scores are added withnormalise=True(self-normalising requirements) — this keeps floating-point drift around unity from tripping the combined-weight guard and lets further requirements be mixed in afterwards with automatic re-normalisation.Tests
14 new tests (168 total, was 154). CODA round-trips through dict, JSON string and file for the bicycle-wheel case study (merit/satisfaction/correlation/weights and all names/limits/values/relationship params asserted), plus optimise-tolerance + unset-value handling and pre-normalised weights. BinWM round-trips including a fixture loaded directly. README updated with a JSON usage example.
🤖 Generated with Claude Code