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)
¶
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
|
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: |
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)
¶
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
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The candidate config (a copy) achieving the best predicted |
dict[str, Any]
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |