本文整理汇总了C++中DVector::Init方法的典型用法代码示例。如果您正苦于以下问题:C++ DVector::Init方法的具体用法?C++ DVector::Init怎么用?C++ DVector::Init使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DVector
的用法示例。
在下文中一共展示了DVector::Init方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
//.........这里部分代码省略.........
double myXtrain_feature = myXtrain[j*Xtrain_N+i];
if (myXtrain_feature != 0)
instances_old.back().push_back(pair<int,double>(index, myXtrain_feature));
}
}
long Xtest_N = Xtest.GetN();
for(i=0;i<Xtest_N;i++){
instances_old.push_back(vector<pair<int,double> >());
for(j=0;j<d;j++){
int index = j+1;
double *myXtest = Xtest.GetPointer();
double myXtest_feature = myXtest[j*Xtest_N+i];
if (myXtest_feature != 0)
instances_old.back().push_back(pair<int,double>(index, myXtest_feature));
}
}
END_CLOCK;
printf("Train. RandBin: Time (in seconds) for converting data format: %g\n", ELAPSED_TIME);fflush(stdout);
// add 0 feature for Enxu's code
START_CLOCK;
random_binning_feature(d+1, r, instances_old, instances_new, sigma);
END_CLOCK;
printf("Train. RandBin: Time (in seconds) for generating random binning features: %g\n", ELAPSED_TIME);fflush(stdout);
START_CLOCK;
SPointArray Xdata_randbin; // Generate random binning features
long int nnz = r*(Xtrain_N + Xtest_N);
long int dd = 0;
for(i = 0; i < instances_new.size(); i++){
if(dd < instances_new[i][r-1].first)
dd = instances_new[i][r-1].first;
}
Xdata_randbin.Init(Xtrain_N+Xtest_N, dd, nnz);
long int ind = 0;
long int *mystart = Xdata_randbin.GetPointerStart();
int *myidx = Xdata_randbin.GetPointerIdx();
double *myX = Xdata_randbin.GetPointerX();
for(i = 0; i < instances_new.size(); i++){
if (i == 0)
mystart[i] = 0;
else
mystart[i] = mystart[i-1] + r;
for(j = 0; j < instances_new[i].size(); j++){
myidx[ind] = instances_new[i][j].first-1;
myX[ind] = instances_new[i][j].second;
ind++;
}
}
mystart[i] = nnz; // mystart has a length N+1
// generate random binning features for Xtrain and Xtest
SPointArray Xtrain; // Training points
SPointArray Xtest; // Testing points
long Row_start = 0;
Xdata_randbin.GetSubset(Row_start, Xtrain_N,Xtrain);
Xdata_randbin.GetSubset(Xtrain_N,Xtest_N,Xtest);
Xdata_randbin.ReleaseAllMemory();
END_CLOCK;
printf("Train. RandBin: Time (in seconds) for converting data format back: %g\n", ELAPSED_TIME);fflush(stdout);
printf("OneVsAll: n train = %ld, m test = %ld, r = %d, D = %ld, Gamma = %f, num threads = %d\n", Xtrain_N, Xtest_N, r, dd, sigma, NumThreads); fflush(stdout);
// solve (Z'Z + lambdaI)w = Z'y, note that we never explicitly form
// Z'Z since Z is a large sparse matrix N*dd
START_CLOCK;
int m = Ytrain.GetN(); // number of classes
long N = Xtrain.GetN(); // number of training points