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(Double val : groundTruth) {
	    mean += val;
	}
	mean /= groundTruth.size();
	
	double err = 0.0;
	for(Double val : expected) {
	    err += Math.pow(mean - val, 2);
	}
	return Math.sqrt(err);
    }
    
    
}
