public OutlierResult run ( Relation < V > relation ) { SimilarityQuery < V > snnInstance = similarityFunction . instantiate ( relation ) ; FiniteProgress progress = LOG . isVerbose ( ) ? new FiniteProgress ( "Assigning Subspace Outlier Degree" , relation . size ( ) , LOG ) : null ; WritableDoubleDataStore sod_scores = DataStoreUtil . makeDoubleStorage ( relation . getDBIDs ( ) , DataStoreFactory . HINT_STATIC ) ; WritableDataStore < SODModel > sod_models = models ? DataStoreUtil . makeStorage ( relation . getDBIDs ( ) , DataStoreFactory . HINT_STATIC , SODModel . class ) : null ; DoubleMinMax minmax = new DoubleMinMax ( ) ; for ( DBIDIter iter = relation . iterDBIDs ( ) ; iter . valid ( ) ; iter . advance ( ) ) { DBIDs neighborhood = getNearestNeighbors ( relation , snnInstance , iter ) ; double [ ] center ; long [ ] weightVector = null ; double sod = 0. ; if ( neighborhood . size ( ) > 0 ) { center = Centroid . make ( relation , neighborhood ) . getArrayRef ( ) ; // Note: per-dimension variances; no covariances. double [ ] variances = computePerDimensionVariances ( relation , center , neighborhood ) ; double expectationOfVariance = Mean . of ( variances ) ; weightVector = BitsUtil . zero ( variances . length ) ; for ( int d = 0 ; d < variances . length ; d ++ ) { if ( variances [ d ] < alpha * expectationOfVariance ) { BitsUtil . setI ( weightVector , d ) ; } } sod = subspaceOutlierDegree ( relation . get ( iter ) , center , weightVector ) ; } else { center = relation . get ( iter ) . toArray ( ) ; } if ( sod_models != null ) { sod_models . put ( iter , new SODModel ( center , weightVector ) ) ; } sod_scores . putDouble ( iter , sod ) ; minmax . put ( sod ) ; LOG . incrementProcessed ( progress ) ; } LOG . ensureCompleted ( progress ) ; // combine results. OutlierScoreMeta meta = new BasicOutlierScoreMeta ( minmax . getMin ( ) , minmax . getMax ( ) ) ; OutlierResult sodResult = new OutlierResult ( meta , new MaterializedDoubleRelation ( "Subspace Outlier Degree" , "sod-outlier" , sod_scores , relation . getDBIDs ( ) ) ) ; if ( sod_models != null ) { sodResult . addChildResult ( new MaterializedRelation <> ( "Subspace Outlier Model" , "sod-outlier" , new SimpleTypeInformation <> ( SODModel . class ) , sod_models , relation . getDBIDs ( ) ) ) ; } return sodResult ; }
Performs the SOD algorithm on the given database .