NuPIC Core
Core algorithms for NuPIC(the Numenta Platform for Intelligent Computing), implemented in C++
 All Classes Namespaces Files Functions Typedefs Enumerations Enumerator Friends Pages
List of all members
nta::Network Class Reference

Represents an HTM network. More...

#include <Network.hpp>

Construction and destruction

 Network ()
 Create an new Network and register it to NuPIC. More...
 
 Network (const std::string &path)
 Create a Network by loading previously saved bundle, and register it to NuPIC. More...
 
 ~Network ()
 Destructor. More...
 
void initialize ()
 Initialize all elements of a network so that it can run. More...
 

Serialization

void save (const std::string &name)
 Save the network to a network bundle (extension .nta). More...
 

Region and Link operations

RegionaddRegion (const std::string &name, const std::string &nodeType, const std::string &nodeParams)
 Create a new region in a network. More...
 
RegionaddRegionFromBundle (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. More...
 
void removeRegion (const std::string &name)
 Removes an existing region from the network. More...
 
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="")
 Create a link and add it to the network. More...
 
void removeLink (const std::string &srcName, const std::string &destName, const std::string &srcOutputName="", const std::string &destInputName="")
 Removes a link. More...
 

Access to components

const Collection< Region * > & getRegions () const
 Get all regions. More...
 
void setPhases (const std::string &name, std::set< UInt32 > &phases)
 Set phases for a region. More...
 
std::set< UInt32getPhases (const std::string &name) const
 Get phases for a region. More...
 
UInt32 getMinPhase () const
 Get minimum phase for regions in this network. More...
 
UInt32 getMaxPhase () const
 Get maximum phase for regions in this network. More...
 
void setMinEnabledPhase (UInt32 minPhase)
 Set the minimum enabled phase for this network. More...
 
void setMaxEnabledPhase (UInt32 minPhase)
 Set the maximum enabled phase for this network. More...
 
UInt32 getMinEnabledPhase () const
 Get the minimum enabled phase for this network. More...
 
UInt32 getMaxEnabledPhase () const
 Get the maximum enabled phase for this network. More...
 

Running

typedef void(* runCallbackFunction )(Network *, UInt64 iteration, void *)
 The type of run callback function. More...
 
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. More...
 
Collection< callbackItem > & getCallbacks ()
 Get reference to callback Collection. More...
 

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.
 

Detailed Description

Represents an HTM network.

A network is a collection of regions.

Definition at line 50 of file Network.hpp.

Member Typedef Documentation

typedef void(* nta::Network::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.

Definition at line 328 of file Network.hpp.

Constructor & Destructor Documentation

nta::Network::Network ( )

Create an new Network and register it to NuPIC.

Note
Creating a Network will auto-initialize NuPIC.
nta::Network::Network ( const std::string &  path)

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

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

Destructor.

Destruct the network and unregister it from NuPIC:

  • Uninitialize all regions
  • Remove all links
  • Delete the regions themselves
Todo:
Should we document the tear down steps above?

Member Function Documentation

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

Create a new region in a network.

Parameters
nameName of the region, Must be unique in the network
nodeTypeType of node in the region, e.g. "FDRNode"
nodeParamsA JSON-encoded string specifying writable params
Returns
A pointer to the newly created Region
Region* nta::Network::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
nameName of the region, Must be unique in the network
nodeTypeType of node in the region, e.g. "FDRNode"
dimensionsDimensions of the region
bundlePathThe path to the bundle
labelThe label of the bundle
Todo:
label is the prefix of filename of the saved bundle, should this be documented?
Returns
A pointer to the newly created Region
Collection<callbackItem>& nta::Network::getCallbacks ( )

Get reference to callback Collection.

Returns
Reference to callback Collection
UInt32 nta::Network::getMaxEnabledPhase ( ) const

Get the maximum enabled phase for this network.

Returns
Maximum enabled phase for this network
UInt32 nta::Network::getMaxPhase ( ) const

Get maximum phase for regions in this network.

If no regions, then max = 0.

Returns
Maximum phase
UInt32 nta::Network::getMinEnabledPhase ( ) const

Get the minimum enabled phase for this network.

Returns
Minimum enabled phase for this network
UInt32 nta::Network::getMinPhase ( ) const

Get minimum phase for regions in this network.

If no regions, then min = 0.

Returns
Minimum phase
std::set<UInt32> nta::Network::getPhases ( const std::string &  name) const

Get phases for a region.

Parameters
nameName of the region
Returns
Set of phases for the region
const Collection<Region*>& nta::Network::getRegions ( ) const

Get all regions.

Returns
A Collection of Region objects in the network
void nta::Network::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.
void nta::Network::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 = "" 
)

Create a link and add it to the network.

Parameters
srcNameName of the source region
destNameName of the destination region
linkTypeType of the link
linkParamsParameters of the link
srcOutputName of the source output
destInputName of the destination input
void nta::Network::removeLink ( const std::string &  srcName,
const std::string &  destName,
const std::string &  srcOutputName = "",
const std::string &  destInputName = "" 
)

Removes a link.

Parameters
srcNameName of the source region
destNameName of the destination region
srcOutputNameName of the source output
destInputNameName of the destination input
void nta::Network::removeRegion ( const std::string &  name)

Removes an existing region from the network.

Parameters
nameName of the Region
void nta::Network::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
nNumber of iterations
void nta::Network::save ( const std::string &  name)

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

Parameters
nameName of the bundle
void nta::Network::setMaxEnabledPhase ( UInt32  minPhase)

Set the maximum enabled phase for this network.

Parameters
minPhaseMaximum enabled phase
void nta::Network::setMinEnabledPhase ( UInt32  minPhase)

Set the minimum enabled phase for this network.

Parameters
minPhaseMinimum enabled phase
void nta::Network::setPhases ( const std::string &  name,
std::set< UInt32 > &  phases 
)

Set phases for a region.

Parameters
nameName of the region
phasesA tuple of phases (must be positive integers)

The documentation for this class was generated from the following file: