SequentialNet#

class pytorch_forecasting.metrics._mqf2_utils.SequentialNet(networks: list[Module])[source]#

Bases: SequentialFlow

Class that combines a list of DeepConvexNet and ActNorm layers and provides energy score computation This class is based on SequentialFlow of the CP-Flow repo (CW-Huang/CP-Flow)

Parameters:

networks – list of DeepConvexNet and/or ActNorm instances

Inherited-members:

Methods

energy_score

es_sample

forward

energy_score(z: Tensor, hidden_state: Tensor, es_num_samples: int = 50, beta: float = 1.0) Tensor[source]#

Computes the (approximated) energy score sum_i ES(g,z_i), where ES(g,z_i) = -1/(2*es_num_samples^2) * sum_{w,w’} ||w-w’||_2^beta + 1/es_num_samples * sum_{w’’} ||w’’-z_i||_2^beta, w’s are samples drawn from the quantile function g(., h_i) (gradient of picnn), h_i is the hidden state associated with z_i, and es_num_samples is the number of samples drawn for each of w, w’, w’’ in energy score approximation

Parameters:
  • z – Observations (numel_batch, dimension)

  • hidden_state – Hidden state (numel_batch, hidden_size)

  • es_num_samples – Number of samples drawn for each of w, w’, w’’ in energy score approximation

  • beta – Hyperparameter of the energy score, see the formula above

Returns:

energy score (numel_batch)

Return type:

loss

es_sample(hidden_state: Tensor, dimension: int) Tensor[source]#

Auxiliary function for energy score computation Drawing samples conditioned on the hidden state

Parameters:
  • hidden_state – hidden_state which the samples conditioned on (num_samples, hidden_size)

  • dimension – dimension of the input

Returns:

samples drawn (num_samples, dimension)

Return type:

samples

forward(x: Tensor, context: Tensor | None = None) Tensor[source]#

MagicMock is a subclass of Mock with default implementations of most of the magic methods. You can use MagicMock without having to configure the magic methods yourself.

If you use the spec or spec_set arguments then only magic methods that exist in the spec will be created.

Attributes and the return value of a MagicMock will also be MagicMocks.