Skip to content

Commit

Permalink
Merge pull request #2 from selimfirat/develop
Browse files Browse the repository at this point in the history
v0.1.1 update
  • Loading branch information
selimfirat authored Aug 19, 2020
2 parents 6c588dc + 7c0a93e commit 1980c36
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 17 deletions.
4 changes: 4 additions & 0 deletions deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
rm -rf ./build/ ./dist/ ./pysad.egg-info/
python3 setup.py sdist bdist_wheel
python3 -m twine upload dist/*
7 changes: 3 additions & 4 deletions docs/features.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@ Streaming methods efficiently handle the limitied memory and processing time req
Streaming Anomaly Detection Tools
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

`PySAD` contains stream simulators, evaluators, preprocessors, statistic trackers, postprocessors, probability calibrators and more.
In addition to streaming models, `PySAD` also provides integrations for batch anomaly detectors of the `PyOD framework <https://github.com/yzhao062/pyod/>`_ so that they can be used in the streaming setting.
`PySAD` contains stream simulators, evaluators, preprocessors, statistic trackers, postprocessors, probability calibrators and more. In addition to streaming models, `PySAD` also provides integrations for batch anomaly detectors of the `PyOD <https://github.com/yzhao062/pyod/>`_ so that they can be used in the streaming setting.


Comprehensiveness
^^^^^^^^^^^^^^^^^

`PySAD` provides models that are specifically designed for multivariate and univariate data. One can experiment via `PySAD` in supervised, semi-supervised and unsupervised setting.
`PySAD` serves models that are specifically designed for both univariate and multivariate data. Furthermore, one can experiment via `PySAD` in supervised, semi-supervised and unsupervised setting.


User Friendly
Expand All @@ -35,4 +34,4 @@ Users with any experience level can easily use `PySAD`. One can easily design ex
Free and Open Source Software (FOSS)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

`PySAD` is distributed under `3-Clause BSD License` and favors FOSS principles.
`PySAD` is distributed under `BSD License 2.0 <https://github.com/selimfirat/pysad/blob/master/LICENSE>`_ and favors FOSS principles.
2 changes: 1 addition & 1 deletion docs/license.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
License
=======

This project is licensed under the `3-Clause BSD License <../LICENSE>`_.
This project is licensed under the `BSD License 2.0 <https://github.com/selimfirat/pysad/blob/master/LICENSE>`_.

.. literalinclude:: ../LICENSE
6 changes: 3 additions & 3 deletions examples/example_probability_calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
np.random.seed(61) # Fix seed.

model = xStream() # Init model.
calibrator = ConformalProbabilityCalibrator(windowed=True, window_size=300) # Init probability calibrator.
streaming_data = Data().get_iterator("arrhythmia.mat") # Get streamer.
calibrator = ConformalProbabilityCalibrator(windowed=True, window_size=300) # Init probability calibrator.
streaming_data = Data().get_iterator("arrhythmia.mat") # Get streamer.

for i, (x, y_true) in enumerate(streaming_data): # Stream data.
anomaly_score = model.fit_score_partial(x) # Fit to an instance x and score it.

calibrated_score = calibrator.fit_transform(anomaly_score) # Fit & calibrate score.

# Output if the instance is anomalous.
if calibrated_score < 0.05: # If probability is less than 5%.
if calibrated_score > 0.95: # If probability of being normal is less than 5%.
print(f"Alert: {i}th data point is anomalous.")
3 changes: 2 additions & 1 deletion examples/example_usage_short.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
from pysad.models import LODA
from pysad.utils import Data


model = LODA() # Init model
metric = AUROCMetric() # Init area under receiver-operating- characteristics curve metric
streaming_data = Data().get_iterator("arrhythmia.mat") # Get data streamer.
streaming_data = Data().get_iterator("arrhythmia.mat") # Get data streamer.

for x, y_true in streaming_data: # Stream data.
anomaly_score = model.fit_score_partial(x) # Fit the instance to model and score the instance.
Expand Down
4 changes: 2 additions & 2 deletions pysad/models/xstream.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ def score_partial(self, X):
return score

def _compute_deltamax(self):
#mx = np.max(np.concatenate(self.ref_window, axis=0), axis=0)
#mn = np.min(np.concatenate(self.ref_window, axis=0), axis=0)
# mx = np.max(np.concatenate(self.ref_window, axis=0), axis=0)
# mn = np.min(np.concatenate(self.ref_window, axis=0), axis=0)
mn, mx = get_minmax_array(np.concatenate(self.ref_window, axis=0))

deltamax = (mx - mn) / 2.0
Expand Down
2 changes: 1 addition & 1 deletion pysad/transform/ensemble/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
The :mod:`pysad.transform.ensemble` module consist of ensemblers to combine scores from multiple anomaly detectors.
"""
from .ensemblers import MaximumScoreEnsembler,AverageScoreEnsembler,MedianScoreEnsembler, PYODScoreEnsembler, AverageOfMaximumScoreEnsembler, MaximumOfAverageScoreEnsembler
from .ensemblers import MaximumScoreEnsembler, AverageScoreEnsembler, MedianScoreEnsembler, AverageOfMaximumScoreEnsembler, MaximumOfAverageScoreEnsembler

__all__ = ["MaximumScoreEnsembler", "MedianScoreEnsembler", "AverageScoreEnsembler", "MaximumOfAverageScoreEnsembler", "AverageOfMaximumScoreEnsembler"]
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,4 @@ def transform_partial(self, score):
Returns:
float: Processed score.
"""

return (np.sum(np.array(self.window.get()) <= score))/ (len(self.window.get()))

return (np.sum(np.array(self.window.get()) > score)) / (len(self.window.get()))
2 changes: 1 addition & 1 deletion pysad/transform/probability_calibration/gaussian_tail.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def transform_partial(self, score):
else:
std = 1.0

return self._qfunction(score, mean, std)
return 1 - self._qfunction(score, mean, std)

def _qfunction(self, x, mean, std):
"""
Expand Down
2 changes: 1 addition & 1 deletion pysad/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@
# 'X.Y.dev0' is the canonical version of 'X.Y.dev'
#

__version__ = '0.1.0'
__version__ = '0.1.1'

0 comments on commit 1980c36

Please sign in to comment.