feat(surrogate): GP/RF interpolation from results table (#82)#108
Merged
Conversation
Add a new `trade_study.surrogate` module that fits scikit-learn Gaussian-process or random-forest models to a ResultsTable and lets users predict any observable at unseen factor combinations. - `fit_surrogate(results, factors, *, method, seed, n_estimators)` returns a `SurrogateModel` carrying one estimator per observable. - Continuous factors are min-max scaled to [0,1]; categorical/discrete factors are one-hot encoded against `factor.levels`. - `SurrogateModel.predict` / `predict_batch` work for both backends; `uncertainty` returns the GP posterior std and raises NotImplementedError for RF. - NaN rows are dropped per-observable. Packaging: - New optional extra `surrogate = ["scikit-learn>=1.3"]`, also added to the `all` aggregate. Docs: - New `docs/api/surrogate.md` page wired into mkdocs nav. Tests: - 13 new tests covering fit/predict round-trip for GP and RF, batch shape, GP uncertainty, RF uncertainty raising, mixed-factor encoding, unknown level / missing factor errors, NaN row handling, and input validation. surrogate.py coverage: 100%. Closes #82. Unblocks #105 (regime-conditional surrogate).
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.
Closes #82.
Summary
Adds a new
trade_study.surrogatemodule that fits scikit-learn surrogates (Gaussian process or random forest) to aResultsTableand predicts any observable at unseen factor combinations.API
[0, 1].factor.levels.method="gp"usesConstantKernel * Matern(nu=1.5) + WhiteKernelwithnormalize_y=True;method="rf"usesRandomForestRegressor.Packaging
pip install "trade-study[surrogate]"(scikit-learn ≥ 1.3).allaggregate.Docs
docs/api/surrogate.mdpage, wired into the mkdocs nav between Stacking and Visualization, with an install hint for the optional extra.Tests
13 new tests covering both backends, GP uncertainty, mixed-factor encoding, NaN row handling, and input validation.
surrogate.pycoverage: 100%. Total: 296 passing, 99.5% project coverage.Follow-ups
SurrogateModeland a regime classifier on top of this infrastructure.