예제 #1
0
void GlobalSpectralPhotonMap::Serialize( 
	IWriteBuffer&			buffer					///< [in] Buffer to serialize to
	) const
{
	buffer.ResizeForMore( sizeof( unsigned int ) * 4 + sizeof( Scalar ) * 3 );

	buffer.setUInt( nMaxPhotons );
	buffer.setUInt( nPrevScale );
	buffer.setDouble( dGatherRadius );
	buffer.setDouble( dEllipseRatio );
	buffer.setUInt( nMinPhotonsOnGather );
	buffer.setUInt( nMaxPhotonsOnGather );
	buffer.setDouble( maxPower );

	// Serialize the bounding box
	bbox.Serialize( buffer );

	// Serialize number of stored photons
	buffer.ResizeForMore( sizeof( unsigned int ) + sizeof( SpectralPhoton ) * vphotons.size() );
	buffer.setUInt( vphotons.size() );

	for( unsigned int i=0; i<vphotons.size(); i++ ) {
		const SpectralPhoton& p = vphotons[i];
		Point3Ops::Serialize( p.ptPosition, buffer );
		buffer.setUChar( p.plane );
		buffer.setDouble( p.power );
		buffer.setUChar( p.theta );
		buffer.setUChar( p.phi );
		buffer.setDouble( p.nm );
	}
}
예제 #2
0
//--------------------------------------------------------------------------------
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();
  }
}
예제 #3
0
//--------------------------------------------------------------------------------
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 << "'";
}