-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Adds a seasonal timeseries * initial commit * Rename to periodic * More assertions * Adds test * Adds trigonometric seasonality * Adds testing * Adds ervent shape * Adds optionals and notebook * NB * Use corret mask, NB * Sigh * NB * Correct * Fix * Removes mask functionality in favor of more general matrix multipplication * Fixes tests * Temp * Remmoves trigonometric.py for now * Fixes * Slightly improved * Fix * Fix * Adds test, to fix * Seasonal working * FIx * FIx * FIx * Adds determinstic sampling procedure * ix * Fix * Fix * Slightly cleaner * Fix * Fix * Adds trigonometric series * Minor cleanup * Docs * Black * Fix * "Fix" * Test fix * version * Think this is the neatest way * Predictions * Black * NB * Bug fix * NB * NB * NB * NB * rename * fix * Also ensure that posterior std is lower than prior * Backwards compatability * Docs * Do not sample * Typing * Adds test just in case * TEst deterministic seasonal * Adds selector to stuff * Fix * NB * Fix * Fix --------- Co-authored-by: victor <baj>
- Loading branch information
1 parent
84f8ff8
commit c5bb414
Showing
12 changed files
with
1,292 additions
and
75 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from .time import TimeSeasonal | ||
from .cyclical import Cyclical | ||
from .trigonometric import TrigonometricSeasonal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import jax.numpy as jnp | ||
from numpy.typing import ArrayLike | ||
|
||
from ..base import LinearTimeseries | ||
from ..util import cast_to_tensor | ||
|
||
|
||
class Cyclical(LinearTimeseries): | ||
""" | ||
Represents a cyclical component by means of a trigonometric series TODO: math | ||
Args: | ||
periodicity: Periodicity of component. | ||
""" | ||
|
||
def __init__(self, n: int, periodicity: ArrayLike, std: ArrayLike, initial_value: ArrayLike, **kwargs): | ||
(lamda,) = cast_to_tensor(periodicity) | ||
|
||
cos_lamda = jnp.cos(lamda) | ||
sin_lamda = jnp.sin(lamda) | ||
|
||
top = jnp.stack([cos_lamda, sin_lamda], axis=-1) | ||
bottom = jnp.stack([-sin_lamda, cos_lamda], axis=-1) | ||
matrix = jnp.stack([top, bottom], axis=-2) | ||
|
||
offset = jnp.zeros(2) | ||
std = jnp.full_like(offset, std) | ||
|
||
super().__init__(n, offset, matrix, std, initial_value, **kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from numpy.typing import ArrayLike | ||
import jax.numpy as jnp | ||
import numpy as np | ||
|
||
from ..base import LinearTimeseries | ||
from ..util import cast_to_tensor | ||
|
||
|
||
class TimeSeasonal(LinearTimeseries): | ||
r""" | ||
Represents a periodic series of the form: | ||
.. math:: | ||
\gamma_{t + 1} = \sum_{i = 1}^{s - 1} \gamma_{t + 1 - j} + \eps_{t + 1} | ||
Args: | ||
num_seasons: Number of seasons to include. | ||
""" | ||
|
||
def __init__(self, n: int, num_seasons: int, std: ArrayLike, initial_value: ArrayLike, **kwargs): | ||
top = -jnp.ones([1, num_seasons - 1]) | ||
bottom = jnp.eye(num_seasons - 2, num_seasons - 1) | ||
|
||
matrix = jnp.concatenate([top, bottom], axis=-2) | ||
offset = jnp.zeros_like(top).squeeze(-2) | ||
|
||
std, initial_value = cast_to_tensor(std, initial_value) | ||
std = jnp.concatenate([std[..., None], jnp.zeros(num_seasons - 2)], axis=-1) | ||
|
||
mask = np.eye(num_seasons - 1, 1, dtype=np.bool_).squeeze(-1) | ||
|
||
super().__init__(n, offset, matrix, std, initial_value, column_mask=mask, **kwargs) |
Oops, something went wrong.