Network¶
NuPIC¶
Network¶
-
class
nupic::
Network
¶ Represents an HTM network.
A network is a collection of regions.
Inherits from nupic::Serializable< NetworkProto >
Construction and destruction
-
Network
()¶
-
Network
(const std::string &path)¶ Create a Network by loading previously saved bundle, and register it to NuPIC.
-
~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 networknodeType
: 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 networknodeType
: Type of node in the region, e.g. “FDRNode”dimensions
: Dimensions of the regionbundlePath
: The path to the bundlelabel
: 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 networkproto
: The capnp proto reader
-
void
removeRegion
(const std::string &name)¶ Removes an existing region from the network.
- Parameters
name
: Name of the Region
-
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 regiondestName
: Name of the destination regionlinkType
: Type of the linklinkParams
: Parameters of the linksrcOutput
: Name of the source outputdestInput
: Name of the destination inputpropagationDelay
: 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 regiondestName
: Name of the destination regionsrcOutputName
: Name of the source outputdestInputName
: 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 regionphases
: 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 avoid*
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
-