当前位置: 首页>>代码示例>>C++>>正文


C++ Input::addLink方法代码示例

本文整理汇总了C++中Input::addLink方法的典型用法代码示例。如果您正苦于以下问题:C++ Input::addLink方法的具体用法?C++ Input::addLink怎么用?C++ Input::addLink使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Input的用法示例。


在下文中一共展示了Input::addLink方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1:

void
Network::link(const std::string& srcRegionName, const std::string& destRegionName, 
              const std::string& linkType, const std::string& linkParams, 
              const std::string& srcOutputName, const std::string& destInputName)
{
  
  // Find the regions
  if (! regions_.contains(srcRegionName))
    NTA_THROW << "Network::link -- source region '" << srcRegionName << "' does not exist";
  Region* srcRegion = regions_.getByName(srcRegionName);
  
  if (! regions_.contains(destRegionName))
    NTA_THROW << "Network::link -- dest region '" << destRegionName << "' does not exist";
  Region* destRegion = regions_.getByName(destRegionName);

  // Find the inputs/outputs
  const Spec* srcSpec = srcRegion->getSpec();
  std::string outputName = srcOutputName;
  if (outputName == "")
    outputName = srcSpec->getDefaultOutputName();
  
  Output* srcOutput = srcRegion->getOutput(outputName);
  if (srcOutput == NULL)
    NTA_THROW << "Network::link -- output " << outputName 
              << " does not exist on region " << srcRegionName;


  const Spec *destSpec = destRegion->getSpec();
  std::string inputName;
  if (destInputName == "")
    inputName = destSpec->getDefaultInputName();
  else
    inputName = destInputName;

  Input* destInput = destRegion->getInput(inputName);
  if (destInput == NULL)
  {
    NTA_THROW << "Network::link -- input '" << inputName 
              << " does not exist on region " << destRegionName;
  }

  // Create the link itself
  destInput->addLink(linkType, linkParams, srcOutput);

}
开发者ID:Asele,项目名称:nupic.core,代码行数:45,代码来源:Network.cpp

示例2: loadFromBundle


//.........这里部分代码省略.........
      (*valiter) >> val;
      phases.insert(val);
    }
    
    // 5. label
    node = (*region).FindValue("label");
    if (node == NULL)
      NTA_THROW << "Invalid network structure file -- region"
                << name << "has no label";
    std::string label;
    *node >> label;
    
    Region *r = addRegionFromBundle(name, nodeType, dimensions, fullPath, label);
    setPhases_(r, phases);


  }

  const YAML::Node *links = doc.FindValue("Links");
  if (links == NULL)
    NTA_THROW << "Invalid network structure file -- no links";

  if (links->Type() != YAML::NodeType::Sequence)
    NTA_THROW << "Invalid network structure file -- links element is not a list";

  for (YAML::Iterator link = links->begin(); link != links->end(); link++)
  {
    // Each link is a map -- extract the 5 values in the map
    if ((*link).Type() != YAML::NodeType::Map)
      NTA_THROW << "Invalid network structure file -- bad link (not a map)";
    
    if ((*link).size() != 6)
      NTA_THROW << "Invalid network structure file -- bad link (wrong size)";
    
    // 1. type
    node = (*link).FindValue("type");
    if (node == NULL)
      NTA_THROW << "Invalid network structure file -- link does not have a type";
    std::string linkType;
    *node >> linkType;

    // 2. params
    node = (*link).FindValue("params");
    if (node == NULL)
      NTA_THROW << "Invalid network structure file -- link does not have params";
    std::string params;
    *node >> params;

    // 3. srcRegion (name)
    node = (*link).FindValue("srcRegion");
    if (node == NULL)
      NTA_THROW << "Invalid network structure file -- link does not have a srcRegion";
    std::string srcRegionName;
    *node >> srcRegionName;


    // 4. srcOutput
    node = (*link).FindValue("srcOutput");
    if (node == NULL)
      NTA_THROW << "Invalid network structure file -- link does not have a srcOutput";
    std::string srcOutputName;
    *node >> srcOutputName;

    // 5. destRegion
    node = (*link).FindValue("destRegion");
    if (node == NULL)
      NTA_THROW << "Invalid network structure file -- link does not have a destRegion";
    std::string destRegionName;
    *node >> destRegionName;

    // 6. destInput
    node = (*link).FindValue("destInput");
    if (node == NULL)
      NTA_THROW << "Invalid network structure file -- link does not have a destInput";
    std::string destInputName;
    *node >> destInputName;

    if (!regions_.contains(srcRegionName))
      NTA_THROW << "Invalid network structure file -- link specifies source region '" << srcRegionName << "' but no such region exists";
    Region* srcRegion = regions_.getByName(srcRegionName);

    if (!regions_.contains(destRegionName))
      NTA_THROW << "Invalid network structure file -- link specifies destination region '" << destRegionName << "' but no such region exists";
    Region* destRegion = regions_.getByName(destRegionName);

    Output* srcOutput = srcRegion->getOutput(srcOutputName);
    if (srcOutput == NULL)
      NTA_THROW << "Invalid network structure file -- link specifies source output '" << srcOutputName << "' but no such name exists";

    Input* destInput = destRegion->getInput(destInputName);
    if (destInput == NULL)
      NTA_THROW << "Invalid network structure file -- link specifies destination input '" << destInputName << "' but no such name exists";

    // Create the link itself
    destInput->addLink(linkType, params, srcOutput);


  } // links

}
开发者ID:Asele,项目名称:nupic.core,代码行数:101,代码来源:Network.cpp

示例3: read

void Network::read(NetworkProto::Reader& proto)
{
  // Clear any previous regions
  while (regions_.getCount() > 0)
  {
    auto pair = regions_.getByIndex(0);
    delete pair.second;
    regions_.remove(pair.first);
  }

  // Add regions
  for (auto entry : proto.getRegions().getEntries())
  {
    auto regionProto = entry.getValue();
    auto region = addRegionFromProto(entry.getKey().cStr(), regionProto);
    // Initialize the phases for the region
    std::set<UInt32> phases;
    for (auto phase : regionProto.getPhases())
    {
      phases.insert(phase);
    }
    setPhases_(region, phases);
  }

  // Add links. Note that we can't just pass the capnp struct to Link.read
  // because the linked input and output need references to the new link.
  for (auto linkProto : proto.getLinks())
  {
    if (!regions_.contains(linkProto.getSrcRegion().cStr()))
    {
      NTA_THROW << "Link references unknown region: "
                << linkProto.getSrcRegion().cStr();
    }
    Region* srcRegion = regions_.getByName(linkProto.getSrcRegion().cStr());
    Output* srcOutput = srcRegion->getOutput(linkProto.getSrcOutput().cStr());
    if (srcOutput == nullptr)
    {
      NTA_THROW << "Link references unknown source output: "
                << linkProto.getSrcOutput().cStr();
    }

    if (!regions_.contains(linkProto.getDestRegion().cStr()))
    {
      NTA_THROW << "Link references unknown region: "
                << linkProto.getDestRegion().cStr();
    }
    Region* destRegion = regions_.getByName(linkProto.getDestRegion().cStr());
    Input* destInput = destRegion->getInput(linkProto.getDestInput().cStr());
    if (destInput == nullptr)
    {
      NTA_THROW << "Link references unknown destination input: "
                << linkProto.getDestInput().cStr();
    }

    // Actually create the link
    destInput->addLink(
        linkProto.getType().cStr(), linkProto.getParams().cStr(), srcOutput);
  }

  initialized_ = false;
}
开发者ID:jaredweiss,项目名称:nupic.core,代码行数:61,代码来源:Network.cpp


注:本文中的Input::addLink方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。