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


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

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


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

示例1: if

void
load(const char *fname, xvec_t &xp, yvec_t &yp)
{
  cout << "Loading " << fname << "." << endl;
  
  igzstream f;
  f.open(fname);
  if (! f.good())
    {
      cerr << "ERROR: cannot open " << fname << "." << endl;
      exit(10);
    }
  int pcount = 0;
  int ncount = 0;

  bool binary;
  string suffix = fname;
  if (suffix.size() >= 7)
    suffix = suffix.substr(suffix.size() - 7);
  if (suffix == ".dat.gz")
    binary = false;
  else if (suffix == ".bin.gz")
    binary = true;
  else
    {
      cerr << "ERROR: filename should end with .bin.gz or .dat.gz" << endl;
      exit(10);
    }

  while (f.good())
    {
      SVector x;
      double y;
      if (binary)
        {
          y = (f.get()) ? +1 : -1;
          x.load(f);
        }
      else
        {
          f >> y >> x;
        }
      if (f.good())
        {
          assert(y == +1 || y == -1);
          xp.push_back(x);
          yp.push_back(y);
          if (y > 0)
            pcount += 1;
          else
            ncount += 1;
          if (x.size() > dim)
            dim = x.size();
        }
      if (trainsize > 0 && xp.size() > (unsigned int)trainsize)
        break;
    }
  cout << "Read " << pcount << "+" << ncount 
       << "=" << pcount + ncount << " examples." << endl;
}
开发者ID:AnryYang,项目名称:cpp_algorithms,代码行数:60,代码来源:svmsgd2.cpp

示例2: main

int main(int argc, const char **argv)
{
  parse(argc, argv);
  config(argv[0]);
  if (trainfile)
    load_datafile(trainfile, xtrain, ytrain, dims, normalize, maxtrain);
  if (testfile)
    load_datafile(testfile, xtest, ytest, dims, normalize);
  cout << "# Number of features " << dims << "." << endl;
  // prepare svm
  int imin = 0;
  int imax = xtrain.size() - 1;
  int tmin = 0;
  int tmax = xtest.size() - 1;
  // heuristic determination of averaging start point
  int avgfrom = fabs(avgstart) * (imax - imin + 1);
  avgfrom = (avgstart < 0 && dims < avgfrom) ? dims : avgfrom;
  // create
  SvmAisgd svm(dims, lambda, avgfrom);
  Timer timer;
  // determine eta0 using sample
  int smin = 0;
  int smax = imin + min(1000, imax);
  timer.start();
  svm.determineEta0(smin, smax, xtrain, ytrain);
  timer.stop();
  // train
  for(int i=0; i<epochs; i++)
    {
      cout << "--------- Epoch " << i+1 << "." << endl;
      timer.start();
      svm.train(imin, imax, xtrain, ytrain);
      timer.stop();
      cout << "Total training time " << setprecision(6)
           << timer.elapsed() << " secs." << endl;
      svm.test(imin, imax, xtrain, ytrain, "train: ");
      if (tmax >= tmin)
        svm.test(tmin, tmax, xtest, ytest, "test:  ");
    }
  svm.renorm();
  // Linear classifier is in svm.a and svm.aBias
  return 0;
}
开发者ID:airoldilab,项目名称:ai-sgd,代码行数:43,代码来源:svmaisgd.cpp

示例3: main

int main(int argc, const char **argv)
{
  parse(argc, argv);
  config(argv[0]);
  if (trainfile)
    load_datafile(trainfile, xtrain, ytrain, dims, normalize, maxtrain);
  if (testfile)
    load_datafile(testfile, xtest, ytest, dims, normalize);
  cout << "# Number of features " << dims << "." << endl;
  // prepare svm
  int imin = 0;
  int imax = xtrain.size() - 1;
  int tmin = 0;
  int tmax = xtest.size() - 1;
  SvmSag svm(dims, lambda);
  Timer timer;
  // determine eta0 using sample
  int smin = 0;
  int smax = imin + min(1000, imax);
  timer.start();
  if (eta > 0)
    svm.setEta(eta);
  else
    svm.determineEta(smin, smax, xtrain, ytrain);
  timer.stop();
  // train
  for(int i=0; i<epochs; i++)
    {
      cout << "--------- Epoch " << i+1 << "." << endl;
      timer.start();
      if (i == 0)
        svm.trainInit(imin, imax, xtrain, ytrain);
      else
        svm.trainSag(imin, imax, xtrain, ytrain);
      timer.stop();
      cout << "Total training time " << setprecision(6) 
           << timer.elapsed() << " secs." << endl;
      svm.test(imin, imax, xtrain, ytrain, "train: ");
      if (tmax >= tmin)
        svm.test(tmin, tmax, xtest, ytest, "test:  ");
    }
  return 0;
}
开发者ID:DavidGrangier,项目名称:svmsparse,代码行数:43,代码来源:svmsag.cpp

示例4: main

int main(int argc, const char **argv)
{
		parse(argc, argv);
		config(argv[0]);
		if (trainfile)
				load_datafile(trainfile, xtrain, ytrain, dims, normalize, maxtrain);
		if (testfile)
				load_datafile(testfile, xtest, ytest, dims, normalize);
		cout << "# Number of features " << dims << "." << endl;
		// prepare svm
		int imin = 0;
		int imax = xtrain.size() - 1;
		int tmin = 0;
		int tmax = xtest.size() - 1;
		SvmSgd svm(dims, lambda);
		Timer timer;
		// determine eta0 using sample
		int smin = 0;
		int smax = imin + min(1000, imax);
		// train

		Timer totalTimer, overheadtimer, exetimer;

		totalTimer.start();
		//winnie, initial wDivisor and wBias

		timeval t1, t4, t5, t6, t7, t8;
		overheadtimer.start();
		if(sample_file){
				int sample_size = 500;
				int bin_num = 20;
				int num_compare = 49;
				int dimension = dims - 1; //The first feature is the classification, does not count in sampling.


				gettimeofday(&t1, NULL);

				Sampling<double> selector(imax, 0 ,
								dimension, sample_size, bin_num, num_compare);

				selector.do_sampling(sample_file);
				gettimeofday(&t4, NULL);
				selector.calc_ecdf();		
				gettimeofday(&t5, NULL);
				//	std::cout << "test init kmeans " << std::endl;
				//step3a, do database search
				if(num_compare <= 0){
						cerr << "Number of comparison is less than or equal to 0" << endl;
						return -1;
				}
				else{
						//TODO: make the comparison choose the second best result, when we use data base that contains dataset itself

						//winnie, prerun several iterations, and log some information
						int prerun_iters = 3;
						FVector old_w(dimension);

						svm.determineEta0(smin, smax, xtrain, ytrain);

						for(int i = 0; i < prerun_iters; i ++ ){

								svm.get_w(old_w);
								svm.train(imin, imax, xtrain, ytrain);
								//svm.test(imin, imax, xtrain, ytrain, "train: ");

						}
						//get the idx of dimensions	

						map <double, int> delta_w;
						svm.get_delta_w(old_w, delta_w);
						//int reducedDimNum[8] = {1, 2, 3, 4, 8, 16, 32, 50};
						int reducedDimNum[8] = {1, 3, 8, 16, 32, 50, 64, 128};
						int selected_id[9];
						multimap <double, int> error_dim;  //error value and dimension
						for(int iout = 0; iout < 8; iout++){

								vector<int> reducedDimIdx(reducedDimNum[iout]);
								map<double, int>::reverse_iterator rmit = delta_w.rbegin();
								double sum_value = 0;
								for(int i = 0; i < reducedDimNum[iout]; i ++){
										reducedDimIdx[i] = rmit->second;
										sum_value += rmit->first;
										//cout << "reduceDim: " << reducedDimIdx[i] << " value " << rmit->first << endl;
										rmit++;
								}
								cout << "sum_value: " << sum_value << " with dim num: " << reducedDimNum[iout] << endl;


								//cout << "distancetype: " << distancetype << endl;
								selected_id[iout] = selector.search_database('b', database_file, distancetype, reducedDimIdx);

								gettimeofday(&t6, NULL);
								if(selected_id[iout] < 0)
										return -1;
								else{
										std::cout << "selected id: " << selected_id[iout] << std::endl;
										//Do data customization, use norm.cpp program, 
										stringstream ss;//create a stringstream
										ss << setfill('0') << setw(2) << selected_id[iout];
										string filename = string(database_dir) + "/" + ss.str() + ".txt";
//.........这里部分代码省略.........
开发者ID:shanil-puri,项目名称:SysResearchLab,代码行数:101,代码来源:init_svmsgd.cpp


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