![]() |
NuPIC Core
Core algorithms for NuPIC(the Numenta Platform for Intelligent Computing), implemented in C++
|
Represents a link between regions in a Network. More...
#include <Link.hpp>
Initialization | |
Links have four-phase initialization.
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="") | |
Initialization Phase 1: setting parameters of the link. More... | |
void | connectToNetwork (Output *src, Input *dest) |
Initialization Phase 2: connecting inputs/outputs to the Network. More... | |
Link (const std::string &linkType, const std::string &linkParams, Output *srcOutput, Input *destInput) | |
void | setSrcDimensions (Dimensions &dims) |
Initialization Phase 3: set the Dimensions for the source Output, and induce the Dimensions for the destination Input . More... | |
void | setDestDimensions (Dimensions &dims) |
Initialization Phase 3: Set the Dimensions for the destination Input, and induce the Dimensions for the source Output . More... | |
void | initialize (size_t destinationOffset) |
Initialization Phase 4: sets the offset in the destination Input . More... | |
~Link () | |
Destructor. | |
Parameter getters of the link | |
const Dimensions & | getSrcDimensions () const |
Get the Dimensions for the source Output . More... | |
const Dimensions & | getDestDimensions () const |
Get the Dimensions for the destination Input . More... | |
const std::string & | getLinkType () const |
Get the type of the link. More... | |
const std::string & | getLinkParams () const |
Get the parameters of the link. More... | |
const std::string & | getSrcRegionName () const |
Get the name of the source Region. More... | |
const std::string & | getSrcOutputName () const |
Get the name of the source Output. More... | |
const std::string & | getDestRegionName () const |
Get the name of the destination Region. More... | |
const std::string & | getDestInputName () const |
Get the name of the destination Input. More... | |
Misc | |
Output & | getSrc () const |
Get the source Output of the link. More... | |
Input & | getDest () const |
Get the destination Input of the link. More... | |
void | compute () |
Copy data from source to destination. More... | |
void | buildSplitterMap (Input::SplitterMap &splitter) |
Build a splitter map from the link. More... | |
const std::string | toString () const |
Convert the Link to a human-readable string. More... | |
void | write (LinkProto::Builder &proto) const |
void | read (LinkProto::Reader &proto) |
std::ostream & | operator<< (std::ostream &f, const Link &link) |
Serialize the link. More... | |
Not implemented | |
size_t | getNodeInputSize (size_t nodeIndex) |
Get the size of the input contributed by this link for a single node. More... | |
bool | isInputContiguous () |
Tells whether the Input is contiguous. More... | |
size_t | getInputOffset (size_t nodeIndex) |
Locate the contiguous input for a node. More... | |
nupic::Link::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 = "" |
||
) |
Initialization Phase 1: setting parameters of the link.
void nupic::Link::buildSplitterMap | ( | Input::SplitterMap & | splitter | ) |
Build a splitter map from the link.
[out] | splitter | The built SplitterMap |
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
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.
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.
void nupic::Link::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.
Input& nupic::Link::getDest | ( | ) | const |
const Dimensions& nupic::Link::getDestDimensions | ( | ) | const |
Get the Dimensions for the destination Input .
const std::string& nupic::Link::getDestInputName | ( | ) | const |
const std::string& nupic::Link::getDestRegionName | ( | ) | const |
size_t nupic::Link::getInputOffset | ( | size_t | nodeIndex | ) |
const std::string& nupic::Link::getLinkParams | ( | ) | const |
Get the parameters of the link.
const std::string& nupic::Link::getLinkType | ( | ) | const |
Get the type of the link.
size_t nupic::Link::getNodeInputSize | ( | size_t | nodeIndex | ) |
Output& nupic::Link::getSrc | ( | ) | const |
const Dimensions& nupic::Link::getSrcDimensions | ( | ) | const |
Get the Dimensions for the source Output .
const std::string& nupic::Link::getSrcOutputName | ( | ) | const |
const std::string& nupic::Link::getSrcRegionName | ( | ) | const |
void nupic::Link::initialize | ( | size_t | destinationOffset | ) |
bool nupic::Link::isInputContiguous | ( | ) |
Tells whether the Input is contiguous.
If the input for a particular node is a contiguous subset of the src output, then the splitter map is overkill, and all we need to know is the offset/size (per node) Returns true if and only if the input for each node is a contiguous chunk of the input buffer.
void nupic::Link::setDestDimensions | ( | Dimensions & | dims | ) |
Initialization Phase 3: Set the Dimensions for the destination Input, and induce the Dimensions for the source Output .
dims | The Dimensions for the destination Input |
void nupic::Link::setSrcDimensions | ( | Dimensions & | dims | ) |
Initialization Phase 3: set the Dimensions for the source Output, and induce the Dimensions for the destination Input .
dims | The Dimensions for the source Output |
const std::string nupic::Link::toString | ( | ) | const |
|
friend |
Serialize the link.
f | The output stream being serialized to |
link | The Link being serialized |