All Downloads are FREE. Search and download functionalities are using the official Maven repository.

smile.math.kernel.GaussianKernel Maven / Gradle / Ivy

There is a newer version: 4.2.0
Show newest version
/*
 * Copyright (c) 2010-2021 Haifeng Li. All rights reserved.
 *
 * Smile is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Smile is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Smile.  If not, see .
 */

package smile.math.kernel;

import smile.math.MathEx;

/**
 * Gaussian kernel, also referred as RBF kernel or squared exponential kernel.
 * 

* k(u, v) = exp(-||u-v||2 / 2σ2) *

* where σ {@code > 0} is the scale parameter of the kernel. *

* The Gaussian kernel is a good choice for a great deal of applications, * although sometimes it is remarked as being overused. * @author Haifeng Li */ public class GaussianKernel extends Gaussian implements MercerKernel { /** * Constructor. * @param sigma The length scale of kernel. */ public GaussianKernel(double sigma) { this(sigma, 1E-05, 1E5); } /** * Constructor. * @param sigma The length scale of kernel. * @param lo The lower bound of length scale for hyperparameter tuning. * @param hi The upper bound of length scale for hyperparameter tuning. */ public GaussianKernel(double sigma, double lo, double hi) { super(sigma, lo, hi); } @Override public double k(double[] x, double[] y) { return k(MathEx.distance(x, y)); } @Override public double[] kg(double[] x, double[] y) { return kg(MathEx.distance(x, y)); } @Override public GaussianKernel of(double[] params) { return new GaussianKernel(params[0], lo, hi); } @Override public double[] hyperparameters() { return new double[] { sigma }; } @Override public double[] lo() { return new double[] { lo }; } @Override public double[] hi() { return new double[] { hi }; } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy