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

TM.anomaly: fix score for likelihood anomaly modes #666

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

breznak
Copy link
Member

@breznak breznak commented Sep 16, 2019

we used to return likelihood (of the score), but for anomaly we must return 1 - likelihood

Fixes #665

TODO:

  • optionally integrate sine wave tests for anomaly modes

@breznak
Copy link
Member Author

breznak commented Sep 16, 2019

I'd like to include the sine wave experiments before this is merged.

@breznak breznak self-assigned this Sep 18, 2019
we returned likelihoods, but TM.anomaly should return anomaly scores,
thus we need to return 1.0-likelihood

Thanks @Thanh-Binh for reporting this issue!
@breznak breznak changed the title TM.anomaly: improve doc for anomaly modes TM.anomaly: fix score for likelihood anomaly modes Sep 18, 2019
@breznak breznak added the ready label Sep 18, 2019
@breznak
Copy link
Member Author

breznak commented Sep 18, 2019

Please review, @Thanh-Binh does this resolve the issue in your tests?
I have a test-case comming in a separate PR.

Copy link

@dkeeney dkeeney left a comment

Choose a reason for hiding this comment

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

I see no problem.
Thanks for the expanded explanations.

@breznak
Copy link
Member Author

breznak commented Sep 18, 2019

Thanks for reviewing!
I'm waiting a bit for @Thanh-Binh if he has time to confirm the seen issue is resolved, otherwise I'll just merge this soon.

@Thanh-Binh
Copy link

@breznak for log-likelihood, I think your proposal

      const Real like = tmAnomaly_.anomalyLikelihood_.anomalyProbability(raw);
      const Real log  = tmAnomaly_.anomalyLikelihood_.computeLogLikelihood(like);
      tmAnomaly_.anomaly_ = 1.0f - log;

is not correct.

I believe it should be :

      const Real like = tmAnomaly_.anomalyLikelihood_.anomalyProbability(raw);
      const Real log  = tmAnomaly_.anomalyLikelihood_.computeLogLikelihood(1.0 - like);
      tmAnomaly_.anomaly_ = log;

@breznak
Copy link
Member Author

breznak commented Sep 18, 2019

believe it should be :

this is one thing I'm considering: if we want to log anomaly (= 1-like) or the likelihoods (?)

does

const Real log = tmAnomaly_.anomalyLikelihood_.computeLogLikelihood(1.0 - like);
behave "correctly" like the plain likelihood (but anomaly) mode?

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.

I'm calling hold-off on this PR, until this is properly explained and tested.

@@ -506,7 +506,8 @@ void TemporalMemory::compute(const SDR &activeColumns,
const Real raw = computeRawAnomalyScore(
activeColumns,
cellsToColumns( getPredictiveCells() ));
tmAnomaly_.anomaly_ = tmAnomaly_.anomalyLikelihood_.anomalyProbability(raw);
tmAnomaly_.anomaly_ = 1.0f - tmAnomaly_.anomalyLikelihood_.anomalyProbability(raw); // AnomalyLikelihood returs a likelihood of the score (given past scores),
// and we want to detect unlikely scores, aka big changes -> 1.0-likelihood represents "anomaly"
Copy link
Member Author

Choose a reason for hiding this comment

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

actually, I'm not sure this is correct at all.
Revisitiing anomaly likelihood in original Numenta's py code:

def anomalyProbability(self, value, anomalyScore, timestamp=None):
"""
Compute the probability that the current value plus anomaly score represents
an anomaly given the historical distribution of anomaly scores. The closer
the number is to 1, the higher the chance it is an anomaly.
...

And both codes (Numenta's py, and ours cpp) internally toggle likelihoods to anomaly before returning
likelihood = 1.0 - likelihoods[0], so doing another 1-anomalyProbability() switches back to likelihoods[0]

So, according to docs and logic of the code, the TM.anomaly should represent anomalyProbability() in AnomalyLikelihood.

@Thanh-Binh can you describe in detail your experiment and where you see errors? We must replicate it here, ideally even simpler, synthetic test for likelihood: anomaly scores high 1.0, 0.9, 0.98, 1.0, ... -> anomalyProbability() should drop. Same for low score: 0.0, 0.1, 0.05, 0.0,.. -> anProb() drops to 0.
For a sudden change (high anomalies -> low, and vice versa) the anProb() should be high.

@breznak breznak removed the ready label Sep 19, 2019
@Zbysekz Zbysekz closed this Jun 26, 2020
@Zbysekz Zbysekz deleted the anomaly_likelihood_docs branch June 26, 2020 06:56
@breznak breznak restored the anomaly_likelihood_docs branch June 26, 2020 07:01
@breznak breznak reopened this Jun 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Anomaly Likelihood does not work correctly!
4 participants