summaryrefslogtreecommitdiff
path: root/src/de/lmu/ifi/dbs/elki/utilities/ensemble
diff options
context:
space:
mode:
Diffstat (limited to 'src/de/lmu/ifi/dbs/elki/utilities/ensemble')
-rw-r--r--src/de/lmu/ifi/dbs/elki/utilities/ensemble/EnsembleVoting.java12
-rw-r--r--src/de/lmu/ifi/dbs/elki/utilities/ensemble/EnsembleVotingBayes.java106
-rw-r--r--src/de/lmu/ifi/dbs/elki/utilities/ensemble/EnsembleVotingInverseMultiplicative.java75
-rw-r--r--src/de/lmu/ifi/dbs/elki/utilities/ensemble/EnsembleVotingMax.java15
-rw-r--r--src/de/lmu/ifi/dbs/elki/utilities/ensemble/EnsembleVotingMean.java15
-rw-r--r--src/de/lmu/ifi/dbs/elki/utilities/ensemble/EnsembleVotingMedian.java9
-rw-r--r--src/de/lmu/ifi/dbs/elki/utilities/ensemble/EnsembleVotingMin.java15
-rw-r--r--src/de/lmu/ifi/dbs/elki/utilities/ensemble/EnsembleVotingMultiplicative.java75
-rw-r--r--src/de/lmu/ifi/dbs/elki/utilities/ensemble/EnsembleVotingRestrictedBayes.java127
-rw-r--r--src/de/lmu/ifi/dbs/elki/utilities/ensemble/package-info.java2
10 files changed, 201 insertions, 250 deletions
diff --git a/src/de/lmu/ifi/dbs/elki/utilities/ensemble/EnsembleVoting.java b/src/de/lmu/ifi/dbs/elki/utilities/ensemble/EnsembleVoting.java
index a83517f0..47c46d46 100644
--- a/src/de/lmu/ifi/dbs/elki/utilities/ensemble/EnsembleVoting.java
+++ b/src/de/lmu/ifi/dbs/elki/utilities/ensemble/EnsembleVoting.java
@@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.utilities.ensemble;
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
- Copyright (C) 2012
+ Copyright (C) 2013
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
@@ -39,4 +39,14 @@ public interface EnsembleVoting extends Parameterizable {
* @return combined score.
*/
public double combine(double[] scores);
+
+ /**
+ * Combine scores function. Note: it is assumed that the scores are
+ * comparable.
+ *
+ * @param scores Scores to combine
+ * @param count Number of entries to use.
+ * @return combined score.
+ */
+ public double combine(double[] scores, int count);
}
diff --git a/src/de/lmu/ifi/dbs/elki/utilities/ensemble/EnsembleVotingBayes.java b/src/de/lmu/ifi/dbs/elki/utilities/ensemble/EnsembleVotingBayes.java
deleted file mode 100644
index 7263513b..00000000
--- a/src/de/lmu/ifi/dbs/elki/utilities/ensemble/EnsembleVotingBayes.java
+++ /dev/null
@@ -1,106 +0,0 @@
-package de.lmu.ifi.dbs.elki.utilities.ensemble;
-
-/*
- This file is part of ELKI:
- Environment for Developing KDD-Applications Supported by Index-Structures
-
- Copyright (C) 2012
- 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;
-import de.lmu.ifi.dbs.elki.utilities.optionhandling.OptionID;
-import de.lmu.ifi.dbs.elki.utilities.optionhandling.constraints.GreaterEqualConstraint;
-import de.lmu.ifi.dbs.elki.utilities.optionhandling.constraints.LessConstraint;
-import de.lmu.ifi.dbs.elki.utilities.optionhandling.parameterization.Parameterization;
-import de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.DoubleParameter;
-
-/**
- * Combination rule based on Bayes theorems.
- *
- * Note: this assumes that the scores are probabilistic!
- *
- * @author Erich Schubert
- */
-public class EnsembleVotingBayes implements EnsembleVoting {
- /**
- * Minimum vote to cast
- */
- private double minvote = 0.05;
-
- /**
- * Constructor.
- *
- * @param minvote Minimum vote to cast (0 to 0.5)
- */
- public EnsembleVotingBayes(double minvote) {
- this.minvote = minvote;
- }
-
- @Override
- public double combine(double[] scores) {
- double pos = 1.0;
- double neg = 1.0;
- for (double score : scores) {
- if (score < minvote) {
- score = minvote;
- } else if (score > 1.0 - minvote) {
- score = 1.0 - minvote;
- }
- pos *= score;
- neg *= (1.0 - score);
- }
- return pos / (pos + neg);
- }
-
- /**
- * Parameterization class.
- *
- * @author Erich Schubert
- *
- * @apiviz.exclude
- */
- public static class Parameterizer extends AbstractParameterizer {
- /**
- * Option ID for the minimum and maximum vote
- */
- public static final OptionID MIN_ID = new OptionID("ensemble.bayes.min", "Minimum (and maximum) vote share, in the range 0 to 0.5");
-
- /**
- * Minimum vote to cast
- */
- private double minvote = 0.05;
-
- @Override
- protected void makeOptions(Parameterization config) {
- super.makeOptions(config);
- DoubleParameter minvoteP = new DoubleParameter(MIN_ID, 0.05);
- minvoteP.addConstraint(new GreaterEqualConstraint(0.0));
- minvoteP.addConstraint(new LessConstraint(0.5));
-
- if (config.grab(minvoteP)) {
- minvote = minvoteP.getValue();
- }
- }
-
- @Override
- protected EnsembleVotingBayes makeInstance() {
- return new EnsembleVotingBayes(minvote);
- }
- }
-}
diff --git a/src/de/lmu/ifi/dbs/elki/utilities/ensemble/EnsembleVotingInverseMultiplicative.java b/src/de/lmu/ifi/dbs/elki/utilities/ensemble/EnsembleVotingInverseMultiplicative.java
new file mode 100644
index 00000000..2e082761
--- /dev/null
+++ b/src/de/lmu/ifi/dbs/elki/utilities/ensemble/EnsembleVotingInverseMultiplicative.java
@@ -0,0 +1,75 @@
+package de.lmu.ifi.dbs.elki.utilities.ensemble;
+
+/*
+ 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;
+
+/**
+ * Inverse multiplicative voting:
+ *
+ * {@code 1-product(1-s_i)}
+ *
+ * @author Erich Schubert
+ */
+public class EnsembleVotingInverseMultiplicative implements EnsembleVoting {
+ /**
+ * Static instance.
+ */
+ public static final EnsembleVotingInverseMultiplicative STATIC = new EnsembleVotingInverseMultiplicative();
+
+ /**
+ * Constructor.
+ */
+ public EnsembleVotingInverseMultiplicative() {
+ super();
+ }
+
+ @Override
+ public double combine(double[] scores) {
+ return combine(scores, scores.length);
+ }
+
+ @Override
+ public double combine(double[] scores, int count) {
+ double prod = 1.;
+ for (int i = 0; i < count; i++) {
+ prod *= (1 - scores[i]);
+ }
+ return 1 - prod;
+ }
+
+ /**
+ * Parameterization class.
+ *
+ * @author Erich Schubert
+ *
+ * @apiviz.exclude
+ */
+ public static class Parameterizer extends AbstractParameterizer {
+ @Override
+ protected EnsembleVotingInverseMultiplicative makeInstance() {
+ return STATIC;
+ }
+ }
+}
diff --git a/src/de/lmu/ifi/dbs/elki/utilities/ensemble/EnsembleVotingMax.java b/src/de/lmu/ifi/dbs/elki/utilities/ensemble/EnsembleVotingMax.java
index b467e9f6..e179999d 100644
--- a/src/de/lmu/ifi/dbs/elki/utilities/ensemble/EnsembleVotingMax.java
+++ b/src/de/lmu/ifi/dbs/elki/utilities/ensemble/EnsembleVotingMax.java
@@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.utilities.ensemble;
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
- Copyright (C) 2012
+ Copyright (C) 2013
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
@@ -39,9 +39,16 @@ public class EnsembleVotingMax implements EnsembleVoting {
@Override
public double combine(double[] scores) {
- double max = Double.NEGATIVE_INFINITY;
- for (double val : scores) {
- max = Math.max(max, val);
+ return combine(scores, scores.length);
+ }
+
+ @Override
+ public double combine(double[] scores, int count) {
+ double max = scores[0];
+ for (int i = 1; i < count; i++) {
+ if (scores[i] > max) {
+ max = scores[i];
+ }
}
return max;
}
diff --git a/src/de/lmu/ifi/dbs/elki/utilities/ensemble/EnsembleVotingMean.java b/src/de/lmu/ifi/dbs/elki/utilities/ensemble/EnsembleVotingMean.java
index 20746927..19643782 100644
--- a/src/de/lmu/ifi/dbs/elki/utilities/ensemble/EnsembleVotingMean.java
+++ b/src/de/lmu/ifi/dbs/elki/utilities/ensemble/EnsembleVotingMean.java
@@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.utilities.ensemble;
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
- Copyright (C) 2012
+ Copyright (C) 2013
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
@@ -39,10 +39,15 @@ public class EnsembleVotingMean implements EnsembleVoting {
@Override
public double combine(double[] scores) {
- double sum = 0.0;
- for (double score : scores) {
- sum += score;
+ return combine(scores, scores.length);
+ }
+
+ @Override
+ public double combine(double[] scores, int count) {
+ double sum = 0.;
+ for (int i = 0; i < count; i++) {
+ sum += scores[i];
}
- return sum / scores.length;
+ return sum / count;
}
}
diff --git a/src/de/lmu/ifi/dbs/elki/utilities/ensemble/EnsembleVotingMedian.java b/src/de/lmu/ifi/dbs/elki/utilities/ensemble/EnsembleVotingMedian.java
index fa1b3fa6..de137b40 100644
--- a/src/de/lmu/ifi/dbs/elki/utilities/ensemble/EnsembleVotingMedian.java
+++ b/src/de/lmu/ifi/dbs/elki/utilities/ensemble/EnsembleVotingMedian.java
@@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.utilities.ensemble;
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
- Copyright (C) 2012
+ Copyright (C) 2013
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
@@ -55,7 +55,12 @@ public class EnsembleVotingMedian implements EnsembleVoting {
@Override
public double combine(double[] scores) {
- return QuickSelect.quantile(scores, quantile);
+ return combine(scores, scores.length);
+ }
+
+ @Override
+ public double combine(double[] scores, int count) {
+ return QuickSelect.quantile(scores, 0, count, quantile);
}
/**
diff --git a/src/de/lmu/ifi/dbs/elki/utilities/ensemble/EnsembleVotingMin.java b/src/de/lmu/ifi/dbs/elki/utilities/ensemble/EnsembleVotingMin.java
index fcf5c138..b4baa4ab 100644
--- a/src/de/lmu/ifi/dbs/elki/utilities/ensemble/EnsembleVotingMin.java
+++ b/src/de/lmu/ifi/dbs/elki/utilities/ensemble/EnsembleVotingMin.java
@@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.utilities.ensemble;
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
- Copyright (C) 2012
+ Copyright (C) 2013
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
@@ -40,9 +40,16 @@ public class EnsembleVotingMin implements EnsembleVoting {
@Override
public double combine(double[] scores) {
- double min = Double.POSITIVE_INFINITY;
- for (double val : scores) {
- min = Math.min(min, val);
+ return combine(scores, scores.length);
+ }
+
+ @Override
+ public double combine(double[] scores, int count) {
+ double min = scores[0];
+ for (int i = 1; i < count; i++) {
+ if (scores[i] < min) {
+ min = scores[i];
+ }
}
return min;
}
diff --git a/src/de/lmu/ifi/dbs/elki/utilities/ensemble/EnsembleVotingMultiplicative.java b/src/de/lmu/ifi/dbs/elki/utilities/ensemble/EnsembleVotingMultiplicative.java
new file mode 100644
index 00000000..3d99b8aa
--- /dev/null
+++ b/src/de/lmu/ifi/dbs/elki/utilities/ensemble/EnsembleVotingMultiplicative.java
@@ -0,0 +1,75 @@
+package de.lmu.ifi.dbs.elki.utilities.ensemble;
+
+/*
+ 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;
+
+/**
+ * Inverse multiplicative voting:
+ *
+ * {@code product(s_i)}
+ *
+ * @author Erich Schubert
+ */
+public class EnsembleVotingMultiplicative implements EnsembleVoting {
+ /**
+ * Static instance.
+ */
+ public static final EnsembleVotingMultiplicative STATIC = new EnsembleVotingMultiplicative();
+
+ /**
+ * Constructor.
+ */
+ public EnsembleVotingMultiplicative() {
+ super();
+ }
+
+ @Override
+ public double combine(double[] scores) {
+ return combine(scores, scores.length);
+ }
+
+ @Override
+ public double combine(double[] scores, int count) {
+ double prod = 1.;
+ for (int i = 0; i < count; i++) {
+ prod *= scores[i];
+ }
+ return prod;
+ }
+
+ /**
+ * Parameterization class.
+ *
+ * @author Erich Schubert
+ *
+ * @apiviz.exclude
+ */
+ public static class Parameterizer extends AbstractParameterizer {
+ @Override
+ protected EnsembleVotingMultiplicative makeInstance() {
+ return STATIC;
+ }
+ }
+}
diff --git a/src/de/lmu/ifi/dbs/elki/utilities/ensemble/EnsembleVotingRestrictedBayes.java b/src/de/lmu/ifi/dbs/elki/utilities/ensemble/EnsembleVotingRestrictedBayes.java
deleted file mode 100644
index c2edcbfd..00000000
--- a/src/de/lmu/ifi/dbs/elki/utilities/ensemble/EnsembleVotingRestrictedBayes.java
+++ /dev/null
@@ -1,127 +0,0 @@
-package de.lmu.ifi.dbs.elki.utilities.ensemble;
-
-/*
- This file is part of ELKI:
- Environment for Developing KDD-Applications Supported by Index-Structures
-
- Copyright (C) 2012
- 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;
-import de.lmu.ifi.dbs.elki.utilities.optionhandling.OptionID;
-import de.lmu.ifi.dbs.elki.utilities.optionhandling.constraints.GreaterConstraint;
-import de.lmu.ifi.dbs.elki.utilities.optionhandling.constraints.GreaterEqualConstraint;
-import de.lmu.ifi.dbs.elki.utilities.optionhandling.constraints.LessConstraint;
-import de.lmu.ifi.dbs.elki.utilities.optionhandling.constraints.LessEqualConstraint;
-import de.lmu.ifi.dbs.elki.utilities.optionhandling.constraints.LessGlobalConstraint;
-import de.lmu.ifi.dbs.elki.utilities.optionhandling.parameterization.Parameterization;
-import de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.DoubleParameter;
-
-/**
- * Combination rule based on Bayes theorems.
- *
- * @author Erich Schubert
- */
-public class EnsembleVotingRestrictedBayes implements EnsembleVoting {
- /**
- * Minimum vote to cast
- */
- private double minvote = 0.05;
-
- /**
- * Maximum vote to cast
- */
- private double maxvote = 1.0;
-
- /**
- * Constructor.
- *
- * @param minvote minimum vote
- * @param maxvote maximum vote
- */
- public EnsembleVotingRestrictedBayes(double minvote, double maxvote) {
- this.minvote = minvote;
- this.maxvote = maxvote;
- }
-
- @Override
- public double combine(double[] scores) {
- double pos = 1.0;
- double neg = 1.0;
- for (double score : scores) {
- score = Math.min(minvote, Math.max(maxvote, score));
- final double cscore = score;
- pos *= cscore;
- neg *= (1.0 - cscore);
- }
- return pos / (pos + neg);
- }
-
- /**
- * Parameterization class.
- *
- * @author Erich Schubert
- *
- * @apiviz.exclude
- */
- public static class Parameterizer extends AbstractParameterizer {
- /**
- * Option ID for the minimum and maximum vote
- */
- public static final OptionID MIN_ID = new OptionID("ensemble.bayes.min", "Minimum vote share.");
-
- /**
- * Option ID for the minimum and maximum vote
- */
- public static final OptionID MAX_ID = new OptionID("ensemble.bayes.max", "Maximum vote share.");
-
- /**
- * Minimum vote to cast
- */
- private double minvote = 0.05;
-
- /**
- * Maximum vote to cast
- */
- private double maxvote = 1.0;
-
- @Override
- protected void makeOptions(Parameterization config) {
- super.makeOptions(config);
- DoubleParameter minvoteP = new DoubleParameter(MIN_ID, 0.05);
- minvoteP.addConstraint(new GreaterEqualConstraint(0.0));
- minvoteP.addConstraint(new LessConstraint(0.0));
- if (config.grab(minvoteP)) {
- minvote = minvoteP.doubleValue();
- }
- DoubleParameter maxvoteP = new DoubleParameter(MAX_ID, 0.95);
- maxvoteP.addConstraint(new GreaterConstraint(0.0));
- maxvoteP.addConstraint(new LessEqualConstraint(0.0));
- if (config.grab(maxvoteP)) {
- maxvote = maxvoteP.doubleValue();
- }
- config.checkConstraint(new LessGlobalConstraint<Double>(minvoteP, maxvoteP));
- }
-
- @Override
- protected EnsembleVotingRestrictedBayes makeInstance() {
- return new EnsembleVotingRestrictedBayes(minvote, maxvote);
- }
- }
-}
diff --git a/src/de/lmu/ifi/dbs/elki/utilities/ensemble/package-info.java b/src/de/lmu/ifi/dbs/elki/utilities/ensemble/package-info.java
index 572b40bb..76ee4ab8 100644
--- a/src/de/lmu/ifi/dbs/elki/utilities/ensemble/package-info.java
+++ b/src/de/lmu/ifi/dbs/elki/utilities/ensemble/package-info.java
@@ -5,7 +5,7 @@
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
-Copyright (C) 2012
+Copyright (C) 2013
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team