@Override
	public GAM build(Instances instances) {
		if (pairs == null) {
			int p = instances.dimension();
			pairs = new ArrayList<IntPair>();
			for (int i = 0; i < p; i++) {
				for (int j = i + 1; j < p; j++) {
					pairs.add(new IntPair(i, j));
				}
			}
		}
		if (maxNumIters < 0) {
			maxNumIters = 20;
		}
		switch (task) {
			case REGRESSION:
				if (validSet != null) {
					buildRegressor(gam, pairs, instances, validSet, maxNumIters);
				} else {
					buildRegressor(gam, pairs, instances, maxNumIters);
				}
				break;
			case CLASSIFICATION:
				if (validSet != null) {
					buildClassifier(gam, pairs, instances, validSet, maxNumIters);
				} else {
					buildClassifier(gam, pairs, instances, maxNumIters);
				}
				break;
			default:
				break;
		}
		return gam;
	}