本文整理汇总了C++中Samples::size方法的典型用法代码示例。如果您正苦于以下问题:C++ Samples::size方法的具体用法?C++ Samples::size怎么用?C++ Samples::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Samples
的用法示例。
在下文中一共展示了Samples::size方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: fitFromData
void BSplineInterpolation::fitFromData(const Samples &samples) {
/* preprocess samples and extract some info */
Samples ssamples = samples;
std::sort(ssamples.begin(), ssamples.end());
const int numSamples = ssamples.size();
const float minSampleX = ssamples[0].first;
const float maxSampleX = ssamples.back().first;
/* prepare fitting data */
gsl_vector *x = gsl_vector_alloc(ssamples.size());
gsl_vector *y = gsl_vector_alloc(ssamples.size());
for (int i=0; i<ssamples.size(); i++) {
gsl_vector_set(x, i, ssamples[i].first);
gsl_vector_set(y, i, ssamples[i].second);
}
/* uniform knots distributed in sample range */
gsl_bspline_knots_uniform(minSampleX, maxSampleX, bSplineWorkspace);
/* construct a fit matrix */
gsl_matrix *fitMatrix = gsl_matrix_alloc(numSamples, nCoeffs);
for (int i=0; i<numSamples; i++) {
/* compute B_j(xi) for all j */
double xi = gsl_vector_get(x, i);
gsl_bspline_eval(xi, bSpline, bSplineWorkspace);
/* fill in row i */
for (int j=0; j<nCoeffs; j++) {
double Bj = gsl_vector_get(bSpline, j);
gsl_matrix_set(fitMatrix, i, j, Bj);
}
}
/* fit spline to data */
gsl_multifit_linear_workspace *mws =
gsl_multifit_linear_alloc(numSamples, nCoeffs);
double chisq;
size_t rank;
double tol = 0.1;
gsl_multifit_linear(fitMatrix, y, cParameters, covMatrix, &chisq, mws);
//gsl_multifit_linear_svd(fitMatrix, y, tol,
// &rank, cParameters, covMatrix, &chisq, mws);
splineMinX = minSampleX;
splineMaxX = maxSampleX;
/* clean up */
gsl_vector_free(x);
gsl_vector_free(y);
gsl_matrix_free(fitMatrix);
gsl_multifit_linear_free(mws);
}
示例2: if
void
diy::detail::KDTreeSamplingPartition<Block,Point>::
operator()(Block* b, const diy::ReduceProxy& srp, const KDTreePartners& partners) const
{
int dim;
if (srp.round() < partners.rounds())
dim = partners.dim(srp.round());
else
dim = partners.dim(srp.round() - 1);
if (srp.round() == partners.rounds())
update_links(b, srp, dim, partners.sub_round(srp.round() - 2), partners.swap_rounds(), partners.wrap, partners.domain); // -1 would be the "uninformative" link round
else if (partners.swap_round(srp.round()) && partners.sub_round(srp.round()) < 0) // link round
{
dequeue_exchange(b, srp, dim); // from the swap round
split_to_neighbors(b, srp, dim);
}
else if (partners.swap_round(srp.round()))
{
Samples samples;
receive_samples(b, srp, samples);
enqueue_exchange(b, srp, dim, samples);
} else if (partners.sub_round(srp.round()) == 0)
{
if (srp.round() > 0)
{
int prev_dim = dim - 1;
if (prev_dim < 0)
prev_dim += dim_;
update_links(b, srp, prev_dim, partners.sub_round(srp.round() - 2), partners.swap_rounds(), partners.wrap, partners.domain); // -1 would be the "uninformative" link round
}
compute_local_samples(b, srp, dim);
} else if (partners.sub_round(srp.round()) < (int) partners.histogram.rounds()/2) // we are reusing partners class, so really we are talking about the samples rounds here
{
Samples samples;
add_samples(b, srp, samples);
srp.enqueue(srp.out_link().target(0), samples);
} else
{
Samples samples;
add_samples(b, srp, samples);
if (samples.size() != 1)
{
// pick the median
std::nth_element(samples.begin(), samples.begin() + samples.size()/2, samples.end());
std::swap(samples[0], samples[samples.size()/2]);
//std::sort(samples.begin(), samples.end());
//samples[0] = (samples[samples.size()/2] + samples[samples.size()/2 + 1])/2;
samples.resize(1);
}
forward_samples(b, srp, samples);
}
}
示例3: SampleSet
RawSampleSet(const RawSampleSet& raw)
: SampleSet(raw.markers), samples(raw.samples) {
byNames.clear();
// duplicate samples
for (size_t i = 0; i < samples.size(); ++i) {
samples[i] = new RawSample( *(samples[i]) );
byNames[samples[i]->name] = samples[i];
}
// ref the marker
marker::manager.ref(markers);
//markers = marker::manager.create(raw.markers.platform);
}
示例4:
void
diy::detail::KDTreeSamplingPartition<Block,Point>::
add_samples(Block* b, const diy::ReduceProxy& srp, Samples& samples) const
{
// dequeue and combine the samples
for (int i = 0; i < srp.in_link().size(); ++i)
{
int nbr_gid = srp.in_link().target(i).gid;
Samples smpls;
srp.dequeue(nbr_gid, smpls);
for (size_t i = 0; i < smpls.size(); ++i)
samples.push_back(smpls[i]);
}
}
示例5: trainEpochs
float FCNetwork::trainEpochs(const Samples &samples, unsigned int epochs) {
for (int i = 0; i < epochs - 1; ++i) {
// Without calculating error
for (const Sample& sample : samples) {
activate(sample.getInputs());
updateDeltas(sample);
updateWeights();
}
}
// Calculating error
float sum = 0;
for (const Sample& sample : samples) {
activate(sample.getInputs());
updateDeltas(sample);
updateWeights();
sum = squaredError(sample.getOutputs());
}
return sum / samples.size();
}
示例6: exception
Y_PROGRAM_START()
{
Record::DataBase db;
for(int i=1;i<argc;++i)
{
const Record::Pointer r = new Record(argv[i]);
if(!db.insert(r))
{
throw exception("multiple file/conc '%s'",*(r->name));
}
}
const size_t nrec = db.size();
std::cerr << "Loaded #" << nrec << " files" << std::endl;
db.sort_keys(compare_natural);
Samples samples;
for( Iterator i=db.begin();i!=db.end();++i)
{
Record &r = **i;
std::cerr << r.filename << std::endl;
samples.push_back(r.sample);
}
assert(samples.size()==nrec);
////////////////////////////////////////////////////////////////////////////
//
// prepare fit
//
////////////////////////////////////////////////////////////////////////////
Fit::LeastSquares<double> ls;
Proton proton;
Fit::Type<double>::Function F( &proton, & Proton::Compute );
////////////////////////////////////////////////////////////////////////////
//
// First pass, individual fits
//
////////////////////////////////////////////////////////////////////////////
Variables &gvars = samples.variables;
Vector C;
Vector P;
Vector Q;
Vector pHi;
Vector pHe;
Vector T0;
{
gvars.free();
gvars << "p" << "q" << "vi" << "ve" << "t0";
const size_t nvar = gvars.size();
Vector aorg( nvar );
Vector aerr( nvar );
vector<bool> used( nvar, false);
{
ios::ocstream fp("ind.dat");
for( Iterator i=db.begin();i!=db.end();++i)
{
Record &r = **i;
Sample &sample = *r.sample;
r.vars = gvars;
std::cerr << "-- Individual for " << r.filename << std::endl;
std::cerr << r.name << ".vars=" << r.vars << std::endl;
gvars(aorg,"p") = 1.0;
gvars(aorg,"q") = r.thalf-r.t_min;
gvars(aorg,"vi") = r.pH_min;
gvars(aorg,"ve") = r.pH_end;
gvars(aorg,"ve") = 7.1;
tao::ld(used,false);
int level = 0;
gvars.display(std::cerr,aorg);
{
//gvars.on(used,"p");
gvars.on(used,"q");
++level;
std::cerr << "starting level " << level << " with: " << std::endl;
gvars.display(std::cerr,aorg);
if( !ls.fit( sample, F, aorg, aerr, used) )
{
throw exception("couldn't fit %s @level-%d", *(r.name), level );
}
//gvars.diplay(std::cerr, aorg, aerr, "\t");
//std::cerr << "\tR2=" << sample.computeR2() << std::endl;
}
if(false)
{
gvars.on(used,"p");
++level;
std::cerr << "starting level " << level << " with: " << std::endl;
gvars.display(std::cerr,aorg);
if( !ls.fit( sample, F, aorg, aerr, used) )
{
//.........这里部分代码省略.........
示例7: filter
void filter(const marker::Set& refMarkers) {
if (markers == NULL) {
throw invalid_argument("Markers in sample set are missing.");
}
// flag markers for removal
markers->filter(refMarkers);
if (samples.size() > 0) {
// Create copy of samples with only unflagged markers
// Shallow copy current samples (copy pointers)
Samples oldSamples = samples;
// clear current data
samples.clear();
byNames.clear();
// pre-allocate space
samples.resize(oldSamples.size());
for (size_t sampleIndex = 0; sampleIndex < oldSamples.size(); ++sampleIndex) {
// iterate through chromosomes
for (size_t chromIndex = 0; chromIndex < oldSamples[0]->size(); ++chromIndex) {
// resize chromosome to be as big as chromosome from old sample
samples[sampleIndex]->resizeChromosome(chromIndex, (*oldSamples[sampleIndex])[chromIndex].size());
}
}
// copy data from unflagged markers
const size_t chromEnd = markers->size();
vector<size_t> validMarkersCounts(chromEnd);
for (size_t chromIndex = 0; chromIndex < chromEnd; ++chromIndex) {
const size_t numMarkers = (*markers)[chromIndex].size();
validMarkersCounts[chromIndex] = 0;
for (size_t markerIndex = 0; markerIndex < numMarkers; ++markerIndex) {
// only copy unflagged markers
if (!(*markers)[chromIndex][markerIndex]->flag) {
// copy marker values from oldSamples
const size_t numSamples = oldSamples.size();
for (size_t sampleIndex = 0; sampleIndex < numSamples; ++sampleIndex) {
(*samples[sampleIndex])[chromIndex][validMarkersCounts[chromIndex]] = (*oldSamples[sampleIndex])[chromIndex][markerIndex];
}
++validMarkersCounts[chromIndex];
}
}
}
// shrink new sample chromosomes to match new size
SamplesIterator it, end = samples.end();
for (it = samples.begin(); it != end; ++it) {
for (size_t chromIndex = 0; chromIndex < chromEnd; ++chromIndex) {
(**it).resizeChromosome(chromIndex, validMarkersCounts[chromIndex]);
}
}
// clear old samples
end = oldSamples.end();
for (it = oldSamples.begin(); it != end; ++it) {
delete (*it);
}
}
// remove flagged markers
markers->clean();
}
示例8: size
size_t size() {
return samples.size();
}