pytorch_forecasting.metrics.distributions.MQF2DistributionLoss#

class pytorch_forecasting.metrics.distributions.MQF2DistributionLoss(prediction_length: int, quantiles: list[float] | None = None, hidden_size: int | None = 4, es_num_samples: int = 50, beta: float = 1.0, icnn_hidden_size: int = 20, icnn_num_layers: int = 2, estimate_logdet: bool = False)[source]#

Multivariate quantile loss based on the article Multivariate Quantile Function Forecaster.

Requires install of additional library: pip install pytorch-forecasting[mqf2]

Initialize MQF2 distribution loss.

Parameters:
  • prediction_length (int) – Maximum prediction length.

  • quantiles (list[float], optional) – Default quantiles to output. Defaults to [0.02, 0.1, 0.25, 0.5, 0.75, 0.9, 0.98].

  • hidden_size (int, optional) – Hidden size per prediction length. Defaults to 4.

  • es_num_samples (int, optional) – Number of samples to calculate energy score. If None, maximum likelihood is used. Defaults to 50.

  • beta (float, optional) – Controls scale sensitivity (1.0 = fully sensitive). Defaults to 1.0.

  • icnn_hidden_size (int, optional) – Hidden size of distribution estimating network. Defaults to 20.

  • icnn_num_layers (int, optional) – Number of hidden layers in distribution estimating network. Defaults to 2.

  • estimate_logdet (bool, optional) – Whether to estimate log determinant. Defaults to False.

__init__(prediction_length: int, quantiles: list[float] | None = None, hidden_size: int | None = 4, es_num_samples: int = 50, beta: float = 1.0, icnn_hidden_size: int = 20, icnn_num_layers: int = 2, estimate_logdet: bool = False) None[source]#

Initialize MQF2 distribution loss.

Parameters:
  • prediction_length (int) – Maximum prediction length.

  • quantiles (list[float], optional) – Default quantiles to output. Defaults to [0.02, 0.1, 0.25, 0.5, 0.75, 0.9, 0.98].

  • hidden_size (int, optional) – Hidden size per prediction length. Defaults to 4.

  • es_num_samples (int, optional) – Number of samples to calculate energy score. If None, maximum likelihood is used. Defaults to 50.

  • beta (float, optional) – Controls scale sensitivity (1.0 = fully sensitive). Defaults to 1.0.

  • icnn_hidden_size (int, optional) – Hidden size of distribution estimating network. Defaults to 20.

  • icnn_num_layers (int, optional) – Number of hidden layers in distribution estimating network. Defaults to 2.

  • estimate_logdet (bool, optional) – Whether to estimate log determinant. Defaults to False.

Methods

__abs__()

Construct compositional metric using the absolute operator.

__add__(metric)

Construct compositional metric using the addition operator.

__and__(other)

Construct compositional metric using the logical and operator.

__call__(*args, **kwargs)

Call self as a function.

__delattr__(name)

Implement delattr(self, name).

__dir__()

Default dir() implementation.

__eq__(other)

Construct compositional metric using the equal operator.

__floordiv__(other)

Construct compositional metric using the floor division operator.

__format__(format_spec, /)

Default object formatter.

__ge__(other)

Construct compositional metric using the greater than or equal operator.

__getattr__(name)

__getattribute__(name, /)

Return getattr(self, name).

__getitem__(idx)

Construct compositional metric using the get item operator.

__getnewargs__()

Needed method for construction of new metrics __new__ method.

__getstate__()

Get the current state, including all metric states, for the metric.

__gt__(other)

Construct compositional metric using the greater than operator.

__hash__()

Return an unique hash of the metric.

__init_subclass__

This method is called when a class is subclassed.

__inv__()

Construct compositional metric using the not operator.

__invert__()

Construct compositional metric using the not operator.

__le__(other)

Construct compositional metric using the less than or equal operator.

__lt__(other)

Construct compositional metric using the less than operator.

__matmul__(other)

Construct compositional metric using the matrix multiplication operator.

__mod__(other)

Construct compositional metric using the remainder operator.

__mul__(multiplier)

Construct compositional metric using the multiplication operator.

__ne__(other)

Construct compositional metric using the not equal operator.

__neg__()

Construct compositional metric using absolute negative operator.

__new__(*args, **kwargs)

__or__(other)

Construct compositional metric using the logical or operator.

__pos__()

Construct compositional metric using absolute operator.

__pow__(other)

Construct compositional metric using the exponential/power operator.

__radd__(other)

Construct compositional metric using the addition operator.

__rand__(other)

Construct compositional metric using the logical and operator.

__reduce__()

Helper for pickle.

__reduce_ex__(protocol, /)

Helper for pickle.

__repr__()

Return repr(self).

__rfloordiv__(other)

Construct compositional metric using the floor division operator.

__rmatmul__(other)

Construct compositional metric using the matrix multiplication operator.

__rmod__(other)

Construct compositional metric using the remainder operator.

__rmul__(multiplier)

Construct compositional metric using the multiplication operator.

__ror__(other)

Construct compositional metric using the logical or operator.

__rpow__(other)

Construct compositional metric using the exponential/power operator.

__rsub__(other)

Construct compositional metric using the subtraction operator.

__rtruediv__(other)

Construct compositional metric using the true divide operator.

__rxor__(other)

Construct compositional metric using the logical xor operator.

__setattr__(name, value)

Overwrite default method to prevent specific attributes from being set by user.

__setstate__(state)

Set the state of the metric, based on a input state.

__sizeof__()

Size of object in memory, in bytes.

__str__()

Return str(self).

__sub__(other)

Construct compositional metric using the subtraction operator.

__subclasshook__

Abstract classes can override this to customize issubclass().

__truediv__(other)

Construct compositional metric using the true divide operator.

__xor__(other)

Construct compositional metric using the logical xor operator.

_apply(fn[, exclude_state])

Overwrite _apply function such that we can also move metric states to the correct device.

_call_impl(*args, **kwargs)

_copy_state_dict()

Copy the current state values.

_filter_kwargs(**kwargs)

Filter kwargs such that they match the update signature of the metric.

_forward_full_state_update(*args, **kwargs)

Forward computation using two calls to update.

_forward_reduce_state_update(*args, **kwargs)

Forward computation using single call to update.

_get_backward_hooks()

Return the backward hooks for use in the call function.

_get_backward_pre_hooks()

_get_name()

_load_from_state_dict(state_dict, prefix, ...)

Load metric states from state_dict.

_maybe_warn_non_full_backward_hook(inputs, ...)

_move_list_states_to_cpu()

Move list states to cpu to save GPU memory.

_named_members(get_members_fn[, prefix, ...])

Help yield various names + members of modules.

_plot([val, ax])

Plot a single or multiple values from the metric.

_reduce_states(incoming_state)

Add an incoming metric state to the current state of the metric.

_register_load_state_dict_pre_hook(hook[, ...])

See register_load_state_dict_pre_hook() for details.

_register_state_dict_hook(hook)

Register a post-hook for the state_dict() method.

_replicate_for_data_parallel()

_save_to_state_dict(destination, prefix, ...)

Save module state to the destination dictionary.

_slow_forward(*input, **kwargs)

_sync_dist(dist_sync_fn, process_group)

_update_losses_and_lengths(losses, lengths)

_wrap_compute(compute)

_wrap_update(update)

_wrapped_call_impl(*args, **kwargs)

add_module(name, module)

Add a child module to the current module.

add_state(name, default[, dist_reduce_fx, ...])

Add metric state variable.

apply(fn)

Apply fn recursively to every submodule (as returned by .children()) as well as self.

bfloat16()

Casts all floating point parameters and buffers to bfloat16 datatype.

buffers([recurse])

Return an iterator over module buffers.

children()

Return an iterator over immediate children modules.

clone()

Make a copy of the metric.

compile(*args, **kwargs)

Compile this Module's forward using torch.compile().

compute()

Abstract method that calculates metric

cpu()

Move all model parameters and buffers to the CPU.

cuda([device])

Move all model parameters and buffers to the GPU.

double()

Override default and prevent dtype casting.

eval()

Set the module in evaluation mode.

extra_repr()

Return the extra representation of the module.

float()

Override default and prevent dtype casting.

forward(*args, **kwargs)

Aggregate and evaluate batch input directly.

get_buffer(target)

Return the buffer given by target if it exists, otherwise throw an error.

get_extra_state()

Return any extra state to include in the module's state_dict.

get_parameter(target)

Return the parameter given by target if it exists, otherwise throw an error.

get_submodule(target)

Return the submodule given by target if it exists, otherwise throw an error.

half()

Override default and prevent dtype casting.

ipu([device])

Move all model parameters and buffers to the IPU.

load_state_dict(state_dict[, strict, assign])

Copy parameters and buffers from state_dict into this module and its descendants.

loss(y_pred, y_actual)

Calculate negative likelihood.

map_x_to_distribution(x)

Map the tensor of parameters to a probability distribution.

mask_losses(losses, lengths[, reduction])

Mask losses.

merge_state(incoming_state)

Merge incoming metric state to the current state of the metric.

modules([remove_duplicate])

Return an iterator over all modules in the network.

mtia([device])

Move all model parameters and buffers to the MTIA.

named_buffers([prefix, recurse, ...])

Return an iterator over module buffers, yielding both the name of the buffer as well as the buffer itself.

named_children()

Return an iterator over immediate children modules, yielding both the name of the module as well as the module itself.

named_modules([memo, prefix, remove_duplicate])

Return an iterator over all modules in the network, yielding both the name of the module as well as the module itself.

named_parameters([prefix, recurse, ...])

Return an iterator over module parameters, yielding both the name of the parameter as well as the parameter itself.

parameters([recurse])

Return an iterator over module parameters.

persistent([mode])

Change post-init if metric states should be saved to its state_dict.

plot(*_, **__)

Override this method plot the metric value.

reduce_loss(losses, lengths[, reduction])

Reduce loss.

register_backward_hook(hook)

Register a backward hook on the module.

register_buffer(name, tensor[, persistent])

Add a buffer to the module.

register_forward_hook(hook, *[, prepend, ...])

Register a forward hook on the module.

register_forward_pre_hook(hook, *[, ...])

Register a forward pre-hook on the module.

register_full_backward_hook(hook[, prepend])

Register a backward hook on the module.

register_full_backward_pre_hook(hook[, prepend])

Register a backward pre-hook on the module.

register_load_state_dict_post_hook(hook)

Register a post-hook to be run after module's load_state_dict() is called.

register_load_state_dict_pre_hook(hook)

Register a pre-hook to be run before module's load_state_dict() is called.

register_module(name, module)

Alias for add_module().

register_parameter(name, param)

Add a parameter to the module.

register_state_dict_post_hook(hook)

Register a post-hook for the state_dict() method.

register_state_dict_pre_hook(hook)

Register a pre-hook for the state_dict() method.

requires_grad_([requires_grad])

Change if autograd should record operations on parameters in this module.

rescale_parameters(parameters, target_scale, ...)

Rescale normalized parameters into the scale required for the output.

reset()

Reset metric state variables to their default value.

sample(y_pred, n_samples)

Sample from distribution.

set_dtype(dst_type)

Transfer all metric state to specific dtype.

set_extra_state(state)

Set extra state contained in the loaded state_dict.

set_submodule(target, module[, strict])

Set the submodule given by target if it exists, otherwise throw an error.

share_memory()

See torch.Tensor.share_memory_().

state_dict([destination, prefix, keep_vars])

Get the current state of metric as an dictionary.

sync([dist_sync_fn, process_group, ...])

Sync function for manually controlling when metrics states should be synced across processes.

sync_context([dist_sync_fn, process_group, ...])

Context manager to synchronize states.

to(device)

Move the loss and its components to the specified device.

to_empty(*, device[, recurse])

Move the parameters and buffers to the specified device without copying storage.

to_prediction(y_pred[, n_samples])

Convert network prediction into a point prediction.

to_quantiles(y_pred[, quantiles])

Convert network prediction into a quantile prediction.

train([mode])

Set the module in training mode.

type(dst_type)

Override default and prevent dtype casting.

unsync([should_unsync])

Unsync function for manually controlling when metrics states should be reverted back to their local states.

update(y_pred, target)

Update method of metric that handles masking of values.

xpu([device])

Move all model parameters and buffers to the XPU.

zero_grad([set_to_none])

Reset gradients of all model parameters.

Attributes

T_destination

__abstractmethods__

__annotations__

__dict__

__doc__

__iter__

__jit_ignored_attributes__

__jit_unused_properties__

__module__

__slots__

__weakref__

list of weak references to the object

_abc_impl

_compiled_call_impl

_update_called

_version

This allows better BC support for load_state_dict().

call_super_init

device

Return the device of the metric.

dtype

Return the default dtype of the metric.

dump_patches

eps

full_state_update

higher_is_better

is_differentiable

is_energy_score

metric_state

Get the current state of the metric.

plot_legend_name

plot_lower_bound

plot_upper_bound

update_called

Returns True if update or forward has been called initialization or last reset.

update_count

Get the number of times update and/or forward has been called since initialization or last reset.

distribution_class

distribution_arguments

training

_parameters

_buffers

_non_persistent_buffers_set

_backward_pre_hooks

_backward_hooks

_is_full_backward_hook

_forward_hooks

_forward_hooks_with_kwargs

_forward_hooks_always_called

_forward_pre_hooks

_forward_pre_hooks_with_kwargs

_state_dict_hooks

_load_state_dict_pre_hooks

_state_dict_pre_hooks

_load_state_dict_post_hooks

_modules