Skip to content

Projects

DavidRagazzi edited this page Nov 17, 2014 · 17 revisions

This chapter provides a brief description of how a project is organized. This will familiarize you with how to create a project and check its internal details.

Creating your first project!

In order to create a new project just click on the File > New Project menu. NuPIC Studio creates a minimal project, with only one region, which is naturally named "Top Region"�. If you try to simulate a neural network at this point, NuPIC Studio will emit an error simply because your neural network has no child element (i.e. a region or sensor) to feed it. So we need to add a child element to the "Top Region"�.

We will create a very simple network with only a single region and one sensor feeding it. Simply click on "Top Region"� with the right mouse-button. In the context menu provided, just click on Add new sensor here� menu.

Now save your new project. Click on File > Save Project menu and specify a name and location for it. You project will be saved to a file with a .nuproj extension.

So.. What is the next step? Well, we need to set the parameters for each one of the two nodes.

Setting a Region

To configure the region just click on it with right mouse-button, then click on the Properties menu in the context menu that is provided. Now you can set the architecture and also spatial and temporal parameters of this region. Any detailed discussion of the parameters for a region would make this tutorial too big, thus we strongly advise you to check the "tool tip"� for each text field; i.e. that yellow rectangle that is shown when you move the mouse over a control. Additionally you can peruse some examples provided with NuPIC Studio and the NuPIC wiki to get a better idea of the best parameter values for your region.

Setting a Sensor

To configure the sensor follow the same steps that you did to set the region. First specify if the inputs will come from a single file or from a database. If from a file, click on File option and on the Browse File button and then pick your file. If from a database, click on the Database option and specify the connection string, the database, and finally the database field of the table.

Setting a sensor is not difficult, but requires some previous knowledge of how the inputs are organized as well as how the encoders are integrated into a sensor.

The logic for understanding the role of a sensor is to remember that any input fed into an HTM region should be a fixed array composed of 0's and 1's. This said, a sensor has two kinds of data that it can receive and re-send to a region:

  • Converted: it is a fixed array of 0's and 1's ready to be fed into a region. The sensor receives this array and re-sends it without any handling.
  • Raw: is a natural value, i.e. a integer, scalar, or string value that needs to be converted into an array of 0's and 1's. This conversion is performed by an encoder.

To configure the type of data just click either on the Converted or the Raw option. If you choose the Raw option, you must specify its primitive type (boolean, integer, date/time, etc) to be handled and its encoder.

To specify an encoder you should fill three essential fields:

  • Module: the python module which the encoder class is located. Ex: nupic.encoders.scalar
  • Class: the encoder class to be handled by NuPIC Studio. Ex: ScalarEncoder
  • Parameters: the list of parameters to be passed to the class constructor. Ex:
parameter    value
==========   =====
w            3
minval       0
maxval       99
n            60
forced       True

Note that there are 2 ways to handle predictions using encoders:

  • Reconstruction: the encoder receives the array of predicted columns and returns the original value represented by such array.
  • Classification: the encoder return predictions based on bit history of the current input.

An encoder class should basically contains the following functions:

  • encode(self, rawData): This function should basically receive a natural value and return an array of 0's and 1's.
  • decode(self, arrayData): This function should basically receive an array and return the original natural value. Not required by Classification method.

During the simulation, NuPIC Studio will import the specified class for call these two functions. First, it will pass the natural value that it received from the file or database that you specified (to encode(rawData) function), and then feed the parent region with the array returned by this function. Then after the region computes this and other inputs, NuPIC Studio will pass the output array (i.e. the prediction) returned by the region and pass it to decode(arrayData) function.

If we try manually code all these actions we would have something like this:

# Import the encoder class
from nupic.encoders.scalar imports ScalarEncoder

# Create an instance of the encoder class
scalarEncoder = ScalarEncoder(w=3, minval=0, maxval=99, n=60, forced=True)

    ...

    # Read a natural value from file, convert it to array,
    # and pass it as input to region
    currentValue = file.readLine()
    inputArray = scalarEncoder.encode(currentValue)
    region.setInput(inputArray)

    ...

    # Get the output array (i.e. prediction) from region 
    # and convert it to its original natural value
    outputArray = region.getOutput()
    predictedValue = scalarEncoder.decode(outputArray)

To visualize the current and the predicted natural values during the simulation just click on a sensor to see its details. You will see something like this:

Encoded and Decoded Values

Before we finish, you should know how raw and converted data should be organized in a file or database table.

In the case of a single file, natural values should be separated by a line break:

20
23
19
17

while converted arrays also should be separated by a line break but grouped by its height and width. So if we have a sensor with width = 6 and height = 4, the file content should be something like:

110000
000000
000000
000000

000000
011000
000000
000000

000000
000000
000110
000000

In the case where the datasource is a database table, every input should be in a single column in the table that you specified. For converted data, you should use string-type datafield.

Prev: Simulation

Clone this wiki locally