public static double calculateFromSamplesUsingVasicek(double[] samples)
    {
        if (samples.length == 0) {
            return Double.NaN;
        }

        Arrays.sort(samples);
        int n = samples.length;
        int m = toIntExact(Math.max(Math.round(Math.sqrt(n)), 2));
        double entropy = 0;
        for (int i = 0; i < n; i++) {
            double sIPlusM = i + m < n ? samples[i + m] : samples[n - 1];
            double sIMinusM = i - m > 0 ? samples[i - m] : samples[0];
            double aI = i + m < n && i - m > 0 ? 2 : 1;
            entropy += Math.log(n / (aI * m) * (sIPlusM - sIMinusM));
        }
        return entropy / n / Math.log(2);
    }
@Test
    public void testNormalDistribution()
    {
        Random random = new Random(13);
        double[] samples = new double[10000000];
        double sigma = 0.5;
        for (int i = 0; i < samples.length; i++) {
            samples[i] = 5 + sigma * random.nextGaussian();
        }
        double expected = 0.5 * Math.log(2 * Math.PI * Math.E * sigma * sigma) / Math.log(2);
        assertEquals(calculateFromSamplesUsingVasicek(samples), expected, 0.02);
    }