Skip to content

Add custom metric functions and ratio metric linearization#56

Open
artemkuzmenko2501-del wants to merge 3 commits intodevfrom
feature/ab-test-abstraction
Open

Add custom metric functions and ratio metric linearization#56
artemkuzmenko2501-del wants to merge 3 commits intodevfrom
feature/ab-test-abstraction

Conversation

@artemkuzmenko2501-del
Copy link
Collaborator

@artemkuzmenko2501-del artemkuzmenko2501-del commented Mar 13, 2026

Summary

  • Custom metric functions in Tester: новый параметр metric_funcs: Dict[str, Callable] позволяет передавать произвольные функции вместо имён колонок. Работает для методов theory и empiric. Функции, переданные в run(), переопределяют те, что заданы в конструкторе.
  • LinearizationTransformer: трансформер для ratio-метрик (например, revenue/orders). Линеаризует метрику по формуле linearized_i = numerator_i - ratio * denominator_i, где ratio считается на референсных данных при fit().
  • Preprocessor.linearize(): интегрирует линеаризацию в существующую chain-архитектуру с поддержкой сериализации и replay.

Changes

  • ambrosia/tester/tester.pymetric_funcs в __init__ и run(), standalone test()
  • ambrosia/tester/handlers.pyTheoreticalTesterHandler поддерживает callable извлечение значений
  • ambrosia/preprocessing/transformers.py — новый LinearizationTransformer
  • ambrosia/preprocessing/preprocessor.py — метод linearize() + импорт трансформера
  • ambrosia/preprocessing/__init__.py — экспорт LinearizationTransformer
  • CLAUDE.md — документация архитектуры для будущих сессий

Test plan

  • 8 новых тестов: metric_funcs (конструктор, run, override) + linearize (формула, chain, сериализация, имя по умолчанию)
  • 1074 существующих теста прошли без изменений

artemkuzmenko2501-del and others added 3 commits March 13, 2026 18:20
- Tester now accepts metric_funcs dict mapping metric names to callables,
  enabling ratio and composite metrics without pre-computing columns
- LinearizationTransformer added for ratio metrics (e.g. revenue/orders):
  linearized_i = numerator_i - ratio * denominator_i, where ratio is
  estimated on reference data passed to fit()
- Preprocessor.linearize() integrates linearization into the existing
  chain pattern with full serialization/replay support
- 8 new tests covering metric_funcs constructor/run/override behaviour
  and linearize formula, chaining, serialization

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
- Remove Python 3.7 from CI matrix (GitHub Actions dropped it, EOL)
- Replace Python 3.10 with 3.11/3.12 (nmslib has unfixable C++ build
  failures on modern gcc; 3.11+ already passes in scheduled runs)
- Make nmslib an optional dependency so missing it doesn't break install
- Lazy-import nmslib in knn.py with a clear ImportError message

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
- Extend python constraint to >=3.8, <3.13 to support 3.11/3.12 in CI
- Restrict nmslib optional dep to python <3.11 (build fails on newer gcc)
- Regenerate poetry.lock to fix 'Extra [knn] is not specified' error

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant