Пример #1
0
void
LeastSquares::Compute()
{
  auto denom = (sum_weights * sum_xi_2 - sum_xi * sum_xi);

  if (fabs(denom) > 0) {
    m = (sum_weights * sum_xi_yi - sum_xi * sum_yi) / denom;
  } else {
    m = 0.;
  }
  b = (sum_yi - m * sum_xi) / sum_weights;

  y_ave = GetYAt(GetMiddleX());
}
Пример #2
0
void
LeastSquares::Update(double x, double y, double weight)
{
  // Add new point
  Add(x, y, weight);
  // Update calculation
  Compute();

  // Calculate error
  auto error = fabs(y - GetYAt(x));
  sum_error += Square(error) * weight;
  if (error > max_error)
    max_error = error;
}
Пример #3
0
 fixed GetYAtMaxX() const {
   return GetYAt(GetMaxX());
 }