本文整理汇总了C++中Samples::back方法的典型用法代码示例。如果您正苦于以下问题:C++ Samples::back方法的具体用法?C++ Samples::back怎么用?C++ Samples::back使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Samples
的用法示例。
在下文中一共展示了Samples::back方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}