Skip to content
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
1 change: 1 addition & 0 deletions src/forest/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class Frequency(Enum):
FP_TOLERANCE = 1e-6 # a minimum threshold (Jasmine)

SECONDS_IN_DAY = 60 * 60 * 24
SECONDS_IN_WEEK = 60 * 60 * 24 * 7

SECONDS_PER_DAY_TIMES_PI = 86_400 * math.pi ## src: SOGP
SECONDS_PER_WEEK_TIMES_PI = 604_800 * math.pi
Expand Down
11 changes: 7 additions & 4 deletions src/forest/jasmine/sogp_gps.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@
import numba
import numpy as np

from forest.constants import K0_PARAMS, SECONDS_PER_DAY_TIMES_PI, SECONDS_PER_WEEK_TIMES_PI
from forest.constants import K0_PARAMS, SECONDS_IN_DAY, SECONDS_IN_WEEK


logger = logging.getLogger(__name__)


PI = np.pi


@numba.njit(cache=True, fastmath=True)
def calculate_k0(x1: np.ndarray, x2: np.ndarray, k0_params: K0_PARAMS) -> float:
""" This function calculates the similarity between two points
Expand All @@ -38,10 +41,10 @@ def calculate_k0(x1: np.ndarray, x2: np.ndarray, k0_params: K0_PARAMS) -> float:
float, the similarity between x1 and x2
"""
l1, l2, l3, a1, a2, b1, b2, b3 = k0_params

dt = abs(x1[0] - x2[0])
sin_daily = np.sin(dt / SECONDS_PER_DAY_TIMES_PI) ** 2
sin_weekly = np.sin(dt / SECONDS_PER_WEEK_TIMES_PI) ** 2
sin_daily = np.sin(dt / SECONDS_IN_DAY * PI) ** 2
sin_weekly = np.sin(dt / SECONDS_IN_WEEK * PI) ** 2
k1 = np.exp(-dt / l1 - sin_daily / a1)
k2 = np.exp(-dt / l2 - sin_weekly / a2)
k3 = np.exp(-abs(x1[1] - x2[1]) / l3)
Expand Down
Loading