# Please throw me a clue: finding anomaly \_likelihood\_

**URL:** <https://discourse.numenta.org/t/please-throw-me-a-clue-finding-anomaly--likelihood-/2332>\
**Category:** HTM.Java\
**Created:** [May 19, 2017, 11:41am UTC](https://discourse.numenta.org/t/please-throw-me-a-clue-finding-anomaly--likelihood-/2332 "2017-05-19T11:41:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![phil\_d\_cat](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.numenta.org/phil_d_cat/32/1289_2.png) [@phil\_d\_cat](https://discourse.numenta.org/u/phil_d_cat)\
**Post date:** [May 19, 2017, 11:41am UTC](https://discourse.numenta.org/t/please-throw-me-a-clue-finding-anomaly--likelihood-/2332/1 "2017-05-19T11:41:25Z")

</div>

Im failing to see / find what seems to be a given obvious value: anomaly _likelihood_ (via Java api). Getting the AnomalyScore is plain enough (even for me) via **Observer.onNext(Inference)**

Was referred to this but apparently the answer isn’t in bold, swirling, neon, stroboscopic highlights:

> [@What constitutes an anomaly? How to tune detection?](https://discourse.numenta.org/t/what-constitutes-an-anomaly-how-to-tune-detection/2326/10):
>
> [http://nupic.docs.numenta.org/prerelease/guides/anomaly-detection.html](http://nupic.docs.numenta.org/prerelease/guides/anomaly-detection.html)

If some kind, forgiving person would (in the words of NPR/Cartalk) “attach the answer to a set of monster truck tires” and drop it on me I would be much obliged.

---

<div class="post-metadata">

**Author:** ![cogmission](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.numenta.org/cogmission/32/11_2.png) [@cogmission](https://discourse.numenta.org/u/cogmission)\
**Post date:** [May 19, 2017, 12:04pm UTC](https://discourse.numenta.org/t/please-throw-me-a-clue-finding-anomaly--likelihood-/2332/2 "2017-05-19T12:04:24Z")

</div>

**Copied from other thread**

Hey @phil_d_cat you switch topics too fast! 🙂

> [@What constitutes an anomaly? How to tune detection?](https://discourse.numenta.org/t/what-constitutes-an-anomaly-how-to-tune-detection/2326/9):
>
> RE likelihood score: how to compute that has been bugging me. Suggestions where to look for this?

Anomaly-likelihood is not automatically configured with this first version of HTM.Java’s Network API “Anomaly Detection Feature”. For now, there is simply the anomaly score that is available. However, the NAPI includes a way to insert your own “nodes” (custom nodes) into the processing chain, which could handle Anomaly-Likelihood calculations, if you wanted to write your own node for that.

In fact, inserting “custom” nodes is really easy in HTM.Java! [Check out this test](https://github.com/numenta/htm.java/blob/master/src/test/java/org/numenta/nupic/network/LayerTest.java#L610), for an example.

The “Inference” object also has a method called [`Inference.getCustomObject()`](https://github.com/numenta/htm.java/blob/master/src/main/java/org/numenta/nupic/network/Inference.java#L68) which can be used to retrieve an object inserted into the Inference by the custom “node” (Func or “function” object), see below (as excerpted from the above mentioned test):

```Java
        // Here's the "Func1" object (node added below in: .add(addedFunc) )
        // This example takes in a ManualInput (mutable subclass of Inference), and returns a ManualInput.
        // Below it simply returns a String. where "I" is the "Inference" object and I.customObject() takes in any
        // object (i.e. your custom Anomaly-Likelihood result) and returns the Inference or ManualInput itself.
        Func1<ManualInput, ManualInput> addedFunc = I -> { 
            // Do your Anomaly Likelihood work here?
            return I.customObject("Interposed: " + Arrays.toString(I.getSDR()));
        };

        Network n = Network.create("Generic Test", p)
            .add(Network.createRegion("R1")
                .add(Network.createLayer("L1", p)
                    .add(addedFunc) // <--- Just insert your function
                    .add(new SpatialPooler())));

```

Anomaly-Likelihood has extensive tests which can be referred to [(see here)](https://github.com/numenta/htm.java/blob/master/src/test/java/org/numenta/nupic/algorithms/AnomalyLikelihoodTest.java)

You will have to talk to the Numenta engineers to learn how to use the Anomaly-Likelihood feature (how to track and feed data back in). But all you would do is instantiate your Anomaly-Likelihood object and use it in the above function.

Easy peasy? 🙂

_**(Hint: Try inserting your anomaly experimental code directly into the above mentioned test, that way you can experiment with it and run it?)**_ You’ll need to add a TemporalMemory() also because the above test doesn’t include one.

Cheers,  
David

---

<div class="post-metadata">

**Author:** ![phil\_d\_cat](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.numenta.org/phil_d_cat/32/1289_2.png) [@phil\_d\_cat](https://discourse.numenta.org/u/phil_d_cat)\
**Post date:** [May 19, 2017, 12:23pm UTC](https://discourse.numenta.org/t/please-throw-me-a-clue-finding-anomaly--likelihood-/2332/3 "2017-05-19T12:23:19Z")

</div>

TY. Clue duly felt hitting back of head on canoe paddle. 😆
