Skip to content

Commit

Permalink
added missing lag in time assymetry statistic
Browse files Browse the repository at this point in the history
closes issue #198
  • Loading branch information
MaxBenChrist committed Jul 10, 2017
1 parent 9ff06a4 commit 02c7bd2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
10 changes: 5 additions & 5 deletions tests/feature_extraction/test_feature_calculations.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,11 +462,11 @@ def test_time_reversal_asymmetry_statistic(self):
self.assertAlmostEqualOnAllArrayTypes(time_reversal_asymmetry_statistic, x, 0, 2)
self.assertAlmostEqualOnAllArrayTypes(time_reversal_asymmetry_statistic, x, 0, 3)

x = [1, 2, -3, 4]
# 1/2 * ( (4^2 * 2 + 3 * 2^2) + (3^2*1)-(2*1^1)) = 1/2 * (32+12+9-2) = 51/2
self.assertAlmostEqualOnAllArrayTypes(time_reversal_asymmetry_statistic, x, 25.5, 1)
# 4^2 * 1 - 2 * 1^2 = 16 -2
self.assertAlmostEqualOnAllArrayTypes(time_reversal_asymmetry_statistic, x, 14, 2)
x = [1, 2, - 3, 4]
# 1/2 * ( (4^2 * -3 + 3 * 2^2) + (3^2*2)-(2*1^1)) = 1/2 * (-48+12+18-2) = 20/2
self.assertAlmostEqualOnAllArrayTypes(time_reversal_asymmetry_statistic, x, -10, 1)
# 4^2 * -3 - (-3) * 1^2 = -48 +3
self.assertAlmostEqualOnAllArrayTypes(time_reversal_asymmetry_statistic, x, -45, 2)
self.assertAlmostEqualOnAllArrayTypes(time_reversal_asymmetry_statistic, x, 0, 3)

def test_binned_entropy(self):
Expand Down
5 changes: 3 additions & 2 deletions tsfresh/feature_extraction/feature_calculators.py
Original file line number Diff line number Diff line change
Expand Up @@ -1069,9 +1069,10 @@ def time_reversal_asymmetry_statistic(x, lag):
if 2 * lag > n:
return 0
elif 2 * lag == n:
return x[n-1] * x[n-1] * x[0] - x[lag-1] * x[0] * x[0]
return x[n-1] * x[n-1] * x[n//2] - x[n//2] * x[0] * x[0]
else:
return np.mean((np.roll(x, 2 * -lag) * np.roll(x, 2 * -lag) * x - np.roll(x, -lag) * x * x)[0:(n - 2 * lag)])
return np.mean((np.roll(x, 2 * -lag) * np.roll(x, 2 * -lag) * np.roll(x, -lag) -
np.roll(x, -lag) * x * x)[0:(n - 2 * lag)])


@set_property("fctype", "simple")
Expand Down

0 comments on commit 02c7bd2

Please sign in to comment.