Debugging your HTM Network

Slashdot  

There are a couple different types of problems that you may encounter as you use HTM networks.

Some issues are relatively easy to debug. For example, if your data files are not in the correct location, the sensor nodes will not find them, and will report an error.

But trickier problems can arise. HTMs can run without producing errors and still have poor recognition performance on new inputs - or even the original training inputs. Often, such issues originate in the network's learning nodes (Zeta1 nodes). Inappropriate parameter settings can hamper node performance without actually causing errors.


This page discusses how to find and remedy problems that occur inside the learning nodes of an HTM network. It contains three sections:

Training one level at a time

If one level of an HTM is not performing well, the level above it will not be able to perform well either, and the performance of the entire hierarchy will suffer. For example, imagine that an L1 node has grouped all its coincidences into a single group. No matter what this node sees during inference, it will always output that same group index, and the parent will have nothing to learn from the node. Neither will its parent, and so on to the top node.


For this reason, we suggest training your HTM one level at a time. First, train the level 1 nodes. Then, look inside the level 1 nodes to see how well they are performing. If you need to, adjust the parameters and retrain level 1. Keep examining and adjusting until it looks like the level 1 nodes are learning fine. Examine 1
Then train level 1 and level 2, and look inside the level 2 nodes. If they look problematic, change their parameters and train again. Examine 1
Keep progressing in this fashion until you've trained the entire hierarchy. Then test the end-to-end accuracy Examine 1

It's possible to look inside the nodes by starting a Session, loading your trained network, and using the Session.execute() method to send commands to the nodes to examine their data structures. But it's far easier to use the Visualizer tool, which was designed for exactly this purpose.



Using Visualizer

This screencast shows you how to use the Visualizer tool to find and fix problems in an HTM Network. We first walk through the Visualizer output using a well-trained Pictures network. Then, we look at what happens when we change the topNeighbors parameter, and how Visualizer helps us see the problem and correct it.



Download Video (28.2 MB)  |  Download Transcript (40 kB)


How to run Visualizer

Running Visualizer is straightforward. There's only one important parameter you need to set, which tells Visualizer how to display the coincidences from your network. In any node, in any network, coincidences are stored as one-dimensional vectors of floats, because HTM networks deal with any kind of input in the same fashion. There's no way to tell whether these coincidences represented pixels of an image, inputs from other nodes, etc. But you can tell Visualizer what kind of data the bottom nodes saw during learning, which allows it to display those coincidences in their original form. The options are:

  •   "image_gray" for grayscale images
  •   "image_bw" for black and white images
  •   "bar_graph" for a bar graph display, useful for any type of 1-dimensional data
  •   "blank" to not attempt to show the coincidences at the bottom level

To run Visualizer, start the python interpreter (or ipython, if you have it). Then, import the Visualizer class:

  •   from nupic.analysis import Visualizer

Create an instance of the Visualizer class, and give it the name of your trained network and the data type:

  •   v = Visualizer(<network_name>, <data_type>)

Then run the visualizeNetwork() method to see the whole network.

  •   v.visualizeNetwork()

Or, you can pass a node name (or a regular expression that matches multiple node names) to only see particular nodes. For example, if your bottom nodes are named level1[0], level1[1], etc., you can just look at those by typing:

  •   v.visualizeNetwork('level1.*')

You may find it's convenient to include these calls at the end of your training script.

If you are using the SimpleHTM class for your network, all you need to do is use its visualize() method, which runs Visualizer.

Happy debugging!

Relevant Wiki Pages & Forums