fracdiff.torch.fdiff#
- fracdiff.torch.fdiff(input, n, dim=-1, prepend=None, append=None, window=10, mode='same')[source]#
Computes the
n
-th differentiation along the given dimension.This is an extension of
torch.diff()
to fractional differentiation. Seefracdiff.torch.Fracdiff
for details.Note
For integer
n
, the output is the same astorch.diff()
and the parameterswindow
andmode
are ignored.- 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”. If prepend and/or append are provided, then \(L_{\mathrm{out}}\) increases by the number of elements in each of these tensors.
Examples
>>> from fracdiff.torch import fdiff ... >>> input = torch.tensor([1, 2, 4, 7, 0]) >>> fdiff(input, 0.5, mode="same", window=3) tensor([ 1.0000, 1.5000, 2.8750, 4.7500, -4.0000])
>>> fdiff(input, 0.5, mode="valid", window=3) tensor([ 2.8750, 4.7500, -4.0000])
>>> fdiff(input, 0.5, mode="valid", window=3, prepend=[1, 1]) tensor([ 0.3750, 1.3750, 2.8750, 4.7500, -4.0000])
>>> input = torch.arange(10).reshape(2, 5) >>> fdiff(input, 0.5) tensor([[0.0000, 1.0000, 1.5000, 1.8750, 2.1875], [5.0000, 3.5000, 3.3750, 3.4375, 3.5547]])