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 ) ; }
Run the parallel kNN weight outlier detector .