SAS Specification Classes
- class mesas.sas.specs.SAS_Spec(spec, data_df)[source]
Bases:
objectBlended SAS (StorAge Selection) function specification.
Represents a time-varying SAS function composed of one or more weighted
Componentobjects. Each component defines a piecewise-linear or continuous CDF over cumulative storage (ST). Components are blended at each timestep using their weight time series to produce a single CDF and inverse CDF.- Parameters:
- components
Ordered mapping of component labels to
Componentinstances.
- ST
Padded (N, max_breakpoints) matrix of ST breakpoints, or
Nonebeforemake_spec_tsis called.- Type:
np.ndarray | None
- P
Corresponding padded probability matrix.
- Type:
np.ndarray | None
- make_spec_ts(data_df=None)[source]
Build per-timestep CDF and inverse-CDF interpolators.
Blends all component SAS functions at each timestep using their respective weights and constructs piecewise-linear interpolation objects for the forward and inverse CDF.
- Parameters:
data_df (pd.DataFrame or None, optional) – Override data frame. If
None, uses the data frame passed at construction.- Return type:
None
- get_parameter_list()[source]
Return concatenated parameter arrays from all learnable components.
- Returns:
1-D array of all SAS function parameters, ordered by component.
- Return type:
np.ndarray
- update_from_parameter_list(parameter_list)[source]
Update component parameters and rebuild interpolators.
Distributes entries of parameter_list across each learnable component’s SAS function, then calls
make_spec_tsto refresh the per-timestep CDF interpolators.- Parameters:
parameter_list (np.ndarray) – 1-D array with the same length as
get_parameter_list().- Return type:
None
- subdivided_copy(label, segment, **kwargs)[source]
Return a copy with one component’s piecewise segment split in two.
- Parameters:
- Returns:
A new spec with the subdivided component; interpolators rebuilt.
- Return type:
- plot(ax=None, **kwargs)[source]
Plot the SAS function for each component.
- Parameters:
ax (matplotlib.axes.Axes or None, optional) – Axes to draw on. A new figure is created if
None.**kwargs – Additional keyword arguments forwarded to each component’s
plotmethod.
- Returns:
Mapping of component labels to the line objects returned by each component’s
plotcall.- Return type:
- get_jacobian(*args, index=None, **kwargs)[source]
Compute the Jacobian of the blended SAS function w.r.t. parameters.
Calls
get_jacobianon each learnable component’s SAS function, weights the result, and concatenates column-wise.- Parameters:
*args (Any) – Positional arguments forwarded to each component’s
get_jacobian.index (np.ndarray or None, optional) – Timestep indices at which to evaluate. Defaults to all timesteps.
**kwargs – Additional keyword arguments forwarded to each component’s
get_jacobian.
- Returns:
Jacobian matrix with shape
(len(index), total_params).- Return type:
np.ndarray
- class mesas.sas.specs.Component(label, spec, data_df, is_only_component)[source]
Bases:
objectA single SAS function component with an associated weight time series.
A
Componentpairs a per-timestep SAS function (eitherPiecewiseorContinuous) with a weight series so that multiple components can be blended bySAS_Spec.- Parameters:
label (str) – Identifier for this component, used as a key in
SAS_Specand as a column name in data_df for the weight series (when there are multiple components).spec (dict) – Specification dictionary. Must contain either
"ST"(and optionally"P") keys for piecewise-linear SAS functions, or"args"with"func"/"scipy.stats"keys for continuous distributions. Values may be scalars, lists, or column-name strings referencing data_df.data_df (pd.DataFrame) – Input time-series data frame.
is_only_component (bool) – If
True, weights default to 1.0 for every timestep instead of being read from data_df.
- weights
Per-timestep blending weights.
- Type:
pd.Series
- expand(value)[source]
Expand a specification value into a per-timestep array.
Scalars are broadcast to all timesteps, strings are looked up as columns in the data frame, and iterables are recursively expanded and stacked.
- Parameters:
value (float, str, or Iterable) – A scalar constant, a column name in the data frame, or a sequence of such values (one per breakpoint).
- Returns:
Array of shape
(N,)for scalar/string inputs or(N, len(value))for iterable inputs, where N is the number of timesteps.- Return type:
np.ndarray
- property sas_fun: list[Continuous | Piecewise]
List of per-timestep SAS function objects.