ErrorStatAnalysis.java [src/java/utils] Revision: default  Date:
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package utils;

import java.util.LinkedList;
import java.util.List;
import oms3.util.Statistics;
import org.bson.Document;
import utils.MongoUtils.Sorting;

/**
 *
 * @author sidereus
 */
public class ErrorStatAnalysis {

    public static Document compute(double[] obs, double[] sim, double pow, double missing, List<Double> errorCheck) {
        Document stat = new Document("absDiff", Statistics.absDiff(obs, sim, missing));
        //stat.append("absDiffLog", Statistics.absDiffLog(obs, sim, missing));
        stat.append("absVolumeError", Statistics.absVolumeError(obs, sim, missing));
        stat.append("dsGrad", Statistics.dsGrad(obs, sim));
        stat.append("err_sum", Statistics.err_sum(obs, sim));
        stat.append("fhf", Statistics.fhf(obs, sim, missing));
        stat.append("flf", Statistics.flf(obs, sim, missing));
        stat.append("ioa", Statistics.ioa(obs, sim, pow, missing));
        stat.append("kge", Statistics.kge(obs, sim, missing));
        stat.append("modelDev", Calc.modelDeviation(obs, sim, missing));
        stat.append("nashSutcliffe", Statistics.nashSutcliffe(obs, sim, pow, missing));
        //stat.append("nashSutcliffeLog", Statistics.nashSutcliffeLog(obs, sim, pow, missing));
        stat.append("nbias", Statistics.nbias(obs, sim, missing));
        stat.append("norm_rmse", Statistics.norm_rmse(obs, sim, missing));
        stat.append("pbias", Statistics.pbias(obs, sim, missing));
        stat.append("personsCorrelation", Statistics.pearsonsCorrelation(obs, sim, missing));
        stat.append("pwrmse", Calc.pwrmse(obs, sim, missing));
        stat.append("r2", Statistics.r2(obs, sim));
        stat.append("rmse", Statistics.rmse(obs, sim, missing));
        stat.append("rrmse", Statistics.rmse(obs, sim, missing)/Statistics.mean(obs)*100);
        stat.append("transformedRmse", Statistics.transformedRmse(obs, sim, missing));

        errorCheck.add(Statistics.kge(obs, sim, missing));
        errorCheck.add(Statistics.nashSutcliffe(obs, sim, pow, missing));

        return stat;
    }


    public static Sorting getSortingOrder(String error) {
        switch (error.toLowerCase()) {
            case "absdiff":
                return Sorting.ASCENDING;
            case "absdifflog":
                return Sorting.ASCENDING;
            case "absvolumeerror":
                return Sorting.ASCENDING;
            case "dsgrad":
                throw new UnsupportedOperationException();
            case "err_sum":
                throw new UnsupportedOperationException();
            case "fhf":
                return Sorting.ASCENDING;
            case "flf":
                return Sorting.ASCENDING;
            case "ioa":
                return Sorting.DESCENDING;
            case "kge":
                return Sorting.DESCENDING;
            case "modeldev":
                throw new UnsupportedOperationException();
            case "nashsutcliffe":
                return Sorting.DESCENDING;
            case "nashsutcliffelog":
                return Sorting.DESCENDING;
            case "nbias":
                return Sorting.ASCENDING;
            case "norm_rmse":
                throw new UnsupportedOperationException();
            case "pbias":
                throw new UnsupportedOperationException();
            case "pearsoncorrelation":
                throw new UnsupportedOperationException();
            case "pwrmse":
                return Sorting.ASCENDING;
            case "r2":
                return Sorting.DESCENDING;
            case "rmse":
                return Sorting.ASCENDING;
            case "transformedrmse":
                return Sorting.ASCENDING;

            default:
                throw new IllegalArgumentException();
        }
    }

}