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

Anomaly likelihood py #457

Merged
merged 11 commits into from
May 10, 2019
Merged

Anomaly likelihood py #457

merged 11 commits into from
May 10, 2019

Conversation

breznak
Copy link
Member

@breznak breznak commented May 8, 2019

  • AnomalyLikelihood available from pure-python code (/py/) + tests passing
    • this pulls utils.py (MovingAverage) + tests
    • nupic.support for unit-tests
  • some python 2-3 compatibility fixes
  • removed canpn serialization related stuff (will not work in this repo)

Fixes #455 , related #124 #205

@breznak breznak added enhancement New feature or request ready anomaly python not py binding, but merge py code in repo labels May 8, 2019
@breznak breznak self-assigned this May 8, 2019
@ctrl-z-9000-times
Copy link
Collaborator

Wow, this is a lot of code! This will take some time to review...

learningPeriod + estimationSamples iterations.

claLearningPeriod and learningPeriod are specifying the same variable,
although claLearningPeriod is a deprecated name for it.
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should go ahead and remove this deprecated thing.

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'd prefer not in this PR, this just pulls the code from python to this repo.

@breznak
Copy link
Member Author

breznak commented May 8, 2019

This will take some time to review...

Actually I hope this would be an easy review :)

It's basically 1:1 to numenta/nupic's code, which I take for reviewed.
I suggest reviewing commit by commit to see only the changes I did. Rest is pulled from nupic.py branch, which tracks nupic.py repo, which tracks original,old numenta/nupic (with some fixes).

I just checked out the needed files, moved them around to correct locations, and made minimal fixes for py2/3,capnp.

@breznak
Copy link
Member Author

breznak commented May 8, 2019

./../../../build/Release/distr/src/nupic/support/init.py:46: in
from .configuration import Configuration
E ImportError: No module named configuration

I was wondering why that one is not needed locally.

@breznak
Copy link
Member Author

breznak commented May 8, 2019

This PR is large for need to bring up support for runing py unittests from nupic. Once it's inplace, porting a new test should be as simple as just copying the file.

Copy link
Collaborator

@ctrl-z-9000-times ctrl-z-9000-times left a comment

Choose a reason for hiding this comment

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

Will finish code review when I have time.

def __init__(self,
claLearningPeriod=None,
learningPeriod=288,
estimationSamples=100,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Arguments learningPeriod & estimationSamples do very similar things, can they be merged?

else:
distributionParams = estimateNormal(dataValues[skipRecords:])

# HACK ALERT! The HTMPredictionModel currently does not handle constant
Copy link
Collaborator

Choose a reason for hiding this comment

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

!

USAGE
+++++

There are two ways to use the code: using the
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this code actually complicated enough to justify two APIs?




def estimateNormal(sampleData, performLowerBoundCheck=True):
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm pretty sure that numpy/scipy have library functions to do this, which return objects with all sorts of conveniences attached.

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 of all, I want to say I really appreciate you do deep code review where you understand the code and question the implementation! 👍

As for many of these comments, I agree, but I don't want to act on them in this PR which just brings 1:1 code from numenta's, which can be considered for sort of a standard.

I'm pretty sure that numpy/scipy have library functions to do this, which return objects with all sorts of conveniences attached.

as for the justified changes. Yes, the code could (should?) be improved. The result of your review should be fixed in nupic.py (and then brought back here?)

Q: do we want to deviate from Numenta's python implementation? (we said (only API-wise?) we'll keep strong compatibility.

Q: the nupic repo is definitely more alive than nupic.core, should we offer fix there? @rhyolight will you accept it?

Q: actually, do we want to (long term) have PY code here, shouldn't we just focus on API compat with numenta/nupic or community/nupic.py? (I think it's fine to merge all py code in this repo)

Copy link
Member Author

@breznak breznak May 8, 2019

Choose a reason for hiding this comment

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

see numenta/nupic-legacy#3876 -> upstream is abandoning active development of nupic, nupic.core, no changes there.

needed for unit-tests in CI, and probably numenta's use of the tests
(supports default config files)
@ctrl-z-9000-times
Copy link
Collaborator

numenta/nupic's code, which I take for reviewed.

I am deeply suspicious of numenta's code. Their ideas are great, their implementations are in places half baked. However since we have a clear need for this code, and because i dont actually have the time to make this better, i will go easy on this code review and not demand too many changes.

@breznak
Copy link
Member Author

breznak commented May 8, 2019

I am deeply suspicious of numenta's code. Their ideas are great, their implementations are in places half baked.

I have to agree on this one.
Still, that code is published in peer-reviewed papers. It'll be good to have it as baseline, if we fix bugs or make it better, it'll be a documented and replicable improvement.

I'll open a follow up issue to have a crack at AnomalyLikelihood code review when we have time.

Maybe someday?  I think most of the things that the support code does is
already part of the standard library, which is preferable.

- Logging is in the standard library.  Nupic should not implement its
own logger.

- Debugging utilities, use the built in debugger `pdb` instead of
make more tools.

- Configuration, is mostly the users problem.  Nupic should not be
overly concerned about setting up the calling application.
Copy link
Collaborator

@ctrl-z-9000-times ctrl-z-9000-times left a comment

Choose a reason for hiding this comment

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

Breznak,

I deleted the support module since it was not really needed. The commit message has details about why I did this.

The rest of the code is okay to merge. At some point we should clean this up, but it's not critical. You can review my changes, and then go ahead and merge this if you'd like.

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.

👍 👍 removing the nupic.support

@@ -35,7 +35,7 @@
import unittest

from nupic.algorithms import anomaly_likelihood as an
from nupic.support.unittesthelpers.testcasebase import TestCaseBase
from unittest import TestCase as TestCaseBase
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 like this change! Makes the diff much smaller, and I agree we should limit the scope of things we care about.
Thanks 👍

@breznak breznak merged commit aa7f235 into master May 10, 2019
@breznak breznak deleted the anomaly_likelihood_py branch May 10, 2019 14:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
anomaly enhancement New feature or request python not py binding, but merge py code in repo ready
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provide missing AnomalyLikelihood from python
2 participants