Exemple #1
0
double getError(const vector<SamplePoint> &samples, const VectorN &curCoeff) {
  double errSum = 0.0;

  for (auto& s : samples) {
    double hx = curCoeff.dotProduct(s.features);
    errSum += (hx - s.value) * (hx - s.value);
  }

  return errSum / samples.size();
}
Exemple #2
0
VectorN getErrorGradients(const vector<SamplePoint> &samples, const VectorN &curCoeff) {
  VectorN result {(unsigned) curCoeff.vals.size()};

  for (unsigned i = 0; i < result.vals.size(); i++) {
    // compute d'err/d'theta(i)

    double derr = 0.0;
    for (auto& s : samples) {
      double hx = curCoeff.dotProduct(s.features);
      derr += 2.0 * s.features.vals[i] * (hx - s.value);
    }

    result.vals[i] = derr / samples.size();
  }

  return result;
}