ebaml 0.8.2__tar.gz → 0.8.3__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.
- {ebaml-0.8.2 → ebaml-0.8.3}/PKG-INFO +1 -1
- {ebaml-0.8.2 → ebaml-0.8.3}/pyproject.toml +1 -1
- {ebaml-0.8.2 → ebaml-0.8.3}/pyproject.toml.orig +1 -1
- {ebaml-0.8.2 → ebaml-0.8.3}/src/ebaml/__init__.py +30 -0
- ebaml-0.8.3/src/ebaml/edit/constraints.py +392 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/ebaml/edit/edit_records.py +44 -11
- {ebaml-0.8.2 → ebaml-0.8.3}/src/ebaml/edit/edits.py +103 -0
- ebaml-0.8.3/src/ebaml/edit/gamchanger_files.py +410 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/ebaml/edit/selections.py +12 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/ebaml/mcp/edit_tools.py +188 -9
- {ebaml-0.8.2 → ebaml-0.8.3}/src/ebaml/mcp/server.py +48 -2
- {ebaml-0.8.2 → ebaml-0.8.3}/LICENSE +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/README.md +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/.baml-generator-output-root +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/.baml-generator-output.json +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/__init__.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/__init__.pyi +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/_baml_sources.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/_function_registry.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/_inlinedbaml.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/_invocation_types.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/_invocation_types.pyi +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/_typemap.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/ai/__init__.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/ai/__init__.pyi +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/ai/clients/__init__.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/ai/clients/__init__.pyi +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/ai/content/__init__.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/ai/content/__init__.pyi +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/ai/errors/__init__.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/ai/errors/__init__.pyi +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/ai/events/__init__.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/ai/events/__init__.pyi +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/ai/internal/__init__.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/ai/internal/__init__.pyi +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/ai/mcp/__init__.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/ai/mcp/__init__.pyi +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/ai/stream/__init__.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/ai/stream/__init__.pyi +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/ai/tools/__init__.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/ai/tools/__init__.pyi +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/ai/wire/__init__.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/ai/wire/__init__.pyi +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/baml/__init__.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/baml/__init__.pyi +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/baml/archive/__init__.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/baml/archive/__init__.pyi +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/baml/crypto/__init__.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/baml/crypto/__init__.pyi +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/baml/csv/__init__.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/baml/csv/__init__.pyi +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/baml/env/__init__.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/baml/env/__init__.pyi +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/baml/errors/__init__.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/baml/errors/__init__.pyi +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/baml/fs/__init__.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/baml/fs/__init__.pyi +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/baml/future/__init__.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/baml/future/__init__.pyi +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/baml/glob/__init__.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/baml/glob/__init__.pyi +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/baml/hash/__init__.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/baml/hash/__init__.pyi +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/baml/host/__init__.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/baml/host/__init__.pyi +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/baml/http/__init__.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/baml/http/__init__.pyi +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/baml/io/__init__.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/baml/io/__init__.pyi +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/baml/iter/__init__.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/baml/iter/__init__.pyi +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/baml/json/__init__.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/baml/json/__init__.pyi +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/baml/media/__init__.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/baml/media/__init__.pyi +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/baml/net/__init__.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/baml/net/__init__.pyi +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/baml/ops/__init__.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/baml/ops/__init__.pyi +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/baml/panics/__init__.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/baml/panics/__init__.pyi +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/baml/path/__init__.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/baml/path/__init__.pyi +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/baml/random/__init__.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/baml/random/__init__.pyi +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/baml/regex/__init__.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/baml/regex/__init__.pyi +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/baml/sap/__init__.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/baml/sap/__init__.pyi +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/baml/spawn/__init__.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/baml/spawn/__init__.pyi +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/baml/sys/__init__.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/baml/sys/__init__.pyi +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/baml/time/__init__.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/baml/time/__init__.pyi +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/baml/toml/__init__.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/baml/toml/__init__.pyi +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/baml/ws/__init__.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/baml/ws/__init__.pyi +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/baml/yaml/__init__.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/baml/yaml/__init__.pyi +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/experimental/__init__.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/experimental/__init__.pyi +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/py.typed +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/reflect/__init__.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/reflect/__init__.pyi +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/reflect/class_/__init__.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/reflect/class_/__init__.pyi +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/reflect/enum/__init__.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/reflect/enum/__init__.pyi +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/reflect/errors/__init__.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/reflect/errors/__init__.pyi +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/reflect/function/__init__.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/reflect/function/__init__.pyi +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/reflect/interface/__init__.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/reflect/interface/__init__.pyi +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/vendor/__init__.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/vendor/__init__.pyi +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/vendor/anthropic/__init__.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/vendor/anthropic/__init__.pyi +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/vendor/anthropic/internal/__init__.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/vendor/anthropic/internal/__init__.pyi +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/vendor/assert_/__init__.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/vendor/assert_/__init__.pyi +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/vendor/aws/__init__.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/vendor/aws/__init__.pyi +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/vendor/aws/internal/__init__.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/vendor/aws/internal/__init__.pyi +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/vendor/claude_code/__init__.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/vendor/claude_code/__init__.pyi +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/vendor/claude_code/internal/__init__.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/vendor/claude_code/internal/__init__.pyi +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/vendor/google/__init__.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/vendor/google/__init__.pyi +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/vendor/google/internal/__init__.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/vendor/google/internal/__init__.pyi +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/vendor/openai/__init__.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/vendor/openai/__init__.pyi +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/vendor/openai/internal/__init__.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/vendor/openai/internal/__init__.pyi +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/vendor/openai/internal/decisions/__init__.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/vendor/openai/internal/decisions/__init__.pyi +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/vendor/testing/__init__.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/vendor/testing/__init__.pyi +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/vendor/trace/__init__.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/vendor/trace/__init__.pyi +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/vendor/typesafeai/__init__.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/vendor/typesafeai/__init__.pyi +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/vendor/typesafeai/internal/__init__.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/vendor/typesafeai/internal/__init__.pyi +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/vendor/vercel/__init__.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/vendor/vercel/__init__.pyi +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/vendor/vercel/internal/__init__.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/baml_sdk/vendor/vercel/internal/__init__.pyi +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/ebaml/benchmark.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/ebaml/core/__init__.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/ebaml/core/beartype_hook.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/ebaml/core/custom_types.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/ebaml/core/ebm_classes.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/ebaml/core/exceptions.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/ebaml/edit/__init__.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/ebaml/edit/data_effect.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/ebaml/edit/edit_report.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/ebaml/edit/edit_session.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/ebaml/edit/history.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/ebaml/edit/model_view.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/ebaml/edit/model_write.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/ebaml/edit/revision_ids.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/ebaml/graphs/__init__.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/ebaml/graphs/ebm_graph.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/ebaml/graphs/graph_text.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/ebaml/graphs/model_kinds.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/ebaml/graphs/request_text.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/ebaml/graphs/terms.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/ebaml/graphs/token_budget.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/ebaml/graphs/token_weights.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/ebaml/llm/__init__.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/ebaml/llm/descriptors.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/ebaml/llm/options.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/ebaml/llm/progress_bars.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/ebaml/llm/provider_errors.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/ebaml/llm/requests.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/ebaml/llm/retry.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/ebaml/llm/sdk_setup.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/ebaml/llm/token_learning.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/ebaml/llm/token_weights.json +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/ebaml/local/__init__.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/ebaml/local/audience.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/ebaml/local/completions.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/ebaml/local/counterfactuals.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/ebaml/local/covering_backend.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/ebaml/local/covering_greedy.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/ebaml/local/covering_problem.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/ebaml/local/covering_solvers.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/ebaml/local/decisions.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/ebaml/local/fact_features.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/ebaml/local/fact_text.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/ebaml/local/fact_types.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/ebaml/local/facts.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/ebaml/local/local_kinds.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/ebaml/local/minimality.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/ebaml/local/ortools_backend.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/ebaml/local/sufficient_reasons.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/ebaml/mcp/__init__.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/ebaml/mcp/chat.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/ebaml/mcp/explain_tools.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/ebaml/mcp/llm_tools.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/ebaml/mcp/model_store.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/ebaml/mcp/read_tools.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/ebaml/mcp/save_tools.py +0 -0
- {ebaml-0.8.2 → ebaml-0.8.3}/src/ebaml/py.typed +0 -0
|
@@ -37,13 +37,26 @@ from ebaml.core.exceptions import (
|
|
|
37
37
|
UnreviewedEditError,
|
|
38
38
|
UnsupportedModelError,
|
|
39
39
|
)
|
|
40
|
+
from ebaml.edit.constraints import (
|
|
41
|
+
Bounded,
|
|
42
|
+
Constraint,
|
|
43
|
+
FixedScore,
|
|
44
|
+
MaxStep,
|
|
45
|
+
Monotone,
|
|
46
|
+
Unused,
|
|
47
|
+
Violation,
|
|
48
|
+
check_constraints,
|
|
49
|
+
)
|
|
40
50
|
from ebaml.edit.edit_report import BinChange, EditReport
|
|
41
51
|
from ebaml.edit.edit_session import EditSession
|
|
42
52
|
from ebaml.edit.edits import (
|
|
43
53
|
Align,
|
|
54
|
+
AssignScores,
|
|
55
|
+
Clip,
|
|
44
56
|
Edit,
|
|
45
57
|
FitLine,
|
|
46
58
|
Interpolate,
|
|
59
|
+
LimitSteps,
|
|
47
60
|
Monotonize,
|
|
48
61
|
Recenter,
|
|
49
62
|
RemoveFeature,
|
|
@@ -53,10 +66,12 @@ from ebaml.edit.edits import (
|
|
|
53
66
|
Shift,
|
|
54
67
|
ZeroTerm,
|
|
55
68
|
)
|
|
69
|
+
from ebaml.edit.gamchanger_files import GamChangerCommit, apply_gamchanger, load_gamchanger
|
|
56
70
|
from ebaml.edit.history import EditEntry, HistoryEntry, HistoryRow, SaveEntry
|
|
57
71
|
from ebaml.edit.selections import (
|
|
58
72
|
Bins,
|
|
59
73
|
Categories,
|
|
74
|
+
EveryBin,
|
|
60
75
|
MissingBin,
|
|
61
76
|
Selection,
|
|
62
77
|
UnseenBin,
|
|
@@ -125,14 +140,18 @@ __version__: str = version("ebaml")
|
|
|
125
140
|
__all__ = [
|
|
126
141
|
"APIKeyRejectedError",
|
|
127
142
|
"Align",
|
|
143
|
+
"AssignScores",
|
|
128
144
|
"Audience",
|
|
129
145
|
"BinChange",
|
|
130
146
|
"BinaryClassifier",
|
|
131
147
|
"Bins",
|
|
148
|
+
"Bounded",
|
|
132
149
|
"Categories",
|
|
133
150
|
"Change",
|
|
134
151
|
"Choice",
|
|
152
|
+
"Clip",
|
|
135
153
|
"CompletionStep",
|
|
154
|
+
"Constraint",
|
|
136
155
|
"Contribution",
|
|
137
156
|
"Counterfactual",
|
|
138
157
|
"Cover",
|
|
@@ -156,10 +175,13 @@ __all__ = [
|
|
|
156
175
|
"EditError",
|
|
157
176
|
"EditReport",
|
|
158
177
|
"EditSession",
|
|
178
|
+
"EveryBin",
|
|
159
179
|
"ExplainInstanceRequest",
|
|
160
180
|
"FactTexts",
|
|
161
181
|
"FeatureType",
|
|
162
182
|
"FitLine",
|
|
183
|
+
"FixedScore",
|
|
184
|
+
"GamChangerCommit",
|
|
163
185
|
"GraphOptions",
|
|
164
186
|
"GraphTextError",
|
|
165
187
|
"GreedyCover",
|
|
@@ -172,10 +194,12 @@ __all__ = [
|
|
|
172
194
|
"InvalidOptionError",
|
|
173
195
|
"LLMRequestError",
|
|
174
196
|
"Layperson",
|
|
197
|
+
"LimitSteps",
|
|
175
198
|
"LocalExplanation",
|
|
176
199
|
"LocalFacts",
|
|
177
200
|
"LocalOptions",
|
|
178
201
|
"LocalSearchCover",
|
|
202
|
+
"MaxStep",
|
|
179
203
|
"MinimalityStatus",
|
|
180
204
|
"MipBackend",
|
|
181
205
|
"MipCover",
|
|
@@ -185,6 +209,7 @@ __all__ = [
|
|
|
185
209
|
"ModelOptions",
|
|
186
210
|
"ModelResult",
|
|
187
211
|
"ModelStatus",
|
|
212
|
+
"Monotone",
|
|
188
213
|
"Monotonize",
|
|
189
214
|
"MulticlassClassifier",
|
|
190
215
|
"Normalization",
|
|
@@ -217,10 +242,14 @@ __all__ = [
|
|
|
217
242
|
"UnreviewedEditError",
|
|
218
243
|
"UnseenBin",
|
|
219
244
|
"UnsupportedModelError",
|
|
245
|
+
"Unused",
|
|
220
246
|
"ValueInterval",
|
|
247
|
+
"Violation",
|
|
221
248
|
"WholeGraph",
|
|
222
249
|
"ZeroTerm",
|
|
223
250
|
"__version__",
|
|
251
|
+
"apply_gamchanger",
|
|
252
|
+
"check_constraints",
|
|
224
253
|
"check_token_budget",
|
|
225
254
|
"compute_local_facts",
|
|
226
255
|
"describe_ebm",
|
|
@@ -228,6 +257,7 @@ __all__ = [
|
|
|
228
257
|
"explain_instance",
|
|
229
258
|
"facts_to_texts",
|
|
230
259
|
"likelihood_word",
|
|
260
|
+
"load_gamchanger",
|
|
231
261
|
"model_kind",
|
|
232
262
|
"points_towards",
|
|
233
263
|
"resolve_audience",
|
|
@@ -0,0 +1,392 @@
|
|
|
1
|
+
"""Business constraints on the graphs of an EBM, and the check that finds the constraints that a model breaks.
|
|
2
|
+
|
|
3
|
+
A constraint states a business requirement, for example "the risk must not fall when the age goes up" or "a missing
|
|
4
|
+
value scores 0". Each constraint is a frozen class with two methods: ``violation`` reads the model and returns what
|
|
5
|
+
breaks the constraint, and ``repair`` names the edit that makes the constraint hold. A new constraint is a new class.
|
|
6
|
+
|
|
7
|
+
A constraint reads the scores of the main effect of a feature. A pair term that uses the feature can still change the
|
|
8
|
+
effect of the feature on a prediction, so only ``Unused`` makes a claim about the pair terms. A score difference at or
|
|
9
|
+
below the tolerance is not a violation, so that the rounding of a repair does not count.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
import abc
|
|
13
|
+
from collections.abc import Iterable, Sequence
|
|
14
|
+
from typing import Literal, override
|
|
15
|
+
|
|
16
|
+
import attrs
|
|
17
|
+
import numpy as np
|
|
18
|
+
import numpy.typing as npt
|
|
19
|
+
|
|
20
|
+
from ebaml.core.custom_types import ExplainableBoostingModel
|
|
21
|
+
from ebaml.core.exceptions import EditError, OptionRangeError, SelectionError
|
|
22
|
+
from ebaml.edit import model_write
|
|
23
|
+
from ebaml.edit.edits import Clip, Edit, LimitSteps, Monotonize, RemoveFeature, SetScores
|
|
24
|
+
from ebaml.edit.model_view import TermView, term_view
|
|
25
|
+
from ebaml.edit.selections import EveryBin, Selection, WholeGraph
|
|
26
|
+
|
|
27
|
+
MonotoneDirection = Literal["increasing", "decreasing"]
|
|
28
|
+
|
|
29
|
+
DEFAULT_TOLERANCE = 1e-9
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def _number(value: float) -> str:
|
|
33
|
+
return format(value, ".4g")
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class Constraint(abc.ABC):
|
|
37
|
+
"""A business requirement on the graph of one feature."""
|
|
38
|
+
|
|
39
|
+
@abc.abstractmethod
|
|
40
|
+
def violation(self, ebm: ExplainableBoostingModel, tolerance: float) -> "Violation | None":
|
|
41
|
+
"""Find what breaks the constraint in a model.
|
|
42
|
+
|
|
43
|
+
Parameters
|
|
44
|
+
----------
|
|
45
|
+
ebm : ExplainableBoostingModel
|
|
46
|
+
The model to check. The check reads the model and changes nothing.
|
|
47
|
+
tolerance : float
|
|
48
|
+
The largest difference that does not count as a violation.
|
|
49
|
+
|
|
50
|
+
Returns
|
|
51
|
+
-------
|
|
52
|
+
Violation | None
|
|
53
|
+
The violation, or ``None`` if the model meets the constraint.
|
|
54
|
+
|
|
55
|
+
Raises
|
|
56
|
+
------
|
|
57
|
+
EditError
|
|
58
|
+
If the constraint does not fit the model.
|
|
59
|
+
SelectionError
|
|
60
|
+
If the feature or the bins of the constraint do not exist.
|
|
61
|
+
|
|
62
|
+
"""
|
|
63
|
+
|
|
64
|
+
@abc.abstractmethod
|
|
65
|
+
def repair(self) -> Edit:
|
|
66
|
+
"""Name the edit that makes the constraint hold.
|
|
67
|
+
|
|
68
|
+
Returns
|
|
69
|
+
-------
|
|
70
|
+
Edit
|
|
71
|
+
The edit.
|
|
72
|
+
|
|
73
|
+
"""
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
@attrs.frozen
|
|
77
|
+
class Violation:
|
|
78
|
+
"""What breaks one constraint in one model.
|
|
79
|
+
|
|
80
|
+
Attributes
|
|
81
|
+
----------
|
|
82
|
+
constraint: Constraint
|
|
83
|
+
The constraint that the model breaks.
|
|
84
|
+
description: str
|
|
85
|
+
What breaks the constraint, in one sentence.
|
|
86
|
+
bins: tuple[str, ...]
|
|
87
|
+
The bins that break the constraint, as the report of an edit names them: ``missing``, ``unseen``, the edges of a
|
|
88
|
+
continuous bin, or a category.
|
|
89
|
+
terms: tuple[str, ...]
|
|
90
|
+
The terms that break the constraint. Only ``Unused`` fills it.
|
|
91
|
+
excess: float
|
|
92
|
+
The largest amount by which one score, or one step between two scores, breaks the constraint.
|
|
93
|
+
repair: Edit
|
|
94
|
+
The edit that makes the constraint hold. Preview it before you apply it, because it changes predictions.
|
|
95
|
+
|
|
96
|
+
"""
|
|
97
|
+
|
|
98
|
+
constraint: Constraint
|
|
99
|
+
description: str
|
|
100
|
+
bins: tuple[str, ...]
|
|
101
|
+
excess: float
|
|
102
|
+
repair: Edit
|
|
103
|
+
terms: tuple[str, ...] = ()
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
@attrs.frozen(eq=False)
|
|
107
|
+
class _Scores:
|
|
108
|
+
"""The selected scores of the main effect of one feature."""
|
|
109
|
+
|
|
110
|
+
view: TermView
|
|
111
|
+
positions: tuple[int, ...]
|
|
112
|
+
|
|
113
|
+
@property
|
|
114
|
+
def values(self) -> npt.NDArray[np.float64]:
|
|
115
|
+
return self.view.scores[list(self.positions)]
|
|
116
|
+
|
|
117
|
+
def labels(self, mask: npt.NDArray[np.bool_]) -> tuple[str, ...]:
|
|
118
|
+
"""Name the bins where a mask is true.
|
|
119
|
+
|
|
120
|
+
Returns
|
|
121
|
+
-------
|
|
122
|
+
tuple[str, ...]
|
|
123
|
+
The name of each such bin, in the order of the bins.
|
|
124
|
+
|
|
125
|
+
"""
|
|
126
|
+
return tuple(self.view.label(position) for position, chosen in zip(self.positions, mask, strict=True) if chosen)
|
|
127
|
+
|
|
128
|
+
def pair_labels(self, mask: npt.NDArray[np.bool_]) -> tuple[str, ...]:
|
|
129
|
+
"""Name both bins of each pair of neighbour bins where a mask is true.
|
|
130
|
+
|
|
131
|
+
Returns
|
|
132
|
+
-------
|
|
133
|
+
tuple[str, ...]
|
|
134
|
+
The name of each such bin, in the order of the bins, with no repeat.
|
|
135
|
+
|
|
136
|
+
"""
|
|
137
|
+
in_pair = np.zeros(len(self.positions), dtype=bool)
|
|
138
|
+
in_pair[:-1] |= mask
|
|
139
|
+
in_pair[1:] |= mask
|
|
140
|
+
return self.labels(in_pair)
|
|
141
|
+
|
|
142
|
+
def describe(self) -> str:
|
|
143
|
+
return self.view.describe_positions(self.positions)
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
def _scores(ebm: ExplainableBoostingModel, feature: str, selection: Selection) -> _Scores:
|
|
147
|
+
view = term_view(ebm, feature)
|
|
148
|
+
return _Scores(view, selection.resolve(view))
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
def _ordered_scores(ebm: ExplainableBoostingModel, feature: str, selection: Selection, name: str) -> _Scores:
|
|
152
|
+
"""Read the selected scores for a constraint on the order of the bins.
|
|
153
|
+
|
|
154
|
+
Returns
|
|
155
|
+
-------
|
|
156
|
+
_Scores
|
|
157
|
+
The real bins of a continuous or ordinal feature.
|
|
158
|
+
|
|
159
|
+
Raises
|
|
160
|
+
------
|
|
161
|
+
EditError
|
|
162
|
+
If the feature has no order, or the selection holds the missing bin or the unseen bin.
|
|
163
|
+
|
|
164
|
+
"""
|
|
165
|
+
scores = _scores(ebm, feature, selection)
|
|
166
|
+
if not scores.view.ordered:
|
|
167
|
+
msg = f"{name} needs an order, but {feature!r} is {scores.view.feature_type}. Use Bounded or FixedScore."
|
|
168
|
+
raise EditError(msg)
|
|
169
|
+
if not scores.view.is_real(scores.positions):
|
|
170
|
+
msg = f"{name} needs real bins, and the selection holds the missing bin or the unseen bin of {feature!r}."
|
|
171
|
+
raise EditError(msg)
|
|
172
|
+
return scores
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
@attrs.frozen
|
|
176
|
+
class Monotone(Constraint):
|
|
177
|
+
"""The selected scores must not fall (``increasing``) or must not rise (``decreasing``) from bin to bin.
|
|
178
|
+
|
|
179
|
+
Select a range for a graph that must rise on one side and fall on the other, such as a U-shape. The repair is
|
|
180
|
+
``Monotonize`` on the same bins.
|
|
181
|
+
"""
|
|
182
|
+
|
|
183
|
+
feature: str
|
|
184
|
+
direction: MonotoneDirection
|
|
185
|
+
selection: Selection = attrs.field(factory=WholeGraph)
|
|
186
|
+
|
|
187
|
+
@override
|
|
188
|
+
def violation(self, ebm: ExplainableBoostingModel, tolerance: float) -> Violation | None:
|
|
189
|
+
scores = _ordered_scores(ebm, self.feature, self.selection, "Monotone")
|
|
190
|
+
steps = np.diff(scores.values)
|
|
191
|
+
wrong_way = -steps if self.direction == "increasing" else steps
|
|
192
|
+
breaks = wrong_way > tolerance
|
|
193
|
+
if not breaks.any():
|
|
194
|
+
return None
|
|
195
|
+
verb = "falls" if self.direction == "increasing" else "rises"
|
|
196
|
+
excess = float(wrong_way.max())
|
|
197
|
+
description = (
|
|
198
|
+
f"The graph of {self.feature} {verb} between {int(breaks.sum())} pairs of neighbour bins"
|
|
199
|
+
f" in {scores.describe()}, by up to {_number(excess)}"
|
|
200
|
+
)
|
|
201
|
+
return Violation(self, description, scores.pair_labels(breaks), excess, self.repair())
|
|
202
|
+
|
|
203
|
+
@override
|
|
204
|
+
def repair(self) -> Edit:
|
|
205
|
+
return Monotonize(self.feature, self.direction, self.selection)
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
@attrs.frozen
|
|
209
|
+
class MaxStep(Constraint):
|
|
210
|
+
"""No step between the scores of two neighbour bins in the selection may be larger than ``step``.
|
|
211
|
+
|
|
212
|
+
The rule stops a jump of the graph that the data does not explain. The repair is ``LimitSteps`` on the same bins.
|
|
213
|
+
"""
|
|
214
|
+
|
|
215
|
+
feature: str
|
|
216
|
+
step: float
|
|
217
|
+
selection: Selection = attrs.field(factory=WholeGraph)
|
|
218
|
+
|
|
219
|
+
@override
|
|
220
|
+
def violation(self, ebm: ExplainableBoostingModel, tolerance: float) -> Violation | None:
|
|
221
|
+
if not 0 <= self.step < np.inf:
|
|
222
|
+
msg = f"MaxStep needs a step that is 0 or more and finite, but the step is {self.step}."
|
|
223
|
+
raise EditError(msg)
|
|
224
|
+
scores = _ordered_scores(ebm, self.feature, self.selection, "MaxStep")
|
|
225
|
+
over = np.abs(np.diff(scores.values)) - self.step
|
|
226
|
+
breaks = over > tolerance
|
|
227
|
+
if not breaks.any():
|
|
228
|
+
return None
|
|
229
|
+
excess = float(over.max())
|
|
230
|
+
description = (
|
|
231
|
+
f"{int(breaks.sum())} steps of the graph of {self.feature} in {scores.describe()} are larger than"
|
|
232
|
+
f" {_number(self.step)}, by up to {_number(excess)}"
|
|
233
|
+
)
|
|
234
|
+
return Violation(self, description, scores.pair_labels(breaks), excess, self.repair())
|
|
235
|
+
|
|
236
|
+
@override
|
|
237
|
+
def repair(self) -> Edit:
|
|
238
|
+
return LimitSteps(self.feature, self.step, self.selection)
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
@attrs.frozen
|
|
242
|
+
class Bounded(Constraint):
|
|
243
|
+
"""Each selected score must be between ``low`` and ``high``, both included.
|
|
244
|
+
|
|
245
|
+
The default selection is every bin, the missing bin and the unseen bin included, because a missing value is scored
|
|
246
|
+
too. The repair is ``Clip`` on the same bins. A score of the graph is not a prediction: the intercept and the other
|
|
247
|
+
terms add to it.
|
|
248
|
+
"""
|
|
249
|
+
|
|
250
|
+
feature: str
|
|
251
|
+
low: float
|
|
252
|
+
high: float
|
|
253
|
+
selection: Selection = attrs.field(factory=EveryBin)
|
|
254
|
+
|
|
255
|
+
@override
|
|
256
|
+
def violation(self, ebm: ExplainableBoostingModel, tolerance: float) -> Violation | None:
|
|
257
|
+
if not self.low <= self.high:
|
|
258
|
+
msg = f"Bounded needs numbers with low not above high, but low is {self.low} and high is {self.high}."
|
|
259
|
+
raise EditError(msg)
|
|
260
|
+
scores = _scores(ebm, self.feature, self.selection)
|
|
261
|
+
values = scores.values
|
|
262
|
+
outside = np.maximum(self.low - values, values - self.high)
|
|
263
|
+
breaks = outside > tolerance
|
|
264
|
+
if not breaks.any():
|
|
265
|
+
return None
|
|
266
|
+
excess = float(outside.max())
|
|
267
|
+
description = (
|
|
268
|
+
f"{int(breaks.sum())} scores of {self.feature} are outside the range {_number(self.low)} to"
|
|
269
|
+
f" {_number(self.high)}, by up to {_number(excess)}"
|
|
270
|
+
)
|
|
271
|
+
return Violation(self, description, scores.labels(breaks), excess, self.repair())
|
|
272
|
+
|
|
273
|
+
@override
|
|
274
|
+
def repair(self) -> Edit:
|
|
275
|
+
return Clip(self.feature, self.selection, self.low, self.high)
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
@attrs.frozen
|
|
279
|
+
class FixedScore(Constraint):
|
|
280
|
+
"""Each selected score must equal ``value``, for example "a missing value scores 0". The repair is ``SetScores``."""
|
|
281
|
+
|
|
282
|
+
feature: str
|
|
283
|
+
selection: Selection
|
|
284
|
+
value: float
|
|
285
|
+
|
|
286
|
+
@override
|
|
287
|
+
def violation(self, ebm: ExplainableBoostingModel, tolerance: float) -> Violation | None:
|
|
288
|
+
scores = _scores(ebm, self.feature, self.selection)
|
|
289
|
+
difference = np.abs(scores.values - self.value)
|
|
290
|
+
breaks = difference > tolerance
|
|
291
|
+
if not breaks.any():
|
|
292
|
+
return None
|
|
293
|
+
excess = float(difference.max())
|
|
294
|
+
count = int(breaks.sum())
|
|
295
|
+
description = f"{count} scores of {self.feature} differ from {_number(self.value)}, by up to {_number(excess)}"
|
|
296
|
+
return Violation(self, description, scores.labels(breaks), excess, self.repair())
|
|
297
|
+
|
|
298
|
+
@override
|
|
299
|
+
def repair(self) -> Edit:
|
|
300
|
+
return SetScores(self.feature, self.selection, self.value)
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
@attrs.frozen
|
|
304
|
+
class Unused(Constraint):
|
|
305
|
+
"""No term of the model may use the feature with a score other than 0, the pair terms included.
|
|
306
|
+
|
|
307
|
+
A term whose scores are all 0 meets the constraint, so ``ZeroTerm`` meets it for a feature with no pair term. The
|
|
308
|
+
repair is ``RemoveFeature``, which removes every term that uses the feature. The model keeps its input columns.
|
|
309
|
+
"""
|
|
310
|
+
|
|
311
|
+
feature: str
|
|
312
|
+
|
|
313
|
+
def _terms(self, ebm: ExplainableBoostingModel) -> Sequence[int]:
|
|
314
|
+
names = list(ebm.feature_names_in_)
|
|
315
|
+
if self.feature not in names:
|
|
316
|
+
msg = f"The model has no feature {self.feature!r}. The features are {names}."
|
|
317
|
+
raise SelectionError(msg)
|
|
318
|
+
feature_index = names.index(self.feature)
|
|
319
|
+
return [term for term, features in enumerate(ebm.term_features_) if feature_index in features]
|
|
320
|
+
|
|
321
|
+
@override
|
|
322
|
+
def violation(self, ebm: ExplainableBoostingModel, tolerance: float) -> Violation | None:
|
|
323
|
+
largest = {
|
|
324
|
+
ebm.term_names_[term]: float(np.abs(np.asarray(ebm.term_scores_[term], dtype=float)).max())
|
|
325
|
+
for term in self._terms(ebm)
|
|
326
|
+
}
|
|
327
|
+
breaking = {name: score for name, score in largest.items() if score > tolerance}
|
|
328
|
+
if not breaking:
|
|
329
|
+
return None
|
|
330
|
+
terms = tuple(breaking)
|
|
331
|
+
excess = max(breaking.values())
|
|
332
|
+
description = (
|
|
333
|
+
f"{len(terms)} terms of the model use {self.feature} with a score other than 0, by up to {_number(excess)}"
|
|
334
|
+
)
|
|
335
|
+
return Violation(self, description, (), excess, self.repair(), terms)
|
|
336
|
+
|
|
337
|
+
@override
|
|
338
|
+
def repair(self) -> Edit:
|
|
339
|
+
return RemoveFeature(self.feature)
|
|
340
|
+
|
|
341
|
+
|
|
342
|
+
def check_constraints(
|
|
343
|
+
ebm: ExplainableBoostingModel,
|
|
344
|
+
constraints: Iterable[Constraint],
|
|
345
|
+
*,
|
|
346
|
+
tolerance: float = DEFAULT_TOLERANCE,
|
|
347
|
+
) -> list[Violation]:
|
|
348
|
+
"""Find the constraints that a model breaks.
|
|
349
|
+
|
|
350
|
+
The check reads the model and changes nothing. Apply the ``repair`` of a violation in an ``EditSession`` to make the
|
|
351
|
+
constraint hold, and check again: a repair of one constraint can break another one.
|
|
352
|
+
|
|
353
|
+
Parameters
|
|
354
|
+
----------
|
|
355
|
+
ebm : ExplainableBoostingModel
|
|
356
|
+
The model to check, for example ``session.model``.
|
|
357
|
+
constraints : Iterable[Constraint]
|
|
358
|
+
The business requirements.
|
|
359
|
+
tolerance : float
|
|
360
|
+
The largest difference that does not count as a violation. It is 0 or more.
|
|
361
|
+
|
|
362
|
+
Returns
|
|
363
|
+
-------
|
|
364
|
+
list[Violation]
|
|
365
|
+
One violation for each constraint that the model breaks, in the order of the constraints.
|
|
366
|
+
|
|
367
|
+
Raises
|
|
368
|
+
------
|
|
369
|
+
OptionRangeError
|
|
370
|
+
If the tolerance is negative or not finite.
|
|
371
|
+
|
|
372
|
+
Examples
|
|
373
|
+
--------
|
|
374
|
+
>>> import numpy as np
|
|
375
|
+
>>> from interpret.glassbox import ExplainableBoostingClassifier
|
|
376
|
+
>>> from ebaml import Bounded, check_constraints
|
|
377
|
+
>>> random_generator = np.random.default_rng(0)
|
|
378
|
+
>>> ages = random_generator.integers(1, 9, size=(300, 1)) * 10.0
|
|
379
|
+
>>> target = (ages[:, 0] + random_generator.normal(0, 20, 300) > 40).astype(int)
|
|
380
|
+
>>> ebm = ExplainableBoostingClassifier(interactions=0, outer_bags=2, feature_names=["age"]).fit(ages, target)
|
|
381
|
+
>>> check_constraints(ebm, [Bounded("age", -100.0, 100.0)])
|
|
382
|
+
[]
|
|
383
|
+
>>> (violation,) = check_constraints(ebm, [Bounded("age", 0.0, 0.0)])
|
|
384
|
+
>>> violation.repair
|
|
385
|
+
Clip(feature='age', selection=EveryBin(), low=0.0, high=0.0)
|
|
386
|
+
|
|
387
|
+
"""
|
|
388
|
+
if not 0 <= tolerance < np.inf:
|
|
389
|
+
msg = f"The tolerance must be 0 or more and finite, but it is {tolerance}."
|
|
390
|
+
raise OptionRangeError(msg)
|
|
391
|
+
model_write.check_editable(ebm)
|
|
392
|
+
return [violation for constraint in constraints if (violation := constraint.violation(ebm, tolerance)) is not None]
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
"""Write an edit and
|
|
1
|
+
"""Write an edit, a constraint and a selection as a record of JSON values, and read it back.
|
|
2
2
|
|
|
3
|
-
The history of a session stores each edit as a record, so that a replay builds the same edit. A
|
|
4
|
-
of the class under ``type`` and the fields of the class. A selection inside an
|
|
3
|
+
The history of a session stores each edit as a record, so that a replay builds the same edit. A tool reads a constraint
|
|
4
|
+
from a record. A record holds the name of the class under ``type`` and the fields of the class. A selection inside an
|
|
5
|
+
edit or a constraint is a record too.
|
|
5
6
|
"""
|
|
6
7
|
|
|
7
8
|
from collections.abc import Mapping
|
|
@@ -12,7 +13,8 @@ from beartype.roar import BeartypeCallHintViolation
|
|
|
12
13
|
|
|
13
14
|
from ebaml.core.custom_types import JSONMapping, JSONObject, JSONValue
|
|
14
15
|
from ebaml.core.exceptions import HistoryError
|
|
15
|
-
from ebaml.edit import edits, selections
|
|
16
|
+
from ebaml.edit import constraints, edits, selections
|
|
17
|
+
from ebaml.edit.constraints import Constraint
|
|
16
18
|
from ebaml.edit.edits import Edit
|
|
17
19
|
from ebaml.edit.selections import Selection
|
|
18
20
|
|
|
@@ -21,10 +23,13 @@ EDIT_TYPES: dict[str, type[Edit]] = {
|
|
|
21
23
|
for edit_class in (
|
|
22
24
|
edits.Shift,
|
|
23
25
|
edits.SetScores,
|
|
26
|
+
edits.AssignScores,
|
|
24
27
|
edits.Align,
|
|
25
28
|
edits.Monotonize,
|
|
26
29
|
edits.Interpolate,
|
|
27
30
|
edits.FitLine,
|
|
31
|
+
edits.Clip,
|
|
32
|
+
edits.LimitSteps,
|
|
28
33
|
edits.Scale,
|
|
29
34
|
edits.ZeroTerm,
|
|
30
35
|
edits.Recenter,
|
|
@@ -32,7 +37,17 @@ EDIT_TYPES: dict[str, type[Edit]] = {
|
|
|
32
37
|
edits.RemoveFeature,
|
|
33
38
|
)
|
|
34
39
|
}
|
|
35
|
-
|
|
40
|
+
CONSTRAINT_TYPES: dict[str, type[Constraint]] = {
|
|
41
|
+
constraint_class.__name__: constraint_class
|
|
42
|
+
for constraint_class in (
|
|
43
|
+
constraints.Monotone,
|
|
44
|
+
constraints.MaxStep,
|
|
45
|
+
constraints.Bounded,
|
|
46
|
+
constraints.FixedScore,
|
|
47
|
+
constraints.Unused,
|
|
48
|
+
)
|
|
49
|
+
}
|
|
50
|
+
# the name of the field of an edit or a constraint that holds a selection
|
|
36
51
|
SELECTION_FIELD = "selection"
|
|
37
52
|
SELECTION_TYPES: dict[str, type[Selection]] = {
|
|
38
53
|
selection_class.__name__: selection_class
|
|
@@ -42,20 +57,20 @@ SELECTION_TYPES: dict[str, type[Selection]] = {
|
|
|
42
57
|
selections.MissingBin,
|
|
43
58
|
selections.UnseenBin,
|
|
44
59
|
selections.WholeGraph,
|
|
60
|
+
selections.EveryBin,
|
|
45
61
|
selections.ValueInterval,
|
|
46
62
|
)
|
|
47
63
|
}
|
|
48
64
|
|
|
49
65
|
|
|
50
66
|
# nosemgrep: ebaml-return-attrs-not-container -- the record is a JSON fragment that the history merges and writes
|
|
51
|
-
def to_record(item: Edit | Selection) -> JSONObject:
|
|
52
|
-
"""Write an edit or a selection as a record.
|
|
67
|
+
def to_record(item: Edit | Constraint | Selection) -> JSONObject:
|
|
68
|
+
"""Write an edit, a constraint or a selection as a record.
|
|
53
69
|
|
|
54
70
|
Parameters
|
|
55
71
|
----------
|
|
56
|
-
item : Edit | Selection
|
|
57
|
-
An attrs class of ``ebaml.edit``. The field ``selection``
|
|
58
|
-
record.
|
|
72
|
+
item : Edit | Constraint | Selection
|
|
73
|
+
An attrs class of ``ebaml.edit``. The field ``selection`` holds a selection, and it becomes a nested record.
|
|
59
74
|
|
|
60
75
|
Returns
|
|
61
76
|
-------
|
|
@@ -108,7 +123,7 @@ def _decode(
|
|
|
108
123
|
raise HistoryError(msg)
|
|
109
124
|
if name not in registry:
|
|
110
125
|
msg = (
|
|
111
|
-
f"The
|
|
126
|
+
f"The record names the {kind} {name!r}, which this version does not know."
|
|
112
127
|
f" The known ones are {sorted(registry)}."
|
|
113
128
|
)
|
|
114
129
|
raise HistoryError(msg)
|
|
@@ -134,3 +149,21 @@ def edit_from_record(record: JSONValue) -> Edit:
|
|
|
134
149
|
|
|
135
150
|
"""
|
|
136
151
|
return cast(Edit, _decode(record, EDIT_TYPES, "edit")) # the registry holds the classes of edits only
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def constraint_from_record(record: JSONValue) -> Constraint:
|
|
155
|
+
"""Build a constraint from its record.
|
|
156
|
+
|
|
157
|
+
Parameters
|
|
158
|
+
----------
|
|
159
|
+
record : JSONValue
|
|
160
|
+
A record that ``to_record`` wrote, or a record of the same form.
|
|
161
|
+
|
|
162
|
+
Returns
|
|
163
|
+
-------
|
|
164
|
+
Constraint
|
|
165
|
+
The constraint. A record that names an unknown class, or has fields that do not fit it, raises a
|
|
166
|
+
``HistoryError``.
|
|
167
|
+
|
|
168
|
+
"""
|
|
169
|
+
return cast(Constraint, _decode(record, CONSTRAINT_TYPES, "constraint")) # the registry holds constraints only
|