summaryrefslogtreecommitdiff
path: root/src/de/lmu/ifi/dbs/elki/math/linearalgebra/pca/weightfunctions
diff options
context:
space:
mode:
authorAndrej Shadura <andrewsh@debian.org>2019-03-09 22:30:28 +0000
committerAndrej Shadura <andrewsh@debian.org>2019-03-09 22:30:28 +0000
commitcde76aeb42240f7270bc6605c606ae07d2dc5a7d (patch)
treec3ebf1d7745224f524da31dbabc5d76b9ea75916 /src/de/lmu/ifi/dbs/elki/math/linearalgebra/pca/weightfunctions
Import Upstream version 0.4.0~beta1
Diffstat (limited to 'src/de/lmu/ifi/dbs/elki/math/linearalgebra/pca/weightfunctions')
-rw-r--r--src/de/lmu/ifi/dbs/elki/math/linearalgebra/pca/weightfunctions/ConstantWeight.java41
-rw-r--r--src/de/lmu/ifi/dbs/elki/math/linearalgebra/pca/weightfunctions/ErfcStddevWeight.java46
-rw-r--r--src/de/lmu/ifi/dbs/elki/math/linearalgebra/pca/weightfunctions/ErfcWeight.java52
-rw-r--r--src/de/lmu/ifi/dbs/elki/math/linearalgebra/pca/weightfunctions/ExponentialStddevWeight.java48
-rw-r--r--src/de/lmu/ifi/dbs/elki/math/linearalgebra/pca/weightfunctions/ExponentialWeight.java51
-rw-r--r--src/de/lmu/ifi/dbs/elki/math/linearalgebra/pca/weightfunctions/GaussStddevWeight.java55
-rw-r--r--src/de/lmu/ifi/dbs/elki/math/linearalgebra/pca/weightfunctions/GaussWeight.java46
-rw-r--r--src/de/lmu/ifi/dbs/elki/math/linearalgebra/pca/weightfunctions/InverseLinearWeight.java49
-rw-r--r--src/de/lmu/ifi/dbs/elki/math/linearalgebra/pca/weightfunctions/InverseProportionalStddevWeight.java44
-rw-r--r--src/de/lmu/ifi/dbs/elki/math/linearalgebra/pca/weightfunctions/InverseProportionalWeight.java44
-rw-r--r--src/de/lmu/ifi/dbs/elki/math/linearalgebra/pca/weightfunctions/LinearWeight.java45
-rw-r--r--src/de/lmu/ifi/dbs/elki/math/linearalgebra/pca/weightfunctions/QuadraticStddevWeight.java56
-rw-r--r--src/de/lmu/ifi/dbs/elki/math/linearalgebra/pca/weightfunctions/QuadraticWeight.java45
-rw-r--r--src/de/lmu/ifi/dbs/elki/math/linearalgebra/pca/weightfunctions/WeightFunction.java48
-rw-r--r--src/de/lmu/ifi/dbs/elki/math/linearalgebra/pca/weightfunctions/package-info.java26
15 files changed, 696 insertions, 0 deletions
diff --git a/src/de/lmu/ifi/dbs/elki/math/linearalgebra/pca/weightfunctions/ConstantWeight.java b/src/de/lmu/ifi/dbs/elki/math/linearalgebra/pca/weightfunctions/ConstantWeight.java
new file mode 100644
index 00000000..2901a75c
--- /dev/null
+++ b/src/de/lmu/ifi/dbs/elki/math/linearalgebra/pca/weightfunctions/ConstantWeight.java
@@ -0,0 +1,41 @@
+package de.lmu.ifi.dbs.elki.math.linearalgebra.pca.weightfunctions;
+/*
+This file is part of ELKI:
+Environment for Developing KDD-Applications Supported by Index-Structures
+
+Copyright (C) 2011
+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/>.
+*/
+
+/**
+ * Constant Weight function
+ *
+ * The result is always 1.0
+ *
+ * @author Erich Schubert
+ */
+public final class ConstantWeight implements WeightFunction {
+ /**
+ * Get the constant weight
+ * No scaling - the result is always 1.0
+ */
+ @Override
+ public double getWeight(@SuppressWarnings("unused") double distance, @SuppressWarnings("unused") double max, @SuppressWarnings("unused") double stddev) {
+ return 1.0;
+ }
+}
diff --git a/src/de/lmu/ifi/dbs/elki/math/linearalgebra/pca/weightfunctions/ErfcStddevWeight.java b/src/de/lmu/ifi/dbs/elki/math/linearalgebra/pca/weightfunctions/ErfcStddevWeight.java
new file mode 100644
index 00000000..fe2fbca2
--- /dev/null
+++ b/src/de/lmu/ifi/dbs/elki/math/linearalgebra/pca/weightfunctions/ErfcStddevWeight.java
@@ -0,0 +1,46 @@
+package de.lmu.ifi.dbs.elki.math.linearalgebra.pca.weightfunctions;
+/*
+This file is part of ELKI:
+Environment for Developing KDD-Applications Supported by Index-Structures
+
+Copyright (C) 2011
+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;
+
+/**
+ * Gaussian Error Function Weight function, scaled using stddev. This probably
+ * is the most statistically sound weight.
+ *
+ * erfc(1 / sqrt(2) * distance / stddev)
+ *
+ * @author Erich Schubert
+ */
+public final class ErfcStddevWeight implements WeightFunction {
+ /**
+ * Return Erfc weight, scaled by standard deviation. max is ignored.
+ */
+ @Override
+ public double getWeight(double distance, @SuppressWarnings("unused") double max, double stddev) {
+ if(stddev <= 0) {
+ return 1;
+ }
+ return MathUtil.erfc(MathUtil.SQRTHALF * distance / stddev);
+ }
+}
diff --git a/src/de/lmu/ifi/dbs/elki/math/linearalgebra/pca/weightfunctions/ErfcWeight.java b/src/de/lmu/ifi/dbs/elki/math/linearalgebra/pca/weightfunctions/ErfcWeight.java
new file mode 100644
index 00000000..b497a29c
--- /dev/null
+++ b/src/de/lmu/ifi/dbs/elki/math/linearalgebra/pca/weightfunctions/ErfcWeight.java
@@ -0,0 +1,52 @@
+package de.lmu.ifi.dbs.elki.math.linearalgebra.pca.weightfunctions;
+/*
+This file is part of ELKI:
+Environment for Developing KDD-Applications Supported by Index-Structures
+
+Copyright (C) 2011
+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;
+
+/**
+ * Gaussian Error Function Weight function, scaled such that the result it 0.1
+ * at distance == max
+ *
+ * erfc(1.1630871536766736 * distance / max)
+ *
+ * The value of 1.1630871536766736 is erfcinv(0.1), to achieve the intended
+ * scaling.
+ *
+ * @author Erich Schubert
+ */
+public final class ErfcWeight implements WeightFunction {
+ /**
+ * Get Erfc Weight, using distance / max. stddev is ignored.
+ */
+ @Override
+ public double getWeight(double distance, double max, @SuppressWarnings("unused") double stddev) {
+ if(max <= 0) {
+ return 1.0;
+ }
+ double relativedistance = distance / max;
+ // the scaling was picked such that getWeight(a,a,0) is 0.1
+ // since erfc(1.1630871536766736) == 1.0
+ return MathUtil.erfc(1.1630871536766736 * relativedistance);
+ }
+}
diff --git a/src/de/lmu/ifi/dbs/elki/math/linearalgebra/pca/weightfunctions/ExponentialStddevWeight.java b/src/de/lmu/ifi/dbs/elki/math/linearalgebra/pca/weightfunctions/ExponentialStddevWeight.java
new file mode 100644
index 00000000..1d657f49
--- /dev/null
+++ b/src/de/lmu/ifi/dbs/elki/math/linearalgebra/pca/weightfunctions/ExponentialStddevWeight.java
@@ -0,0 +1,48 @@
+package de.lmu.ifi.dbs.elki.math.linearalgebra.pca.weightfunctions;
+/*
+This file is part of ELKI:
+Environment for Developing KDD-Applications Supported by Index-Structures
+
+Copyright (C) 2011
+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/>.
+*/
+
+/**
+ * Exponential Weight function, scaled such that the result it 0.1 at distance
+ * == max
+ *
+ * stddev * exp(-.5 * distance/stddev)
+ *
+ * This is similar to the Gaussian weight function, except distance/stddev is
+ * not squared.
+ *
+ * @author Erich Schubert
+ */
+public final class ExponentialStddevWeight implements WeightFunction {
+ /**
+ * Get exponential weight, max is ignored.
+ */
+ @Override
+ public double getWeight(double distance, @SuppressWarnings("unused") double max, double stddev) {
+ if(stddev <= 0) {
+ return 1;
+ }
+ double scaleddistance = distance / stddev;
+ return stddev * java.lang.Math.exp(-.5 * scaleddistance);
+ }
+} \ No newline at end of file
diff --git a/src/de/lmu/ifi/dbs/elki/math/linearalgebra/pca/weightfunctions/ExponentialWeight.java b/src/de/lmu/ifi/dbs/elki/math/linearalgebra/pca/weightfunctions/ExponentialWeight.java
new file mode 100644
index 00000000..f204c1da
--- /dev/null
+++ b/src/de/lmu/ifi/dbs/elki/math/linearalgebra/pca/weightfunctions/ExponentialWeight.java
@@ -0,0 +1,51 @@
+package de.lmu.ifi.dbs.elki.math.linearalgebra.pca.weightfunctions;
+/*
+This file is part of ELKI:
+Environment for Developing KDD-Applications Supported by Index-Structures
+
+Copyright (C) 2011
+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/>.
+*/
+
+/**
+ * Exponential Weight function, scaled such that the result it 0.1 at distance
+ * == max
+ *
+ * exp(-2.3025850929940455 * distance/max)
+ *
+ * This is similar to the Gaussian weight function, except distance/max is not
+ * squared.
+ *
+ * -2.3025850929940455 is log(-.1) to achieve the intended range of 1.0 - 0.1
+ *
+ * @author Erich Schubert
+ */
+public final class ExponentialWeight implements WeightFunction {
+ /**
+ * Exponential Weight function. stddev is not used.
+ */
+ @Override
+ public double getWeight(double distance, double max, @SuppressWarnings("unused") double stddev) {
+ if(max <= 0) {
+ return 1.0;
+ }
+ double relativedistance = distance / max;
+ // scaling -2.303 is log(-.1) to suit the intended range of 1.0-0.1
+ return java.lang.Math.exp(-2.3025850929940455 * relativedistance);
+ }
+}
diff --git a/src/de/lmu/ifi/dbs/elki/math/linearalgebra/pca/weightfunctions/GaussStddevWeight.java b/src/de/lmu/ifi/dbs/elki/math/linearalgebra/pca/weightfunctions/GaussStddevWeight.java
new file mode 100644
index 00000000..f4a64462
--- /dev/null
+++ b/src/de/lmu/ifi/dbs/elki/math/linearalgebra/pca/weightfunctions/GaussStddevWeight.java
@@ -0,0 +1,55 @@
+package de.lmu.ifi.dbs.elki.math.linearalgebra.pca.weightfunctions;
+/*
+This file is part of ELKI:
+Environment for Developing KDD-Applications Supported by Index-Structures
+
+Copyright (C) 2011
+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;
+
+/**
+ * Gaussian Weight function, scaled such using standard deviation
+ *
+ * factor * exp(-.5 * (distance/stddev)^2)
+ *
+ * with factor being 1 / sqrt(2 * PI)
+ *
+ * @author Erich Schubert
+ */
+public final class GaussStddevWeight implements WeightFunction {
+ /**
+ * Constant scaling factor of Gaussian distribution.
+ *
+ * In fact, in most use cases we could leave this away.
+ */
+ private final static double scaling = 1 / MathUtil.SQRTTWOPI;
+
+ /**
+ * Get Gaussian Weight using standard deviation for scaling. max is ignored.
+ */
+ @Override
+ public double getWeight(double distance, @SuppressWarnings("unused") double max, double stddev) {
+ if(stddev <= 0) {
+ return 1;
+ }
+ double normdistance = distance / stddev;
+ return scaling * java.lang.Math.exp(-.5 * normdistance * normdistance) / stddev;
+ }
+}
diff --git a/src/de/lmu/ifi/dbs/elki/math/linearalgebra/pca/weightfunctions/GaussWeight.java b/src/de/lmu/ifi/dbs/elki/math/linearalgebra/pca/weightfunctions/GaussWeight.java
new file mode 100644
index 00000000..87a69d4f
--- /dev/null
+++ b/src/de/lmu/ifi/dbs/elki/math/linearalgebra/pca/weightfunctions/GaussWeight.java
@@ -0,0 +1,46 @@
+package de.lmu.ifi.dbs.elki.math.linearalgebra.pca.weightfunctions;
+/*
+This file is part of ELKI:
+Environment for Developing KDD-Applications Supported by Index-Structures
+
+Copyright (C) 2011
+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/>.
+*/
+
+/**
+ * Gaussian Weight function, scaled such that the result it 0.1 at distance ==
+ * max
+ *
+ * exp(-2.3025850929940455 * (distance/max)^2)
+ *
+ * @author Erich Schubert
+ */
+public final class GaussWeight implements WeightFunction {
+ /**
+ * Get Gaussian weight. stddev is not used, scaled using max.
+ */
+ @Override
+ public double getWeight(double distance, double max, @SuppressWarnings("unused") double stddev) {
+ if(max <= 0) {
+ return 1.0;
+ }
+ double relativedistance = distance / max;
+ // -2.303 is log(.1) to suit the intended range of 1.0-0.1
+ return java.lang.Math.exp(-2.3025850929940455 * relativedistance * relativedistance);
+ }
+}
diff --git a/src/de/lmu/ifi/dbs/elki/math/linearalgebra/pca/weightfunctions/InverseLinearWeight.java b/src/de/lmu/ifi/dbs/elki/math/linearalgebra/pca/weightfunctions/InverseLinearWeight.java
new file mode 100644
index 00000000..58b8d047
--- /dev/null
+++ b/src/de/lmu/ifi/dbs/elki/math/linearalgebra/pca/weightfunctions/InverseLinearWeight.java
@@ -0,0 +1,49 @@
+package de.lmu.ifi.dbs.elki.math.linearalgebra.pca.weightfunctions;
+/*
+This file is part of ELKI:
+Environment for Developing KDD-Applications Supported by Index-Structures
+
+Copyright (C) 2011
+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/>.
+*/
+
+/**
+ * Inverse Linear Weight Function.
+ *
+ * This weight is not particularly reasonable. Instead it serves the purpose of
+ * testing the effects of a badly chosen weight function.
+ *
+ * This function has increasing weight, from 0.1 to 1.0 at distance == max.
+ *
+ * @author Erich Schubert
+ */
+public final class InverseLinearWeight implements WeightFunction {
+ /**
+ * Linear increasing weight, from 0.1 to 1.0
+ *
+ * NOTE: increasing weights are non-standard, and mostly for testing
+ */
+ @Override
+ public double getWeight(double distance, double max, @SuppressWarnings("unused") double stddev) {
+ if(max <= 0) {
+ return 0.1;
+ }
+ double relativedistance = distance / max;
+ return .1 + relativedistance * .9;
+ }
+} \ No newline at end of file
diff --git a/src/de/lmu/ifi/dbs/elki/math/linearalgebra/pca/weightfunctions/InverseProportionalStddevWeight.java b/src/de/lmu/ifi/dbs/elki/math/linearalgebra/pca/weightfunctions/InverseProportionalStddevWeight.java
new file mode 100644
index 00000000..b157a7e5
--- /dev/null
+++ b/src/de/lmu/ifi/dbs/elki/math/linearalgebra/pca/weightfunctions/InverseProportionalStddevWeight.java
@@ -0,0 +1,44 @@
+package de.lmu.ifi.dbs.elki.math.linearalgebra.pca.weightfunctions;
+/*
+This file is part of ELKI:
+Environment for Developing KDD-Applications Supported by Index-Structures
+
+Copyright (C) 2011
+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/>.
+*/
+
+/**
+ * Inverse proportional weight function, scaled using the standard deviation.
+ *
+ * 1 / (1 + distance/stddev)
+ *
+ * @author Erich Schubert
+ */
+public final class InverseProportionalStddevWeight implements WeightFunction {
+ /**
+ * Get inverse proportional weight. max is ignored.
+ */
+ @Override
+ public double getWeight(double distance, @SuppressWarnings("unused") double max, double stddev) {
+ if(stddev <= 0) {
+ return 1;
+ }
+ double scaleddistance = distance / stddev;
+ return 1 / (1 + scaleddistance);
+ }
+} \ No newline at end of file
diff --git a/src/de/lmu/ifi/dbs/elki/math/linearalgebra/pca/weightfunctions/InverseProportionalWeight.java b/src/de/lmu/ifi/dbs/elki/math/linearalgebra/pca/weightfunctions/InverseProportionalWeight.java
new file mode 100644
index 00000000..2d19cf03
--- /dev/null
+++ b/src/de/lmu/ifi/dbs/elki/math/linearalgebra/pca/weightfunctions/InverseProportionalWeight.java
@@ -0,0 +1,44 @@
+package de.lmu.ifi.dbs.elki.math.linearalgebra.pca.weightfunctions;
+/*
+This file is part of ELKI:
+Environment for Developing KDD-Applications Supported by Index-Structures
+
+Copyright (C) 2011
+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/>.
+*/
+
+/**
+ * Inverse proportional weight function, scaled using the maximum.
+ *
+ * 1 / (1 + distance/max)
+ *
+ * @author Erich Schubert
+ */
+public final class InverseProportionalWeight implements WeightFunction {
+ /**
+ * Get inverse proportional weight. stddev is ignored.
+ */
+ @Override
+ public double getWeight(double distance, double max, @SuppressWarnings("unused") double stddev) {
+ if(max <= 0) {
+ return 1.0;
+ }
+ double relativedistance = distance / max;
+ return 1 / (1 + 9 * relativedistance);
+ }
+} \ No newline at end of file
diff --git a/src/de/lmu/ifi/dbs/elki/math/linearalgebra/pca/weightfunctions/LinearWeight.java b/src/de/lmu/ifi/dbs/elki/math/linearalgebra/pca/weightfunctions/LinearWeight.java
new file mode 100644
index 00000000..907a81d9
--- /dev/null
+++ b/src/de/lmu/ifi/dbs/elki/math/linearalgebra/pca/weightfunctions/LinearWeight.java
@@ -0,0 +1,45 @@
+package de.lmu.ifi.dbs.elki.math.linearalgebra.pca.weightfunctions;
+/*
+This file is part of ELKI:
+Environment for Developing KDD-Applications Supported by Index-Structures
+
+Copyright (C) 2011
+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/>.
+*/
+
+/**
+ * Linear weight function, scaled using the maximum such that it goes from 1.0
+ * to 0.1
+ *
+ * 1 - 0.9 * (distance/max)
+ *
+ * @author Erich Schubert
+ */
+public final class LinearWeight implements WeightFunction {
+ /**
+ * Linear decreasing weight, from 1.0 to 0.1. Stddev is ignored.
+ */
+ @Override
+ public double getWeight(double distance, double max, @SuppressWarnings("unused") double stddev) {
+ if(max <= 0) {
+ return 1.0;
+ }
+ double relativedistance = distance / max;
+ return 1 - relativedistance * .9;
+ }
+}
diff --git a/src/de/lmu/ifi/dbs/elki/math/linearalgebra/pca/weightfunctions/QuadraticStddevWeight.java b/src/de/lmu/ifi/dbs/elki/math/linearalgebra/pca/weightfunctions/QuadraticStddevWeight.java
new file mode 100644
index 00000000..3b26a85e
--- /dev/null
+++ b/src/de/lmu/ifi/dbs/elki/math/linearalgebra/pca/weightfunctions/QuadraticStddevWeight.java
@@ -0,0 +1,56 @@
+package de.lmu.ifi.dbs.elki.math.linearalgebra.pca.weightfunctions;
+/*
+This file is part of ELKI:
+Environment for Developing KDD-Applications Supported by Index-Structures
+
+Copyright (C) 2011
+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/>.
+*/
+
+/**
+ * Quadratic weight function, scaled using the standard deviation.
+ *
+ * We needed another scaling here, we chose the cutoff point to be 3*stddev. If
+ * you need another value, you have to reimplement this class.
+ *
+ * max(0.0, 1.0 - (distance/(3*stddev))^2
+ *
+ * @author Erich Schubert
+ */
+public final class QuadraticStddevWeight implements WeightFunction {
+ /**
+ * Scaling: at scaling * stddev the function will hit 0.0
+ */
+ private static final double scaling = 3;
+
+ /**
+ * Evaluate weight function at given parameters. max is ignored.
+ */
+ @Override
+ public double getWeight(double distance, @SuppressWarnings("unused") double max, double stddev) {
+ if(stddev <= 0) {
+ return 1;
+ }
+ double scaleddistance = distance / (scaling * stddev);
+ // After this, the result would be negative.
+ if(scaleddistance >= 1.0) {
+ return 0.0;
+ }
+ return 1.0 - scaleddistance * scaleddistance;
+ }
+}
diff --git a/src/de/lmu/ifi/dbs/elki/math/linearalgebra/pca/weightfunctions/QuadraticWeight.java b/src/de/lmu/ifi/dbs/elki/math/linearalgebra/pca/weightfunctions/QuadraticWeight.java
new file mode 100644
index 00000000..7de38dda
--- /dev/null
+++ b/src/de/lmu/ifi/dbs/elki/math/linearalgebra/pca/weightfunctions/QuadraticWeight.java
@@ -0,0 +1,45 @@
+package de.lmu.ifi.dbs.elki.math.linearalgebra.pca.weightfunctions;
+/*
+This file is part of ELKI:
+Environment for Developing KDD-Applications Supported by Index-Structures
+
+Copyright (C) 2011
+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/>.
+*/
+
+/**
+ * Quadratic weight function, scaled using the maximum to reach 0.1 at that
+ * point.
+ *
+ * 1.0 - 0.9 * (distance/max)^2
+ *
+ * @author Erich Schubert
+ */
+public final class QuadraticWeight implements WeightFunction {
+ /**
+ * Evaluate quadratic weight. stddev is ignored.
+ */
+ @Override
+ public double getWeight(double distance, double max, @SuppressWarnings("unused") double stddev) {
+ if(max <= 0) {
+ return 1.0;
+ }
+ double relativedistance = distance / max;
+ return 1.0 - 0.9 * relativedistance * relativedistance;
+ }
+} \ No newline at end of file
diff --git a/src/de/lmu/ifi/dbs/elki/math/linearalgebra/pca/weightfunctions/WeightFunction.java b/src/de/lmu/ifi/dbs/elki/math/linearalgebra/pca/weightfunctions/WeightFunction.java
new file mode 100644
index 00000000..bf8e32e6
--- /dev/null
+++ b/src/de/lmu/ifi/dbs/elki/math/linearalgebra/pca/weightfunctions/WeightFunction.java
@@ -0,0 +1,48 @@
+package de.lmu.ifi.dbs.elki.math.linearalgebra.pca.weightfunctions;
+/*
+This file is part of ELKI:
+Environment for Developing KDD-Applications Supported by Index-Structures
+
+Copyright (C) 2011
+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.InspectionUtilFrequentlyScanned;
+
+/**
+ * WeightFunction interface that allows the use of various distance-based weight
+ * functions. In addition to the distance parameter, the maximum distance and
+ * standard deviation are also given, to allow distance functions to be
+ * normalized according to the maximum or standard deviation.
+ *
+ * @author Erich Schubert
+ */
+public interface WeightFunction extends InspectionUtilFrequentlyScanned {
+ /**
+ * Evaluate weight function with given parameters.
+ *
+ * Note that usually implementations will ignore either max or stddev.
+ *
+ * @param distance distance of the query point
+ * @param max maximum distance of all included points
+ * @param stddev standard deviation (i.e. quadratic mean / RMS) of the
+ * included points
+ * @return weight for the query point
+ */
+ double getWeight(double distance, double max, double stddev);
+}
diff --git a/src/de/lmu/ifi/dbs/elki/math/linearalgebra/pca/weightfunctions/package-info.java b/src/de/lmu/ifi/dbs/elki/math/linearalgebra/pca/weightfunctions/package-info.java
new file mode 100644
index 00000000..268a3e89
--- /dev/null
+++ b/src/de/lmu/ifi/dbs/elki/math/linearalgebra/pca/weightfunctions/package-info.java
@@ -0,0 +1,26 @@
+/**
+ * <p>Weight functions used in weighted PCA via {@link de.lmu.ifi.dbs.elki.math.linearalgebra.pca.WeightedCovarianceMatrixBuilder}</p>
+ */
+/*
+This file is part of ELKI:
+Environment for Developing KDD-Applications Supported by Index-Structures
+
+Copyright (C) 2011
+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/>.
+*/
+package de.lmu.ifi.dbs.elki.math.linearalgebra.pca.weightfunctions; \ No newline at end of file