use of de.lmu.ifi.dbs.elki.database.ids.DBIDs in project elki by elki-project.
the class ParallelKNNWeightOutlier method run.
/**
* Run the parallel kNN weight outlier detector.
*
* @param database Database to process
* @param relation Relation to analyze
* @return Outlier detection result
*/
public OutlierResult run(Database database, Relation<O> relation) {
DBIDs ids = relation.getDBIDs();
WritableDoubleDataStore store = DataStoreUtil.makeDoubleStorage(ids, DataStoreFactory.HINT_DB);
DistanceQuery<O> distq = database.getDistanceQuery(relation, getDistanceFunction());
KNNQuery<O> knnq = database.getKNNQuery(distq, k + 1);
// Find kNN
KNNProcessor<O> knnm = new KNNProcessor<>(k + 1, knnq);
SharedObject<KNNList> knnv = new SharedObject<>();
knnm.connectKNNOutput(knnv);
// Extract outlier score
KNNWeightProcessor kdistm = new KNNWeightProcessor(k + 1);
SharedDouble kdistv = new SharedDouble();
kdistm.connectKNNInput(knnv);
kdistm.connectOutput(kdistv);
// Store in output result
WriteDoubleDataStoreProcessor storem = new WriteDoubleDataStoreProcessor(store);
storem.connectInput(kdistv);
// And gather statistics for metadata
DoubleMinMaxProcessor mmm = new DoubleMinMaxProcessor();
mmm.connectInput(kdistv);
ParallelExecutor.run(ids, knnm, kdistm, storem, mmm);
DoubleMinMax minmax = mmm.getMinMax();
DoubleRelation scoreres = new MaterializedDoubleRelation("kNN weight Outlier Score", "knnw-outlier", store, ids);
OutlierScoreMeta meta = new BasicOutlierScoreMeta(minmax.getMin(), minmax.getMax(), 0., Double.POSITIVE_INFINITY, 0.);
return new OutlierResult(meta, scoreres);
}
use of de.lmu.ifi.dbs.elki.database.ids.DBIDs in project elki by elki-project.
the class IDOS method run.
/**
* Run the algorithm
*
* @param database Database
* @param relation Data relation
* @return Outlier result
*/
public OutlierResult run(Database database, Relation<O> relation) {
StepProgress stepprog = LOG.isVerbose() ? new StepProgress("IDOS", 3) : null;
if (stepprog != null) {
stepprog.beginStep(1, "Precomputing neighborhoods", LOG);
}
KNNQuery<O> knnQ = DatabaseUtil.precomputedKNNQuery(database, relation, getDistanceFunction(), Math.max(k_c, k_r) + 1);
DBIDs ids = relation.getDBIDs();
if (stepprog != null) {
stepprog.beginStep(2, "Computing intrinsic dimensionalities", LOG);
}
DoubleDataStore intDims = computeIDs(ids, knnQ);
if (stepprog != null) {
stepprog.beginStep(3, "Computing IDOS scores", LOG);
}
DoubleMinMax idosminmax = new DoubleMinMax();
DoubleDataStore ldms = computeIDOS(ids, knnQ, intDims, idosminmax);
if (stepprog != null) {
stepprog.setCompleted(LOG);
}
DoubleRelation scoreResult = new MaterializedDoubleRelation("Intrinsic Dimensionality Outlier Score", "idos", ldms, ids);
OutlierScoreMeta scoreMeta = new QuotientOutlierScoreMeta(idosminmax.getMin(), idosminmax.getMax(), 0.0, Double.POSITIVE_INFINITY, 1.0);
return new OutlierResult(scoreMeta, scoreResult);
}
use of de.lmu.ifi.dbs.elki.database.ids.DBIDs in project elki by elki-project.
the class LOF method run.
/**
* Runs the LOF algorithm on the given database.
*
* @param database Database to query
* @param relation Data to process
* @return LOF outlier result
*/
public OutlierResult run(Database database, Relation<O> relation) {
StepProgress stepprog = LOG.isVerbose() ? new StepProgress("LOF", 3) : null;
DBIDs ids = relation.getDBIDs();
LOG.beginStep(stepprog, 1, "Materializing nearest-neighbor sets.");
KNNQuery<O> knnq = DatabaseUtil.precomputedKNNQuery(database, relation, getDistanceFunction(), k);
// Compute LRDs
LOG.beginStep(stepprog, 2, "Computing Local Reachability Densities (LRD).");
WritableDoubleDataStore lrds = DataStoreUtil.makeDoubleStorage(ids, DataStoreFactory.HINT_HOT | DataStoreFactory.HINT_TEMP);
computeLRDs(knnq, ids, lrds);
// compute LOF_SCORE of each db object
LOG.beginStep(stepprog, 3, "Computing Local Outlier Factors (LOF).");
WritableDoubleDataStore lofs = DataStoreUtil.makeDoubleStorage(ids, DataStoreFactory.HINT_HOT | DataStoreFactory.HINT_DB);
// track the maximum value for normalization.
DoubleMinMax lofminmax = new DoubleMinMax();
computeLOFScores(knnq, ids, lrds, lofs, lofminmax);
LOG.setCompleted(stepprog);
// Build result representation.
DoubleRelation scoreResult = new MaterializedDoubleRelation("Local Outlier Factor", "lof-outlier", lofs, ids);
OutlierScoreMeta scoreMeta = new QuotientOutlierScoreMeta(lofminmax.getMin(), lofminmax.getMax(), 0.0, Double.POSITIVE_INFINITY, 1.0);
return new OutlierResult(scoreMeta, scoreResult);
}
use of de.lmu.ifi.dbs.elki.database.ids.DBIDs in project elki by elki-project.
the class COF method run.
/**
* Runs the COF algorithm on the given database.
*
* @param database Database to query
* @param relation Data to process
* @return COF outlier result
*/
public OutlierResult run(Database database, Relation<O> relation) {
StepProgress stepprog = LOG.isVerbose() ? new StepProgress("COF", 3) : null;
DistanceQuery<O> dq = database.getDistanceQuery(relation, getDistanceFunction());
LOG.beginStep(stepprog, 1, "Materializing COF neighborhoods.");
KNNQuery<O> knnq = DatabaseUtil.precomputedKNNQuery(database, relation, dq, k);
DBIDs ids = relation.getDBIDs();
LOG.beginStep(stepprog, 2, "Computing Average Chaining Distances.");
WritableDoubleDataStore acds = DataStoreUtil.makeDoubleStorage(ids, DataStoreFactory.HINT_HOT | DataStoreFactory.HINT_TEMP);
computeAverageChainingDistances(knnq, dq, ids, acds);
// compute COF_SCORE of each db object
LOG.beginStep(stepprog, 3, "Computing Connectivity-based Outlier Factors.");
WritableDoubleDataStore cofs = DataStoreUtil.makeDoubleStorage(ids, DataStoreFactory.HINT_HOT | DataStoreFactory.HINT_DB);
// track the maximum value for normalization.
DoubleMinMax cofminmax = new DoubleMinMax();
computeCOFScores(knnq, ids, acds, cofs, cofminmax);
LOG.setCompleted(stepprog);
// Build result representation.
DoubleRelation scoreResult = new MaterializedDoubleRelation("Connectivity-Based Outlier Factor", "cof-outlier", cofs, ids);
OutlierScoreMeta scoreMeta = new QuotientOutlierScoreMeta(cofminmax.getMin(), cofminmax.getMax(), 0.0, Double.POSITIVE_INFINITY, 1.0);
return new OutlierResult(scoreMeta, scoreResult);
}
use of de.lmu.ifi.dbs.elki.database.ids.DBIDs in project elki by elki-project.
the class ParallelLOF method run.
public OutlierResult run(Database database, Relation<O> relation) {
DBIDs ids = relation.getDBIDs();
DistanceQuery<O> distq = database.getDistanceQuery(relation, getDistanceFunction());
KNNQuery<O> knnq = database.getKNNQuery(distq, k + 1);
// Phase one: KNN and k-dist
WritableDoubleDataStore kdists = DataStoreUtil.makeDoubleStorage(ids, DataStoreFactory.HINT_DB);
WritableDataStore<KNNList> knns = DataStoreUtil.makeStorage(ids, DataStoreFactory.HINT_DB, KNNList.class);
{
// Compute kNN
KNNProcessor<O> knnm = new KNNProcessor<>(k + 1, knnq);
SharedObject<KNNList> knnv = new SharedObject<>();
WriteDataStoreProcessor<KNNList> storek = new WriteDataStoreProcessor<>(knns);
knnm.connectKNNOutput(knnv);
storek.connectInput(knnv);
// Compute k-dist
KDistanceProcessor kdistm = new KDistanceProcessor(k + 1);
SharedDouble kdistv = new SharedDouble();
WriteDoubleDataStoreProcessor storem = new WriteDoubleDataStoreProcessor(kdists);
kdistm.connectKNNInput(knnv);
kdistm.connectOutput(kdistv);
storem.connectInput(kdistv);
ParallelExecutor.run(ids, knnm, storek, kdistm, storem);
}
// Phase two: lrd
WritableDoubleDataStore lrds = DataStoreUtil.makeDoubleStorage(ids, DataStoreFactory.HINT_DB);
{
LRDProcessor lrdm = new LRDProcessor(knns, kdists);
SharedDouble lrdv = new SharedDouble();
WriteDoubleDataStoreProcessor storelrd = new WriteDoubleDataStoreProcessor(lrds);
lrdm.connectOutput(lrdv);
storelrd.connectInput(lrdv);
ParallelExecutor.run(ids, lrdm, storelrd);
}
// No longer needed.
kdists.destroy();
kdists = null;
// Phase three: LOF
WritableDoubleDataStore lofs = DataStoreUtil.makeDoubleStorage(ids, DataStoreFactory.HINT_DB);
DoubleMinMax minmax;
{
LOFProcessor lofm = new LOFProcessor(knns, lrds, true);
SharedDouble lofv = new SharedDouble();
DoubleMinMaxProcessor mmm = new DoubleMinMaxProcessor();
WriteDoubleDataStoreProcessor storelof = new WriteDoubleDataStoreProcessor(lofs);
lofm.connectOutput(lofv);
mmm.connectInput(lofv);
storelof.connectInput(lofv);
ParallelExecutor.run(ids, lofm, storelof, mmm);
minmax = mmm.getMinMax();
}
DoubleRelation scoreres = new MaterializedDoubleRelation("Local Outlier Factor", "lof-outlier", lofs, ids);
OutlierScoreMeta meta = new BasicOutlierScoreMeta(minmax.getMin(), minmax.getMax(), 0.0, Double.POSITIVE_INFINITY, 1.0);
return new OutlierResult(meta, scoreres);
}
Aggregations