Fracdiff#

class fracdiff.torch.Fracdiff(d, dim=-1, window=10, mode='same')[source]#

A torch.nn.Module to compute fractional differentiation.

Parameters:
  • d (float) – The order of differentiation.

  • dim (int, default=-1) – The dimension to differentiate. Currently, only the last dimension is supported.

  • window (int, default=10) – The window size for fractional differentiation.

  • mode (str, default="same") – “same” or “valid”. See fracdiff.fdiff() for details.

Shape:
  • input: \((N, *, L_{\mathrm{in}})\), where where \(*\) means any number of additional dimensions.

  • output: \((N, *, L_{\mathrm{out}})\), where \(L_{\mathrm{out}}\) is given by \(L_{\mathrm{in}}\) if mode=”same” and \(L_{\mathrm{in}} - \mathrm{window} + 1\) if mode=”valid”.

Examples

>>> from fracdiff.torch import Fracdiff
>>> m = Fracdiff(0.5)
>>> m
Fracdiff(0.5, dim=-1, window=10, mode='same')
>>> input = torch.arange(10).reshape(2, 5)
>>> m(input)
tensor([[0.0000, 1.0000, 1.5000, 1.8750, 2.1875],
        [5.0000, 3.5000, 3.3750, 3.4375, 3.5547]])
forward(input, prepend=None, append=None)[source]#

Apply fractional differentiation.

Parameters:
  • input (torch.Tensor) – The input tensor.

  • prepend (torch.Tensor, optional) – The tensor to prepend to input along self.dim before computing the differentiation. Their dimensions must be equivalent to that of input, and their shapes must match input’s shape except on dim.

  • append (torch.Tensor, optional) – The tensor to append.

Returns:

torch.Tensor