From e73d83012d11fc1f8441692a288a20551280a204 Mon Sep 17 00:00:00 2001 From: Matt Bartos Date: Mon, 25 Mar 2019 23:38:42 -0400 Subject: [PATCH] Fix error with coveralls build (#51) * Update dev from master (#47) * Working version of insert_point * Fix bug with query and insertpoint * Cleanup disp and codisp functions * Reorder methods * Insertpoint operational, add docstrings * Small fix * Remove old files * Allow empty tree; handle duplicates in insert_point and forget_point * Account for duplicates in tree construction * Add ability to print tree * Update docstrings and minor fixes * Docstring fix * Minor fixes * Bugfix for forget_point * Add image * Update readme * Update README.md * Type check for point * Update README.md * Update README.md * Store bounding boxes * Minor changes * Fix bbox bug, add unit tests * Add support for CI * Remove Python 3.7 * Update README.md * Fix duplicate precision bug * Fix duplicates issue? * Use new indexing strategy with forget_point * Update n bug * Return 0 for codisp if leaf is root * Add efficient shingle * Add sine wave image * Update README.md * Minor cleanup * sklearn test * Add classification notebook * Updated gitignore * Edit classification notebook * taxi data test * removed swamp * taxi data 200 tree run * IF test * Add OC-SVM example with sine wave * Add OC-SVM example with taxi data * Add IF example with sine wave * Minor changes * Minor updates * Delete old sine_ocsvm_test notebook * Delete old taxi_ocsvm_test notebook * Delete old sine_if notebook * Add IF example with sine wave * Add OC-SVM example with sine wave * Add OC-SVM example with taxi data * Delete old taxi_ocsvm notebook * Add OC-SVM example with taxi data * sine wave comaprasion * table1 notebook * rrcf notebook * renamed rrcf * taxi data if * Fix shingle bug; clean up classification example * Set theme jekyll-theme-minimal * Add index labels * Update batch image * Update README.md * Update README.md * Update README.md * Create _config.yml * Create default.html * Create index.md * Update index.md * Create nav.html * Create nav.yml * Create tree-construction.html * Rename tree-construction.html to tree-construction.md * Create insert-and-delete.md * Create anomaly-scoring.md * Create batch.md * Create streaming.md * Update tree-construction.md * Update tree-construction.md * Update tree-construction.md * Update tree-construction.md * Update tree-construction.md * Update tree-construction.md * Update insert-and-delete.md * Update insert-and-delete.md * Update tree-construction.md * Update insert-and-delete.md * Update insert-and-delete.md * Update anomaly-scoring.md * Create related-work.md * Update nav.yml * Update related-work.md * Create random-cut-tree.md * Update nav.yml * Create modifying-rctree.md * Update nav.yml * Update random-cut-tree.md * Update random-cut-tree.md * Update random-cut-tree.md * Update random-cut-tree.md * Update modifying-rctree.md * Update random-cut-tree.md * Create scoring-rctree.md * Update nav.yml * Update scoring-rctree.md * Update README.md * Update README.md * Update index.md * Update index.md * Update index.md * Create paper.md * Create paper.bib * Add files via upload * Update paper.md * Update README.md * Delete figure_1.png * Add files via upload * Update paper.md * Add files via upload * Create taxi.md * Update nav.yml * Update batch.md * Update streaming.md * Update streaming.md * Update streaming.md * Update streaming.md * Update taxi.md * Update related-work.md * Update related-work.md * Update related-work.md * Update tree-construction.md * Update insert-and-delete.md * Update anomaly-scoring.md * Update related-work.md * Update tree-construction.md * Update insert-and-delete.md * Update taxi.md * Update README.md * Update batch.md * Update streaming.md * Updates to authors * Update paper * updated abhi orcid * Create rctree-api.md * Update rctree-api.md * Update rctree-api.md * Update rctree-api.md * Update rctree-api.md * Update rctree-api.md * Update rctree-api.md * Update rctree-api.md * Update nav.yml * Update rctree-api.md * Update rctree-api.md * Update docstrings * Update rctree-api.md * Update rctree-api.md * Update anomaly-scoring.md * Update random-cut-tree.md * Update rctree-api.md * Update related-work.md * Update rctree-api.md * Update setup.py * Update __init__.py * Update paper.md * Update paper.md * JOSS review updates (#48) * Working version of insert_point * Fix bug with query and insertpoint * Cleanup disp and codisp functions * Reorder methods * Insertpoint operational, add docstrings * Small fix * Remove old files * Allow empty tree; handle duplicates in insert_point and forget_point * Account for duplicates in tree construction * Add ability to print tree * Update docstrings and minor fixes * Docstring fix * Minor fixes * Bugfix for forget_point * Add image * Update readme * Update README.md * Type check for point * Update README.md * Update README.md * Store bounding boxes * Minor changes * Fix bbox bug, add unit tests * Add support for CI * Remove Python 3.7 * Update README.md * Fix duplicate precision bug * Fix duplicates issue? * Use new indexing strategy with forget_point * Update n bug * Return 0 for codisp if leaf is root * Add efficient shingle * Add sine wave image * Update README.md * Minor cleanup * sklearn test * Add classification notebook * Updated gitignore * Edit classification notebook * taxi data test * removed swamp * taxi data 200 tree run * IF test * Add OC-SVM example with sine wave * Add OC-SVM example with taxi data * Add IF example with sine wave * Minor changes * Minor updates * Delete old sine_ocsvm_test notebook * Delete old taxi_ocsvm_test notebook * Delete old sine_if notebook * Add IF example with sine wave * Add OC-SVM example with sine wave * Add OC-SVM example with taxi data * Delete old taxi_ocsvm notebook * Add OC-SVM example with taxi data * sine wave comaprasion * table1 notebook * rrcf notebook * renamed rrcf * taxi data if * Fix shingle bug; clean up classification example * Set theme jekyll-theme-minimal * Add index labels * Update batch image * Update README.md * Update README.md * Update README.md * Create _config.yml * Create default.html * Create index.md * Update index.md * Create nav.html * Create nav.yml * Create tree-construction.html * Rename tree-construction.html to tree-construction.md * Create insert-and-delete.md * Create anomaly-scoring.md * Create batch.md * Create streaming.md * Update tree-construction.md * Update tree-construction.md * Update tree-construction.md * Update tree-construction.md * Update tree-construction.md * Update tree-construction.md * Update insert-and-delete.md * Update insert-and-delete.md * Update tree-construction.md * Update insert-and-delete.md * Update insert-and-delete.md * Update anomaly-scoring.md * Create related-work.md * Update nav.yml * Update related-work.md * Create random-cut-tree.md * Update nav.yml * Create modifying-rctree.md * Update nav.yml * Update random-cut-tree.md * Update random-cut-tree.md * Update random-cut-tree.md * Update random-cut-tree.md * Update modifying-rctree.md * Update random-cut-tree.md * Create scoring-rctree.md * Update nav.yml * Update scoring-rctree.md * Update README.md * Update README.md * Update index.md * Update index.md * Update index.md * Create paper.md * Create paper.bib * Add files via upload * Update paper.md * Update README.md * Delete figure_1.png * Add files via upload * Update paper.md * Add files via upload * Create taxi.md * Update nav.yml * Update batch.md * Update streaming.md * Update streaming.md * Update streaming.md * Update streaming.md * Update taxi.md * Update related-work.md * Update related-work.md * Update related-work.md * Update tree-construction.md * Update insert-and-delete.md * Update anomaly-scoring.md * Update related-work.md * Update tree-construction.md * Update insert-and-delete.md * Update taxi.md * Update README.md * Update batch.md * Update streaming.md * Updates to authors * Update paper * updated abhi orcid * Create rctree-api.md * Update rctree-api.md * Update rctree-api.md * Update rctree-api.md * Update rctree-api.md * Update rctree-api.md * Update rctree-api.md * Update rctree-api.md * Update nav.yml * Update rctree-api.md * Update rctree-api.md * Update docstrings * Update rctree-api.md * Update rctree-api.md * Update anomaly-scoring.md * Update random-cut-tree.md * Update rctree-api.md * Update related-work.md * Update rctree-api.md * Update setup.py * Update __init__.py * Update paper.md * Update paper.md * Update README.md * Update paper.bib * Update paper.md * Update paper.md * JOSS review suggested changes * Add license badge * Move installation instructions; list dependencies * Add coveralls support * Add classification and comparison to docs * Move notebook material into documentation * Add example data * Update data locations in docs * Fix error with coveralls build * Add coveralls badge * Add init for pytest * Increase test coverage --- .travis.yml | 2 +- README.md | 2 +- test/__init__.py | 0 test/test_rrcf.py | 57 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 test/__init__.py diff --git a/.travis.yml b/.travis.yml index 14c5169..a3c42c2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,6 +9,6 @@ install: - pip install coveralls # command to run tests script: - - pytest --cov=pysheds/ + - pytest --cov=rrcf/ after_success: - coveralls diff --git a/README.md b/README.md index 0a42e14..03d4291 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # rrcf 🌲🌲🌲 -[![Build Status](https://travis-ci.org/kLabUM/rrcf.svg?branch=master)](https://travis-ci.org/kLabUM/rrcf) [![Python 3.6](https://img.shields.io/badge/python-3.6-blue.svg)](https://www.python.org/downloads/release/python-360/) ![GitHub](https://img.shields.io/github/license/kLabUM/rrcf.svg) +[![Build Status](https://travis-ci.org/kLabUM/rrcf.svg?branch=master)](https://travis-ci.org/kLabUM/rrcf) [![Coverage Status](https://coveralls.io/repos/github/kLabUM/rrcf/badge.svg?branch=master)](https://coveralls.io/github/kLabUM/rrcf?branch=master) [![Python 3.6](https://img.shields.io/badge/python-3.6-blue.svg)](https://www.python.org/downloads/release/python-360/) ![GitHub](https://img.shields.io/github/license/kLabUM/rrcf.svg) Implementation of the *Robust Random Cut Forest Algorithm* for anomaly detection by [Guha et al. (2016)](http://proceedings.mlr.press/v48/guha16.pdf). diff --git a/test/__init__.py b/test/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/test/test_rrcf.py b/test/test_rrcf.py index ffbef6a..6b6cf25 100644 --- a/test/test_rrcf.py +++ b/test/test_rrcf.py @@ -5,7 +5,11 @@ n = 100 d = 3 X = np.random.randn(n, d) +Z = np.copy(X) +Z[90:, :] = 1 + tree = rrcf.RCTree(X) +duplicate_tree = rrcf.RCTree(Z) deck = np.arange(n, dtype=int) np.random.shuffle(deck) @@ -23,6 +27,16 @@ def test_batch(): bbox = tree.get_bbox(branch) assert (bbox == branch.b).all() +def test_codisp(): + for i in range(100): + codisp = tree.codisp(i) + assert codisp > 0 + +def test_disp(): + for i in range(100): + disp = tree.disp(i) + assert disp > 0 + def test_forget_batch(): # Check stored bounding boxes and leaf counts after forgetting points for index in indexes: @@ -71,3 +85,46 @@ def test_insert_batch(): print('Computed:\n', bbox) print('Stored:\n', branch.b) raise + +def test_batch_with_duplicates(): + # Instantiate tree with 10 duplicates + leafcount = duplicate_tree._count_leaves(tree.root) + assert (leafcount == n) + for i in range(90, 100): + try: + assert duplicate_tree.leaves[i].n == 10 + except: + print(i) + print(duplicate_tree.leaves[i].n) + raise + +def test_insert_duplicate(): + # Insert duplicate point + point = (1., 1., 1.) + leaf = duplicate_tree.insert_point(point, index=100) + assert leaf.n == 11 + for i in range(90, 100): + try: + assert duplicate_tree.leaves[i].n == 11 + except: + print(i) + print(duplicate_tree.leaves[i].n) + raise + +def test_find_duplicate(): + # Find duplicate point + point = (1, 1, 1) + duplicate = duplicate_tree.find_duplicate(point) + assert duplicate is not None + +def test_forget_duplicate(): + # Forget duplicate point + leaf = duplicate_tree.forget_point(100) + for i in range(90, 100): + assert duplicate_tree.leaves[i].n == 10 + +def test_shingle(): + shingle = rrcf.shingle(X, 3) + step_0 = next(shingle) + step_1 = next(shingle) + assert (step_0[1] == step_1[0]).all()