Ejemplo n.º 1
0
  void TestNode::serialize(BundleIO& bundle)
  {
    {
      std::ofstream& f = bundle.getOutputStream("main");
      // There is more than one way to do this. We could serialize to YAML, which
      // would make a readable format, or we could serialize directly to the stream
      // Choose the easier one.
      f << "TestNode-v2" << " "
        << nodeCount_ << " "
        << int32Param_ << " "
        << uint32Param_ << " "
        << int64Param_ << " "
        << uint64Param_ << " "
        << real32Param_ << " "
        << real64Param_ << " "
        << boolParam_ << " "
        << outputElementCount_ << " "
        << delta_ << " "
        << iter_ << " ";

      arrayOut(f, real32ArrayParam_, "real32ArrayParam_");
      arrayOut(f, int64ArrayParam_, "int64ArrayParam_");
      arrayOut(f, boolArrayParam_, "boolArrayParam_");
      arrayOut(f, unclonedParam_, "unclonedParam_");
      f << shouldCloneParam_ << " ";

      // outer vector needs to be done by hand.
      f << "unclonedArray ";
      f << unclonedInt64ArrayParam_.size() << " "; // number of nodes
      for (size_t i = 0; i < unclonedInt64ArrayParam_.size(); i++)
      {
        std::stringstream name;
        name << "unclonedInt64ArrayParam[" << i << "]";
        arrayOut(f, unclonedInt64ArrayParam_[i], name.str());
      }
      f.close();
    }  // main file


    // auxilliary file using stream
    {
      std::ofstream& f = bundle.getOutputStream("aux");
      f << "This is an auxilliary file!\n";
      f.close();
    }

    // auxilliary file using path
    {
      std::string path = bundle.getPath("aux2");
      std::ofstream f(path.c_str());
      f << "This is another auxilliary file!\n";
      f.close();
    }
  }
Ejemplo n.º 2
0
void TestNode::serialize(BundleIO &bundle) {
  {
    std::ostream &f = bundle.getOutputStream();
    // There is more than one way to do this. We could serialize to YAML, which
    // would make a readable format, or we could serialize directly to the
    // stream Choose the easier one.
    f << "TestNode-v2"
      << " " << nodeCount_ << " " << int32Param_ << " " << uint32Param_ << " "
      << int64Param_ << " " << uint64Param_ << " " << real32Param_ << " "
      << real64Param_ << " " << boolParam_ << " " << outputElementCount_ << " "
      << delta_ << " " << iter_ << " " << dim_ << " ";

    arrayOut(f, real32ArrayParam_, "real32ArrayParam_");
    arrayOut(f, int64ArrayParam_, "int64ArrayParam_");
    arrayOut(f, boolArrayParam_, "boolArrayParam_");
    arrayOut(f, unclonedParam_, "unclonedParam_");
    f << shouldCloneParam_ << " ";

    // outer vector needs to be done by hand.
    f << "unclonedArray ";
    f << unclonedInt64ArrayParam_.size() << " "; // number of nodes
    for (size_t i = 0; i < unclonedInt64ArrayParam_.size(); i++) {
      std::stringstream name;
      name << "unclonedInt64ArrayParam[" << i << "]";
      arrayOut(f, unclonedInt64ArrayParam_[i], name.str());
    }
      // save the output buffers
      f << "outputs [";
      std::map<std::string, Output *> outputs = region_->getOutputs();
      for (auto iter : outputs) {
        const Array &outputBuffer = iter.second->getData();
        if (outputBuffer.getCount() != 0) {
          f << iter.first << " ";
          outputBuffer.save(f);
        }
      }
      f << "] "; // end of all output buffers
  } // main file

 }
Ejemplo n.º 3
0
void SpatialPoolerNode::serialize(BundleIO& bundle)
{
  std::ofstream& f = bundle.getOutputStream("spmain");
  f   << current_spatial_pooler_node_version_ << " "
      << (UInt32) mode_ << " "
      << (UInt32) clonedNodes_ << " "
      << nodeCount_ << " "
      << segmentSize_ << " "
      << (UInt32) sparsificationMode_ << " "
      << (UInt32) inferenceMode_ << " "
      // patchMasksStr_ not serialized
      << (UInt32) normalize_ << " "
      << norm_ << " "
      << kWinners_ << " "
      << maxDistance_ << " "
      << minAcceptNorm_ << " "
      << minProtoSum_ << " "
      << sigma_ << " "
      << seed_ << " "
      << maxNAttempts_ << " "
      << maxNPrototypes_ << " "
      << acceptanceProbability_ << " "
      // save actual seed separately from seed_ in case it was seeded with "0"
      // TODO: actually serialize rgen_;
      << (UInt32) rgen_.getSeed() << " " 
      << (UInt32) poolersAllocated_ << " ";

  if (poolersAllocated_)
  {
    // If cloned, there is a single pooler. 
    // If not cloned, everybody is saved here. 
    UInt actualNumNodes = clonedNodes_ ? 1 : nodeCount_;
    for (UInt i = 0; i != actualNumNodes; ++i) {
      poolers_[i]->saveState(f);
      f << " ";
    }
  }
  f.close();
}
Ejemplo n.º 4
0
void VectorFileSensor::serialize(BundleIO &bundle) {
  std::ofstream &f = bundle.getOutputStream("vfs");
  f << repeatCount_ << " " << activeOutputCount_ << " " << filename_ << " "
    << scalingMode_ << " ";
  f.close();
}
Ejemplo n.º 5
0
void ScalarSensor::serialize(BundleIO &bundle) {
    std::ostream &f = bundle.getOutputStream();
    f << "ScalerSensor ";
    f.write((char*)&params_, sizeof(params_));
    f << "~ScalerSensor" << std::endl;
}