haifengl / smile

Statistical Machine Intelligence & Learning Engine
https://haifengl.github.io
Other
5.99k stars 1.12k forks source link

Issue with Matern kernel, nu=2.5 #709

Closed lawrenceClark99 closed 2 years ago

lawrenceClark99 commented 2 years ago

Describe the bug nu=2.5 behaviour of Matern kernel is different to that in Rasmussen "Gaussian Processes for Machine Learning" (eq 4.17)

Expected behavior Expected k(x, y) = (1 + root5 d / sigma + 5 d^2 / (3 sigma^2)) * exp(- root5 d / sigma) where d = ||x - y||_2

Actual behavior Got k(x, y) = (1 + root5 d / sigma) * exp(- root5 d / sigma)

Code snippet

    public double k(double dist) {
        double d = dist / this.sigma;
        if (this.nu == 1.5D) {
            d *= SQRT3;
            return (1.0D + d) * Math.exp(-d);
        } else if (this.nu == 2.5D) {
            d *= SQRT5;
            return (1.0D + d) * Math.exp(-d);
        } else if (this.nu == 0.5D) {
            return Math.exp(-d);
        } else if (Double.isInfinite(this.nu)) {
            return Math.exp(-0.5D * d * d);
        } else {
            throw new IllegalStateException("Unsupported nu = " + this.nu);
        }
    }
haifengl commented 2 years ago

Fixed. thanks