use of de.lmu.ifi.dbs.elki.parallel.variables.SharedObject in project elki by elki-project.
the class ParallelKNNOutlier method run.
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);
// Compute the kNN
KNNProcessor<O> knnm = new KNNProcessor<>(k + 1, knnq);
SharedObject<KNNList> knnv = new SharedObject<>();
knnm.connectKNNOutput(knnv);
// Extract the k-distance
KDistanceProcessor kdistm = new KDistanceProcessor(k + 1);
SharedDouble kdistv = new SharedDouble();
kdistm.connectKNNInput(knnv);
kdistm.connectOutput(kdistv);
// Store in outlier scores
WriteDoubleDataStoreProcessor storem = new WriteDoubleDataStoreProcessor(store);
storem.connectInput(kdistv);
// Gather statistics
DoubleMinMaxProcessor mmm = new DoubleMinMaxProcessor();
mmm.connectInput(kdistv);
ParallelExecutor.run(ids, knnm, kdistm, storem, mmm);
DoubleMinMax minmax = mmm.getMinMax();
DoubleRelation scoreres = new MaterializedDoubleRelation("kNN Outlier Score", "knn-outlier", store, ids);
OutlierScoreMeta meta = new BasicOutlierScoreMeta(minmax.getMin(), minmax.getMax(), 0.0, Double.POSITIVE_INFINITY, 0.0);
return new OutlierResult(meta, scoreres);
}
use of de.lmu.ifi.dbs.elki.parallel.variables.SharedObject 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.parallel.variables.SharedObject 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);
}
use of de.lmu.ifi.dbs.elki.parallel.variables.SharedObject in project elki by elki-project.
the class ParallelSimplifiedLOF 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
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);
ParallelExecutor.run(ids, knnm, storek);
}
// Phase two: simplified-lrd
WritableDoubleDataStore lrds = DataStoreUtil.makeDoubleStorage(ids, DataStoreFactory.HINT_DB);
{
SimplifiedLRDProcessor lrdm = new SimplifiedLRDProcessor(knns);
SharedDouble lrdv = new SharedDouble();
WriteDoubleDataStoreProcessor storelrd = new WriteDoubleDataStoreProcessor(lrds);
lrdm.connectOutput(lrdv);
storelrd.connectInput(lrdv);
ParallelExecutor.run(ids, lrdm, storelrd);
}
// Phase three: Simplified-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("Simplified Local Outlier Factor", "simplified-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