diff options
Diffstat (limited to 'src/de/lmu/ifi/dbs/elki/math/statistics/kernelfunctions')
10 files changed, 870 insertions, 0 deletions
diff --git a/src/de/lmu/ifi/dbs/elki/math/statistics/kernelfunctions/BiweightKernelDensityFunction.java b/src/de/lmu/ifi/dbs/elki/math/statistics/kernelfunctions/BiweightKernelDensityFunction.java new file mode 100644 index 00000000..4b6ec7b7 --- /dev/null +++ b/src/de/lmu/ifi/dbs/elki/math/statistics/kernelfunctions/BiweightKernelDensityFunction.java @@ -0,0 +1,102 @@ +package de.lmu.ifi.dbs.elki.math.statistics.kernelfunctions; + +/* + This file is part of ELKI: + Environment for Developing KDD-Applications Supported by Index-Structures + + Copyright (C) 2013 + Ludwig-Maximilians-Universität München + Lehr- und Forschungseinheit für Datenbanksysteme + ELKI Development Team + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program 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 Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +import de.lmu.ifi.dbs.elki.utilities.Alias; +import de.lmu.ifi.dbs.elki.utilities.documentation.Reference; +import de.lmu.ifi.dbs.elki.utilities.optionhandling.AbstractParameterizer; + +/** + * Biweight (Quartic) kernel density estimator. + * + * @author Erich Schubert + */ +@Alias({ "biweight", "quartic" }) +public final class BiweightKernelDensityFunction implements KernelDensityFunction { + /** + * Static instance. + */ + public static final BiweightKernelDensityFunction KERNEL = new BiweightKernelDensityFunction(); + + /** + * Canonical bandwidth: 35^(1/5) + */ + @Reference(authors = "J.S. Marron, D. Nolan", title = "Canonical kernels for density estimation", booktitle = "Statistics & Probability Letters, Volume 7, Issue 3", url = "http://dx.doi.org/10.1016/0167-7152(88)90050-8") + public static final double CANONICAL_BANDWIDTH = Math.pow(35., .2); + + /** + * Standard deviation. + */ + public static final double STDDEV = 1. / Math.sqrt(7.); + + /** + * R constant. + */ + public static final double R = 5. / 7.; + + /** + * Private, empty constructor. Use the static instance! + */ + private BiweightKernelDensityFunction() { + // Nothing to do. + } + + @Override + public double density(double delta) { + if (delta >= 1.) { + return 0; + } + final double u = 1 - delta * delta; + return 0.9375 * u * u; + } + + @Override + public double canonicalBandwidth() { + return CANONICAL_BANDWIDTH; + } + + @Override + public double standardDeviation() { + return STDDEV; + } + + @Override + public double getR() { + return R; + } + + /** + * Parameterization stub. + * + * @author Erich Schubert + * + * @apiviz.exclude + */ + public static class Parameterizer extends AbstractParameterizer { + @Override + protected BiweightKernelDensityFunction makeInstance() { + return KERNEL; + } + } +} diff --git a/src/de/lmu/ifi/dbs/elki/math/statistics/kernelfunctions/CosineKernelDensityFunction.java b/src/de/lmu/ifi/dbs/elki/math/statistics/kernelfunctions/CosineKernelDensityFunction.java new file mode 100644 index 00000000..230cb404 --- /dev/null +++ b/src/de/lmu/ifi/dbs/elki/math/statistics/kernelfunctions/CosineKernelDensityFunction.java @@ -0,0 +1,99 @@ +package de.lmu.ifi.dbs.elki.math.statistics.kernelfunctions; + +/* + This file is part of ELKI: + Environment for Developing KDD-Applications Supported by Index-Structures + + Copyright (C) 2013 + Ludwig-Maximilians-Universität München + Lehr- und Forschungseinheit für Datenbanksysteme + ELKI Development Team + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program 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 Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +import de.lmu.ifi.dbs.elki.math.MathUtil; +import de.lmu.ifi.dbs.elki.utilities.optionhandling.AbstractParameterizer; + +/** + * Cosine kernel density estimator. + * + * @author Erich Schubert + */ +public final class CosineKernelDensityFunction implements KernelDensityFunction { + /** + * Static instance. + */ + public static final CosineKernelDensityFunction KERNEL = new CosineKernelDensityFunction(); + + /** + * Canonical bandwidth. + * + * Computed as (R / STDDEV^4)^(1/5) + * + * This is approximately: 1.7662654022050532 + */ + public static final double CANONICAL_BANDWIDTH = Math.pow(MathUtil.PISQUARE / (16. * (1. - 8. / MathUtil.PISQUARE) * (1. - 8. / MathUtil.PISQUARE)), .2); + + /** + * Standard deviation. + */ + private static final double STDDEV = Math.sqrt(1. - 8. / MathUtil.PISQUARE); + + /** + * R constant. + */ + private static final double R = Math.PI * Math.PI / 16.; + + /** + * Private, empty constructor. Use the static instance! + */ + private CosineKernelDensityFunction() { + // Nothing to do. + } + + @Override + public double density(double delta) { + return (delta < 1.) ? MathUtil.QUARTERPI * Math.cos(MathUtil.HALFPI * delta) : 0.; + } + + @Override + public double canonicalBandwidth() { + return CANONICAL_BANDWIDTH; + } + + @Override + public double standardDeviation() { + return STDDEV; + } + + @Override + public double getR() { + return R; + } + + /** + * Parameterization stub. + * + * @author Erich Schubert + * + * @apiviz.exclude + */ + public static class Parameterizer extends AbstractParameterizer { + @Override + protected CosineKernelDensityFunction makeInstance() { + return KERNEL; + } + } +} diff --git a/src/de/lmu/ifi/dbs/elki/math/statistics/kernelfunctions/EpanechnikovKernelDensityFunction.java b/src/de/lmu/ifi/dbs/elki/math/statistics/kernelfunctions/EpanechnikovKernelDensityFunction.java new file mode 100644 index 00000000..bf91e227 --- /dev/null +++ b/src/de/lmu/ifi/dbs/elki/math/statistics/kernelfunctions/EpanechnikovKernelDensityFunction.java @@ -0,0 +1,98 @@ +package de.lmu.ifi.dbs.elki.math.statistics.kernelfunctions; + +/* + This file is part of ELKI: + Environment for Developing KDD-Applications Supported by Index-Structures + + Copyright (C) 2013 + Ludwig-Maximilians-Universität München + Lehr- und Forschungseinheit für Datenbanksysteme + ELKI Development Team + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program 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 Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +import de.lmu.ifi.dbs.elki.utilities.Alias; +import de.lmu.ifi.dbs.elki.utilities.documentation.Reference; +import de.lmu.ifi.dbs.elki.utilities.optionhandling.AbstractParameterizer; + +/** + * Epanechnikov kernel density estimator. + * + * @author Erich Schubert + */ +@Alias({ "epanechnikov" }) +public final class EpanechnikovKernelDensityFunction implements KernelDensityFunction { + /** + * Static instance. + */ + public static final EpanechnikovKernelDensityFunction KERNEL = new EpanechnikovKernelDensityFunction(); + + /** + * Canonical bandwidth: 15^(1/5) + */ + @Reference(authors = "J.S. Marron, D. Nolan", title = "Canonical kernels for density estimation", booktitle = "Statistics & Probability Letters, Volume 7, Issue 3", url = "http://dx.doi.org/10.1016/0167-7152(88)90050-8") + public static final double CANONICAL_BANDWIDTH = Math.pow(15., .2); + + /** + * Standard deviation. + */ + public static final double STDDEV = 1. / Math.sqrt(5.); + + /** + * R constant. + */ + public static final double R = 3. / 5.; + + /** + * Private, empty constructor. Use the static instance! + */ + private EpanechnikovKernelDensityFunction() { + // Nothing to do. + } + + @Override + public double density(double delta) { + return (delta < 1.) ? .75 * (1 - delta * delta) : 0.; + } + + @Override + public double canonicalBandwidth() { + return CANONICAL_BANDWIDTH; + } + + @Override + public double standardDeviation() { + return STDDEV; + } + + @Override + public double getR() { + return R; + } + + /** + * Parameterization stub. + * + * @author Erich Schubert + * + * @apiviz.exclude + */ + public static class Parameterizer extends AbstractParameterizer { + @Override + protected EpanechnikovKernelDensityFunction makeInstance() { + return KERNEL; + } + } +} diff --git a/src/de/lmu/ifi/dbs/elki/math/statistics/kernelfunctions/GaussianKernelDensityFunction.java b/src/de/lmu/ifi/dbs/elki/math/statistics/kernelfunctions/GaussianKernelDensityFunction.java new file mode 100644 index 00000000..2e666871 --- /dev/null +++ b/src/de/lmu/ifi/dbs/elki/math/statistics/kernelfunctions/GaussianKernelDensityFunction.java @@ -0,0 +1,92 @@ +package de.lmu.ifi.dbs.elki.math.statistics.kernelfunctions; + +/* + This file is part of ELKI: + Environment for Developing KDD-Applications Supported by Index-Structures + + Copyright (C) 2013 + Ludwig-Maximilians-Universität München + Lehr- und Forschungseinheit für Datenbanksysteme + ELKI Development Team + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program 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 Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +import de.lmu.ifi.dbs.elki.math.MathUtil; +import de.lmu.ifi.dbs.elki.utilities.documentation.Reference; +import de.lmu.ifi.dbs.elki.utilities.optionhandling.AbstractParameterizer; + +/** + * Gaussian kernel density estimator. + * + * @author Erich Schubert + */ +public final class GaussianKernelDensityFunction implements KernelDensityFunction { + /** + * Static instance. + */ + public static final GaussianKernelDensityFunction KERNEL = new GaussianKernelDensityFunction(); + + /** + * Canonical bandwidth: (1./(4*pi))^(1/10) + */ + @Reference(authors = "J.S. Marron, D. Nolan", title = "Canonical kernels for density estimation", booktitle = "Statistics & Probability Letters, Volume 7, Issue 3", url = "http://dx.doi.org/10.1016/0167-7152(88)90050-8") + public static final double CANONICAL_BANDWIDTH = Math.pow(.25 / Math.PI, .1); + + /** + * R constant. + */ + public static final double R = .5 * MathUtil.ONE_BY_SQRTPI; + + /** + * Private, empty constructor. Use the static instance! + */ + private GaussianKernelDensityFunction() { + // Nothing to do. + } + + @Override + public double density(double delta) { + return MathUtil.ONE_BY_SQRTTWOPI * Math.exp(-.5 * delta * delta); + } + + @Override + public double canonicalBandwidth() { + return CANONICAL_BANDWIDTH; + } + + @Override + public double standardDeviation() { + return 1.; + } + + @Override + public double getR() { + return R; + } + + /** + * Parameterization stub. + * + * @author Erich Schubert + * + * @apiviz.exclude + */ + public static class Parameterizer extends AbstractParameterizer { + @Override + protected GaussianKernelDensityFunction makeInstance() { + return KERNEL; + } + } +} diff --git a/src/de/lmu/ifi/dbs/elki/math/statistics/kernelfunctions/KernelDensityFunction.java b/src/de/lmu/ifi/dbs/elki/math/statistics/kernelfunctions/KernelDensityFunction.java new file mode 100644 index 00000000..ce6d5a0d --- /dev/null +++ b/src/de/lmu/ifi/dbs/elki/math/statistics/kernelfunctions/KernelDensityFunction.java @@ -0,0 +1,76 @@ +package de.lmu.ifi.dbs.elki.math.statistics.kernelfunctions; + +/* + This file is part of ELKI: + Environment for Developing KDD-Applications Supported by Index-Structures + + Copyright (C) 2013 + Ludwig-Maximilians-Universität München + Lehr- und Forschungseinheit für Datenbanksysteme + ELKI Development Team + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program 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 Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +import de.lmu.ifi.dbs.elki.utilities.documentation.Reference; + +/** + * Inner function of a kernel density estimator. + * + * Note: as of now, this API does not support asymmetric kernels. + * + * @author Erich Schubert + */ +public interface KernelDensityFunction { + /** + * Density contribution of a point at the given relative distance + * {@code delta >= 0}. + * + * Note that for {@code delta < 0}, in particular for {@code delta < 1}, the + * results may become invalid. So usually, you will want to invoke this as: + * + * {@code kernel.density(Math.abs(delta))} + * + * @param delta Relative distance + * @return density contribution + */ + public double density(double delta); + + /** + * Get the canonical bandwidth for this kernel. + * + * Note: R uses a different definition of "canonical bandwidth", and also uses + * differently scaled kernels. + * + * @return Canonical bandwidth + */ + @Reference(authors = "J.S. Marron, D. Nolan", title = "Canonical kernels for density estimation", booktitle = "Statistics & Probability Letters, Volume 7, Issue 3", url = "http://dx.doi.org/10.1016/0167-7152(88)90050-8") + public double canonicalBandwidth(); + + /** + * Get the standard deviation of the kernel function. + * + * @return Standard deviation + */ + public double standardDeviation(); + + /** + * Get the R integral of the kernel, \int K^2(x) dx + * + * TODO: any better name for this? + * + * @return R value + */ + public double getR(); +} diff --git a/src/de/lmu/ifi/dbs/elki/math/statistics/kernelfunctions/TriangularKernelDensityFunction.java b/src/de/lmu/ifi/dbs/elki/math/statistics/kernelfunctions/TriangularKernelDensityFunction.java new file mode 100644 index 00000000..c6acf031 --- /dev/null +++ b/src/de/lmu/ifi/dbs/elki/math/statistics/kernelfunctions/TriangularKernelDensityFunction.java @@ -0,0 +1,96 @@ +package de.lmu.ifi.dbs.elki.math.statistics.kernelfunctions; + +/* + This file is part of ELKI: + Environment for Developing KDD-Applications Supported by Index-Structures + + Copyright (C) 2013 + Ludwig-Maximilians-Universität München + Lehr- und Forschungseinheit für Datenbanksysteme + ELKI Development Team + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program 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 Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +import de.lmu.ifi.dbs.elki.utilities.optionhandling.AbstractParameterizer; + +/** + * Triangular kernel density estimator. + * + * @author Erich Schubert + */ +public final class TriangularKernelDensityFunction implements KernelDensityFunction { + /** + * Static instance. + */ + public static final TriangularKernelDensityFunction KERNEL = new TriangularKernelDensityFunction(); + + /** + * Canonical bandwidth. + * + * Computed as (R / STDDEV^4)^(1/5) + */ + public static final double CANONICAL_BANDWIDTH = Math.pow(24., .2); + + /** + * Standard deviation. + */ + private static final double STDDEV = 1. / Math.sqrt(6.); + + /** + * R constant. + */ + private static final double R = 2. / 3.; + + /** + * Private, empty constructor. Use the static instance! + */ + private TriangularKernelDensityFunction() { + // Nothing to do. + } + + @Override + public double density(double delta) { + return (delta < 1.) ? 1. - delta : 0.; + } + + @Override + public double canonicalBandwidth() { + return CANONICAL_BANDWIDTH; + } + + @Override + public double standardDeviation() { + return STDDEV; + } + + @Override + public double getR() { + return R; + } + + /** + * Parameterization stub. + * + * @author Erich Schubert + * + * @apiviz.exclude + */ + public static class Parameterizer extends AbstractParameterizer { + @Override + protected TriangularKernelDensityFunction makeInstance() { + return KERNEL; + } + } +} diff --git a/src/de/lmu/ifi/dbs/elki/math/statistics/kernelfunctions/TricubeKernelDensityFunction.java b/src/de/lmu/ifi/dbs/elki/math/statistics/kernelfunctions/TricubeKernelDensityFunction.java new file mode 100644 index 00000000..933207ed --- /dev/null +++ b/src/de/lmu/ifi/dbs/elki/math/statistics/kernelfunctions/TricubeKernelDensityFunction.java @@ -0,0 +1,105 @@ +package de.lmu.ifi.dbs.elki.math.statistics.kernelfunctions; + +/* + This file is part of ELKI: + Environment for Developing KDD-Applications Supported by Index-Structures + + Copyright (C) 2013 + Ludwig-Maximilians-Universität München + Lehr- und Forschungseinheit für Datenbanksysteme + ELKI Development Team + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program 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 Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +import de.lmu.ifi.dbs.elki.utilities.optionhandling.AbstractParameterizer; + +/** + * Tricube kernel density estimator. + * + * @author Erich Schubert + */ +public final class TricubeKernelDensityFunction implements KernelDensityFunction { + /** + * Static instance. + */ + public static final TricubeKernelDensityFunction KERNEL = new TricubeKernelDensityFunction(); + + /** + * Canonical bandwidth. + * + * Computed as (R / STDDEV^4)^(1/5) + */ + public static final double CANONICAL_BANDWIDTH = Math.pow(59049 / 1729, .2); + + /** + * Standard deviation. + */ + private static final double STDDEV = Math.sqrt(35. / 243.); + + /** + * R constant. + */ + private static final double R = 175. / 247.; + + /** + * Scaling factor. + */ + private final double SCALE = 70. / 81.; + + /** + * Private, empty constructor. Use the static instance! + */ + private TricubeKernelDensityFunction() { + // Nothing to do. + } + + @Override + public double density(double delta) { + if (delta >= 1.) { + return 0; + } + final double u = 1 - delta * delta * delta; + return SCALE * u * u * u; + } + + @Override + public double canonicalBandwidth() { + return CANONICAL_BANDWIDTH; + } + + @Override + public double standardDeviation() { + return STDDEV; + } + + @Override + public double getR() { + return R; + } + + /** + * Parameterization stub. + * + * @author Erich Schubert + * + * @apiviz.exclude + */ + public static class Parameterizer extends AbstractParameterizer { + @Override + protected TricubeKernelDensityFunction makeInstance() { + return KERNEL; + } + } +} diff --git a/src/de/lmu/ifi/dbs/elki/math/statistics/kernelfunctions/TriweightKernelDensityFunction.java b/src/de/lmu/ifi/dbs/elki/math/statistics/kernelfunctions/TriweightKernelDensityFunction.java new file mode 100644 index 00000000..993ab8bf --- /dev/null +++ b/src/de/lmu/ifi/dbs/elki/math/statistics/kernelfunctions/TriweightKernelDensityFunction.java @@ -0,0 +1,102 @@ +package de.lmu.ifi.dbs.elki.math.statistics.kernelfunctions; + +/* + This file is part of ELKI: + Environment for Developing KDD-Applications Supported by Index-Structures + + Copyright (C) 2013 + Ludwig-Maximilians-Universität München + Lehr- und Forschungseinheit für Datenbanksysteme + ELKI Development Team + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program 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 Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +import de.lmu.ifi.dbs.elki.utilities.Alias; +import de.lmu.ifi.dbs.elki.utilities.documentation.Reference; +import de.lmu.ifi.dbs.elki.utilities.optionhandling.AbstractParameterizer; + +/** + * Triweight kernel density estimator. + * + * @author Erich Schubert + */ +@Alias({ "triweight" }) +public final class TriweightKernelDensityFunction implements KernelDensityFunction { + /** + * Static instance. + */ + public static final TriweightKernelDensityFunction KERNEL = new TriweightKernelDensityFunction(); + + /** + * Canonical bandwidth: (9450/143)^(1/5) + */ + @Reference(authors = "J.S. Marron, D. Nolan", title = "Canonical kernels for density estimation", booktitle = "Statistics & Probability Letters, Volume 7, Issue 3", url = "http://dx.doi.org/10.1016/0167-7152(88)90050-8") + public static final double CANONICAL_BANDWIDTH = Math.pow(9450. / 143., .2); + + /** + * Standard deviation. + */ + private static final double STDDEV = 1. / 3.; + + /** + * R constant. + */ + private static final double R = 350. / 429.; + + /** + * Private, empty constructor. Use the static instance! + */ + private TriweightKernelDensityFunction() { + // Nothing to do. + } + + @Override + public double density(double delta) { + if (delta >= 1.) { + return 0; + } + final double u = 1 - delta * delta; + return 1.09375 * u * u * u; + } + + @Override + public double canonicalBandwidth() { + return CANONICAL_BANDWIDTH; + } + + @Override + public double standardDeviation() { + return STDDEV; + } + + @Override + public double getR() { + return R; + } + + /** + * Parameterization stub. + * + * @author Erich Schubert + * + * @apiviz.exclude + */ + public static class Parameterizer extends AbstractParameterizer { + @Override + protected TriweightKernelDensityFunction makeInstance() { + return KERNEL; + } + } +} diff --git a/src/de/lmu/ifi/dbs/elki/math/statistics/kernelfunctions/UniformKernelDensityFunction.java b/src/de/lmu/ifi/dbs/elki/math/statistics/kernelfunctions/UniformKernelDensityFunction.java new file mode 100644 index 00000000..2a820355 --- /dev/null +++ b/src/de/lmu/ifi/dbs/elki/math/statistics/kernelfunctions/UniformKernelDensityFunction.java @@ -0,0 +1,96 @@ +package de.lmu.ifi.dbs.elki.math.statistics.kernelfunctions; + +/* + This file is part of ELKI: + Environment for Developing KDD-Applications Supported by Index-Structures + + Copyright (C) 2013 + Ludwig-Maximilians-Universität München + Lehr- und Forschungseinheit für Datenbanksysteme + ELKI Development Team + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program 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 Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +import de.lmu.ifi.dbs.elki.utilities.documentation.Reference; +import de.lmu.ifi.dbs.elki.utilities.optionhandling.AbstractParameterizer; + +/** + * Uniform / Rectangular kernel density estimator. + * + * @author Erich Schubert + */ +public final class UniformKernelDensityFunction implements KernelDensityFunction { + /** + * Static instance. + */ + public static final UniformKernelDensityFunction KERNEL = new UniformKernelDensityFunction(); + + /** + * Canonical bandwidth: (9/2)^(1/5) + */ + @Reference(authors = "J.S. Marron, D. Nolan", title = "Canonical kernels for density estimation", booktitle = "Statistics & Probability Letters, Volume 7, Issue 3", url = "http://dx.doi.org/10.1016/0167-7152(88)90050-8") + public static final double CANONICAL_BANDWIDTH = Math.pow(4.5, .2); + + /** + * Standard deviation. + */ + private static final double STDDEV = 1. / Math.sqrt(3.); + + /** + * R constant. + */ + private static final double R = .5; + + /** + * Private, empty constructor. Use the static instance! + */ + private UniformKernelDensityFunction() { + // Nothing to do. + } + + @Override + public double density(double delta) { + return (delta < 1.) ? .5 : 0.; + } + + @Override + public double canonicalBandwidth() { + return CANONICAL_BANDWIDTH; + } + + @Override + public double standardDeviation() { + return STDDEV; + } + + @Override + public double getR() { + return R; + } + + /** + * Parameterization stub. + * + * @author Erich Schubert + * + * @apiviz.exclude + */ + public static class Parameterizer extends AbstractParameterizer { + @Override + protected UniformKernelDensityFunction makeInstance() { + return KERNEL; + } + } +} diff --git a/src/de/lmu/ifi/dbs/elki/math/statistics/kernelfunctions/package-info.java b/src/de/lmu/ifi/dbs/elki/math/statistics/kernelfunctions/package-info.java new file mode 100644 index 00000000..adcadcaf --- /dev/null +++ b/src/de/lmu/ifi/dbs/elki/math/statistics/kernelfunctions/package-info.java @@ -0,0 +1,4 @@ +/** + * Kernel functions from statistics. + */ +package de.lmu.ifi.dbs.elki.math.statistics.kernelfunctions;
\ No newline at end of file |