//-------------------------------------------------------------------------------- void SpatialPoolerNode::getParameterFromBuffer(const std::string& paramName, Int64 index, IWriteBuffer& value) { // Note: string parameters are handled in getParameterString const char* where = "SpatialPoolerNode, while getting parameter: "; try { if (paramName == "learningMode") { value.write((UInt32) (mode_ == Learning ? 1 : 0)); } else if (paramName == "inferenceMode") { value.write((UInt32) (mode_ == Inference ? 1 : 0)); } else if (paramName == "maxCoincidenceCount") { value.write(maxNPrototypes_); } else if (paramName == "clonedNodes") { value.write((UInt32) (clonedNodes_ ? 1 : 0)); } else if (paramName == "nta_phaseIndex") { value.write((UInt32) phaseIndex_); } else if (paramName == "nta_maxNAttempts") { value.write((UInt32) maxNAttempts_); } else if (paramName == "nta_acceptanceProbability") { value.write(acceptanceProbability_); } else if (paramName == "nta_seed") { value.write((nta::Int32)rgen_.getSeed()); } else { if (!poolersAllocated_) NTA_THROW << "Invalid operation -- SpatialPoolerNode must be initialized by initializing the network"; // per-node parameter UInt poolerIndex = clonedNodes_ ? 0 : (UInt) index; OMemStream buf; if (paramName == "maxDistance") { Real val = poolers_[poolerIndex]->getMinAcceptDistance(); if (val <= nta::Epsilon) val = (Real) 0; value.write(val); } else if (paramName == "sigma") { value.write(poolers_[poolerIndex]->getSigma()); } else if (paramName == "coincidenceCount") { value.write(poolers_[poolerIndex]->getTotalNPrototypes()); } else if (paramName == "activeOutputCount") { value.write(poolers_[poolerIndex]->getTotalNPrototypes()); } else if (paramName == "nta_segmentSize") { value.write((UInt32) poolers_[poolerIndex]->getSegmentSize()); } else if (paramName == "nta_normalize") { value.write(poolers_[poolerIndex]->getDoNormalization()); } else if (paramName == "nta_norm") { value.write(poolers_[poolerIndex]->getNorm()); } else if (paramName == "nta_kWinners") { value.write(poolers_[poolerIndex]->getKWinners()); } else if (paramName == "nta_minAcceptNorm") { value.write(poolers_[poolerIndex]->getMinAcceptNorm()); } else if (paramName == "nta_minProtoSum") { value.write(poolers_[poolerIndex]->getMinProtoSum()); } else { NTA_THROW << "Unknown parameter: " << paramName; } } } catch (std::exception& e) { NTA_THROW << where << "Couldn't retrieve " << paramName << ": " << e.what(); } }
//-------------------------------------------------------------------------------- void VectorFileSensor::getParameterFromBuffer(const std::string &name, Int64 index, IWriteBuffer &value) { const char *where = "VectorFileSensor, while getting parameter: "; Int32 res = 0; if (name == "vectorCount") { res = value.write((UInt32)vectorFile_.vectorCount()); } else if (name == "position") { res = value.write(UInt32(curVector_ + 1)); } else if (name == "repeatCount") { res = value.write(UInt32(repeatCount_)); } else if (name == "scalingMode") { // res = value.writeString(scalingMode_.data(), (Size)scalingMode_.size()); res = value.write(scalingMode_.data(), (Size)scalingMode_.size()); } else if (name == "recentFile") { // res = value.writeString(recentFile_.data(), (Size)recentFile_.size()); if (recentFile_.empty()) { res = value.write("", 1); } else { res = value.write(recentFile_.data(), (Size)recentFile_.size()); } } else if (name == "scaleVector") { stringstream buf; Real s = 0, o = 0; for (UInt i = 0; i < vectorFile_.getElementCount(); i++) { vectorFile_.getScaling(i, s, o); buf << s << " "; } string bufstr = buf.str(); res = value.write(bufstr.c_str(), (Size)bufstr.size()); } else if (name == "activeOutputCount") { res = value.write(UInt32(activeOutputCount_)); } else if (name == "maxOutputVectorCount") { res = value.write(UInt32(vectorFile_.vectorCount() * repeatCount_)); } else if (name == "offsetVector") { stringstream buf; Real s = 0, o = 0; for (UInt i = 0; i < vectorFile_.getElementCount(); i++) { vectorFile_.getScaling(i, s, o); buf << o << " "; } string bufstr = buf.str(); res = value.write(bufstr.c_str(), (Size)bufstr.size()); } else if (name == "hasCategoryOut") { res = value.write(UInt32(hasCategoryOut_)); } else if (name == "hasResetOut") { res = value.write(UInt32(hasResetOut_)); } NTA_CHECK(res >= 0) << where << "couldn't retrieve '" << name << "'"; }