summaryrefslogtreecommitdiff
path: root/src/de/lmu/ifi/dbs/elki/application/greedyensemble/VisualizePairwiseGainMatrix.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/de/lmu/ifi/dbs/elki/application/greedyensemble/VisualizePairwiseGainMatrix.java')
-rw-r--r--src/de/lmu/ifi/dbs/elki/application/greedyensemble/VisualizePairwiseGainMatrix.java69
1 files changed, 33 insertions, 36 deletions
diff --git a/src/de/lmu/ifi/dbs/elki/application/greedyensemble/VisualizePairwiseGainMatrix.java b/src/de/lmu/ifi/dbs/elki/application/greedyensemble/VisualizePairwiseGainMatrix.java
index 3ef30c10..60678bea 100644
--- a/src/de/lmu/ifi/dbs/elki/application/greedyensemble/VisualizePairwiseGainMatrix.java
+++ b/src/de/lmu/ifi/dbs/elki/application/greedyensemble/VisualizePairwiseGainMatrix.java
@@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.application.greedyensemble;
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
- Copyright (C) 2013
+ Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
@@ -39,13 +39,14 @@ import de.lmu.ifi.dbs.elki.database.ids.DBIDIter;
import de.lmu.ifi.dbs.elki.database.ids.DBIDUtil;
import de.lmu.ifi.dbs.elki.database.relation.Relation;
import de.lmu.ifi.dbs.elki.database.relation.RelationUtil;
-import de.lmu.ifi.dbs.elki.evaluation.roc.ROC;
+import de.lmu.ifi.dbs.elki.evaluation.scores.ROCEvaluation;
+import de.lmu.ifi.dbs.elki.evaluation.scores.adapter.DecreasingVectorIter;
+import de.lmu.ifi.dbs.elki.evaluation.scores.adapter.VectorNonZero;
import de.lmu.ifi.dbs.elki.evaluation.similaritymatrix.ComputeSimilarityMatrixImage;
import de.lmu.ifi.dbs.elki.evaluation.similaritymatrix.ComputeSimilarityMatrixImage.SimilarityMatrix;
import de.lmu.ifi.dbs.elki.logging.Logging;
import de.lmu.ifi.dbs.elki.logging.progress.FiniteProgress;
import de.lmu.ifi.dbs.elki.math.DoubleMinMax;
-import de.lmu.ifi.dbs.elki.math.geometry.XYCurve;
import de.lmu.ifi.dbs.elki.math.linearalgebra.Vector;
import de.lmu.ifi.dbs.elki.result.ResultUtil;
import de.lmu.ifi.dbs.elki.utilities.DatabaseUtil;
@@ -134,21 +135,21 @@ public class VisualizePairwiseGainMatrix extends AbstractApplication {
@Override
public void run() {
final Database database = inputstep.getDatabase();
- Relation<NumberVector<?>> relation = database.getRelation(TypeUtil.NUMBER_VECTOR_FIELD);
+ Relation<NumberVector> relation = database.getRelation(TypeUtil.NUMBER_VECTOR_FIELD);
final Relation<String> labels = DatabaseUtil.guessLabelRepresentation(database);
final DBID firstid = DBIDUtil.deref(labels.iterDBIDs());
final String firstlabel = labels.get(firstid);
- if (!firstlabel.matches(".*by.?label.*")) {
+ if(!firstlabel.matches(".*by.?label.*")) {
throw new AbortException("No 'by label' reference outlier found, which is needed for weighting!");
}
relation = GreedyEnsembleExperiment.applyPrescaling(prescaling, relation, firstid);
// Dimensionality and reference vector
final int dim = RelationUtil.dimensionality(relation);
- final NumberVector<?> refvec = relation.get(firstid);
+ final NumberVector refvec = relation.get(firstid);
// Build the truth vector
- ROC.VectorNonZero pos = new ROC.VectorNonZero(refvec);
+ VectorNonZero pos = new VectorNonZero(refvec);
ArrayModifiableDBIDs ids = DBIDUtil.newArray(relation.getDBIDs());
ids.remove(firstid);
@@ -162,46 +163,40 @@ public class VisualizePairwiseGainMatrix extends AbstractApplication {
FiniteProgress prog = LOG.isVerbose() ? new FiniteProgress("Computing ensemble gain.", size * (size + 1) >> 1, LOG) : null;
double[] buf = new double[2]; // Vote combination buffer.
int a = 0;
- for (DBIDIter id = ids.iter(); id.valid(); id.advance(), a++) {
- final NumberVector<?> veca = relation.get(id);
+ for(DBIDIter id = ids.iter(); id.valid(); id.advance(), a++) {
+ final NumberVector veca = relation.get(id);
// Direct AUC score:
{
- double auc = XYCurve.areaUnderCurve(ROC.materializeROC(pos, new ROC.DecreasingVectorIter(veca)));
+ double auc = ROCEvaluation.computeROCAUC(pos, new DecreasingVectorIter(veca));
data[a][a] = auc;
// minmax.put(auc);
- if (prog != null) {
- prog.incrementProcessed(LOG);
- }
+ LOG.incrementProcessed(prog);
}
// Compare to others, exploiting symmetry
DBIDArrayIter id2 = ids.iter();
id2.seek(a + 1);
- for (int b = a + 1; b < size; b++, id2.advance()) {
- final NumberVector<?> vecb = relation.get(id2);
+ for(int b = a + 1; b < size; b++, id2.advance()) {
+ final NumberVector vecb = relation.get(id2);
double[] combined = new double[dim];
- for (int d = 0; d < dim; d++) {
+ for(int d = 0; d < dim; d++) {
buf[0] = veca.doubleValue(d);
buf[1] = vecb.doubleValue(d);
combined[d] = voting.combine(buf);
}
- double auc = XYCurve.areaUnderCurve(ROC.materializeROC(pos, new ROC.DecreasingVectorIter(new Vector(combined))));
+ double auc = ROCEvaluation.computeROCAUC(pos, new DecreasingVectorIter(new Vector(combined)));
// logger.verbose(auc + " " + labels.get(ids.get(a)) + " " +
// labels.get(ids.get(b)));
data[a][b] = auc;
data[b][a] = auc;
commax.put(data[a][b]);
// minmax.put(auc);
- if (prog != null) {
- prog.incrementProcessed(LOG);
- }
+ LOG.incrementProcessed(prog);
}
}
- if (prog != null) {
- prog.ensureCompleted(LOG);
- }
+ LOG.ensureCompleted(prog);
}
- for (int a = 0; a < size; a++) {
- for (int b = a + 1; b < size; b++) {
+ for(int a = 0; a < size; a++) {
+ for(int b = a + 1; b < size; b++) {
double ref = Math.max(data[a][a], data[b][b]);
data[a][b] = (data[a][b] - ref) / (1 - ref);
data[b][a] = (data[b][a] - ref) / (1 - ref);
@@ -210,7 +205,7 @@ public class VisualizePairwiseGainMatrix extends AbstractApplication {
minmax.put(data[a][b]);
}
}
- for (int a = 0; a < size; a++) {
+ for(int a = 0; a < size; a++) {
data[a][a] = 0;
}
@@ -218,25 +213,27 @@ public class VisualizePairwiseGainMatrix extends AbstractApplication {
boolean hasneg = (minmax.getMin() < -1E-3);
LinearScaling scale;
- if (!hasneg) {
+ if(!hasneg) {
scale = LinearScaling.fromMinMax(0., minmax.getMax());
- } else {
+ }
+ else {
scale = LinearScaling.fromMinMax(0.0, Math.max(minmax.getMax(), -minmax.getMin()));
}
scale = LinearScaling.fromMinMax(0., .5);
BufferedImage img = new BufferedImage(size, size, BufferedImage.TYPE_INT_RGB);
- for (int x = 0; x < size; x++) {
- for (int y = x; y < size; y++) {
+ for(int x = 0; x < size; x++) {
+ for(int y = x; y < size; y++) {
double val = data[x][y];
val = Math.max(-1, Math.min(1., scale.getScaled(val)));
// Compute color:
final int col;
{
- if (val >= 0) {
+ if(val >= 0) {
int ival = 0xFF & (int) (255 * val);
col = 0xff000000 | (ival << 8);
- } else {
+ }
+ else {
int ival = 0xFF & (int) (255 * -val);
col = 0xff000000 | (ival << 16);
}
@@ -255,8 +252,8 @@ public class VisualizePairwiseGainMatrix extends AbstractApplication {
factory.processNewResult(database, database);
List<VisualizationTask> tasks = ResultUtil.filterResults(database, VisualizationTask.class);
- for (VisualizationTask task : tasks) {
- if (task.getFactory() == factory) {
+ for(VisualizationTask task : tasks) {
+ if(task.getFactory() == factory) {
showVisualization(context, factory, task);
}
}
@@ -320,12 +317,12 @@ public class VisualizePairwiseGainMatrix extends AbstractApplication {
// Prescaling
ObjectParameter<ScalingFunction> prescalingP = new ObjectParameter<>(GreedyEnsembleExperiment.Parameterizer.PRESCALING_ID, ScalingFunction.class);
prescalingP.setOptional(true);
- if (config.grab(prescalingP)) {
+ if(config.grab(prescalingP)) {
prescaling = prescalingP.instantiateClass(config);
}
ObjectParameter<EnsembleVoting> votingP = new ObjectParameter<>(GreedyEnsembleExperiment.Parameterizer.VOTING_ID, EnsembleVoting.class, EnsembleVotingMean.class);
- if (config.grab(votingP)) {
+ if(config.grab(votingP)) {
voting = votingP.instantiateClass(config);
}
}