# Mapping the hyper parameter space of classifcation using SP

**URL:** <https://discourse.numenta.org/t/mapping-the-hyper-parameter-space-of-classifcation-using-sp/6815>\
**Category:** Engineering\
**Created:** [November 16, 2019, 3:00am UTC](https://discourse.numenta.org/t/mapping-the-hyper-parameter-space-of-classifcation-using-sp/6815 "2019-11-16T03:00:26Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![marty1885](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.numenta.org/marty1885/32/1891_2.png) [@marty1885](https://discourse.numenta.org/u/marty1885)\
**Post date:** [November 16, 2019, 3:00am UTC](https://discourse.numenta.org/t/mapping-the-hyper-parameter-space-of-classifcation-using-sp/6815/1 "2019-11-16T03:00:26Z")

</div>

Again, this is one of my stupid engineering ideas. In the past, HTM use swarming for hyper parameter optimization. But I find no data about how the hyper parameter space looks like. Is is like Neural Networks’s non-continuous, full of local minimum one? Or is it smooth and in fact we can use gradient assent for hyper-param optimization?

So I decided to map out a simple 2D parameter space (boost strength and # of bits). To see the surface for myself. The setup is to have 2 free variables, boost strength and # of bits of the SP’s output. And we measure the accuracy of the classification to create a 2D map of the hyperparam space.

 ![c1](https://canada1.discourse-cdn.com/flex030/uploads/numenta/original/2X/5/546e5f1c5ec2b984b23c4fdb840362b9179c90c3.png)

(The classier scores a **40% accuracy when directly operating on the images without a SP**. So it is possible to get worse performance with bad parameter.)

The parameter space isn’t exactly smooth. But (from experience) looks like momentum enabled gradient optimization can work. It also seems like we get the best performance when boost strength = ~0.1. Coincidentally being `1/num_classes` in this case. Not saying the relation is definite.

Other picture from another angle:

 ![c1](https://canada1.discourse-cdn.com/flex030/uploads/numenta/original/2X/5/5d7879fe43000301d3a236b19f11804328de4238.png)

If we look at a slice of the map at `boost factor = 0`, we can approximate the plot pretty well with a linear function. But I don’t suspect the trend keeping this way too much.

 ![c1](https://canada1.discourse-cdn.com/flex030/uploads/numenta/original/2X/9/972987cf1870f61ef9dbdeffa2265df601a7fe43.png)

We can find the general trend (instead of the details) by smoothing the plot a bit. Basically, the more bits, the better. But you should set boost factor to 0.1

 ![c1](https://canada1.discourse-cdn.com/flex030/uploads/numenta/original/2X/f/f67a09dddbefeaddeaabbada52c2ec6cf2906d48.png)

This is the _source code_ for the plot. Run it in ROOT and the plot will show up.

> <https://gist.github.com/marty1885/afbe7734281254133b2176ad01f8d0e6>

And the original data.

> **[record.npy](https://drive.google.com/file/d/1NUNoICDrmjQelOg5ZoS-CXEEDWkkX0-g/view?usp=sharing)**
>
> Google Drive file.

Let me know what else/analysis can I do with this data. I have no idea.

#### Other findings

For some reason or another. Zen 2 CPU performs extremely well for HTM. My Zen 2 machine though running at a lower RAM speed, is overall 40% faster than a Zen 1.

---

<div class="post-metadata">

**Author:** ![brev](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.numenta.org/brev/32/5548_2.png) [@brev](https://discourse.numenta.org/u/brev)\
**Post date:** [November 16, 2019, 6:39am UTC](https://discourse.numenta.org/t/mapping-the-hyper-parameter-space-of-classifcation-using-sp/6815/2 "2019-11-16T06:39:39Z")

</div>

Thanks @marty1885, I’ve been curious about this for years!

---

<div class="post-metadata">

**Author:** ![SeanOConnor](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.numenta.org/seanoconnor/32/3441_2.png) [@SeanOConnor](https://discourse.numenta.org/u/SeanOConnor)\
**Post date:** [November 16, 2019, 8:08am UTC](https://discourse.numenta.org/t/mapping-the-hyper-parameter-space-of-classifcation-using-sp/6815/3 "2019-11-16T08:08:22Z")

</div>

I always use this algorithm for optimization:  
[https://www.cs.bham.ac.uk/~jer/papers/ctsgray.pdf](https://www.cs.bham.ac.uk/~jer/papers/ctsgray.pdf)  
It uses a simple mutation operator to produce a child vector from a parent vector. Then see if the child vector is better than the parent vector.

The mutation for parameters that are constrained to be between -1 and 1 is random plus or minus 2.exp(-p.rnd()) where rnd() returns a uniform random number between 0 and 1 and p is the precision of the mutation. You add such a mutation to each element of the parent vector to get the child vector. You have some choices about what to do if any of the child elements go beyond the -1 to 1 range. I choose to return them to the corresponding parent value.  
What’s the use of all that?  
1/ It’s simple.  
2/ It works well.  
3/ The mutations are scale free. A mutation of 1 is equally as likely as one of 0.0000001. You are going to get a mutation at any scale needed relatively soon.  
4/ A parameter can radically change it value in a single shot. -1 can be mutated to 1 in one step. This allows a much better chance to step out of a local minimum compared to crawling around the cost landscape with consistently tiny changes to parameters.

---

<div class="post-metadata">

**Author:** ![marty1885](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.numenta.org/marty1885/32/1891_2.png) [@marty1885](https://discourse.numenta.org/u/marty1885)\
**Post date:** [November 18, 2019, 1:47am UTC](https://discourse.numenta.org/t/mapping-the-hyper-parameter-space-of-classifcation-using-sp/6815/4 "2019-11-18T01:47:33Z")

</div>

This looks like some sort of genetic/annealing based method. Interesting.

---

<div class="post-metadata">

**Author:** ![gmirey](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.numenta.org/gmirey/32/2245_2.png) [@gmirey](https://discourse.numenta.org/u/gmirey)\
**Post date:** [November 20, 2019, 8:56pm UTC](https://discourse.numenta.org/t/mapping-the-hyper-parameter-space-of-classifcation-using-sp/6815/5 "2019-11-20T20:56:47Z")

</div>

> [@marty1885](#):
>
> But you should set boost factor to 0.1

As a side note, here is the potential space for the boost “value” of each column with such a boost “factor” of 0.1  
 ![BoostingOneTenth](https://canada1.discourse-cdn.com/flex030/uploads/numenta/original/2X/7/7936000981672747c1b23fc60843cb3ed02fc86d.jpeg)  
…  
probably worth skipping the call to an exponential function, by the look of it 😛

---

<div class="post-metadata">

**Author:** ![marty1885](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.numenta.org/marty1885/32/1891_2.png) [@marty1885](https://discourse.numenta.org/u/marty1885)\
**Post date:** [November 21, 2019, 2:39am UTC](https://discourse.numenta.org/t/mapping-the-hyper-parameter-space-of-classifcation-using-sp/6815/6 "2019-11-21T02:39:57Z")

</div>

> [@gmirey](#):
>
> probably worth skipping the call to an exponential function, by the look of it 😛

Not really. The boost factor is a scalar applied to the average activation frequency to generate the boosting. Assuming we have the cells’ value `x` , the average active frequency `a` , the expected activation frequency `t` and the boost factor `b` (how aggressively the boosting should be). We can calculate the new value after boosting `x'` as `x' = x*exp((t-a)*b)` . Assuming having t=0.15, b = 2.5 thus having the function `f(x) = exp((0.15-x)*2.5)` . We can plot it as:

 ![c1](https://canada1.discourse-cdn.com/flex030/uploads/numenta/original/2X/3/3481123d74dd4c82f3719054c08ec070c51f6cb7.png)

---

<div class="post-metadata">

**Author:** ![Bitking](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.numenta.org/bitking/32/3099_2.png) [@Bitking](https://discourse.numenta.org/u/Bitking)\
**Post date:** [November 21, 2019, 3:09am UTC](https://discourse.numenta.org/t/mapping-the-hyper-parameter-space-of-classifcation-using-sp/6815/7 "2019-11-21T03:09:11Z")

</div>

If you use Subutai’s 8 bit values you can do this with a lookup table for blinding speed. For that matter, if you need better resolution a megabyte table is not unreasonable with today’s hardware.

---

<div class="post-metadata">

**Author:** ![gmirey](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.numenta.org/gmirey/32/2245_2.png) [@gmirey](https://discourse.numenta.org/u/gmirey)\
**Post date:** [November 21, 2019, 9:10am UTC](https://discourse.numenta.org/t/mapping-the-hyper-parameter-space-of-classifcation-using-sp/6815/8 "2019-11-21T09:10:16Z")

</div>

> [@marty1885](#):
>
> Assuming having t=0.15, b = 2.5 thus having the function `f(x) = exp((0.15-x)*2.5)`

Yup.  
But I was plotting for your proposed b = 0.1

“how aggressive the boosting should be” is for all intents and purpose a config value, only “variable” during research and tweak rounds to pin-point an ideal behaving function.  
Now… you seem to have proposed arguments for a sweet-spot of 0.1 for it, so if we consider we’ve done with “research and tweak rounds” in that regard, we can look at the resulting function as if b was constant.

Now we see that the `exp((t-a)*b)` evaluated over (t-a) in [-1…1] with b fixed to 0.1 is like my plot 🙂  
I personally have implemented the resulting boosting function as linear.

---

<div class="post-metadata">

**Author:** ![marty1885](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.numenta.org/marty1885/32/1891_2.png) [@marty1885](https://discourse.numenta.org/u/marty1885)\
**Post date:** [November 21, 2019, 1:38pm UTC](https://discourse.numenta.org/t/mapping-the-hyper-parameter-space-of-classifcation-using-sp/6815/9 "2019-11-21T13:38:41Z")

</div>

> [@gmirey](#):
>
> But I was plotting for your proposed b = 0.1

Stupid me. I see. 😛

 ![c1](https://canada1.discourse-cdn.com/flex030/uploads/numenta/original/2X/3/3104ba0500c9bbb795e9cfde26458502597d7be7.png)

> [@gmirey](#):
>
> you seem to have proposed arguments for a sweet-spot of 0.1

For MNIST, yes. (The experiment was MNIST classification). But I’m not sure about anomaly detection and other kinds of classifications.

---

<div class="post-metadata">

**Author:** ![AMZ](https://avatars.discourse-cdn.com/v4/letter/a/65b543/32.png) [@AMZ](https://discourse.numenta.org/u/AMZ)\
**Post date:** [November 21, 2019, 6:27pm UTC](https://discourse.numenta.org/t/mapping-the-hyper-parameter-space-of-classifcation-using-sp/6815/10 "2019-11-21T18:27:52Z")

</div>

I do not recommend using boosting with MNIST as long as the input space is not statistically uniform.

---

<div class="post-metadata">

**Author:** ![marty1885](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.numenta.org/marty1885/32/1891_2.png) [@marty1885](https://discourse.numenta.org/u/marty1885)\
**Post date:** [November 22, 2019, 12:34am UTC](https://discourse.numenta.org/t/mapping-the-hyper-parameter-space-of-classifcation-using-sp/6815/11 "2019-11-22T00:34:10Z")

</div>

But the evidence show a tiny boost can increase the performance. 😄

---

<div class="post-metadata">

**Author:** ![AMZ](https://avatars.discourse-cdn.com/v4/letter/a/65b543/32.png) [@AMZ](https://discourse.numenta.org/u/AMZ)\
**Post date:** [November 22, 2019, 2:49pm UTC](https://discourse.numenta.org/t/mapping-the-hyper-parameter-space-of-classifcation-using-sp/6815/12 "2019-11-22T14:49:31Z")

</div>

I see your point! Honestly, I would agree if you got high classification accuracy. My recommendation is to achieve state-of-art performance or at least something close (I believe in HTM, you can achieve up to (94-96)% with MNIST), Then, try to see if the boosting can improve the performance further.

---

<div class="post-metadata">

**Author:** ![marty1885](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.numenta.org/marty1885/32/1891_2.png) [@marty1885](https://discourse.numenta.org/u/marty1885)\
**Post date:** [November 22, 2019, 2:54pm UTC](https://discourse.numenta.org/t/mapping-the-hyper-parameter-space-of-classifcation-using-sp/6815/13 "2019-11-22T14:54:07Z")

</div>

> [@AMZ](#):
>
> I believe in HTM, you can achieve up to (94-96)% with MNIST

The 98% accuracy is done by using a SDRClassifer. Which is a softmax regresser(i.e. a single layer neural network w/ softmax). So… Kinda yes and no. The plot I show is using an old CLAClassifer. It is more biologically consistent.

---

<div class="post-metadata">

**Author:** ![thanh-binh.to](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.numenta.org/thanh-binh.to/32/1793_2.png) [@thanh-binh.to](https://discourse.numenta.org/u/thanh-binh.to)\
**Post date:** [November 22, 2019, 5:34pm UTC](https://discourse.numenta.org/t/mapping-the-hyper-parameter-space-of-classifcation-using-sp/6815/14 "2019-11-22T17:34:15Z")

</div>

@marty1885 currently we reach 96%. 98% is excellent result

---

<div class="post-metadata">

**Author:** ![AMZ](https://avatars.discourse-cdn.com/v4/letter/a/65b543/32.png) [@AMZ](https://discourse.numenta.org/u/AMZ)\
**Post date:** [November 22, 2019, 7:09pm UTC](https://discourse.numenta.org/t/mapping-the-hyper-parameter-space-of-classifcation-using-sp/6815/15 "2019-11-22T19:09:48Z")

</div>

@marty1885, have you got the 98%? Any reference?

Thanks,

---

<div class="post-metadata">

**Author:** ![marty1885](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.numenta.org/marty1885/32/1891_2.png) [@marty1885](https://discourse.numenta.org/u/marty1885)\
**Post date:** [November 23, 2019, 4:06am UTC](https://discourse.numenta.org/t/mapping-the-hyper-parameter-space-of-classifcation-using-sp/6815/16 "2019-11-23T04:06:22Z")

</div>

With the biological consistent classier? Wow, I must be doing something wrong.

---

<div class="post-metadata">

**Author:** ![gmirey](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.numenta.org/gmirey/32/2245_2.png) [@gmirey](https://discourse.numenta.org/u/gmirey)\
**Post date:** [November 26, 2019, 9:35pm UTC](https://discourse.numenta.org/t/mapping-the-hyper-parameter-space-of-classifcation-using-sp/6815/17 "2019-11-26T21:35:17Z")

</div>

Toying with different boost functions and strengths atm, trying to investigate what SP does.

What I’m getting out of it is that activation of similar-columns when similar-input from one epoch to the next can get really scrambled with too aggressive a boost function. Thus we’d expect the subsequent TM to be more at a loss remembering anything.

> [@marty1885](#):
>
> For MNIST, yes. (The experiment was MNIST classification). But I’m not sure about anomaly detection and other kinds of classifications.

SP method + boosting method & level + learning strength + input signal distribution + wait for how long (I’ve seen stuff strangely stabilizing over… really long periods at times) + which to prefer between output stability and “every cell shall carry equal information” = some quite high “hyper” parameter space to explore indeed… too high for me at least ☹
