results
results
Result structures.
Classes
Name | Description |
---|---|
Result | Array-like container for holding sim results. |
Results | Container for storing results |
Result
results.Result(self,
=None,
name=None,
label=float,
dtype=None,
shape=True,
scale=True,
auto_plot=None,
module=None,
values=None,
timevec=None,
low=None,
high=None,
summarize_by**kwargs,
)
Array-like container for holding sim results.
Parameters
Name | Type | Description | Default |
---|---|---|---|
module | str | the name or label of the parent module, e.g. ‘SIR’ | None |
name | str | the name of this result, e.g. ‘new_infections’ | None |
shape | int / tuple | the shape of the result array (usually module.npts ) |
None |
scale | bool | whether or not the result scales by population size (e.g. a count does, a prevalence does not) | True |
auto_plot | bool | whether to include automatically in sim.plot() results |
True |
label | str | a human-readable label for the result | None |
values | array | prepopulate the Result with these values | None |
timevec | array | an array of time points | None |
low | array | values for the lower bound | None |
high | array | values for the upper bound | None |
summarize_by | str | how to summarize the data, e.g. ‘sum’ or ‘mean’ | None |
In most cases, ss.Result
behaves exactly like np.array()
, except with the additional fields listed above. To see everything contained in a result, you can use result.disp().
Attributes
Name | Description |
---|---|
full_label | Return the full label of the result: |
has_dates | Check whether the time vector uses dates (rather than numbers) |
key | Return the unique key of the result: |
Methods
Name | Description |
---|---|
convert_timevec | Make sure we’re using a timevec that’s in the right format i.e. dates |
disp | Full display of all attributes/methods |
from_df | Make a copy of the result with new values from a dataframe |
init_values | Handle values |
plot | Plot a single result; kwargs are interpreted as plot_kw |
resample | Resample the result, e.g. from days to years. Leverages the pandas resample method. |
to_df | Convert to a dataframe with timevec, value, low, and high columns |
to_series | Convert to a series with timevec as the index and value as the data |
to_str | Convert Result object to a string |
update | Update parameters, and initialize values if needed |
convert_timevec
=False) results.Result.convert_timevec(force
Make sure we’re using a timevec that’s in the right format i.e. dates
disp
results.Result.disp()
Full display of all attributes/methods
from_df
results.Result.from_df(df)
Make a copy of the result with new values from a dataframe
init_values
=None, dtype=None, shape=None, force=False) results.Result.init_values(values
Handle values
plot
results.Result.plot(=None,
fig=None,
ax=None,
fig_kw=None,
plot_kw=None,
fill_kw**kwargs,
)
Plot a single result; kwargs are interpreted as plot_kw
resample
results.Result.resample(='year',
new_unit=None,
summarize_by='vlh',
col_names=False,
die='series',
output_form=False,
use_years='_',
sep )
Resample the result, e.g. from days to years. Leverages the pandas resample method. Accepts all the Starsim units, plus the Pandas ones documented here: https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#offset-aliases
Parameters
Name | Type | Description | Default |
---|---|---|---|
new_unit | str | the new unit to resample to, e.g. ‘year’, ‘month’, ‘week’, ‘day’, ‘1W’, ‘2M’, etc. | 'year' |
summarize_by | str | how to summarize the data, e.g. ‘sum’ or ‘mean’ | None |
col_names | str | whether to rename the columns with the name of the result | 'vlh' |
die | bool | whether to raise an error if the summarization method cannot be determined | False |
output_form | str | ‘series’, ‘dataframe’, or ‘result’ | 'series' |
use_years | bool | whether to use years as the unit of time | False |
to_df
results.Result.to_df(='_',
sep='vlh',
col_names=True,
bounds=None,
resample=False,
set_date_index**kwargs,
)
Convert to a dataframe with timevec, value, low, and high columns
Parameters
Name | Type | Description | Default |
---|---|---|---|
sep | str | separator for the column names | '_' |
col_names | str or None | if None, uses the name of the result. Default is ‘vlh’ which uses value, low, high | 'vlh' |
set_date_index | bool | if True, use the timevec as the index | False |
bounds | bool | include high and low bounds as well (if and only if they exist, e.g. from a MultiSim) | True |
resample | str | if provided, resample the data to this frequency | None |
kwargs | passed to the resample method if resample=True | {} |
to_series
=False, resample=None, sep='_', **kwargs) results.Result.to_series(set_name
Convert to a series with timevec as the index and value as the data Args: set_name (bool): whether to set the name of the series to the name of the result resample (str): if provided, resample the data to this frequency kwargs: passed to the resample method
to_str
=True) results.Result.to_str(label
Convert Result object to a string
update
*args, **kwargs) results.Result.update(
Update parameters, and initialize values if needed
Results
self, module, *args, strict=True, **kwargs) results.Results(
Container for storing results
Attributes
Name | Description |
---|---|
all_results | Iterator over all results, skipping any nested values |
all_results_dict | Dictionary of all results, skipping any nested values |
equal_len | Check if all results are equal length |
is_msim | Check if this is a MultiSim |
Methods
Name | Description |
---|---|
append | This is activated by adding as well, e.g. results += result |
flatten | Turn from a nested dictionary into a flat dictionary, keeping only results by default |
plot | Plot all the results |
to_df | Merge all results dataframes into one |
append
=None) results.Results.append(arg, key
This is activated by adding as well, e.g. results += result
flatten
results.Results.flatten(='_',
sep=True,
only_results=False,
only_auto=False,
keep_case**kwargs,
)
Turn from a nested dictionary into a flat dictionary, keeping only results by default
plot
='fancy', fig_kw=None, plot_kw=None) results.Results.plot(style
Plot all the results
to_df
='_', descend=False, **kwargs) results.Results.to_df(sep
Merge all results dataframes into one Args: sep (str): separator for the column names descend (bool): whether to descend into nested results kwargs: passed to the Result.to_df()
method, can include instructions for summarizing results by time