"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "uppsrc/ScatterDraw/Equation.cpp" between
upp-x11-src-13648.tar.gz and upp-x11-src-13659.tar.gz

About: Ultimate++ is a C++ cross-platform rapid application development framework. Stable release.

Equation.cpp  (upp-x11-src-13648):Equation.cpp  (upp-x11-src-13659)
skipping to change at line 33 skipping to change at line 33
return 0; return 0;
} }
}; };
void ExplicitEquation::SetNumCoeff(int num) { void ExplicitEquation::SetNumCoeff(int num) {
coeff.SetCount(num); coeff.SetCount(num);
for (int i = 0; i < num; ++i) for (int i = 0; i < num; ++i)
coeff[i] = 0; coeff[i] = 0;
} }
ExplicitEquation::FitError ExplicitEquation::Fit(DataSource &series, double &r2) { ExplicitEquation::FitError ExplicitEquation::Fit(DataSource &serie, double &r2) {
r2 = Null; r2 = Null;
if (series.IsExplicit() || series.IsParam()) if (serie.IsExplicit() || serie.IsParam())
return InadequateDataSource; return InadequateDataSource;
if (series.GetCount() < coeff.GetCount()) if (serie.GetCount() < coeff.GetCount())
return SmallDataSource; return SmallDataSource;
ptrdiff_t numUnknowns = coeff.GetCount(); ptrdiff_t numUnknowns = coeff.GetCount();
VectorXd x(numUnknowns); VectorXd x(numUnknowns);
for (int i = 0; i < numUnknowns; ++i) for (int i = 0; i < numUnknowns; ++i)
x(i) = coeff[i]; x(i) = coeff[i];
Equation_functor functor; Equation_functor functor;
functor.series = &series; functor.series = &serie;
functor.fSource = this; functor.fSource = this;
functor.unknowns = numUnknowns; functor.unknowns = numUnknowns;
functor.datasetLen = series.GetCount(); functor.datasetLen = serie.GetCount();
NumericalDiff<Equation_functor> numDiff(functor); NumericalDiff<Equation_functor> numDiff(functor);
LevenbergMarquardt<NumericalDiff<Equation_functor> > lm(numDiff); LevenbergMarquardt<NumericalDiff<Equation_functor> > lm(numDiff);
// ftol is a nonnegative input variable that measures the relative error des ired in the sum of squares // ftol is a nonnegative input variable that measures the relative error des ired in the sum of squares
lm.parameters.ftol = 1.E4*NumTraits<double>::epsilon(); lm.parameters.ftol = 1.E4*NumTraits<double>::epsilon();
// xtol is a nonnegative input variable that measures the relative error desire d in the approximate solution // xtol is a nonnegative input variable that measures the relative error desire d in the approximate solution
lm.parameters.xtol = 1.E4*NumTraits<double>::epsilon(); lm.parameters.xtol = 1.E4*NumTraits<double>::epsilon();
lm.parameters.maxfev = maxFitFunctionEvaluations; lm.parameters.maxfev = maxFitFunctionEvaluations;
int ret = lm.minimize(x); int ret = lm.minimize(x);
if (ret == LevenbergMarquardtSpace::ImproperInputParameters) if (ret == LevenbergMarquardtSpace::ImproperInputParameters)
return ExplicitEquation::ImproperInputParameters; return ExplicitEquation::ImproperInputParameters;
if (ret == LevenbergMarquardtSpace::TooManyFunctionEvaluation) if (ret == LevenbergMarquardtSpace::TooManyFunctionEvaluation)
return TooManyFunctionEvaluation; return TooManyFunctionEvaluation;
r2 = R2Y(series); r2 = R2Y(serie);
return NoError; return NoError;
} }
double ExplicitEquation::R2Y(DataSource &series, double mean) { double ExplicitEquation::R2Y(DataSource &serie, double mean) {
if (IsNull(mean)) if (IsNull(mean))
mean = series.AvgY(); mean = serie.AvgY();
double sse = 0, sst = 0; double sse = 0, sst = 0;
for (int64 i = 0; i < series.GetCount(); ++i) { for (int64 i = 0; i < serie.GetCount(); ++i) {
double y = series.y(i); double y = serie.y(i);
if (!IsNull(y)) { if (!IsNull(y)) {
double err = y - f(series.x(i)); double err = y - f(serie.x(i));
sse += err*err; sse += err*err;
double d = y - mean; double d = y - mean;
sst += d*d; sst += d*d;
} }
} }
if (sst < 1E-50 || sse > sst) if (sst < 1E-50 || sse > sst)
return 0; return 0;
return 1 - sse/sst; return 1 - sse/sst;
} }
 End of changes. 10 change blocks. 
11 lines changed or deleted 11 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)