/** Returns the function value after training. */
    double predict(T x) {
      double f = b;

      if (kernel instanceof Linear && w != null) {
        if (x instanceof double[]) {
          f += Matrix.InnerProduct(w, (double[]) x);
        } else if (x instanceof SparseArray) {
          for (SparseArray.Entry e : (SparseArray) x) {
            f += w[e.i] * e.x;
          }
        } else {
          throw new UnsupportedOperationException("Unsupported data type for linear kernel");
        }
      } else {

        for (SupportVector v : sv) {
          if (v != null) {
            f += v.alpha * kernel.Function(v.x, x);
          }
        }
      }

      return f;
    }