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

All scores are zero except the last, which is a NaN #45

Open
NAThompson opened this issue Nov 10, 2023 · 1 comment
Open

All scores are zero except the last, which is a NaN #45

NAThompson opened this issue Nov 10, 2023 · 1 comment

Comments

@NAThompson
Copy link
Contributor

To reproduce:

#!/usr/bin/env python3
import numpy
from deepod.models.time_series.dif import DeepIsolationForestTS

arr = numpy.empty(shape=(33, 741))
arr.fill(1.0)

# Also reproduces the issue:
# arr = numpy.random.rand(33, 741)

dif = DeepIsolationForestTS(device=None, seq_len=min(arr.shape[0], 100), max_samples=min(arr.shape[0], 256), hidden_dims=100)
dif.fit(arr)
scores = dif.decision_function(arr)
print(scores)

Output:

$VIRTUAL_ENV/lib/python3.9/site-packages/deepod/models/tabular/dif.py:256: RuntimeWarning: invalid value encountered in divide
  scores = 2 ** (-depth_sum / (len(clf.estimators_) * _average_path_length([clf.max_samples_])))
[00:00<00:00, 1088.64it/s]
[ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.
  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0. nan]
@NAThompson
Copy link
Contributor Author

NAThompson commented Nov 15, 2023

Some more clues as to the source of this issue: The first seq_len -1 samples are always zero (which should perhaps be the title of the issue):

#!/usr/bin/env python3
import numpy
from deepod.models.time_series.dif import DeepIsolationForestTS

arr = numpy.random.rand(256, 256)

dif = DeepIsolationForestTS(device='cpu', seq_len=10, max_samples=min(arr.shape[0], 256), hidden_dims=100)
dif.fit(arr)
scores = dif.decision_function(arr)
print(scores)
# Output:
[    0.             0.             0.             0.
     0.             0.             0.             0.
     0.         31026.44215442 30419.1558587  31492.80078777
 31453.71368052 31583.28407603 31244.13219935 31221.5422394
...

It would appear that these lines are responsible:

padding = np.zeros(self.seq_len-1)
scores = np.hstack((padding, scores))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant