Network

NuPIC

class nupic::NuPIC

Initialization and shutdown operations for NuPIC engine.

Public Static Functions

static void init()

Initialize NuPIC.

Note

It’s safe to reinitialize an initialized NuPIC.

Creating a Network will auto-initialize NuPIC.

static void shutdown()

Shutdown NuPIC.

Note
As a safety measure, NuPIC with any Network still registered to it is not allowed to be shut down.

static bool isInitialized()

Return
Whether NuPIC is initialized successfully.

Network

class nupic::Network

Represents an HTM network.

A network is a collection of regions.

Inherits from nupic::Serializable< NetworkProto >

Construction and destruction

Network()

Create an new Network and register it to NuPIC.

Note
Creating a Network will auto-initialize NuPIC.

Network(const std::string &path)

Create a Network by loading previously saved bundle, and register it to NuPIC.

Note
Creating a Network will auto-initialize NuPIC.
Parameters
  • path: The path to the previously saved bundle file, currently only support files with .nta extension.

~Network()

Destructor.

Destruct the network and unregister it from NuPIC:

  • Uninitialize all regions
  • Remove all links
  • Delete the regions themselves

void initialize()

Initialize all elements of a network so that it can run.

Note
This can be called after the Network structure has been set and before Network.run(). However, if you don’t call it, Network.run() will call it for you. Also sets up various memory buffers etc. once the Network structure has been finalized.

Serialization

void save(const std::string &name)

Save the network to a network bundle (extension .nta).

Parameters
  • name: Name of the bundle

Region and Link operations

Region *addRegion(const std::string &name, const std::string &nodeType, const std::string &nodeParams)

Create a new region in a network.

Return
A pointer to the newly created Region
Parameters
  • name: Name of the region, Must be unique in the network
  • nodeType: Type of node in the region, e.g. “FDRNode”
  • nodeParams: A JSON-encoded string specifying writable params

Region *addRegionFromBundle(const std::string &name, const std::string &nodeType, const Dimensions &dimensions, const std::string &bundlePath, const std::string &label)

Create a new region from saved state.

Parameters
  • name: Name of the region, Must be unique in the network
  • nodeType: Type of node in the region, e.g. “FDRNode”
  • dimensions: Dimensions of the region
  • bundlePath: The path to the bundle
  • label: The label of the bundle

Return
A pointer to the newly created Region

Region *addRegionFromProto(const std::string &name, RegionProto::Reader &proto)

Create a new region from saved Cap’n Proto state.

Return
A pointer to the newly created Region
Parameters
  • name: Name of the region, Must be unique in the network
  • proto: The capnp proto reader

void removeRegion(const std::string &name)

Removes an existing region from the network.

Parameters

void link(const std::string &srcName, const std::string &destName, const std::string &linkType, const std::string &linkParams, const std::string &srcOutput = "", const std::string &destInput = "", const size_t propagationDelay = 0)

Create a link and add it to the network.

Parameters
  • srcName: Name of the source region
  • destName: Name of the destination region
  • linkType: Type of the link
  • linkParams: Parameters of the link
  • srcOutput: Name of the source output
  • destInput: Name of the destination input
  • propagationDelay: Propagation delay of the link as number of network run iterations involving the link as input; the delay vectors, if any, are initially populated with 0’s. Defaults to 0=no delay

void removeLink(const std::string &srcName, const std::string &destName, const std::string &srcOutputName = "", const std::string &destInputName = "")

Removes a link.

Parameters
  • srcName: Name of the source region
  • destName: Name of the destination region
  • srcOutputName: Name of the source output
  • destInputName: Name of the destination input

Access to components

const Collection<Region *> &getRegions() const

Get all regions.

Return
A Collection of Region objects in the network

Collection<Link *> getLinks()

Get all links between regions.

Return
A Collection of Link objects in the network

void setPhases(const std::string &name, std::set<UInt32> &phases)

Set phases for a region.

Parameters
  • name: Name of the region
  • phases: A tuple of phases (must be positive integers)

std::set<UInt32> getPhases(const std::string &name) const

Get phases for a region.

Return
Set of phases for the region
Parameters
  • name: Name of the region

UInt32 getMinPhase() const

Get minimum phase for regions in this network.

If no regions, then min = 0.

Return
Minimum phase

UInt32 getMaxPhase() const

Get maximum phase for regions in this network.

If no regions, then max = 0.

Return
Maximum phase

void setMinEnabledPhase(UInt32 minPhase)

Set the minimum enabled phase for this network.

Parameters
  • minPhase: Minimum enabled phase

void setMaxEnabledPhase(UInt32 minPhase)

Set the maximum enabled phase for this network.

Parameters
  • minPhase: Maximum enabled phase

UInt32 getMinEnabledPhase() const

Get the minimum enabled phase for this network.

Return
Minimum enabled phase for this network

UInt32 getMaxEnabledPhase() const

Get the maximum enabled phase for this network.

Return
Maximum enabled phase for this network

Running

typedef void (*runCallbackFunction)(Network *, UInt64 iteration, void *)

The type of run callback function.

You can attach a callback function to a network, and the callback function is called after every iteration of run().

To attach a callback, just get a reference to the callback collection with getCallbacks() , and add a callback.

typedef std::pair<runCallbackFunction, void *> callbackItem

Type definition for a callback item, combines a runCallbackFunction and a void* pointer to the associated data.

void run(int n)

Run the network for the given number of iterations of compute for each Region in the correct order.

For each iteration, Region.compute() is called.

Parameters
  • n: Number of iterations

Collection<callbackItem> &getCallbacks()

Get reference to callback Collection.

Return
Reference to callback Collection

Profiling

void enableProfiling()

Start profiling for all regions of this network.

void disableProfiling()

Stop profiling for all regions of this network.

void resetProfiling()

Reset profiling timers for all regions of this network.