openscm_calibration.cost.scmdata#
Cost calculations for models that return [scmdata.run.BaseScmRun][scmdata.run.BaseScmRun] objects
Classes:
| Name | Description |
|---|---|
AlignmentError |
Raised when our data's metadata does not align as expected |
OptCostCalculatorSSE |
Cost calculator based on sum of squared errors |
AlignmentError #
Bases: ValueError
Raised when our data's metadata does not align as expected
Methods:
| Name | Description |
|---|---|
__init__ |
Initialise the error |
Source code in src/openscm_calibration/cost/scmdata.py
__init__ #
__init__(
name_left: str,
val_left: DataFrame | Series[Any],
name_right: str,
val_right: DataFrame | Series[Any],
extra_context: str | None = None,
) -> None
Initialise the error
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name_left
|
str
|
The name of the first thing being referenced (variable, attribute etc.) |
required |
val_left
|
DataFrame | Series[Any]
|
The values referred to by |
required |
name_right
|
str
|
The name of the other thing being referenced (variable, attribute etc.) |
required |
name_right
|
str
|
The values referred to by |
required |
extra_context
|
str | None
|
Any extra context to include in the message |
None
|
Source code in src/openscm_calibration/cost/scmdata.py
OptCostCalculatorSSE #
Cost calculator based on sum of squared errors
This is a convenience class. We may want to refactor it in future to provide greater flexibility for other cost calculations.
Methods:
| Name | Description |
|---|---|
calculate_cost |
Calculate cost function based on model results |
calculate_negative_log_likelihood |
Calculate the negative log likelihood of a given set of results |
from_series_normalisation |
Initialise from a series that defines normalisation for each timeseries. |
from_unit_normalisation |
Initialise assuming unit normalisation for each timeseries. |
Attributes:
| Name | Type | Description |
|---|---|---|
model_col |
str
|
Column which contains the name of the model. |
normalisation |
BaseScmRun
|
Normalisation values |
target |
BaseScmRun
|
Target timeseries |
Source code in src/openscm_calibration/cost/scmdata.py
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 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 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 | |
model_col
class-attribute
instance-attribute
#
Column which contains the name of the model.
This is used when subtracting the model results from the target
normalisation
class-attribute
instance-attribute
#
normalisation: BaseScmRun = field(
validator=[_works_with_self_target]
)
Normalisation values
Should have same timeseries as target. See the class methods for helpers.
calculate_cost #
calculate_cost(model_results: BaseScmRun) -> float
Calculate cost function based on model results
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_results
|
BaseScmRun
|
Model results of which to calculate the cost |
required |
Returns:
| Type | Description |
|---|---|
Cost
|
|
Source code in src/openscm_calibration/cost/scmdata.py
calculate_negative_log_likelihood #
calculate_negative_log_likelihood(
model_results: BaseScmRun,
) -> float
Calculate the negative log likelihood of a given set of results
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_results
|
BaseScmRun
|
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/cost/scmdata.py
from_series_normalisation
classmethod
#
from_series_normalisation(
target: BaseScmRun,
model_col: str,
normalisation_series: Series[float],
) -> OptCostCalculatorSSE
Initialise from a series that defines normalisation for each timeseries.
The series is broadcast to match the timeseries in target, using the same value for all timepoints in each timeseries.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
BaseScmRun
|
Target timeseries |
required |
model_col
|
str
|
Column which contains of the model in |
required |
normalisation_series
|
Series[float]
|
Series to broadcast to create the desired normalisation |
required |
Returns:
| Type | Description |
|---|---|
Initialised :obj:`OptCostCalculatorSSE`
|
|
Source code in src/openscm_calibration/cost/scmdata.py
from_unit_normalisation
classmethod
#
from_unit_normalisation(
target: BaseScmRun, model_col: str
) -> OptCostCalculatorSSE
Initialise assuming unit normalisation for each timeseries.
This is a convenience method, but is not recommended for any serious work as unit normalisation is unlikely to be a good choice for most problems.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
BaseScmRun
|
Target timeseries |
required |
model_col
|
str
|
Column which contains of the model in |
required |
Returns:
| Type | Description |
|---|---|
:obj:`OptCostCalculatorSSE` such that the normalisation is 1 for
|
all timepoints (with the units defined by whatever the units of
each timeseries are in |