Links¶
Link¶
-
class
nupic::
Link
¶ Represents a link between regions in a Network.
Inherits from nupic::Serializable< LinkProto >
Initialization
Links have four-phase initialization.
- construct with link type, params, names of regions and inputs/outputs
- wire in to network (setting src and dest Output/Input pointers)
- set source and destination dimensions
- initialize sets the offset in the destination Input (not known earlier)
De-serializing is the same as phase 1.
In phase 3, NuPIC will set and/or get source and/or destination dimensions until both are set. Normally we will only set the src dimensions, and the dest dimensions will be induced. It is possible to go the other way, though.
The linkType and linkParams parameters are given to the LinkPolicyFactory to create a link policy
-
Link
(const std::string &linkType, const std::string &linkParams, const std::string &srcRegionName, const std::string &destRegionName, const std::string &srcOutputName = "", const std::string &destInputName = "", const size_t propagationDelay = 0)¶ Initialization Phase 1: setting parameters of the link.
- Parameters
linkType
: The type of the linklinkParams
: The parameters of the linksrcRegionName
: The name of the source RegiondestRegionName
: The name of the destination RegionsrcOutputName
: The name of the source OutputdestInputName
: The 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
-
Link
()¶ De-serialization use case.
Creates a “blank” link. The caller must follow up with Link::read and Link::connectToNetwork
- Parameters
proto
: LinkProto::Reader
-
void
connectToNetwork
(Output *src, Input *dest)¶ Initialization Phase 2: connecting inputs/outputs to the Network.
-
void
setSrcDimensions
(Dimensions &dims)¶ Initialization Phase 3: set the Dimensions for the source Output, and induce the Dimensions for the destination Input .
- Parameters
dims
: The Dimensions for the source Output
-
void
setDestDimensions
(Dimensions &dims)¶ Initialization Phase 3: Set the Dimensions for the destination Input, and induce the Dimensions for the source Output .
- Parameters
dims
: The Dimensions for the destination Input
-
void
initialize
(size_t destinationOffset)¶ Initialization Phase 4: sets the offset in the destination Input .
- Parameters
destinationOffset
: The offset in the destination Input, i.e. TODO
-
~Link
()¶ Destructor.
Parameter getters of the link
-
const Dimensions &
getSrcDimensions
() const¶ Get the Dimensions for the source Output .
- Return
- The Dimensions for the source Output
-
const Dimensions &
getDestDimensions
() const¶ Get the Dimensions for the destination Input .
- Return
- The Dimensions for the destination Input
-
const std::string &
getLinkType
() const¶ Get the type of the link.
- Return
- The type of the link
-
const std::string &
getLinkParams
() const¶ Get the parameters of the link.
- Return
- The parameters of the link
-
const std::string &
getSrcRegionName
() const¶ Get the name of the source Region.
- Return
- The name of the source Region
-
const std::string &
getSrcOutputName
() const¶ Get the name of the source Output.
- Return
- The name of the source Output
Misc
-
Input &
getDest
() const¶ Get the destination Input of the link.
- Return
- The destination Input of the link
-
void
compute
()¶ Copy data from source to destination.
Nodes request input data from their input objects. The input objects, in turn, request links to copy data into the inputs.
- Note
- This method must be called on a fully initialized link(all 4 phases).
-
void
buildSplitterMap
(Input::SplitterMap &splitter)¶ Build a splitter map from the link.
A splitter map is a matrix that maps the full input of a region to the inputs of individual nodes within the region. A splitter map “sm” is declared as:
vector< vector<size_t> > sm; sm.length() == number of nodes
- Parameters
splitter
: The built SplitterMap
sm[i]
is a “sparse vector” used to gather the input for node i.sm[i].size()
is the size (in elements) of the input for node i.sm[i]
gathers the inputs as follows:T *regionInput; // input buffer for the whole region T *nodeInput; // pre-allocated for (size_t elem = 0; elem < sm[i].size; elem++) nodeInput[elem] = regionInput[sm[i][elem]];
The offset specified by
sm[i][j]
is in units of elements. To get byte offsets, you’d multiply by the size of an input/output element.An input to a region may come from several links. Each link contributes a contiguous block of the region input starting from a certain offset. The splitter map indices are with respect to the full region input, not the partial region input contributed by this link, so the destinationOffset for this link is included in each of the splitter map entries.
Finally, the API is designed so that each link associated with an input can contribute its portion to a full splitter map. Thus the splitter map is an input-output parameter. This method appends data to each row of the splitter map, assuming that existing data in the splitter map comes from other links.
For region-level inputs, a splitter map has just a single row.
Splitter map ownership
The splitter map is owned by the containing Input. Each Link in the input contributes a portion to the splitter map, through the buildSplitterMap method.
LinkPolicy¶
-
class
nupic::
LinkPolicy
¶ Subclassed by nupic::UniformLinkPolicy