Regime Surrogate¶
Regime-conditional surrogate that interpolates factor recommendations
across regime descriptors (e.g. dataset size, noise level) instead of
relying on hard regime buckets. Builds on
fit_surrogate.
Install via the optional extra (same as the base surrogate):
trade_study.fit_regime_surrogate(results, regime_factors, factors, *, method='gp', seed=0, n_estimators=200, cv_folds=5, warn_below_r2=0.0)
¶
Fit a surrogate that conditions on regime features.
Internally fits a single :class:SurrogateModel over the joint
regime_factors + factors space, so observables can be
interpolated across continuous regime axes.
Every config in results.configs must contain values for both the
regime features and the design factors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
results
|
ResultsTable
|
A :class: |
required |
regime_factors
|
list[Factor]
|
Factors describing the regime (additional input dimensions of the surrogate; typically continuous). |
required |
factors
|
list[Factor]
|
Tunable design factors. Together with
|
required |
method
|
str
|
Surrogate backend, |
'gp'
|
seed
|
int
|
Random seed forwarded to the backend estimators. |
0
|
n_estimators
|
int
|
Number of trees for the |
200
|
cv_folds
|
int
|
Cross-validation folds for the held-out accuracy check
(#114). See :func: |
5
|
warn_below_r2
|
float | None
|
Warn if any observable's cross-validated R^2 falls
below this threshold. See :func: |
0.0
|
Returns:
| Type | Description |
|---|---|
RegimeSurrogate
|
A fitted :class: |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src/trade_study/regime.py
trade_study.RegimeSurrogate(inner, regime_factors, factors)
dataclass
¶
Surrogate that conditions on regime features.
Wraps a single :class:SurrogateModel fit over the union of regime
descriptors and design factors. Use :func:fit_regime_surrogate to
construct one.
Attributes:
| Name | Type | Description |
|---|---|---|
inner |
SurrogateModel
|
The underlying :class: |
regime_factors |
list[Factor]
|
Factors describing the regime (additional input dimensions of the surrogate). |
factors |
list[Factor]
|
Tunable design factors that are optimized at a given
regime by :meth: |
cv_r2
property
¶
Per-observable held-out cross-validated R^2 (#114).
Returns:
| Name | Type | Description |
|---|---|---|
dict[str, float]
|
Mapping from observable name to cross-validated R^2, from the |
|
underlying |
dict[str, float]
|
attr: |
cv_rmse
property
¶
Per-observable held-out cross-validated RMSE (#114).
Returns:
| Type | Description |
|---|---|
dict[str, float]
|
Mapping from observable name to cross-validated RMSE, from |
dict[str, float]
|
the underlying :attr: |
predict(regime, config)
¶
Predict observables at a regime + config pair.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
regime
|
dict[str, Any]
|
Mapping of regime-feature names to values. |
required |
config
|
dict[str, Any]
|
Mapping of design-factor names to values. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, float]
|
Mapping from observable name to predicted scalar. |
Source code in src/trade_study/regime.py
predict_batch(regime, configs)
¶
Predict observables for a batch of configs at one regime.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
regime
|
dict[str, Any]
|
Mapping of regime-feature names to values. |
required |
configs
|
Sequence[dict[str, Any]]
|
Sequence of design-factor configs to score at
|
required |
Returns:
| Type | Description |
|---|---|
dict[str, NDArray[float64]]
|
Mapping from observable name to a length- |
dict[str, NDArray[float64]]
|
array of predictions. |
Source code in src/trade_study/regime.py
uncertainty(regime, config)
¶
Predictive standard deviation per observable (GP only).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
regime
|
dict[str, Any]
|
Mapping of regime-feature names to values. |
required |
config
|
dict[str, Any]
|
Mapping of design-factor names to values. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict[str, float]
|
Mapping from observable name to predictive standard deviation. |
|
Propagates |
dict[str, float]
|
class: |
dict[str, float]
|
surrogate when the backend does not expose calibrated |
|
dict[str, float]
|
uncertainties (non-GP backends). |
Source code in src/trade_study/regime.py
recommend(regime, *, objective, mode='min', n_candidates=512, seed=0, candidates=None, warn_below_r2=0.0)
¶
Recommend a design-factor config at a query regime.
Samples n_candidates configs from the design-factor space via
a scrambled Sobol' sequence and returns the one whose surrogate
prediction for objective is best under mode.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
regime
|
dict[str, Any]
|
Mapping of regime-feature names to values. |
required |
objective
|
str
|
Name of the observable to optimize. Must be one
of |
required |
mode
|
str
|
|
'min'
|
n_candidates
|
int
|
Number of design-space samples to evaluate.
Ignored when |
512
|
seed
|
int
|
Seed for the Sobol' sampler. |
0
|
candidates
|
Sequence[dict[str, Any]] | None
|
Optional explicit list of design-factor configs
to score; if given, overrides |
None
|
warn_below_r2
|
float | None
|
Warn if |
0.0
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The candidate config (a copy) achieving the best predicted |
dict[str, Any]
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src/trade_study/regime.py
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 | |