//-------------------------------------------------------------------------------- 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(); } }
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 << "'"; } }
inline std::string ReadStringFromBuffer(const IReadBuffer &buf) { NTA_Byte *value = 0; NTA_UInt32 size = 0; NTA_Int32 result = buf.readString(value, size, _ReadString_alloc, _ReadString_dealloc); if(result != 0) throw std::runtime_error("Failed to read string from stream."); std::string toReturn(value, size); // Real fps must be provided to use delete here. delete[] value; return toReturn; }
void remove( const IReadBuffer& key, const uint32_t hash[] = NULL ) { remove( key.GetRawData(), key.GetLength(), hash ); }
bool contains( const IReadBuffer& key, const uint32_t hash[] = NULL) { return contains( key.GetRawData(), key.GetLength(), hash ); }
void GlobalSpectralPhotonMap::Deserialize( IReadBuffer& buffer ///< [in] Buffer to deserialize from ) { nMaxPhotons = buffer.getUInt(); nPrevScale = buffer.getUInt(); dGatherRadius = buffer.getDouble(); dEllipseRatio = buffer.getDouble(); nMinPhotonsOnGather = buffer.getUInt(); nMaxPhotonsOnGather = buffer.getUInt(); maxPower = buffer.getDouble(); bbox.Deserialize( buffer ); const unsigned int numphot = buffer.getUInt(); vphotons.reserve( numphot ); for( unsigned int i=0; i<numphot; i++ ) { SpectralPhoton p; Point3Ops::Deserialize( p.ptPosition, buffer ); p.plane = buffer.getUChar(); p.power = buffer.getDouble(); p.theta = buffer.getUChar(); p.phi = buffer.getUChar(); p.nm = buffer.getDouble(); vphotons.push_back( p ); } }