Skip to content

NAPI Quick Start Guide

David Ray edited this page Jun 6, 2015 · 39 revisions

Here you can find a more in depth explanation of the NAPI details, together with examples, and links to example code.

Let's get started!

Here's an example of the code it takes to get a full featured network up and running:

Parameters p = NetworkDemoHarness.getParameters();
p = p.union(NetworkDemoHarness.getNetworkDemoTestEncoderParams());

Network network = Network.create("Network API Demo", p)
    .add(Network.createRegion("Region 1")
        .add(Network.createLayer("Layer 2/3", p)
            .alterParameter(KEY.AUTO_CLASSIFY, Boolean.TRUE)
            .add(Anomaly.create())
            .add(new TemporalMemory())
            .add(new SpatialPooler())
            .add(Sensor.create(FileSensor::create, SensorParams.create(
                Keys::path, "", ResourceLocator.path("rec-center-hourly.csv"))))));

network.start();

...and that's it! The above network (while simple), contains a full complement of all NuPIC algorithms and computational devices. Let's list them to get an understanding of what the api is doing underneath - (from bottom to top):

  1. ResourceLocator - Used to locate resources on the classpath such as files or even files in Jars! It provides a virtual resource link to the Sensor. This is very useful, but does have room for improvement/enhancement (hint) :-)

  2. Sensor - Contains 3 flavors: FileSensor, URLSensor, ObservableSensor. These specify different ways to connect to data and submit input into a network.

  3. MultiEncoder - (Not seen above) Is created automagically by all Sensors using the encoder parameters inserted into the Parameters object and header lines found in the given file (or in the case of ObservableSensor which is used for manual/programmatic data submission, headers can be inserted by hand). A MultiEncoder is a specialized encoder which is a container for other encoders. In this case, there are two child encoders created; a Scalar encoder for the "consumption" field (double); and a DateEncoder to parse and encode the date column of the CSV input file.

  4. SpatialPooler - Optionally added to a given network to provide spatial learning.

  5. TemporalMemory - Optionally added to a given network to provide temporal/sequence learning.

  6. CLAClassifier - (Not seen above) ...at least not explicitly. There are two things of note here. The first is that only a Boolean is declared here to indicate that a classifier is desired at this location; and secondly there is this method:

alterParameter(KEY.AUTO_CLASSIFY, Boolean.TRUE) 

This method statement which is specifically injected here, tells the framework to use a copy of the Parameters object within this Layer. Normally, Parameters are inherited from the parent container (i.e. Region or Network), but when used, this method allows local altering of a given parameter without affecting the Parameters object used throughout the network.

  1. Anomaly - The anomaly computer. Can be used as shown above or can be further customized by creation outside of the fluent network declaration.

  2. Layer - Created by a factory method of Network, this is a network specific construct which is the container for all algorithms. Layers are the structure or allegory for the physical layers found in the neocortex. Layers contain the columns and cells discretely used by its configured algorithms (meaning two layers must be specifically configured to share columns, cells or Connections objects - which is possible). Multiple Layers may be connected together within a given Region.

  3. Regions - Also created by a factory method of Network, and is the container of Layers. Networks can contain multiple Regions which in turn (as stated above), can contain multiple Layers.

Clone this wiki locally