Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passed max_shift_seconds to milliseconds #39

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/luminol/algorithms/correlator_algorithms/cross_correlator.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ def __init__(self, time_series_a, time_series_b, max_shift_seconds=None, shift_i
Initializer
:param TimeSeries time_series_a: TimeSeries a.
:param TimeSeries time_series_b: TimeSeries b.
:param int max_shift_milliseconds: allowed maximal shift seconds.
:param int max_shift_seconds: allowed maximal shift seconds.
:param time_period: if given, correlate the data inside the time period only.
"""
super(CrossCorrelator, self).__init__(self.__class__.__name__, time_series_a, time_series_b)
self.shift_impact = shift_impact or DEFAULT_SHIFT_IMPACT
if max_shift_seconds is not None:
self.max_shift_milliseconds = max_shift_seconds
self.max_shift_seconds = max_shift_seconds
else:
self.max_shift_milliseconds = DEFAULT_ALLOWED_SHIFT_SECONDS * 1000
self.max_shift_seconds = DEFAULT_ALLOWED_SHIFT_SECONDS

def _detect_correlation(self):
"""
Expand Down Expand Up @@ -73,8 +73,8 @@ def _detect_correlation(self):
r = s / denom if denom != 0 else s
correlations.append([delay_in_seconds, r])
# Take shift into account to create a "shifted correlation coefficient".
if self.max_shift_milliseconds:
shifted_correlations.append(r * (1 + float(delay_in_seconds) / self.max_shift_milliseconds * self.shift_impact))
if self.max_shift_seconds:
shifted_correlations.append(r * (1 + float(delay_in_seconds) / self.max_shift_seconds * self.shift_impact))
else:
shifted_correlations.append(r)
max_correlation = list(max(correlations, key=lambda k: k[1]))
Expand All @@ -84,13 +84,13 @@ def _detect_correlation(self):

def _find_allowed_shift(self, timestamps):
"""
Find the maximum allowed shift steps based on max_shift_milliseconds.
Find the maximum allowed shift steps based on max_shift_seconds.
param list timestamps: timestamps of a time series.
"""
init_ts = timestamps[0]
residual_timestamps = [ts - init_ts for ts in timestamps]
n = len(residual_timestamps)
return self._find_first_bigger(residual_timestamps, self.max_shift_milliseconds, 0, n)
return self._find_first_bigger(residual_timestamps, self.max_shift_seconds, 0, n)

def _find_first_bigger(self, timestamps, target, lower_bound, upper_bound):
"""
Expand Down