Exemplo n.º 1
0
void VectorFileSensor::setParameterFromBuffer(const std::string &name,
                                              Int64 index, IReadBuffer &value) {
  const char *where = "VectorFileSensor, while setting parameter: ";

  UInt32 int_param = 0;

  if (name == "repeatCount") {
    NTA_CHECK(value.read(int_param) == 0)
        << where << "Unable to read repeatCount: " << int_param
        << " - Should be a positive integer";

    if (int_param >= 1) {
      repeatCount_ = int_param;
    }
  }

  else if (name == "position") {
    NTA_CHECK(value.read(int_param) == 0)
        << where << "Unable to read position: " << int_param
        << " - Should be a positive integer";
    if (int_param < vectorFile_.vectorCount()) {
      seek(int_param);
    } else {
      NTA_THROW << "VectorFileSensor: invalid position "
                << " to seek to: " << int_param;
    }
  }

  else if (name == "scalingMode") {
    // string mode = ReadStringFromvaluefer(value);
    string mode(value.getData(), value.getSize());
    if (mode == "none")
      vectorFile_.resetScaling();
    else if (mode == "standardForm")
      vectorFile_.setStandardScaling();
    else if (mode != "custom") // Do nothing if set to custom
      NTA_THROW << where << " Unknown scaling mode: " << mode;
    scalingMode_ = mode;
  }

  else if (name == "hasCategoryOut") {
    NTA_CHECK(value.read(int_param) == 0)
        << where << "Unable to read hasCategoryOut: " << int_param
        << " - Should be a positive integer";

    hasCategoryOut_ = int_param == 1;
  }

  else if (name == "hasResetOut") {
    NTA_CHECK(value.read(int_param) == 0)
        << where << "Unable to read hasResetOut: " << int_param
        << " - Should be a positive integer";

    hasResetOut_ = int_param == 1;
  }

  else {
    NTA_THROW << where << "couldn't set '" << name << "'";
  }
}
Exemplo n.º 2
0
//--------------------------------------------------------------------------------
void SpatialPoolerNode::setParameterFromBuffer(const std::string& paramName, Int64 index, 
                                               IReadBuffer& buf)
{
  // Note: string parametrs are all handled in setParameterString
  const char* where = "SpatialPoolerNode, while setting parameter: ";

  try {

    UInt int_param = 0;
    //Real float_param = (Real) 0;
  
    if (paramName == "nta_phaseIndex") {
      buf.read(int_param);
      phaseIndex_ = (UInt32) int_param;
    }
    
    else if (paramName == "learningMode") {
      buf.read(int_param);
      mode_ = (int_param == 1) ? Learning : Inference;
      if (mode_ == Inference)
        switchToInference_();
    }

    else if (paramName == "inferenceMode") {
      buf.read(int_param);
      mode_ = (int_param == 1) ? Inference : Learning;
      if (mode_ == Inference)
        switchToInference_();
    } 


    else if (paramName == "nta_acceptanceProbability") {
      double x = 1.0;
      buf.read(x);

      // Only 48-bits in a typical draw.
      NTA_CHECK(x > (1.0 / double(0x1LL << 48)))
        << "Acceptance probability is too small. "
        "Fewer samples would be learned than expected.";

      acceptanceProbability_ = x;
    }

    else {

      NTA_THROW << "Unknown parameter: " << paramName;

    }
  } catch (std::exception& e) {
    NTA_THROW << where << "Couldn't set " << paramName
              << ": " << e.what();
  }
}