package dkohl.util;

import java.util.LinkedList;

public class RootMeanSquareError {

	private LinkedList<Double> expected;
	private LinkedList<Double> groundTruth;

	public RootMeanSquareError() {
		expected = new LinkedList<Double>();
		groundTruth = new LinkedList<Double>();
	}

	public void push(double predicted, double actual) {
		expected.add(predicted);
		groundTruth.add(actual);
	}

	public double error() {
		double mean = 0.0;
		for (int i = 0; i < expected.size(); i++){
			mean += Math.pow(expected.get(i) - groundTruth.get(i), 2);
		}
		mean /= groundTruth.size();

		return Math.sqrt(mean);
	}

}
