Пример #1
0
  @Override
  protected void setInputOutput() {
    input = new GeoElement[2];
    input[0] = inputList;
    input[1] = function.toGeoElement();

    setOnlyOutput(r2);
    setDependencies(); // done by AlgoElement
  }
Пример #2
0
  @Override
  public final void compute() {

    size = inputList.size();
    if (!inputList.isDefined() || !function.toGeoElement().isDefined()) {
      r2.setUndefined();
      return;
    }

    GeoFunction funGeo = function.getGeoFunction();

    // Calculate errorsum and ssy:
    double sumyy = 0.0d;
    double sumy = 0.0d;
    double syy = 0.0d;
    double errorsum = 0.0d;
    GeoElement geo = null;
    GeoPoint point = null;
    double x, y, v;

    for (int i = 0; i < size; i++) {
      geo = inputList.get(i);
      if (geo.isGeoPoint()) {
        point = (GeoPoint) geo;
        x = point.getX();
        y = point.getY();
        v = funGeo.evaluate(x);
        errorsum += (v - y) * (v - y);
        sumy += y;
        sumyy += y * y;
      } else {
        r2.setUndefined();
        return;
      } // if calculation is possible
    } // for all points

    syy = sumyy - sumy * sumy / size;

    // calculate RSquare
    r2.setValue(1 - errorsum / syy);
  } // compute()