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

HTM community detector (py3) #5

Merged
merged 16 commits into from
Jul 29, 2019
Merged

Conversation

breznak
Copy link
Member

@breznak breznak commented Jul 24, 2019

Adds htm.core https://github.com/htm-community/htm.core as a detector

Currently WIP, please review after #2 is merged as this builds atop that.

Features

  • native htm.core improvements

  • python3

  • installs htm.core seamlessly

  • finish the HtmcoreDetector detector

    • inspired from nab/detectors/numenta/numenta*_detector.py here; py/htm/examples/hotgym.py in htm.core
  • run on all data and commit results

    • add to comparison Score board

TODO optional in separate PRs

For numenta#337 where it should be then submitted as well

Fixes htm-community/htm.core#205

@breznak breznak added the enhancement New feature or request label Jul 24, 2019
@breznak breznak self-assigned this Jul 24, 2019
runable POC for community HTM detector from famous htm.core repo!
Copy link
Member Author

@breznak breznak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review with planned work to do.

If you have time, @dkeeney @ctrl-z-9000-times please have a look at the TODOs, I'll be implementing some here, some to htm.core

nab/detectors/htmcore/README.md Outdated Show resolved Hide resolved

def getAdditionalHeaders(self):
"""Returns a list of strings."""
return ["raw_score"] #TODO add "prediction"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO output also predictions

nab/detectors/htmcore/htmcore_detector.py Outdated Show resolved Hide resolved
nab/detectors/htmcore/htmcore_detector.py Outdated Show resolved Hide resolved
rawScore = 0.5 #FIXME result.inferences["anomalyScore"]

# Update min/max values and check if there is a spatial anomaly
spatialAnomaly = False #TODO make this computed in SP (and later improve)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

# Compute log(anomaly likelihood)
anomalyScore = self.anomalyLikelihood.anomalyProbability(inputData["value"], rawScore, inputData["timestamp"])
logScore = self.anomalyLikelihood.computeLogLikelihood(anomalyScore)
finalScore = logScore #TODO returls logScore and not probability? Fix that in our Likelihood.cpp; #TODO TM to provide anomaly {none, raw, likelihood}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nab/detectors/htmcore/htmcore_detector.py Outdated Show resolved Hide resolved
nab/detectors/htmcore/htmcore_detector.py Outdated Show resolved Hide resolved

curr_dir = os.getcwd()
os.chdir(REPO_DIR)
os.system("git clone --depth=5 https://github.com/htm-community/htm.core")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when htm.core can be available on PyPI, skip all this mess htm-community/htm.core#19

@@ -159,7 +159,7 @@ def main(args):
parser.add_argument("-d", "--detectors",
nargs="*",
type=str,
default=["numenta", "numentaTM", "htmjava", "null", "random",
default=["numenta", "numentaTM", "htmcore", "htmjava", "null", "random",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new htmcore detector!

params and initialization same as in hotgym.py example in htm.core repo.
With one expection: RDSE resulotion changed to match one of
numenta_detector, not the former value swarmed in hotgym.
implemented the model and runs nice!
(Model same as hotgym.py)
as unused in this (cleaner) HTM model.
not so good, need to optimize parameters.
@breznak breznak changed the title HTM community detector (py3) WIP HTM community detector (py3) Jul 25, 2019
@breznak breznak added the model detector, model label Jul 25, 2019
Copy link
Member Author

@breznak breznak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new NAB detector with our community HTM implementation (htmcore) is ready.

@dkeeney @ctrl-z-9000-times please review, everything is working, additional task would be improving params for our model

| [KNN CAD](https://github.com/htm-community/NAB/tree/master/nab/detectors/knncad)† | 58.0 | 43.4 | 64.8 | | |
| [Relative Entropy](http://www.hpl.hp.com/techreports/2011/HPL-2011-8.pdf) | 54.6 | 47.6 | 58.8 | | |
| [Random Cut Forest](http://proceedings.mlr.press/v48/guha16.pdf) **** | 51.7 | 38.4 | 59.7 | | |
| [htm.core](https://github.com/htm-community/htm.core/) | 50.83 | 49.95 | 52.64 | `htmcore` | |
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

first shot results are not really good, we have to pump it up guys! 📌

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've pushed commit that uses numenta_detector's params, currently running benchmarks

SPATIAL_TOLERANCE = 0.05

## parameters to initialize our HTM model (encoder, SP, TM, AnomalyLikelihood)
# TODO optional: optimize these params, either manually and/or swarming. But first keep comparable to numenta_detector
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO optimize params taken from hotgym

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parameters for the original NAB are written down, somewhere in the original nupic.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parameters for the original NAB

yes, I've created params from the orig nab numenta_detector. But we do not score as well (localAreaDensity instead of removed numActiveColsPerInhArea, more importantly removed BacktrackingTM, which had best results on NAB,...)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, ive started looking at and playing with these parameters, and wow it runs fast! I am optimizing a few of the parameters by hand and will push the results soon. Then i can see about hooking this up to the optimization framework

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am optimizing a few of the parameters by hand and will push the results soon

please do. I've been trying to do some hand-optimizations, but I was still getting much worse results than Numenta's HTM :/

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is the new current score. It's just a few points less than the target.

  • "reward_low_FN_rate": 66.1922106936328,
  • "reward_low_FP_rate": 58.7930712907694,
  • "standard": 63.081419488725054

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new current score. It's just a few points less than the target.

that does look good! 👍 Let's merge this so we can go from there..

nab/detectors/htmcore/htmcore_detector.py Outdated Show resolved Hide resolved
breznak and others added 4 commits July 25, 2019 14:05
use the same params as much as possible to have comparison,
print statistics
FIXME for anomaly computation is not needed, as TM provides TM.anomaly
already!
@ctrl-z-9000-times ctrl-z-9000-times merged commit b2f7862 into master Jul 29, 2019
@ctrl-z-9000-times ctrl-z-9000-times deleted the htm_community_detector branch July 29, 2019 13:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request model detector, model
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Numenta Anomaly Benchmark
2 participants