Beispiel #1
0
void ScalarSensor::deserialize(BundleIO &bundle) {
  std::istream &f = bundle.getInputStream();
  std::string tag;
  f >> tag;
  NTA_CHECK(tag == "ScalerSensor");
  f.ignore(1);
  f.read((char *)&params_, sizeof(params_));
  f >> tag;
  NTA_CHECK(tag == "~ScalerSensor");
  f.ignore(1);

  if (params_.periodic) {
    encoder_ = new PeriodicScalarEncoder(params_.w, 
                                  params_.minValue, 
                                  params_.maxValue, 
                                  params_.n, 
                                  params_.radius, 
                                  params_.resolution);
  } else {
    encoder_ = new ScalarEncoder( params_.w, 
                                  params_.minValue, 
                                  params_.maxValue, 
                                  params_.n, 
                                  params_.radius, 
                                  params_.resolution, 
                                  params_.clipInput);
  }
  initialize();
  encodedOutput_->initialize();
  bucketOutput_->initialize();
  compute();
}
Beispiel #2
0
void SpatialPoolerNode::deserialize(BundleIO& bundle)
{
  std::ifstream& f = bundle.getInputStream("spmain");
  std::string version;
  f >> version;
  NTA_CHECK(version == current_spatial_pooler_node_version_);
  {
    // f >> mode_ doesn't work. 
    Int32 mode;
    f >> mode;
    mode_ = (Mode)mode;
  }
  f >> clonedNodes_;
  f >> nodeCount_;
  f >> segmentSize_;
  {
    Int32 mode;
    f >> mode;
    sparsificationMode_ = (SparsePooler::SparsificationMode) mode;
    f >> mode;
    inferenceMode_ = (SparsePooler::InferenceMode) mode;
  }
  f >> normalize_;
  f >> norm_;
  f >> kWinners_;
  f >> maxDistance_;
  f >> minAcceptNorm_;
  f >> minProtoSum_;
  f >> sigma_;
  // don't use this value to seed; use the one saved from rgen, below
  f >> seed_;
  f >> maxNAttempts_;
  f >> maxNPrototypes_;
  f >> acceptanceProbability_;
  {
    UInt32 actualSeed;
    f >> actualSeed;
    // TODO: this isn't really useful unless the network hasn't been used. 
    // The seed is the same, but internal state is lost.
    rgen_ = nta::Random(actualSeed);
  }
  
  f >> poolersAllocated_;
  if (poolersAllocated_)
  {
    UInt poolerCount = clonedNodes_ ? 1 : nodeCount_;
    poolers_.resize(poolerCount);
    for (UInt i = 0; i != poolerCount; ++i) {
      poolers_[i] = new SparsePooler();
      poolers_[i]->readState(f);
    }
  }
  f.close();


}
Beispiel #3
0
  void TestNode::deserialize(BundleIO& bundle)
  {
    {
      std::ifstream& f = bundle.getInputStream("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.
      std::string versionString;
      f >> versionString;
      if (versionString != "TestNode-v2")
      {
        NTA_THROW << "Bad serialization for region '" << region_->getName()
                  << "' of type TestNode. Main serialization file must start "
                  << "with \"TestNode-v2\" but instead it starts with '"
                  << versionString << "'";

      }
      f >> nodeCount_;
      f >> int32Param_;
      f >> uint32Param_;
      f >> int64Param_;
      f >> uint64Param_;
      f >> real32Param_;
      f >> real64Param_;
      f >> boolParam_;
      f >> outputElementCount_;
      f >> delta_;
      f >> iter_;

      arrayIn(f, real32ArrayParam_, "real32ArrayParam_");
      arrayIn(f, int64ArrayParam_, "int64ArrayParam_");
      arrayIn(f, int64ArrayParam_, "boolArrayParam_");
      arrayIn(f, unclonedParam_, "unclonedParam_");

      f >> shouldCloneParam_;

      std::string label;
      f >> label;
      if (label != "unclonedArray")
        NTA_THROW << "Missing label for uncloned array. Got '" << label << "'";
      size_t vecsize;
      f >> vecsize;
      unclonedInt64ArrayParam_.clear();
      unclonedInt64ArrayParam_.resize(vecsize);
      for (size_t i = 0; i < vecsize; i++)
      {
        std::stringstream name;
        name << "unclonedInt64ArrayParam[" << i << "]";
        arrayIn(f, unclonedInt64ArrayParam_[i], name.str());
      }
      f.close();
    }  // main file

    // auxilliary file using stream
    {
      std::ifstream& f = bundle.getInputStream("aux");
      char line1[100];
      f.read(line1, 100);
      line1[f.gcount()] = '\0';
      if (std::string(line1) != "This is an auxilliary file!\n")
      {
        NTA_THROW << "Invalid auxilliary serialization file for TestNode";
      }
      f.close();
    }

    // auxilliary file using path
    {
      std::string path = bundle.getPath("aux2");
      std::ifstream f(path.c_str());
      char line1[100];
      f.read(line1, 100);
      line1[f.gcount()] = '\0';
      if (std::string(line1) != "This is another auxilliary file!\n")
      {
        NTA_THROW << "Invalid auxilliary2 serialization file for TestNode";
      }

      f.close();
    }
  }
void VectorFileSensor::deserialize(BundleIO &bundle) {
  std::ifstream &f = bundle.getInputStream("vfs");
  f >> repeatCount_ >> activeOutputCount_ >> filename_ >> scalingMode_;
  f.close();
}
Beispiel #5
0
void TestNode::deserialize(BundleIO &bundle) {
  {
    std::istream &f = bundle.getInputStream();
    // 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.
    std::string versionString;
    f >> versionString;
    if (versionString != "TestNode-v2") {
      NTA_THROW << "Bad serialization for region '" << region_->getName()
                << "' of type TestNode. Main serialization file must start "
                << "with \"TestNode-v2\" but instead it starts with '"
                << versionString << "'";
    }
    f >> nodeCount_;
    f >> int32Param_;
    f >> uint32Param_;
    f >> int64Param_;
    f >> uint64Param_;
    f >> real32Param_;
    f >> real64Param_;
    f >> boolParam_;
    f >> outputElementCount_;
    f >> delta_;
    f >> iter_;
    f >> dim_;

    arrayIn(f, real32ArrayParam_, "real32ArrayParam_");
    arrayIn(f, int64ArrayParam_, "int64ArrayParam_");
    arrayIn(f, int64ArrayParam_, "boolArrayParam_");
    arrayIn(f, unclonedParam_, "unclonedParam_");

    f >> shouldCloneParam_;

      std::string tag;
      f >> tag;
      if (tag != "unclonedArray")
        NTA_THROW << "Missing label for uncloned array. Got '" << tag << "'";
      size_t vecsize;
      f >> vecsize;
      unclonedInt64ArrayParam_.clear();
      unclonedInt64ArrayParam_.resize(vecsize);
      for (size_t i = 0; i < vecsize; i++)
      {
        std::stringstream name;
        name << "unclonedInt64ArrayParam[" << i << "]";
        arrayIn(f, unclonedInt64ArrayParam_[i], name.str());
      }

	    // Restore outputs
	    f >> tag;
	    NTA_CHECK(tag == "outputs");
	    f.ignore(1);
	    NTA_CHECK(f.get() == '['); // start of outputs

	    while (true) {
	      f >> tag;
	      f.ignore(1);
	      if (tag == "]")
	        break;
	      getOutput(tag)->getData().load(f);
	    }
	  }

  }