use of de.lmu.ifi.dbs.elki.database.ids.DBIDs in project elki by elki-project.
the class JudgeOutlierScores method processNewResult.
@Override
public void processNewResult(ResultHierarchy hier, Result result) {
Database db = ResultUtil.findDatabase(hier);
List<OutlierResult> ors = ResultUtil.filterResults(hier, OutlierResult.class);
if (ors == null || ors.isEmpty()) {
// logger.warning("No results found for "+JudgeOutlierScores.class.getSimpleName());
return;
}
ModifiableDBIDs ids = DBIDUtil.newHashSet(ors.iterator().next().getScores().getDBIDs());
DBIDs outlierIds = DatabaseUtil.getObjectsByLabelMatch(db, positiveClassName);
ids.removeDBIDs(outlierIds);
for (OutlierResult or : ors) {
db.getHierarchy().add(or, computeScore(ids, outlierIds, or));
}
}
use of de.lmu.ifi.dbs.elki.database.ids.DBIDs in project elki by elki-project.
the class OutlierPrecisionRecallCurve 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 P/R curve failed - no objects matched.");
return;
}
List<OutlierResult> oresults = OutlierResult.getOutlierResults(result);
List<OrderingResult> orderings = ResultUtil.getOrderingResults(result);
// Outlier results are the main use case.
for (OutlierResult o : oresults) {
DBIDs sorted = o.getOrdering().order(o.getOrdering().getDBIDs());
PRCurve curve = computePrecisionResult(o.getScores().size(), positiveids, sorted.iter(), o.getScores());
db.getHierarchy().add(o, curve);
EvaluationResult ev = EvaluationResult.findOrCreate(db.getHierarchy(), o, "Evaluation of ranking", "ranking-evaluation");
ev.findOrCreateGroup("Evaluation measures").addMeasure(PRAUC_LABEL, curve.getAUC(), 0., 1., false);
// Process them only once.
orderings.remove(o.getOrdering());
}
// otherwise apply an ordering to the database IDs.
for (OrderingResult or : orderings) {
DBIDs sorted = or.order(or.getDBIDs());
PRCurve curve = computePrecisionResult(or.getDBIDs().size(), positiveids, sorted.iter(), null);
db.getHierarchy().add(or, curve);
EvaluationResult ev = EvaluationResult.findOrCreate(db.getHierarchy(), or, "Evaluation of ranking", "ranking-evaluation");
ev.findOrCreateGroup("Evaluation measures").addMeasure(PRAUC_LABEL, curve.getAUC(), 0., 1., false);
}
}
use of de.lmu.ifi.dbs.elki.database.ids.DBIDs in project elki by elki-project.
the class OutlierRankingEvaluation method processNewResult.
@Override
public void processNewResult(ResultHierarchy hier, Result result) {
Database db = ResultUtil.findDatabase(hier);
SetDBIDs positiveids = DBIDUtil.ensureSet(DatabaseUtil.getObjectsByLabelMatch(db, positiveClassName));
if (positiveids.size() == 0) {
LOG.warning("Cannot evaluate outlier results - no objects matched the given pattern.");
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) {
db.getHierarchy().add(o, evaluateOutlierResult(o.getScores().size(), positiveids, o));
// Process them 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());
db.getHierarchy().add(or, evaluateOrderingResult(or.getDBIDs().size(), positiveids, sorted));
nonefound = false;
}
if (nonefound) {
return;
// LOG.warning("No results found to process with ROC curve analyzer. Got
// "+iterables.size()+" iterables, "+orderings.size()+" orderings.");
}
}
use of de.lmu.ifi.dbs.elki.database.ids.DBIDs in project elki by elki-project.
the class OutlierPrecisionAtKCurve 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);
// Outlier results are the main use case.
for (OutlierResult o : oresults) {
DBIDs sorted = o.getOrdering().order(o.getOrdering().getDBIDs());
db.getHierarchy().add(o, computePrecisionResult(o.getScores().size(), positiveids, sorted));
// Process them only once.
orderings.remove(o.getOrdering());
}
// otherwise apply an ordering to the database IDs.
for (OrderingResult or : orderings) {
DBIDs sorted = or.order(or.getDBIDs());
db.getHierarchy().add(or, computePrecisionResult(or.getDBIDs().size(), positiveids, sorted));
}
}
use of de.lmu.ifi.dbs.elki.database.ids.DBIDs in project elki by elki-project.
the class CTLuMeanMultipleAttributes method run.
/**
* Run the algorithm
*
* @param database Database
* @param spatial Spatial relation
* @param attributes Numerical attributes
* @return Outlier detection result
*/
public OutlierResult run(Database database, Relation<N> spatial, Relation<O> attributes) {
if (LOG.isDebugging()) {
LOG.debug("Dimensionality: " + RelationUtil.dimensionality(attributes));
}
final NeighborSetPredicate npred = getNeighborSetPredicateFactory().instantiate(database, spatial);
CovarianceMatrix covmaker = new CovarianceMatrix(RelationUtil.dimensionality(attributes));
WritableDataStore<double[]> deltas = DataStoreUtil.makeStorage(attributes.getDBIDs(), DataStoreFactory.HINT_TEMP, double[].class);
for (DBIDIter iditer = attributes.iterDBIDs(); iditer.valid(); iditer.advance()) {
final O obj = attributes.get(iditer);
final DBIDs neighbors = npred.getNeighborDBIDs(iditer);
// TODO: remove object itself from neighbors?
// Mean vector "g"
double[] mean = Centroid.make(attributes, neighbors).getArrayRef();
// Delta vector "h"
double[] delta = minusEquals(obj.toArray(), mean);
deltas.put(iditer, delta);
covmaker.put(delta);
}
// Finalize covariance matrix:
double[] mean = covmaker.getMeanVector();
double[][] cmati = inverse(covmaker.destroyToSampleMatrix());
DoubleMinMax minmax = new DoubleMinMax();
WritableDoubleDataStore scores = DataStoreUtil.makeDoubleStorage(attributes.getDBIDs(), DataStoreFactory.HINT_STATIC);
for (DBIDIter iditer = attributes.iterDBIDs(); iditer.valid(); iditer.advance()) {
final double score = mahalanobisDistance(cmati, deltas.get(iditer), mean);
minmax.put(score);
scores.putDouble(iditer, score);
}
DoubleRelation scoreResult = new MaterializedDoubleRelation("mean multiple attributes spatial outlier", "mean-multipleattributes-outlier", scores, attributes.getDBIDs());
OutlierScoreMeta scoreMeta = new BasicOutlierScoreMeta(minmax.getMin(), minmax.getMax(), 0.0, Double.POSITIVE_INFINITY, 0);
OutlierResult or = new OutlierResult(scoreMeta, scoreResult);
or.addChildResult(npred);
return or;
}
Aggregations