本文整理汇总了C++中sample函数的典型用法代码示例。如果您正苦于以下问题:C++ sample函数的具体用法?C++ sample怎么用?C++ sample使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sample函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: while
void PanoramaTracker::run() {
while (isRunning() && m_scaled.size() <= MAX_TRACKER_FRAMES) {
QScopedPointer<QtCamGstSample> sample(m_input->sample());
if (!sample) {
continue;
}
if (!Tracker::isInitialized()) {
QSize size = QSize(sample->width(), sample->height());
int m_width = size.width() > 720 ? size.width() / 8 : size.width() / 4;
int m_height = size.width() > 720 ? size.height() / 8 : size.height() / 4;
m_inputSize = size;
// TODO: This should be 5.0 but we fail to stitch sometimes if we set it to 5
if (!Tracker::initialize(m_width, m_height, 2.0f)) {
emit error(Panorama::ErrorTrackerInit);
return;
}
}
// Now we can process the sample:
const guint8 *src = sample->data();
QScopedArrayPointer<guint8>
dst(new guint8[m_inputSize.width() * m_inputSize.height() * 3 / 2]);
enum libyuv::FourCC fmt;
switch (sample->format()) {
case GST_VIDEO_FORMAT_UYVY:
fmt = libyuv::FOURCC_UYVY;
break;
default:
qCritical() << "Unsupported color format";
emit error(Panorama::ErrorTrackerFormat);
return;
}
guint8 *y = dst.data(),
*u = y + m_inputSize.width() * m_inputSize.height(),
*v = u + m_inputSize.width()/2 * m_inputSize.height()/2;
if (ConvertToI420(src, sample->size(),
y, m_inputSize.width(),
u, m_inputSize.width() / 2,
v, m_inputSize.width() / 2,
0, 0,
m_inputSize.width(), m_inputSize.height(),
m_inputSize.width(), m_inputSize.height(),
libyuv::kRotate0, fmt) != 0) {
emit error(Panorama::ErrorTrackerConvert);
return;
}
QScopedArrayPointer<guint8> scaled(new guint8[m_width * m_height * 3 / 2]);
guint8 *ys = scaled.data(),
*us = ys + m_width * m_height,
*vs = us + m_width/2 * m_height/2;
// Now scale:
// No need for error checking because the function always returns 0
libyuv::I420Scale(y, m_inputSize.width(),
u, m_inputSize.width()/2,
v, m_inputSize.width()/2,
m_inputSize.width(), m_inputSize.height(),
ys, m_width,
us, m_width/2,
vs, m_width/2,
m_width, m_height,
libyuv::kFilterBilinear);
int err = addFrame(scaled.data());
if (err >= 0) {
m_scaled.push_back(scaled.take());
m_frames.push_back(dst.take());
emit frameCountChanged();
}
}
}
示例2: sample_z
kernel void sample_z(global int *cur_y,
global int *cur_z,
global int *cur_r,
global int *z_by_ry,
global int *z_col_sum,
global int *obs,
global float *rand,
uint N, uint D, uint K, uint f_img_width,
float lambda, float epislon, float theta) {
const uint V_SCALE = 0, H_SCALE = 1, V_TRANS = 2, H_TRANS = 3, NUM_TRANS = 4;
uint h, w, new_index; // variables used in the for loop
uint nth = get_global_id(0); // n is the index of data
uint kth = get_global_id(1); // k is the index of features
uint f_img_height = D / f_img_width;
// calculate the prior probability of each cell is 1
float on_prob_temp = (z_col_sum[kth] - cur_z[nth * K + kth]) / (float)N;
float off_prob_temp = 1 - (z_col_sum[kth] - cur_z[nth * K + kth]) / (float)N;
// retrieve the transformation applied to this feature by this object
int v_scale = cur_r[nth * (K * NUM_TRANS) + kth * NUM_TRANS + V_SCALE];
int h_scale = cur_r[nth * (K * NUM_TRANS) + kth * NUM_TRANS + H_SCALE];
int v_dist = cur_r[nth * (K * NUM_TRANS) + kth * NUM_TRANS + V_TRANS];
int h_dist = cur_r[nth * (K * NUM_TRANS) + kth * NUM_TRANS + H_TRANS];
int new_height = f_img_height + v_scale, new_width = f_img_width + h_scale;
uint d, hh, ww;
// extremely hackish way to calculate the likelihood
for (d = 0; d < D; d++) {
// if the kth feature can turn on a pixel at d
if (cur_y[kth * D + d] == 1) {
// unpack d into h and w and get new index
h = d / f_img_width;
w = d % f_img_width;
for (hh = 0; hh < f_img_height; hh++) {
for (ww = 0; ww < f_img_width; ww++) {
if ((int)round((float)hh / new_height * f_img_height) == h &
(int)round((float)ww / new_width * f_img_width) == w) {
new_index = ((v_dist + hh) % f_img_height) * f_img_width + (h_dist + ww) % f_img_width;
// then the corresponding observed pixel is at new_index
// so, if the observed pixel at new_index is on
if (obs[nth * D + new_index] == 1) {
// if the nth object previously has the kth feature
if (cur_z[nth * K + kth] == 1) {
on_prob_temp *= 1 - pow(1 - lambda, z_by_ry[nth * D + new_index]) * (1 - epislon);
off_prob_temp *= 1 - pow(1 - lambda, z_by_ry[nth * D + new_index] - 1) * (1 - epislon);
} else {
on_prob_temp *= 1 - pow(1 - lambda, z_by_ry[nth * D + new_index] + 1) * (1 - epislon);
off_prob_temp *= 1 - pow(1 - lambda, z_by_ry[nth * D + new_index]) * (1 - epislon);
}
} else {
on_prob_temp *= 1 - lambda;
off_prob_temp *= 1.0f;
}
}
}
}
}
}
//printf("index: %d post_on: %f post_off: %f\n", nth * K + kth, on_prob_temp, off_prob_temp);
float post[2] = {on_prob_temp, off_prob_temp};
uint labels[2] = {1, 0};
pnormalize(post, 0, 2);
//printf("before index: %d %f %f %d \n", nth * K + kth, post[0], post[1], cur_z[nth * K + kth]);
cur_z[nth * K + kth] = sample(2, labels, post, 0, rand[nth * K + kth]);
//printf("after index: %d %f %f %d \n", nth * K + kth, post[0], post[1], cur_z[nth * K + kth]);
}
示例3: gui
void Mesh2Cloud::addProperties() {
auto group = gui()->properties()->add<Section>("Sampling", "group");
auto samples = group->add<Number>("Samples Per Square Unit", "samples");
samples->setDigits(0);
samples->setMin(1);
samples->setMax(100000);
samples->setValue(100);
group->add<Button>("Sample", "sample")->setCallback([&] () { auto ns = gui()->properties()->get<Number>({"group", "samples"})->value(); sample(ns); });;
auto iogroup = gui()->properties()->add<Section>("Input/Output", "iogroup");
auto outFile = iogroup->add<File>("Save to: ", "outFile");
outFile->setMode(File::SAVE);
outFile->setCallback([&] (fs::path p) {
pcl::io::savePCDFileBinary(p.string(), *m_cloud);
gui()->log()->info("Saved pointcloud to: \""+p.string()+"\"");
});
outFile->disable();
}
示例4: MOZ_ASSERT
nsresult
EMEH264Decoder::GmpInput(MP4Sample* aSample)
{
MOZ_ASSERT(IsOnGMPThread());
nsAutoPtr<MP4Sample> sample(aSample);
if (!mGMP) {
mCallback->Error();
return NS_ERROR_FAILURE;
}
if (sample->crypto.valid) {
CDMCaps::AutoLock caps(mProxy->Capabilites());
MOZ_ASSERT(caps.CanDecryptAndDecodeVideo());
const auto& keyid = sample->crypto.key;
if (!caps.IsKeyUsable(keyid)) {
nsRefPtr<nsIRunnable> task(new DeliverSample(this, sample.forget()));
caps.CallWhenKeyUsable(keyid, task, mGMPThread);
return NS_OK;
}
}
mLastStreamOffset = sample->byte_offset;
GMPVideoFrame* ftmp = nullptr;
GMPErr err = mHost->CreateFrame(kGMPEncodedVideoFrame, &ftmp);
if (GMP_FAILED(err)) {
mCallback->Error();
return NS_ERROR_FAILURE;
}
gmp::GMPVideoEncodedFrameImpl* frame = static_cast<gmp::GMPVideoEncodedFrameImpl*>(ftmp);
err = frame->CreateEmptyFrame(sample->size);
if (GMP_FAILED(err)) {
mCallback->Error();
return NS_ERROR_FAILURE;
}
memcpy(frame->Buffer(), sample->data, frame->Size());
frame->SetEncodedWidth(mConfig.display_width);
frame->SetEncodedHeight(mConfig.display_height);
frame->SetTimeStamp(sample->composition_timestamp);
frame->SetCompleteFrame(true);
frame->SetDuration(sample->duration);
if (sample->crypto.valid) {
frame->InitCrypto(sample->crypto);
}
frame->SetFrameType(sample->is_sync_point ? kGMPKeyFrame : kGMPDeltaFrame);
frame->SetBufferType(GMP_BufferLength32);
nsTArray<uint8_t> info; // No codec specific per-frame info to pass.
nsresult rv = mGMP->Decode(frame, false, info, 0);
if (NS_FAILED(rv)) {
mCallback->Error();
return rv;
}
return NS_OK;
}
示例5: sample_hidden
// Sample a hidden neuron, given a visible neuron vector
double sample_hidden(rbm* r, unsigned int j, std::vector<int> visible) {
return sample(hidden_probability(r, j, visible));
}
示例6: sample
void Shape::sample(const core::Vec3 &ps, float u1, float u2, float u3, int *primID, core::Vec3 *p, core::Vec3 *n) const
{
return sample(u1, u2, u3, primID, p, n);
}
示例7: clear
//.........这里部分代码省略.........
return false;
}
//Load the info text
file >> word;
infoText = "";
while( word != "NumDimensions:" ){
infoText += word + " ";
file >> word;
}
//Get the number of dimensions in the training data
if( word != "NumDimensions:" ){
errorLog << "loadDatasetFromFile(const std::string &filename) - failed to find NumDimensions header!" << std::endl;
file.close();
return false;
}
file >> numDimensions;
//Get the total number of training examples in the training data
file >> word;
if( word != "TotalNumTrainingExamples:" && word != "TotalNumExamples:" ){
errorLog << "loadDatasetFromFile(const std::string &filename) - failed to find TotalNumTrainingExamples header!" << std::endl;
file.close();
return false;
}
file >> totalNumSamples;
//Get the total number of classes in the training data
file >> word;
if(word != "NumberOfClasses:"){
errorLog << "loadDatasetFromFile(string filename) - failed to find NumberOfClasses header!" << std::endl;
file.close();
return false;
}
file >> numClasses;
//Resize the class counter buffer and load the counters
classTracker.resize(numClasses);
//Get the total number of classes in the training data
file >> word;
if(word != "ClassIDsAndCounters:"){
errorLog << "loadDatasetFromFile(const std::string &filename) - failed to find ClassIDsAndCounters header!" << std::endl;
file.close();
return false;
}
for(UINT i=0; i<classTracker.getSize(); i++){
file >> classTracker[i].classLabel;
file >> classTracker[i].counter;
file >> classTracker[i].className;
}
//Check if the dataset should be scaled using external ranges
file >> word;
if(word != "UseExternalRanges:"){
errorLog << "loadDatasetFromFile(const std::string &filename) - failed to find UseExternalRanges header!" << std::endl;
file.close();
return false;
}
file >> useExternalRanges;
//If we are using external ranges then load them
if( useExternalRanges ){
externalRanges.resize(numDimensions);
for(UINT i=0; i<externalRanges.getSize(); i++){
file >> externalRanges[i].minValue;
file >> externalRanges[i].maxValue;
}
}
//Get the main training data
file >> word;
if( word != "LabelledTrainingData:" && word != "Data:"){
errorLog << "loadDatasetFromFile(const std::string &filename) - failed to find LabelledTrainingData header!" << std::endl;
file.close();
return false;
}
ClassificationSample tempSample( numDimensions );
data.resize( totalNumSamples, tempSample );
for(UINT i=0; i<totalNumSamples; i++){
UINT classLabel = 0;
VectorFloat sample(numDimensions,0);
file >> classLabel;
for(UINT j=0; j<numDimensions; j++){
file >> sample[j];
}
data[i].set(classLabel, sample);
}
file.close();
//Sort the class labels
sortClassLabels();
return true;
}
示例8: main
int main() {
srand(time(NULL));
sample(10000000, 1000000);
}
示例9: UniformSample
double UniformSample(double max) {
boost::uniform_real<> dist(0, max);
boost::variate_generator<boost::mt19937&, boost::uniform_real<> > sample(
gen, dist);
return sample();
}
示例10: DeltaStarGibbs
//.........这里部分代码省略.........
for (it = chol[i].begin(); it != chol[i].end(); it++) {
int j = it->first;
double value = it->second;
if (j == i)
diag = value;
else
sum += value * mean[j];
}
mean[i] = (u[i] - sum) / diag;
}
// print mean value
/*
{
char filename[120];
sprintf(filename,"mean.txt");
FILE *out = fopen(filename,"w");
int i;
for (i = 0; i < mean.size(); i++) {
fprintf(out,"%20.18e\n",mean[i]);
}
fclose(out);
}
*/
// finished printing
// generate a sample with zero mean, or compute the sample that should have been sampled
// cout << "start sampling" << endl;
vector<double> sample(chol.size(),0.0);
if (draw == 1) {
vector<double> z(chol.size(),0.0);
for (k = 0; k < z.size(); k++)
z[k] = ran.Norm01();
// print z
/*
{
char filename[120];
sprintf(filename,"z.txt");
FILE *out = fopen(filename,"w");
int i;
for (i = 0; i < z.size(); i++) {
fprintf(out,"%20.18e\n",z[i]);
}
fclose(out);
}
*/
// finished printing
for (i = 0; i < sample.size(); i++) {
double diag = 0.0;
double sum = 0.0;
map<int,double>::iterator it;
for (it = chol[i].begin(); it != chol[i].end(); it++) {
int j = it->first;
double value = it->second;
if (j == i)
diag = value;
示例11: GaussianMean1DRegressionCompute
void GaussianMean1DRegressionCompute(const QUESO::BaseEnvironment& env,
double priorMean, double priorVar, const likelihoodData& dat)
{
// parameter space: 1-D on (-infinity, infinity)
QUESO::VectorSpace<P_V, P_M> paramSpace(
env, // queso environment
"param_", // name prefix
1, // dimensions
NULL); // names
P_V paramMin(paramSpace.zeroVector());
P_V paramMax(paramSpace.zeroVector());
paramMin[0] = -INFINITY;
paramMax[0] = INFINITY;
QUESO::BoxSubset<P_V, P_M> paramDomain(
"paramBox_", // name prefix
paramSpace, // vector space
paramMin, // min values
paramMax); // max values
// gaussian prior with user supplied mean and variance
P_V priorMeanVec(paramSpace.zeroVector());
P_V priorVarVec(paramSpace.zeroVector());
priorMeanVec[0] = priorMean;
priorVarVec[0] = priorVar;
QUESO::GaussianVectorRV<P_V, P_M> priorRv("prior_", paramDomain, priorMeanVec,
priorVarVec);
// likelihood is important
QUESO::GenericScalarFunction<P_V, P_M> likelihoodFunctionObj(
"like_", // name prefix
paramDomain, // image set
LikelihoodFunc<P_V, P_M>, // routine
(void *) &dat, // routine data ptr
true); // routineIsForLn
QUESO::GenericVectorRV<P_V, P_M> postRv(
"post_", // name prefix
paramSpace); // image set
// Initialize and solve the Inverse Problem with Bayes multi-level sampling
QUESO::StatisticalInverseProblem<P_V, P_M> invProb(
"", // name prefix
NULL, // alt options
priorRv, // prior RV
likelihoodFunctionObj, // likelihood fcn
postRv); // posterior RV
invProb.solveWithBayesMLSampling();
// compute mean and second moment of samples on each proc via Knuth online mean/variance algorithm
int N = invProb.postRv().realizer().subPeriod();
double subMean = 0.0;
double subM2 = 0.0;
double delta;
P_V sample(paramSpace.zeroVector());
for (int n = 1; n <= N; n++) {
invProb.postRv().realizer().realization(sample);
delta = sample[0] - subMean;
subMean += delta / n;
subM2 += delta * (sample[0] - subMean);
}
// gather all Ns, means, and M2s to proc 0
std::vector<int> unifiedNs(env.inter0Comm().NumProc());
std::vector<double> unifiedMeans(env.inter0Comm().NumProc());
std::vector<double> unifiedM2s(env.inter0Comm().NumProc());
MPI_Gather(&N, 1, MPI_INT, &(unifiedNs[0]), 1, MPI_INT, 0,
env.inter0Comm().Comm());
MPI_Gather(&subMean, 1, MPI_DOUBLE, &(unifiedMeans[0]), 1, MPI_DOUBLE, 0,
env.inter0Comm().Comm());
MPI_Gather(&subM2, 1, MPI_DOUBLE, &(unifiedM2s[0]), 1, MPI_DOUBLE, 0,
env.inter0Comm().Comm());
// get the total number of likelihood calls at proc 0
unsigned long totalLikelihoodCalls = 0;
MPI_Reduce(&likelihoodCalls, &totalLikelihoodCalls, 1, MPI_UNSIGNED_LONG,
MPI_SUM, 0, env.inter0Comm().Comm());
// compute global posterior mean and std via Chan algorithm, output results on proc 0
if (env.inter0Rank() == 0) {
int postN = unifiedNs[0];
double postMean = unifiedMeans[0];
double postVar = unifiedM2s[0];
for (unsigned int i = 1; i < unifiedNs.size(); i++) {
delta = unifiedMeans[i] - postMean;
postMean = (postN * postMean + unifiedNs[i] * unifiedMeans[i]) /
(postN + unifiedNs[i]);
postVar += unifiedM2s[i] + delta * delta *
(((double)postN * unifiedNs[i]) / (postN + unifiedNs[i]));
postN += unifiedNs[i];
}
postVar /= postN;
//compute exact answer - available in this case since the exact posterior is a gaussian
N = dat.dataSet.size();
double dataSum = 0.0;
for (int i = 0; i < N; i++)
dataSum += dat.dataSet[i];
//.........这里部分代码省略.........
示例12: sample
Point Geometry::sample(const Point&, const GeomSample &gs, Normal &normal) const {
return sample(gs, normal);
}
示例13: main
int main (int argc, char **argv)
{
char c;
unsigned int flag = 0;
int interval = 1, count = 0, max_count = 1;
struct vg_data vg_now, vg_prev;
VMGuestLibError ret;
while ((c = getopt(argc, argv, "i:c:hvru")) != -1) {
switch(c) {
case 'i':
interval = atoi(optarg);
break;
case 'c':
max_count = atoi(optarg);
break;
case 'h':
usage();
return 0;
break;
case 'r': /* raw output */
flag |= FLAG_RAWOUTPUT;
break;
case 'v': /* verbose mode */
flag |= FLAG_VERBOSE;
break;
case 'u':
flag |= FLAG_UNIXTIME;
break;
default:
printf("Unkown option '%c'\n", c);
}
}
memset(&vg_now, 0x0, sizeof(struct vg_data));
ret = VMGuestLib_OpenHandle(&vg_now.handle);
if (ret != VMGUESTLIB_ERROR_SUCCESS) {
if (IS_VERBOSE(flag)) {
printf("VMGuestLib_OpenHandle: %d (%s)\n",
ret, VMGuestLib_GetErrorText(ret));
}
return 1;
}
if (sample(&vg_now, flag) != 0) {
goto bailout;
}
if (IS_RAWOUTPUT(flag)) {
printf("Timestamp "
"SessionId "
"HostProcessorSpeed "
"CpuReservationMHz CpuLimitMHz CpuShares "
"ElapsedMs CpuUsedMs CpuStolenMs "
"MemReservationMB MemLimitMB MemShares MemMappedMB "
"MemActiveMB MemOverheadMB MemBalloonedMB MemSwappedMB "
"MemSharedMB MemSharedSavedMB MemUsedMB\n"
);
} else {
printf("%-24s %-8s %-8s %8s %8s %8s %8s\n",
"Timestamp", "intvl(g)", "intvl(h)",
"used", "stolen", "%used", "%ready");
}
for (count = 0; count < max_count; count++) {
vg_prev = vg_now;
sleep(interval);
if (sample(&vg_now, flag) != 0) {
goto bailout;
}
output(&vg_now, &vg_prev, flag);
}
bailout:
ret = VMGuestLib_CloseHandle(vg_now.handle);
if (ret != VMGUESTLIB_ERROR_SUCCESS) {
if (IS_VERBOSE(flag)) {
printf("VMGuestLib_CloseHandle: %d (%s)\n",
ret, VMGuestLib_GetErrorText(ret));
}
return 1;
}
return 0;
}
示例14: main
int main ( int argc, char *argv[] )
{
//Variables for parsing the data file
std::string filename = "SPECT.train";
std::string line;
std::stringstream parse;
int ssize = 100; //establish a buffer size to store attribute values,
//which for binary classification string are no bigger than 1
char c[ssize];
char delimiter = ',';
//Variables to store the values in the data file
std::vector<int> tmpcase;
std::vector< std::vector<int> > training_set;
cv::Mat sample(0, 1, CV_32FC1);
cv::Mat labels(0, 1 , CV_16SC1);
cv::Mat train_set;
std::ifstream dataset_file(filename.c_str(), std::ios::in);
if(!dataset_file)
{
std::cerr << "Cannot load training set file" << std::endl;
}
else
{
while( (getline(dataset_file, line))!= NULL )
{
parse << line;
while( parse.getline(c,ssize,delimiter) )
{
tmpcase.push_back( (*c-'0') );
sample.push_back( (float)(*c-'0') );
}
parse.str(""); //safety measure to erase previous contents
parse.clear(); //clear flags to be able to read from it again
training_set.push_back(tmpcase);
tmpcase.clear();
train_set.push_back(sample.reshape(0,1));
labels.push_back((int)(sample.at<float>(0)));
sample = cv::Mat();
}
}
std::cout << train_set << std::endl;
cv::FileStorage fstore_traindata("spect_train.yml",cv::FileStorage::WRITE);
cv::Mat train_samples(train_set.colRange(1,train_set.cols));
fstore_traindata << "train_samples" << train_samples;
fstore_traindata << "train_labels" << labels;
fstore_traindata.release();
std::cout << train_samples << std::endl;
std::cout << labels << std::endl;
std::vector<int> tmp;
for(std::vector< std::vector<int> >::iterator it = training_set.begin(); it != training_set.end(); ++it)
{
tmp = *it;
for(std::vector<int>::iterator it2 = tmp.begin(); it2 != tmp.end(); ++it2)
{
std::cout << *it2 << " ";
}
std::cout << std::endl;
tmp.clear();
}
}
示例15: compute_tree_bagging
static int compute_tree_bagging(ETree *etree,int n,int d,double *x[],
int y[], int nmodels,int stumps, int minsize)
{
int i,b;
int *samples;
double **trx;
int *try;
if(nmodels<1){
fprintf(stderr,"compute_tree_bagging: nmodels must be greater than 0\n");
return 1;
}
if(stumps != 0 && stumps != 1){
fprintf(stderr,"compute_tree_bagging: parameter stumps must be 0 or 1\n");
return 1;
}
if(minsize < 0){
fprintf(stderr,"compute_tree_bagging: parameter minsize must be >= 0\n");
return 1;
}
etree->nclasses=iunique(y,n, &(etree->classes));
if(etree->nclasses<=0){
fprintf(stderr,"compute_tree_bagging: iunique error\n");
return 1;
}
if(etree->nclasses==1){
fprintf(stderr,"compute_tree_bagging: only 1 class recognized\n");
return 1;
}
if(etree->nclasses==2)
if(etree->classes[0] != -1 || etree->classes[1] != 1){
fprintf(stderr,"compute_tree_bagging: for binary classification classes must be -1,1\n");
return 1;
}
if(etree->nclasses>2)
for(i=0;i<etree->nclasses;i++)
if(etree->classes[i] != i+1){
fprintf(stderr,"compute_tree_bagging: for %d-class classification classes must be 1,...,%d\n",etree->nclasses,etree->nclasses);
return 1;
}
if(!(etree->tree=(Tree *)calloc(nmodels,sizeof(Tree)))){
fprintf(stderr,"compute_tree_bagging: out of memory\n");
return 1;
}
etree->nmodels=nmodels;
if(!(etree->weights=dvector(nmodels))){
fprintf(stderr,"compute_tree_bagging: out of memory\n");
return 1;
}
for(b=0;b<nmodels;b++)
etree->weights[b]=1.0 / (double) nmodels;
if(!(trx=(double **)calloc(n,sizeof(double*)))){
fprintf(stderr,"compute_tree_bagging: out of memory\n");
return 1;
}
if(!(try=ivector(n))){
fprintf(stderr,"compute_tree_bagging: out of memory\n");
return 1;
}
for(b=0;b<nmodels;b++){
if(sample(n, NULL, n, &samples, TRUE,b)!=0){
fprintf(stderr,"compute_tree_bagging: sample error\n");
return 1;
}
for(i =0;i<n;i++){
trx[i] = x[samples[i]];
try[i] = y[samples[i]];
}
if(compute_tree(&(etree->tree[b]),n,d,trx,try,stumps,minsize)!=0){
fprintf(stderr,"compute_tree_bagging: compute_tree error\n");
return 1;
}
free_ivector(samples);
}
free(trx);
free_ivector(try);
return 0;
}
static int compute_tree_aggregate(ETree *etree,int n,int d,double *x[],int y[],
int nmodels,int stumps, int minsize)
//.........这里部分代码省略.........