package net.woodyfolsom.msproj.ann2.math;

public class MSSE implements ErrorFunction{
	public static final ErrorFunction function = new MSSE();
	
	public double compute(double[] ideal, double[] actual) {
		int idealSize = ideal.length;
		int actualSize = actual.length;
		
		if (idealSize != actualSize) {
			throw new IllegalArgumentException("actualSize != idealSize");
		}
		
		double SSE = 0.0;
		
		for (int i = 0; i < idealSize; i++) {
			SSE += Math.pow(ideal[i] - actual[i], 2);
		}
		
		return SSE / idealSize;
	}
}
