当前位置: 首页>>代码示例>>C++>>正文


C++ DataVector::size方法代码示例

本文整理汇总了C++中DataVector::size方法的典型用法代码示例。如果您正苦于以下问题:C++ DataVector::size方法的具体用法?C++ DataVector::size怎么用?C++ DataVector::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DataVector的用法示例。


在下文中一共展示了DataVector::size方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: RMSE

double RMSE(const DataVector &data, const PredictVector &predict, size_t len) {
  assert(data.size() >= len);
  assert(predict.size() >= len);
  double s = 0;
  double c = 0;

  for (size_t i = 0; i < data.size(); ++i) {
    s += Squared(predict[i] - data[i]->label) * data[i]->weight;
    c += data[i]->weight;
  }

  return std::sqrt(s / c);
}
开发者ID:StevenLee-belief,项目名称:gbdt,代码行数:13,代码来源:fitness.cpp

示例2: handleDataLoading

    void FancyMeshSystem::handleDataLoading( Ra::Engine::Entity* entity, const std::string& rootFolder, 
                                             const std::map<std::string, Ra::Core::Any>& data )
    {
        LOG(logDEBUG) << "FancyMeshSystem : loading " << data.size() << " data items...";

        // Find mesh
        std::string filename;
        auto meshData = data.find("mesh");
        if ( meshData != data.end() )
        {
            filename = rootFolder + "/" + meshData->second.as<std::string>();
        }

        DataVector componentsData = FancyMeshLoader::loadFile( filename );

        if (componentsData.empty())
        {
            // Something wrong happened while trying to load the file
            return;
        }

        if (componentsData.size() > 1)
        {
            LOG(logWARNING) << "Too much objects have been loaded, some data will be ignored.";
        }

        FancyComponentData componentData = componentsData[0];

        FancyMeshComponent* component = static_cast<FancyMeshComponent*>(addComponentToEntity(entity));
        component->handleMeshLoading(componentData);
    }
开发者ID:,项目名称:,代码行数:31,代码来源:

示例3: Same

bool Same(const DataVector &data, size_t len) {
  assert(len <= data.size());
  if (len <= 1)
    return true;

  ValueType t = data[0]->target;
  for (size_t i = 1; i < len; ++i) {
    if (!AlmostEqual(t, data[i]->target))
      return false;
  }
  return true;
}
开发者ID:StevenLee-belief,项目名称:gbdt,代码行数:12,代码来源:fitness.cpp

示例4: Average

ValueType Average(const DataVector & data, size_t len) {
  assert(len <= data.size());
  if (len == 0)
    return 0;
  double s = 0;
  double c = 0;
  for (size_t i = 0; i < len; ++i) {
    s += data[i]->target * data[i]->weight;
    c += data[i]->weight;
  }
  return static_cast<ValueType>(s / c);
}
开发者ID:StevenLee-belief,项目名称:gbdt,代码行数:12,代码来源:fitness.cpp

示例5: std_logic_error

void
WindowingThread::OnProcess( const GenericSignal& Input, GenericSignal& Output )
{
  for( size_t ch = 0; ch < Channels().size(); ++ch )
  {
    // Fill the rightmost part of the buffer with new input:
    size_t i = max<ptrdiff_t>( 0, mBuffers[ch].size() - mInputElements ),
           j = 0;
    while( i < mBuffers[ch].size() )
      mBuffers[ch][i++] = Input( Channels()[ch], j++ );

    DataVector* pDetrendedData = NULL;
    switch( mDetrend )
    {
      case None:
        pDetrendedData = &mBuffers[ch];
        break;

      case Mean:
        Detrend::MeanDetrend( mBuffers[ch], mDetrendBuffer );
        pDetrendedData = &mDetrendBuffer;
        break;

      case Linear:
        Detrend::LinearDetrend( mBuffers[ch], mDetrendBuffer );
        pDetrendedData = &mDetrendBuffer;
        break;

      default:
        throw std_logic_error( "Unknown detrend option" );
    }

    if( mWindowFunction == Rectangular )
      for( size_t i = 0; i < pDetrendedData->size(); ++i )
        Output( Channels()[ch], i ) = ( *pDetrendedData )[i];
    else
      for( size_t i = 0; i < pDetrendedData->size(); ++i )
        Output( Channels()[ch], i ) = mWindow[i] * ( *pDetrendedData )[i];
  }
}
开发者ID:ACrazyer,项目名称:NeuralSystemsBCI2000,代码行数:40,代码来源:WindowingFilter.cpp

示例6: squared_core_distance

    /** Finds the squared core distance of one given point.
     * @param p The point to be examined.
     * @param min_pts The minimum number of points to be found within an epsilon-neigborhood.
     * @param N_eps All points in the the epsilon-neighborhood of p, including p itself.
     * @return The squared core distance of p.
     */
    real squared_core_distance( const DataPoint* p, const unsigned int min_pts, DataVector& N_eps) {    
        assert( min_pts > 0 && "min_pts must be greater than 0");
        real ret( OPTICS::UNDEFINED);
    
        if( N_eps.size() > min_pts) {
            std::nth_element( N_eps.begin(), 
                              N_eps.begin()+min_pts, 
                              N_eps.end(), 
                              [p]( const DataPoint* a, const DataPoint* b){ return squared_distance( p, a) < squared_distance( p, b); } );

            ret = squared_distance( p, N_eps[min_pts]);
        }
        return ret;
    }
开发者ID:langenhagen,项目名称:Master-Thesis,代码行数:20,代码来源:optics.hpp

示例7: ReadFromSocket

/**
 * Read from socket
 * returns 0 on success
 */
int ReadFromSocket(HSOCKET sock, DataVector& buffer, int &nRead)
{
	int tmp;
	nRead = 0;
	bool chunked = false;

	if (!buffer.size())
		return 1;

	memset(buffer.data(), 0, buffer.size());
	do
	{
#ifndef _WIN32
		tmp = read(sock, &buffer.data()[nRead], buffer.size() - nRead);
#else
		tmp = recv(sock, &buffer[nRead], nBuffer - nRead, 0);
#endif
		if (tmp > 0)
			nRead += tmp;

		if (!chunked)
			chunked = strstr(buffer.data(), "Transfer-Encoding: chunked\r\n") != NULL;

		if ( chunked && strstr(buffer.data(), "0\r\n\r\n") != NULL )
			break;
		else if ( strstr(buffer.data(), "\r\n\r\n") != NULL ||  strstr(buffer.data(), "\n\n") != NULL ) // eof msg received
			break;
	} while(tmp > 0);

	if (tmp < 0)
		return tmp;

//	if (chunked)
//		ParseChunkedMessage(buffer);

	return 0;
}
开发者ID:erikssm,项目名称:toratio,代码行数:41,代码来源:network.cpp

示例8: WriteSocket

/**
 * Write to socket
 * returns 0 on success
 */
int WriteSocket(HSOCKET sock, const DataVector& buffer, size_t bytes)
{
	int tmp;
	size_t n {};

	do
	{
#ifndef _WIN32
		tmp = write(sock, &buffer[n], buffer.size() - n);
#else
		tmp = send(sock, &buffer[n], nData - n, 0);
#endif
		if (tmp > 0)
			n += tmp;
	} while(tmp > 0 && n < bytes && n < buffer.size());

	if (tmp < 0)
	{
		fprintf(stderr, "socket error: %s, bytes written: %lu\n", strerror(errno), n);
		return tmp;
	}

	return 0;
}
开发者ID:erikssm,项目名称:toratio,代码行数:28,代码来源:network.cpp

示例9: Init

void GBDT::Init(DataVector &d, size_t len) {
  assert(d.size() >= len);

  if (g_conf.enable_initial_guess) {
    return;
  }

  if (g_conf.loss == SQUARED_ERROR) {
    bias = static_cast<ValueType>(LabelAverage(d, len));
  } else if (g_conf.loss == LOG_LIKELIHOOD) {
    double v = LabelAverage(d, len);
    bias = static_cast<ValueType>(std::log((1+v) / (1-v)) / 2.0);
  } else if (g_conf.loss == LAD) {
    bias = WeightedLabelMedian(d, len);
  }
}
开发者ID:qiyiping,项目名称:gbdt,代码行数:16,代码来源:gbdt.cpp

示例10: LogitOptimalValue

ValueType LogitOptimalValue(const DataVector &d, size_t len) {
  assert(d.size() >= len);

  double s = 0;
  double c = 0;
  for (size_t i = 0; i < len; ++i) {
    s += d[i]->target * d[i]->weight;
    double y = Abs(d[i]->target);
    c += y*(2-y) * d[i]->weight;
  }

  if (c == 0) {
    return static_cast<ValueType>(0);
  } else {
    return static_cast<ValueType> (s / c);
  }
}
开发者ID:StevenLee-belief,项目名称:gbdt,代码行数:17,代码来源:fitness.cpp

示例11: handleFileLoading

    void FancyMeshSystem::handleFileLoading( const std::string& filename )
    {
        DataVector componentsData = FancyMeshLoader::loadFile( filename );

        for ( uint i = 0; i < componentsData.size(); ++i )
        {
            FancyComponentData data = componentsData[i];

            // Retrieve entity if exist, create it otherwise
            Ra::Engine::Entity* e = m_engine->getEntityManager()->getOrCreateEntity( data.name );
            e->setTransform( data.transform );

            FancyMeshComponent* component =
                static_cast<FancyMeshComponent*>( addComponentToEntity( e ) );

            component->handleMeshLoading( data );
        }
    }
开发者ID:,项目名称:,代码行数:18,代码来源:

示例12: Init

void GBDT::Init(const DataVector &d, size_t len) {
  assert(d.size() >= len);

  double s = 0;
  double c = 0;
  for (size_t i = 0; i < len; ++i) {
    s += d[i]->label * d[i]->weight;
    c += d[i]->weight;
  }

  double v = s / c;

  if (g_conf.loss == SQUARED_ERROR) {
    bias = static_cast<ValueType>(v);
  } else if (g_conf.loss == LOG_LIKELIHOOD) {
    bias = static_cast<ValueType>(std::log((1+v) / (1-v)) / 2.0);
  }
}
开发者ID:litaoshao,项目名称:gbdt,代码行数:18,代码来源:gbdt.cpp

示例13: compareRowColumn

//return: 0: all comparing data are close to each other
int compareRowColumn(const DataVector& data1, const DataVector& data2, const size_t linesToCompare, const double tolerance){
  int failure_found=EXIT_SUCCESS;

  if (data1.size() != data2.size() && linesToCompare > std::min(data1.size(),data2.size())){
    std::cout<< "two files have different numbers of lines needing comparing." <<std::endl;
    failure_found = VALUE_TOLERANCE_FAILURE_CODE;
  }

  if ( ! failure_found && linesToCompare > std::min(data1.size(),data2.size()) ) {
    std::cout<< "linesToCompare is greater than the number of data lines." <<std::endl;
    failure_found = VALUE_TOLERANCE_FAILURE_CODE;
  }

  if( ! failure_found )
  {
    for(size_t i=0; i< linesToCompare; ++i){
      std::vector< double > row1 = data1[i];
      std::vector< double > row2 = data2[i];
      const size_t column = row1.size();
      if (column != row2.size()){
        printf("In the line %zu, 2 data has different column.\n", i);
        failure_found = VALUE_TOLERANCE_FAILURE_CODE;
      }
      for (size_t j=0; j< column; ++j){
        if (std::abs(row1[j] - row2[j]) > tolerance){
          printf("In the line %zu, column %zu:\ndata1 has value: %.8f;\ndata2 has value: %.8f.\n", i+1,j+1,row1[j],row2[j]);
          printf("The difference is greater than the tolerance %g. \nSo data in two files are not close within specific tolerance.\nProgram exits.\n", tolerance);
          failure_found = VALUE_TOLERANCE_FAILURE_CODE;
        }
      }
    }
  }
  if ( ! failure_found )
  {
    printf("Two files are close within the specific tolerance %g \n", tolerance);
    printf("Program exits successfully.\n");
  }
  else{
    std::cout << "ERROR! ERROR! ERROR! The files do not match." << std::endl;
  }
  return failure_found;
}
开发者ID:,项目名称:,代码行数:43,代码来源:

示例14: main

int main(int argc, char *argv[]) {
  std::srand ( unsigned ( std::time(0) ) );

#ifdef USE_OPENMP
  const int threads_wanted = 4;
  omp_set_num_threads(threads_wanted);
#endif

  g_conf.number_of_feature = 79;
  g_conf.max_depth = 6;
  g_conf.iterations = 10;
  g_conf.shrinkage = 0.1F;

  if (argc < 3) return -1;

  std::string train_file(argv[1]);
  std::string test_file(argv[2]);

  if (argc > 3) {
    g_conf.max_depth = boost::lexical_cast<int>(argv[3]);
  }

  if (argc > 4) {
    g_conf.iterations = boost::lexical_cast<int>(argv[4]);
  }

  if (argc > 5) {
    g_conf.shrinkage = boost::lexical_cast<float>(argv[5]);
  }

  if (argc > 6) {
    g_conf.feature_sample_ratio = boost::lexical_cast<float>(argv[6]);
  }

  if (argc > 7) {
    g_conf.data_sample_ratio = boost::lexical_cast<float>(argv[7]);
  }

  int debug = 0;
  if (argc > 8) {
    debug = boost::lexical_cast<int>(argv[8]);
  }

  g_conf.loss = LOG_LIKELIHOOD;
  g_conf.debug = debug > 0? true : false;

  DataVector d;
  bool r = LoadDataFromFile(train_file, &d);
  assert(r);

  g_conf.min_leaf_size = d.size() / 40;
  std::cout << "configure: " << std::endl
            << g_conf.ToString() << std::endl;

  if (argc > 9) {
    g_conf.LoadFeatureCost(argv[9]);
  }

  GBDT gbdt;
  Elapsed elapsed;
  gbdt.Fit(&d);
  std::cout << "fit time: " << elapsed.Tell() << std::endl;

  std::string model_file = train_file + ".model";
  std::ofstream model_output(model_file.c_str());
  model_output << gbdt.Save();

  CleanDataVector(&d);
  FreeVector(&d);

  DataVector d2;
  r = LoadDataFromFile(test_file, &d2);
  assert(r);

  elapsed.Reset();
  DataVector::iterator iter = d2.begin();
  PredictVector predict;
  for ( ; iter != d2.end(); ++iter) {
    ValueType p = Logit(gbdt.Predict(**iter));
    predict.push_back(p);

  }
  std::cout << "predict time: " << elapsed.Tell() << std::endl;

  std::string predict_file = test_file + ".predict";
  std::ofstream predict_output(predict_file.c_str());

  Auc auc;
  for (size_t i = 0; i < d2.size(); ++i) {
    predict_output << predict[i] << " " << d2[i]->ToString() << std::endl;
    auc.Add(predict[i], d2[i]->label);
  }
  std::cout << "auc: " << auc.CalculateAuc() << std::endl;
  auc.PrintConfusionTable();

  CleanDataVector(&d2);

  return 0;
}
开发者ID:mafeichao,项目名称:gbdt,代码行数:99,代码来源:ctr.cpp

示例15: checkInput

void DataTransformation::checkInput(const DataVector &input) const
{
    Q_ASSERT(input.size() == inputNumber());
}
开发者ID:sarum9in,项目名称:lab_neuro,代码行数:4,代码来源:DataTransformation.cpp


注:本文中的DataVector::size方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。