Calculate the Mean Absolute Error between predictions and targets.
masks can be used for filtering. For values==0 in masks,
values at their corresponding positions in predictions will be ignored.
Parameters:
predictions (Union[ndarray, Tensor]) – The prediction data to be evaluated.
targets (Union[ndarray, Tensor]) – The target data for helping evaluate the predictions.
masks (Union[ndarray, Tensor, None]) – The masks for filtering the specific values in inputs and target from evaluation.
When given, only values at corresponding positions where values ==1 in masks will be used for evaluation.
Calculate the Mean Square Error between predictions and targets.
masks can be used for filtering. For values==0 in masks,
values at their corresponding positions in predictions will be ignored.
Parameters:
predictions (Union[ndarray, Tensor]) – The prediction data to be evaluated.
targets (Union[ndarray, Tensor]) – The target data for helping evaluate the predictions.
masks (Union[ndarray, Tensor, None]) – The masks for filtering the specific values in inputs and target from evaluation.
When given, only values at corresponding positions where values ==1 in masks will be used for evaluation.
Calculate the Root Mean Square Error between predictions and targets.
masks can be used for filtering. For values==0 in masks,
values at their corresponding positions in predictions will be ignored.
Parameters:
predictions (Union[ndarray, Tensor]) – The prediction data to be evaluated.
targets (Union[ndarray, Tensor]) – The target data for helping evaluate the predictions.
masks (Union[ndarray, Tensor, None]) – The masks for filtering the specific values in inputs and target from evaluation.
When given, only values at corresponding positions where values ==1 in masks will be used for evaluation.
Calculate the Mean Relative Error between predictions and targets.
masks can be used for filtering. For values==0 in masks,
values at their corresponding positions in predictions will be ignored.
Parameters:
predictions (Union[ndarray, Tensor]) – The prediction data to be evaluated.
targets (Union[ndarray, Tensor]) – The target data for helping evaluate the predictions.
masks (Union[ndarray, Tensor, None]) – The masks for filtering the specific values in inputs and target from evaluation.
When given, only values at corresponding positions where values ==1 in masks will be used for evaluation.
Continuous rank probability score for distributional predictions.
Parameters:
predictions (Union[ndarray, Tensor]) – The prediction data to be evaluated.
targets (Union[ndarray, Tensor]) – The target data for helping evaluate the predictions.
masks (Union[ndarray, Tensor]) – The masks for filtering the specific values in inputs and target from evaluation.
Only values at corresponding positions where values ==1 in masks will be used for evaluation.
scaler_mean – Mean value of the scaler used to scale the data.
scaler_stddev – Standard deviation value of the scaler used to scale the data.
Sum continuous rank probability score for distributional predictions.
Parameters:
predictions (Union[ndarray, Tensor]) – The prediction data to be evaluated.
targets (Union[ndarray, Tensor]) – The target data for helping evaluate the predictions.
masks (Union[ndarray, Tensor]) – The masks for filtering the specific values in inputs and target from evaluation.
Only values at corresponding positions where values ==1 in masks will be used for evaluation.
scaler_mean – Mean value of the scaler used to scale the data.
scaler_stddev – Standard deviation value of the scaler used to scale the data.
Calculate the evaluation metrics for the binary classification task,
including accuracy, precision, recall, f1 score, area under ROC curve, and area under Precision-Recall curve.
If targets contains multiple categories, please set the positive category as pos_label.
Parameters:
prob_predictions (ndarray) – Estimated probability predictions returned by a decision function.
targets (ndarray) – Ground truth (correct) classification results.
pos_label (int) – The label of the positive class.
Note that pos_label is also the index used to extract binary prediction probabilities from predictions.
Returns:
A dictionary contains classification metrics and useful results:
predictions: binary categories of the prediction results;
accuracy: prediction accuracy;
precision: prediction precision;
recall: prediction recall;
f1: F1-score;
precisions: precision values of Precision-Recall curve
Base class for all NN models’ core.
For most of the NN models (inheriting BaseNNModel) in PyPOTS, their model core inherits this class and
implement the forward and calc_criterion methods, and they exempt from overwriting _train_model() which
carries concrete model training details, e.g. SAITS, Transformer, and this is task agnostic.
But some models’ processing procedures are too complex to be abstracted into this class, e.g. GAN models
(like US-GAN and CRLI) which have more than one optimizer need to update or VaDER which needs pretraining and
has complicated manipulations for its Gaussian mixture model, their model core don’t have to inherit this class,
just be a subclass of torch.nn.Module and obey basic rules (include the loss/metric as keys in the return dict)
to be compatible with PyPOTS. Additionally, in this case, they need to overwrite _train_model() to implement
their own training procedures.
Forward pass of the model.
This method should be implemented to include all operations in the NN model’s forward propagation.
Parameters:
inputs (dict) – The dictionary including all necessary input data for the model’s forward pass.
calc_criterion (bool) – Whether to calculate training loss (when self.training==True) and
validation metric (when self.training!=True),
and pass the criterion out together with the model forward results.
Returns:
The model’s output results of its forward propagation.
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Should be overridden by all subclasses.
:rtype: Tensor
Note
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Should be overridden by all subclasses.
:rtype: Tensor
Note
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
return the laplacian of the graph.
:type graph:
:param graph: the graph structure without self loop, [N, N].
:type normalize:
:param normalize: whether to used the normalized laplacian.
:return: graph laplacian.
Compute the Chebyshev Polynomial, according to the graph laplacian.
:type laplacian:
:param laplacian: the graph laplacian, [N, N].
:return: the multi order Chebyshev laplacian, [K, N, N].
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
attn_mask (Optional[Tensor]) – Masking tensor for the attention map. The shape should be [batch_size, n_heads, n_steps, n_steps].
0 in attn_mask means values at the according position in the attention map will be masked out.
attn_mask (Optional[Tensor]) – Masking tensor for the attention map. The shape should be [batch_size, n_heads, n_steps, n_steps].
0 in attn_mask means values at the according position in the attention map will be masked out.
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Should be overridden by all subclasses.
:rtype: Tensor
Note
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Should be overridden by all subclasses.
:rtype: Tuple[Tensor, Tensor]
Note
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Should be overridden by all subclasses.
:rtype: Tuple[Tensor, ...]
Note
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
The module used to capture the correlation between features for imputation in BRITS.
Attributes:
W (tensor) – The weights (parameters) of the module.
b (tensor) – The bias of the module.
m (buffer) (tensor) – The mask matrix, a squire matrix with diagonal entries all zeroes while left parts all ones.
It is applied to the weight matrix to mask out the estimation contributions from features themselves.
It is used to help enhance the imputation performance of the network.
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Koopman Predictor with DMD (analysitical solution of Koopman operator)
Utilize local variations within individual sliding window to predict the future of time-variant term
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Should be overridden by all subclasses.
:rtype: Tuple[Tensor, Tensor]
Note
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Should be overridden by all subclasses.
:rtype: Tensor
Note
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Should be overridden by all subclasses.
:rtype: Tuple[Tensor, None]
Note
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Should be overridden by all subclasses.
:rtype: Tuple[Tensor, None]
Note
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Should be overridden by all subclasses.
:rtype: Tuple[Tensor, None]
Note
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Should be overridden by all subclasses.
:rtype: Tuple[Tensor, None]
Note
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
NonstationaryTransformer encoder.
Its arch is the same with the original Transformer encoder,
but the attention operator is replaced by the DeStationaryAttention.
Parameters:
n_layers (int) – The number of layers in the encoder.
d_model (int) – The dimension of the module manipulation space.
The input tensor will be projected to a space with d_model dimensions.
n_heads (int) – The number of heads in multi-head attention.
d_k (int) – The dimension of the key and query tensor.
Should be overridden by all subclasses.
:rtype: Tuple[Tensor, Tensor]
Note
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Should be overridden by all subclasses.
:rtype: Tuple[Tensor, ...]
Note
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Should be overridden by all subclasses.
:rtype: Tuple[Tensor, Tensor]
Note
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Should be overridden by all subclasses.
:rtype: Tuple[Tensor, Tensor]
Note
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Should be overridden by all subclasses.
:rtype: Tensor
Note
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
x (Tensor) – This should have a shape of (n_samples, n_steps, n_features). All missing data should be set to NaN.
mask (Optional[str]) – The mask used by encoder can be specified with this parameter.
This can be set to ‘binomial’, ‘continuous’, ‘all_true’, ‘all_false’ or ‘mask_last’.
encoding_window (Optional[str]) – When this param is specified, the computed representation would the max pooling over this window.
This can be set to ‘full_series’, ‘multiscale’ or an integer specifying the pooling kernel size.
causal (bool) – When this param is set to True, the future information would not be encoded into representation of
each timestamp.
sliding_length (Optional[int]) – The length of sliding window. When this param is specified,
a sliding inference would be applied on the time series.
sliding_padding (int) – This param specifies the contextual data length used for inference every sliding windows.
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.
Should be overridden by all subclasses.
:rtype: Tuple[Tensor, ...]
Note
Although the recipe for forward pass needs to be defined within
this function, one should call the Module instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.