use of de.lmu.ifi.dbs.elki.result.outlier.OutlierResult in project elki by elki-project.
the class OutlierROCCurve method processNewResult.
@Override
public void processNewResult(ResultHierarchy hier, Result result) {
Database db = ResultUtil.findDatabase(hier);
// Prepare
SetDBIDs positiveids = DBIDUtil.ensureSet(DatabaseUtil.getObjectsByLabelMatch(db, positiveClassName));
if (positiveids.size() == 0) {
LOG.warning("Computing a ROC curve failed - no objects matched.");
return;
}
boolean nonefound = true;
List<OutlierResult> oresults = OutlierResult.getOutlierResults(result);
List<OrderingResult> orderings = ResultUtil.getOrderingResults(result);
// Outlier results are the main use case.
for (OutlierResult o : oresults) {
ROCResult rocres = computeROCResult(o.getScores().size(), positiveids, o);
db.getHierarchy().add(o, rocres);
EvaluationResult ev = EvaluationResult.findOrCreate(db.getHierarchy(), o, "Evaluation of ranking", "ranking-evaluation");
MeasurementGroup g = ev.findOrCreateGroup("Evaluation measures");
if (!g.hasMeasure(ROCAUC_LABEL)) {
g.addMeasure(ROCAUC_LABEL, rocres.auc, 0., 1., false);
}
// Process each ordering only once.
orderings.remove(o.getOrdering());
nonefound = false;
}
// otherwise apply an ordering to the database IDs.
for (OrderingResult or : orderings) {
DBIDs sorted = or.order(or.getDBIDs());
ROCResult rocres = computeROCResult(or.getDBIDs().size(), positiveids, sorted);
db.getHierarchy().add(or, rocres);
EvaluationResult ev = EvaluationResult.findOrCreate(db.getHierarchy(), or, "Evaluation of ranking", "ranking-evaluation");
MeasurementGroup g = ev.findOrCreateGroup("Evaluation measures");
if (!g.hasMeasure(ROCAUC_LABEL)) {
g.addMeasure(ROCAUC_LABEL, rocres.auc, 0., 1., false);
}
nonefound = false;
}
if (nonefound) {
return;
// logger.warning("No results found to process with ROC curve analyzer.
// Got "+iterables.size()+" iterables, "+orderings.size()+" orderings.");
}
}
use of de.lmu.ifi.dbs.elki.result.outlier.OutlierResult in project elki by elki-project.
the class OutlierSmROCCurve method processNewResult.
@Override
public void processNewResult(ResultHierarchy hier, Result result) {
Database db = ResultUtil.findDatabase(hier);
// Prepare
SetDBIDs positiveids = DBIDUtil.ensureSet(DatabaseUtil.getObjectsByLabelMatch(db, positiveClassName));
if (positiveids.size() == 0) {
LOG.warning("Computing a ROC curve failed - no objects matched.");
return;
}
List<OutlierResult> oresults = OutlierResult.getOutlierResults(result);
List<OrderingResult> orderings = ResultUtil.getOrderingResults(result);
for (OutlierResult o : oresults) {
db.getHierarchy().add(o, computeSmROCResult(positiveids, o));
orderings.remove(o.getOrdering());
}
}
use of de.lmu.ifi.dbs.elki.result.outlier.OutlierResult in project elki by elki-project.
the class SimpleCOP method run.
public OutlierResult run(Database database, Relation<V> data) throws IllegalStateException {
KNNQuery<V> knnQuery = QueryUtil.getKNNQuery(data, getDistanceFunction(), k + 1);
DBIDs ids = data.getDBIDs();
WritableDoubleDataStore cop_score = DataStoreUtil.makeDoubleStorage(ids, DataStoreFactory.HINT_HOT | DataStoreFactory.HINT_STATIC);
WritableDataStore<double[]> cop_err_v = DataStoreUtil.makeStorage(ids, DataStoreFactory.HINT_HOT | DataStoreFactory.HINT_STATIC, double[].class);
WritableDataStore<double[][]> cop_datav = DataStoreUtil.makeStorage(ids, DataStoreFactory.HINT_HOT | DataStoreFactory.HINT_STATIC, double[][].class);
WritableIntegerDataStore cop_dim = DataStoreUtil.makeIntegerStorage(ids, DataStoreFactory.HINT_HOT | DataStoreFactory.HINT_STATIC, -1);
WritableDataStore<CorrelationAnalysisSolution<?>> cop_sol = DataStoreUtil.makeStorage(ids, DataStoreFactory.HINT_HOT | DataStoreFactory.HINT_STATIC, CorrelationAnalysisSolution.class);
{
// compute neighbors of each db object
FiniteProgress progressLocalPCA = LOG.isVerbose() ? new FiniteProgress("Correlation Outlier Probabilities", data.size(), LOG) : null;
double sqrt2 = MathUtil.SQRT2;
for (DBIDIter id = data.iterDBIDs(); id.valid(); id.advance()) {
KNNList neighbors = knnQuery.getKNNForDBID(id, k + 1);
ModifiableDBIDs nids = DBIDUtil.newArray(neighbors);
nids.remove(id);
// TODO: do we want to use the query point as centroid?
CorrelationAnalysisSolution<V> depsol = dependencyDerivator.generateModel(data, nids);
double stddev = depsol.getStandardDeviation();
double distance = depsol.distance(data.get(id));
double prob = NormalDistribution.erf(distance / (stddev * sqrt2));
cop_score.putDouble(id, prob);
cop_err_v.put(id, times(depsol.errorVector(data.get(id)), -1));
double[][] datav = depsol.dataProjections(data.get(id));
cop_datav.put(id, datav);
cop_dim.putInt(id, depsol.getCorrelationDimensionality());
cop_sol.put(id, depsol);
LOG.incrementProcessed(progressLocalPCA);
}
LOG.ensureCompleted(progressLocalPCA);
}
// combine results.
DoubleRelation scoreResult = new MaterializedDoubleRelation("Original Correlation Outlier Probabilities", "origcop-outlier", cop_score, ids);
OutlierScoreMeta scoreMeta = new ProbabilisticOutlierScore();
OutlierResult result = new OutlierResult(scoreMeta, scoreResult);
// extra results
result.addChildResult(new MaterializedRelation<>("Local Dimensionality", COP.COP_DIM, TypeUtil.INTEGER, cop_dim, ids));
result.addChildResult(new MaterializedRelation<>("Error vectors", COP.COP_ERRORVEC, TypeUtil.DOUBLE_ARRAY, cop_err_v, ids));
result.addChildResult(new MaterializedRelation<>("Data vectors", "cop-datavec", TypeUtil.MATRIX, cop_datav, ids));
result.addChildResult(new MaterializedRelation<>("Correlation analysis", "cop-sol", new SimpleTypeInformation<CorrelationAnalysisSolution<?>>(CorrelationAnalysisSolution.class), cop_sol, ids));
return result;
}
use of de.lmu.ifi.dbs.elki.result.outlier.OutlierResult in project elki by elki-project.
the class ComputeSimilarityMatrixImage method processNewResult.
@Override
public void processNewResult(ResultHierarchy hier, Result result) {
Database db = ResultUtil.findDatabase(hier);
boolean nonefound = true;
List<OutlierResult> oresults = OutlierResult.getOutlierResults(result);
List<OrderingResult> orderings = ResultUtil.getOrderingResults(result);
// Outlier results are the main use case.
for (OutlierResult o : oresults) {
final OrderingResult or = o.getOrdering();
Relation<O> relation = db.getRelation(distanceFunction.getInputTypeRestriction());
db.getHierarchy().add(or, computeSimilarityMatrixImage(relation, or.order(relation.getDBIDs()).iter()));
// Process them only once.
orderings.remove(or);
nonefound = false;
}
// otherwise apply an ordering to the database IDs.
for (OrderingResult or : orderings) {
Relation<O> relation = db.getRelation(distanceFunction.getInputTypeRestriction());
DBIDIter iter = or.order(relation.getDBIDs()).iter();
db.getHierarchy().add(or, computeSimilarityMatrixImage(relation, iter));
nonefound = false;
}
if (nonefound) {
// Use the database ordering.
// But be careful to NOT cause a loop, process new databases only.
List<Database> iter = ResultUtil.filterResults(hier, Database.class);
for (Database database : iter) {
// Get an arbitrary representation
Relation<O> relation = database.getRelation(distanceFunction.getInputTypeRestriction());
db.getHierarchy().add(db, computeSimilarityMatrixImage(relation, relation.iterDBIDs()));
}
}
}
use of de.lmu.ifi.dbs.elki.result.outlier.OutlierResult in project elki by elki-project.
the class KMLOutputHandler method processNewResult.
@Override
public void processNewResult(ResultHierarchy hier, Result newResult) {
ArrayList<OutlierResult> ors = ResultUtil.filterResults(hier, newResult, OutlierResult.class);
ArrayList<Clustering<?>> crs = ResultUtil.filterResults(hier, newResult, Clustering.class);
if (ors.size() + crs.size() > 1) {
throw new AbortException("More than one visualizable result found. The KML writer only supports a single result!");
}
Database database = ResultUtil.findDatabase(hier);
for (OutlierResult outlierResult : ors) {
try {
XMLOutputFactory factory = XMLOutputFactory.newInstance();
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(filename));
out.putNextEntry(new ZipEntry("doc.kml"));
final XMLStreamWriter xmlw = factory.createXMLStreamWriter(out);
writeOutlierResult(xmlw, outlierResult, database);
xmlw.flush();
xmlw.close();
out.closeEntry();
out.flush();
out.close();
if (autoopen) {
Desktop.getDesktop().open(filename);
}
} catch (XMLStreamException e) {
LOG.exception(e);
throw new AbortException("XML error in KML output.", e);
} catch (IOException e) {
LOG.exception(e);
throw new AbortException("IO error in KML output.", e);
}
}
for (Clustering<?> clusteringResult : crs) {
try {
XMLOutputFactory factory = XMLOutputFactory.newInstance();
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(filename));
out.putNextEntry(new ZipEntry("doc.kml"));
final XMLStreamWriter xmlw = factory.createXMLStreamWriter(out);
@SuppressWarnings("unchecked") Clustering<Model> cres = (Clustering<Model>) clusteringResult;
writeClusteringResult(xmlw, cres, database);
xmlw.flush();
xmlw.close();
out.closeEntry();
out.flush();
out.close();
if (autoopen) {
Desktop.getDesktop().open(filename);
}
} catch (XMLStreamException e) {
LOG.exception(e);
throw new AbortException("XML error in KML output.", e);
} catch (IOException e) {
LOG.exception(e);
throw new AbortException("IO error in KML output.", e);
}
}
}
Aggregations