openscm_calibration.calibration_demo#
Classes and functions used in our calibration demo notebook
See docs/how-to-guides/how-to-run-a-calibration.py.
These are in their own module to help the parallelisation (local functions and classes don't pickle well), but also just for clarity in the documentation.
Classes:
| Name | Description |
|---|---|
CostCalculator |
Calculate the cost function for a given set of model results |
ExperimentResult |
Results of an experiment |
ExperimentResultCollection |
Collection of results from one or more experiments |
Timeseries |
Timeseries container |
Functions:
| Name | Description |
|---|---|
add_iteration_info |
Add iteration info to a result |
convert_results_to_plot_dict |
Convert results into a dictionary, grouped for plotting |
get_timeseries |
Get timeseries from results |
plot_timeseries |
Plot timeseries |
CostCalculator #
Calculate the cost function for a given set of model results
Methods:
| Name | Description |
|---|---|
calculate_cost |
Calculate cost function |
calculate_negative_log_likelihood |
Calculate the negative log likelihood of a given set of results |
Attributes:
| Name | Type | Description |
|---|---|---|
normalisation |
Quantity
|
The normalisation to apply to the difference between model results and the target |
target |
ExperimentResultCollection
|
The target to which we are calibrating |
Source code in src/openscm_calibration/calibration_demo.py
normalisation
instance-attribute
#
The normalisation to apply to the difference between model results and the target
target
instance-attribute
#
target: ExperimentResultCollection
The target to which we are calibrating
calculate_cost #
calculate_cost(
model_results: ExperimentResultCollection,
) -> float
Calculate cost function
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_results
|
ExperimentResultCollection
|
Model results for which to calculate the cost |
required |
Returns:
| Type | Description |
|---|---|
float
|
Cost function value |
Source code in src/openscm_calibration/calibration_demo.py
calculate_negative_log_likelihood #
calculate_negative_log_likelihood(
model_results: ExperimentResultCollection,
) -> float
Calculate the negative log likelihood of a given set of results
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_results
|
ExperimentResultCollection
|
Model results for which to calculate the negative log likelihood |
required |
Returns:
| Type | Description |
|---|---|
float
|
Negative log likelihood (up to an additive constant) |
Source code in src/openscm_calibration/calibration_demo.py
ExperimentResult #
Results of an experiment
Attributes:
| Name | Type | Description |
|---|---|---|
experiment_id |
str
|
ID of the experiment |
result |
Timeseries
|
The position of the mass over time in the experiment |
Source code in src/openscm_calibration/calibration_demo.py
ExperimentResultCollection #
Collection of results from one or more experiments
Methods:
| Name | Description |
|---|---|
lineplot |
Make a line plot |
to_dict |
Convert to a dictionary |
to_timeseries |
Convert self to timeseries |
Attributes:
| Name | Type | Description |
|---|---|---|
iteration |
int | None
|
Optimisation iteration in which these results were generated |
results |
tuple[ExperimentResult, ...]
|
Results of the experiments |
Source code in src/openscm_calibration/calibration_demo.py
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 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 | |
iteration
class-attribute
instance-attribute
#
iteration: int | None = None
Optimisation iteration in which these results were generated
lineplot #
Make a line plot
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ax
|
Axes
|
Axes on which to plot |
required |
x_units
|
str
|
Units to use for the x-axis |
'yr'
|
y_units
|
str
|
Units to use for the y-axis |
'm'
|
Returns:
| Type | Description |
|---|---|
Axes
|
Axes on which the plot was made |
Source code in src/openscm_calibration/calibration_demo.py
to_dict #
to_dict() -> dict[str, Timeseries]
to_timeseries #
Convert self to timeseries
In OpenSCM Calibration, timeseries means that the time axis is the index
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value_unit
|
str | None
|
Unit to use for the values. If not supplied, no conversion is performed. |
None
|
time_unit
|
str
|
Unit to use for the time axis |
'yr'
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
'Timeseries' view of the data in |
Source code in src/openscm_calibration/calibration_demo.py
Timeseries #
add_iteration_info #
add_iteration_info(
res: ExperimentResultCollection, iteration: int
) -> ExperimentResultCollection
convert_results_to_plot_dict #
convert_results_to_plot_dict(
res: ExperimentResultCollection,
) -> dict[str, ExperimentResultCollection]
Convert results into a dictionary, grouped for plotting
Source code in src/openscm_calibration/calibration_demo.py
get_timeseries #
get_timeseries(
res: ExperimentResultCollection,
value_unit: str | None = None,
) -> DataFrame
plot_timeseries #
plot_timeseries(
best_run: ExperimentResultCollection,
others_to_plot: tuple[ExperimentResultCollection, ...],
target: ExperimentResultCollection,
convert_results_to_plot_dict: Callable[
[ExperimentResultCollection],
dict[str, ExperimentResultCollection],
],
timeseries_keys: Iterable[str],
axes: dict[str, Axes],
get_timeseries: Callable[
[ExperimentResultCollection], DataFrame
],
) -> None
Plot timeseries
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
best_run
|
ExperimentResultCollection
|
Best run from iterations |
required |
others_to_plot
|
tuple[ExperimentResultCollection, ...]
|
Other results to plot from iterations |
required |
target
|
ExperimentResultCollection
|
Target to which we are calibrating |
required |
convert_results_to_plot_dict
|
Callable[[ExperimentResultCollection], dict[str, ExperimentResultCollection]]
|
Callable which converts the data into a dictionary
in which the keys are a subset of the values in |
required |
timeseries_keys
|
Iterable[str]
|
Keys of the timeseries to plot |
required |
axes
|
dict[str, Axes]
|
Axes on which to plot |
required |
get_timeseries
|
Callable[[ExperimentResultCollection], DataFrame]
|
Function which converts the data into a
[ |
required |
Source code in src/openscm_calibration/calibration_demo.py
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 | |