elicito.losses#
Built-in loss functions
Classes:
| Name | Description |
|---|---|
MMD2 |
Maximum mean discrepancy loss |
Functions:
| Name | Description |
|---|---|
L2 |
Compute norm of a difference |
indiv_loss |
Compute the individual loss between expert data and model-simulated data. |
preprocess |
Preprocess elicited statistics |
total_loss |
Compute weighted average |
MMD2 #
Maximum mean discrepancy loss
Methods:
| Name | Description |
|---|---|
__call__ |
Compute the biased, squared maximum mean discrepancy of two samples |
__init__ |
Compute the biased, squared maximum mean discrepancy |
clip |
Upper and lower clipping of value |
diag |
Get diagonal elements of a matrix |
kernel |
Kernel used in MMD to compute discrepancy between samples. |
Source code in src/elicito/losses.py
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 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 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 | |
__call__ #
Compute the biased, squared maximum mean discrepancy of two samples
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
Preprocessed expert-elicited statistics. Preprocessing refers to broadcasting expert data to same shape as model-simulated data. |
required |
y
|
Tensor
|
Model-simulated statistics corresponding to expert-elicited statistics |
required |
Returns:
| Name | Type | Description |
|---|---|---|
MMD2_mean |
Tensor
|
Average biased, squared maximum mean discrepancy between expert- elicited and model simulated data. |
Source code in src/elicito/losses.py
__init__ #
Compute the biased, squared maximum mean discrepancy
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kernel
|
str
|
Kernel type used for computing the MMD. When using a gaussian kernel an additional 'sigma' argument has to be passed. |
'energy'
|
**kwargs
|
dict[Any, Any]
|
additional keyword arguments that might be required by the different individual kernels |
{}
|
Raises:
| Type | Description |
|---|---|
ValueError
|
|
Examples:
Source code in src/elicito/losses.py
clip #
clip(u: Tensor) -> Any
Upper and lower clipping of value u to improve numerical stability
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u
|
Tensor
|
result of prior computation. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
u_clipped |
Any
|
clipped u value with |
Source code in src/elicito/losses.py
diag #
diag(xx: Tensor) -> Any
Get diagonal elements of a matrix
Get diagonale elements of a matrix, whereby the first tensor dimension are batches and should not be considered to get diagonale elements.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
xx
|
Tensor
|
Similarity matrices with batch dimension in axis=0. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
diag |
Any
|
diagonale elements of matrices per batch. |
Source code in src/elicito/losses.py
kernel #
Kernel used in MMD to compute discrepancy between samples.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u
|
Tensor
|
squared distance between samples. |
required |
kernel
|
str
|
name of kernel used for computing discrepancy. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
d |
Any
|
discrepancy between samples. |
Source code in src/elicito/losses.py
L2 #
L2(
loss_component_expert: Tensor,
loss_component_training: Tensor,
axis: Optional[int] = None,
ord: Union[str, int] = "euclidean",
) -> Tensor
Compute norm of a difference
compute the norm of the difference between two tensors along the specified axis. Used for the correlation loss when priors are assumed to be independent
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
loss_component_expert
|
Tensor
|
Preprocessed expert-elicited data |
required |
loss_component_training
|
Tensor
|
Preprocessed model-simulated data |
required |
axis
|
Optional[int]
|
Axis along which to compute the norm of the difference. |
None
|
ord
|
Union[str, int]
|
Order of the norm. Supports 'euclidean' and other norms supported by tf.norm. Default is 'euclidean'. |
'euclidean'
|
Source code in src/elicito/losses.py
indiv_loss #
indiv_loss(
elicit_expert: dict[str, Tensor],
elicit_training: dict[str, Tensor],
targets: list[Target],
) -> list[float]
Compute the individual loss between expert data and model-simulated data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
elicit_expert
|
dict[str, Tensor]
|
Dictionary including all preprocessed elicited statistics |
required |
elicit_training
|
dict[str, Tensor]
|
Dictionary including all preprocessed model statistics |
required |
targets
|
list[Target]
|
Target quantities and specification of elicitation technique |
required |
Returns:
| Name | Type | Description |
|---|---|---|
indiv_losses |
list[float]
|
List of individual losses for each loss component |
Source code in src/elicito/losses.py
preprocess #
Preprocess elicited statistics
Preprocess elicited statistics such that they have the required format for computing the individual losses between expert- and simulated statistics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
elicited_statistics
|
dict[str, Tensor]
|
Dictionary including the elicited statistics. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
preprocessed_elicits |
dict[str, Tensor]
|
Dictionary including all preprocessed elicited statistics which will enter the loss function to compute the individual loss components. |
Raises:
| Type | Description |
|---|---|
AssertionError
|
|
Source code in src/elicito/losses.py
total_loss #
total_loss(
elicit_training: dict[str, Tensor],
elicit_expert: dict[str, Tensor],
targets: list[Target],
) -> tuple[
Tensor,
list[float],
dict[str, Tensor],
dict[str, Tensor],
]
Compute weighted average
Compute the weighted average across all individual losses between expert data and model simulations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
elicit_training
|
dict[str, Tensor]
|
Elicited statistics simulated by the model. |
required |
elicit_expert
|
dict[str, Tensor]
|
Elicited statistics as queried from the expert. |
required |
targets
|
list[Target]
|
Specification of target quantities and elicitation techniques. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
loss |
Tensor
|
Weighted average across individual losses quantifying the discrepancy between expert data and model simulations. |
individual_losses |
list[float]
|
List of individual losses for each loss component. |
elicit_expert_prep |
dict[str, Tensor]
|
Dictionary including all preprocessed expert elicited statistics. |
elicit_training_prep |
dict[str, Tensor]
|
Dictionary including all preprocessed model-simulated elicited statistics. |