public static double of(double[] truth, double[] prediction) {
        if (truth.length != prediction.length) {
            throw new IllegalArgumentException(String.format("The vector sizes don't match: %d != %d.", truth.length, prediction.length));
        }

        double RSS = 0.0;
        double TSS = 0.0;
        double ybar = MathEx.mean(truth);

        int n = truth.length;
        for (int i = 0; i < n; i++) {
            double r = truth[i] - prediction[i];
            RSS += r * r;
            double t = truth[i] - ybar;
            TSS += t * t;
        }

        return 1.0 - RSS / TSS;
    }
@Test
    public void test() {
        System.out.println("R2");
        double[] truth = {
                83.0,  88.5,  88.2,  89.5,  96.2,  98.1,  99.0, 100.0, 101.2,
                104.6, 108.4, 110.8, 112.6, 114.2, 115.7, 116.9
        };

        double[] prediction = {
                83.60082, 86.94973, 88.09677, 90.73065, 96.53551, 97.83067,
                98.12232, 99.87776, 103.20861, 105.08598, 107.33369, 109.57251,
                112.98358, 113.92898, 115.50214, 117.54028,
        };

        double expResult = 0.9926;
        double result = R2.of(truth, prediction);
        assertEquals(expResult, result, 1E-4);
    }