JAVA example for linking artifacts

Hi all,

looking for JAVA example, which does same or similar like this example:

  network.link(externalInputName, L4ColumnName, "UniformLink", "",
                  srcOutput="dataOut", destInput="basalInput")

  network.link(externalInputName, L4ColumnName, "UniformLink", "",
                 srcOutput="dataOut", destInput="basalGrowthCandidates")

JAVA network API provides following method:
network.connect(String regionSink, String regionSource)

I miss here link-type arguments like basalGrowthCandidates, basalInput, datOutput etc. Is there some documentation related to them?

My question is, how to build network shown in Python code above with JAVA network API?

Thanks
Damir

Hi @ddobric,

An overview of building a network in HTM.java can be found here: https://github.com/numenta/htm.java/wiki/NAPI-Quick-Start-Guide

I would start here (and the HTM.java wiki in general), but if you’re uncertain of what the configuration options mean, I’d go back to the theory until it makes sense.

1 Like

Hi @jimmyw,

thank you so much for your response. I’m already aware of this API. Unfortunately, I do not see a way to build layers exactly as shown in my Python example above. JAVA API provides network/layer API, as you pointed out. However, inside of HTM we have different kinds of input and output like activeCells , predictiveCells, winner cells, feedforward output an may be more.

Take a look on these posts:
https://discourse.numenta.org/t/a-theory-of-how-columns-in-the-neocortex-enable-learning-the-structure-of-the-world/2524/92

https://discourse.numenta.org/t/a-theory-of-how-columns-in-the-neocortex-enable-learning-the-structure-of-the-world/2524/93

I do not see the way how to do this in JAVA. We can say in JAVA “connect Lx to Ly”. But we cannot say how exactly. At least I didn’t find out how.

Damir

I see, I think I’ve walked into a much larger question that I’d need to read the context of.

In the meantime, all I can offer is that you can inspect the state of each of the cells after you call the compute method of the TemporalMemory object:

1 Like

Hi @ddobric @jimmyw,

My goto response has always been to look at the tests. They show very explicitly how to set up a network in a number of different ways! :slight_smile: (Specifically those in the “network” package)

Cheers,
David

2 Likes

Hi @cogmission,

I already did that and unfortunately I do not see any example in there, which shows how following (just an example) can be done:

 network.link(externalInputName, L4ColumnName, "UniformLink", "",
                  srcOutput="NAME OF OUTPUT", destInput="NAME OF INPUT")

It might be I have overseen something. Could you please point out, which example is doing something similar.

Damir

1 Like

Hi @ddobric,

Darn near the whole API :slight_smile: Networks/Layers have nearly the same syntax where “named” inputs are directed to “named” outputs. Let me take a look and work up an explanation for you…

Also (@rhyolight), am I missing something that that “link()” method might be doing in NuPIC’s Networking API that I’m not doing in the Java version? It could be ME that’s missing something? Because I don’t understand what about @ddobric’s example above he’s not seeing in the Java version? IT looks plain as day to me! :slight_smile:

Sorry @cogmission I have no clue here.

1 Like

I’m not very familiar with the NuPIC Network API, can you please tell me what (you think) this line is doing, and what you would like to accomplish?

I think within a ‘network’ object, this line connects the outputs of an encoder with a certain region in the network (L4, which the usual SP+TM algorithm is drawn from). If I understand right NuPIC OPF models call essentially this function from the Network API in their instantiation.

Comparable lines (from the L2456 network) are:

  # Link up the sensors
  network.link(locationInputName, L6ColumnName, "UniformLink", "",
               srcOutput="dataOut", destInput="basalInput")
  network.link(coarseSensorInputName, L6ColumnName, "UniformLink", "",
               srcOutput="dataOut", destInput="activeColumns")
  network.link(sensorInputName, L4ColumnName, "UniformLink", "",
               srcOutput="dataOut", destInput="activeColumns")

Using the raw Network API you can also connect Layers to each other (like modulating Layer 4 with Layer 6 grid cell activity as done in the L4L6 network model).

  # Link L6 to L4
  network.link(L6ColumnName, L4ColumnName, "UniformLink", "",
               srcOutput="activeCells", destInput="basalInput")
1 Like

@sheiser1 @ddobric,

So essentially the corollary is true for the Java version. You connect the Sensor responsible for “reading” the input source type (there are a few types which can act as sources), to an encoder of your choosing, then to a layer for the SpatialPooler, then the Temporal Memory, then to classifier etc.

As such: (there are many different examples)

Parameters p = NetworkDemoHarness.getParameters(); // "Default" test parameters (you will need to tweak)
p = p.union(NetworkDemoHarness.getNetworkDemoTestEncoderParams()); // Combine "default" encoder parameters.


Network network = Network.create("Network API Demo", p)         // Name the Network whatever you wish...
    .add(Network.createRegion("Region 1")                       // Name the Region whatever you wish...
        .add(Network.createLayer("Layer 2/3", p)                // Name the Layer whatever you wish...
            .alterParameter(KEY.AUTO_CLASSIFY, Boolean.TRUE)    // (Optional) Add a CLAClassifier
            .add(Anomaly.create())                              // (Optional) Add an Anomaly detector
            .add(new TemporalMemory())                          // Core Component but also it's "optional"
            .add(new SpatialPooler())                           // Core Component, but also "optional"
            .add(Sensor.create(FileSensor::create, SensorParams.create(
                Keys::path, "", ResourceLocator.path("rec-center-hourly.csv"))))));  // Sensors automatically connect to your source data, but you may omit this and pump data directly in!

network.start();

3 Likes

@cogmission + @sheiser1 thanks to all for your feedback.

@cogmission all examples in JAVA, which I know, use same programming model as in the code you have shown above. This is all fine. It makes it easy to developer to build the network and it keeps transparent scientific details. However, Python examples above provide a way to explicitly specify which output to connect to specific input. For example, connect resulting ‘activeCells’ of a TM inside of a layer with ‘basalInput’ of the next layer. One could also try to connect ‘predictiveCells’ of a TM with ‘basalInput’, etc.
JAVA example shown above uses (I guess) TM compute cycle output (which holds both active and predictive cells) as input to CLAClassifier. This is fine, but it does not demonstrates how to do connections (links) between layers as shown in my very first example on the beginning of this post.
Possibly I didn’t find this unit test (or sample)?! It might also be that this is not supported by JAVA API or it is transparent.

Thanks
Damir

1 Like