Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Dec 16, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PROJECT_NAME := fracdiff

.PHONY: check
check: test lint
check: test lint typecheck

.PHONY: install
install:
Expand Down Expand Up @@ -45,6 +45,7 @@ doc:
@cd docs && make html

.PHONY: typecheck
typecheck:
@poetry run mypy $(PROJECT_NAME)

.PHONY: publish
Expand Down
10 changes: 8 additions & 2 deletions fracdiff/fdiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from scipy.special import binom # type: ignore


def fdiff_coef(d, window) -> np.ndarray:
def fdiff_coef(d: float, window: int) -> np.ndarray:
"""Returns sequence of coefficients in fracdiff operator.

Parameters
Expand Down Expand Up @@ -35,7 +35,13 @@ def fdiff_coef(d, window) -> np.ndarray:


def fdiff(
a, n=1.0, axis=-1, prepend=np._NoValue, append=np._NoValue, window=10, mode="full"
a: np.ndarray,
n: float = 1.0,
axis: int = -1,
prepend=np._NoValue,
append=np._NoValue,
window: int = 10,
mode: str = "full",
) -> np.ndarray:
"""Calculate the `n`-th differentiation along the given axis.

Expand Down
7 changes: 4 additions & 3 deletions fracdiff/sklearn/stat.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import numpy as np # type:ignore
import statsmodels.tsa.stattools as stattools # type: ignore


Expand Down Expand Up @@ -31,7 +32,7 @@ class StatTester:
False
"""

def __init__(self, method="ADF"):
def __init__(self, method: str = "ADF"):
self.method = method

@property
Expand All @@ -41,7 +42,7 @@ def null_hypothesis(self) -> str:
else:
raise ValueError(f"Unknown method: {self.method}")

def pvalue(self, x) -> float:
def pvalue(self, x: np.ndarray) -> float:
"""
Return p-value of the stationarity test.

Expand All @@ -61,7 +62,7 @@ def pvalue(self, x) -> float:
else:
raise ValueError(f"Unknown method: {self.method}")

def is_stat(self, x, pvalue=0.05) -> bool:
def is_stat(self, x: np.ndarray, pvalue: float = 0.05) -> bool:
"""
Return whether stationarity test implies stationarity.

Expand Down
6 changes: 4 additions & 2 deletions fracdiff/sklearn/tol.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from fracdiff.fdiff import fdiff_coef


def window_from_tol_coef(n, tol_coef, max_window=2 ** 12) -> int:
def window_from_tol_coef(n: float, tol_coef: float, max_window: int = 2 ** 12) -> int:
"""
Return length of window determined from tolerance to memory loss.

Expand Down Expand Up @@ -43,7 +43,9 @@ def window_from_tol_coef(n, tol_coef, max_window=2 ** 12) -> int:
return np.searchsorted(-coef, -tol_coef) + 1 # index -> length


def window_from_tol_memory(n, tol_memory, max_window=2 ** 12) -> int:
def window_from_tol_memory(
n: float, tol_memory: float, max_window: int = 2 ** 12
) -> int:
"""
Return length of window determined from tolerance to memory loss.

Expand Down
3 changes: 1 addition & 2 deletions fracdiff/torch/functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from fracdiff.fdiff import fdiff_coef as fdiff_coef_numpy


def fdiff_coef(d: float, window: int) -> torch.Tensor:
def fdiff_coef(d: float, window: int) -> Tensor:
"""Returns sequence of coefficients in fracdiff operator.

Args:
Expand Down Expand Up @@ -59,7 +59,6 @@ def fdiff(
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)
Expand Down
1 change: 0 additions & 1 deletion fracdiff/torch/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ class Fracdiff(Module):
:math:`L_{\\mathrm{in}} - \\mathrm{window} + 1` if `mode="valid"`.

Examples:

>>> from fracdiff.torch import Fracdiff
>>> m = Fracdiff(0.5)
>>> m
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Sphinx = "^4.2.0"
furo = "^2021.9.22"
sphinx-autobuild = "^2021.3.14"
sphinx-copybutton = "^0.4.0"
mypy = "^0.910"

[build-system]
requires = ["poetry>=0.12"]
Expand Down