use of de.lmu.ifi.dbs.elki.result.outlier.OutlierResult in project elki by elki-project.
the class SOD method run.
/**
* Performs the SOD algorithm on the given database.
*
* @param relation Data relation to process
* @return Outlier result
*/
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;
final WritableDoubleDataStore sod_scores = DataStoreUtil.makeDoubleStorage(relation.getDBIDs(), DataStoreFactory.HINT_STATIC);
WritableDataStore<SODModel> sod_models = null;
if (models) {
// Models requested
sod_models = DataStoreUtil.makeStorage(relation.getDBIDs(), DataStoreFactory.HINT_STATIC, SODModel.class);
}
DoubleMinMax minmax = new DoubleMinMax();
for (DBIDIter iter = relation.iterDBIDs(); iter.valid(); iter.advance()) {
LOG.incrementProcessed(progress);
DBIDs neighborhood = getNearestNeighbors(relation, snnInstance, iter);
double[] center;
long[] weightVector;
double sod;
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();
weightVector = null;
sod = 0.;
}
if (sod_models != null) {
sod_models.put(iter, new SODModel(center, weightVector));
}
sod_scores.putDouble(iter, sod);
minmax.put(sod);
}
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) {
Relation<SODModel> models = new MaterializedRelation<>("Subspace Outlier Model", "sod-outlier", new SimpleTypeInformation<>(SODModel.class), sod_models, relation.getDBIDs());
sodResult.addChildResult(models);
}
return sodResult;
}
use of de.lmu.ifi.dbs.elki.result.outlier.OutlierResult in project elki by elki-project.
the class COPTest method testCOP.
@Test
public void testCOP() {
Database db = makeSimpleDatabase(UNITTEST + "outlier-parabolic.ascii", 530);
OutlierResult result = //
new ELKIBuilder<COP<DoubleVector>>(COP.class).with(COP.Parameterizer.K_ID, 30).build().run(db);
testAUC(db, "Noise", result, 0.89476666);
testSingleScore(result, 416, 0.26795866);
}
use of de.lmu.ifi.dbs.elki.result.outlier.OutlierResult in project elki by elki-project.
the class COPTest method testCOPRANSAC.
@Test
public void testCOPRANSAC() {
Database db = makeSimpleDatabase(UNITTEST + "outlier-parabolic.ascii", 530);
OutlierResult result = //
new ELKIBuilder<COP<DoubleVector>>(COP.class).with(COP.Parameterizer.K_ID, //
30).with(COP.Parameterizer.PCARUNNER_ID, //
AutotuningPCA.class).with(AutotuningPCA.Parameterizer.PCA_EIGENPAIR_FILTER, //
PercentageEigenPairFilter.class).with(AutotuningPCA.Parameterizer.PCA_COVARIANCE_MATRIX, //
RANSACCovarianceMatrixBuilder.class).with(RANSACCovarianceMatrixBuilder.Parameterizer.ITER_ID, //
25).with(RANSACCovarianceMatrixBuilder.Parameterizer.SEED_ID, //
0).build().run(db);
testAUC(db, "Noise", result, 0.89526);
testSingleScore(result, 416, 0.382879);
}
use of de.lmu.ifi.dbs.elki.result.outlier.OutlierResult in project elki by elki-project.
the class ABODTest method testABOD.
@Test
public void testABOD() {
Database db = makeSimpleDatabase(UNITTEST + "outlier-3d-3clusters.ascii", 960);
OutlierResult result = new ELKIBuilder<ABOD<DoubleVector>>(ABOD.class).build().run(db);
testAUC(db, "Noise", result, 0.9297962962962);
testSingleScore(result, 945, 2.0897348547799E-5);
}
use of de.lmu.ifi.dbs.elki.result.outlier.OutlierResult in project elki by elki-project.
the class KNNSOSTest method testToyExample.
@Test
public void testToyExample() {
Database db = makeSimpleDatabase(UNITTEST + "outlier-3d-3clusters.ascii", 960);
OutlierResult result = //
new ELKIBuilder<KNNSOS<DoubleVector>>(KNNSOS.class).with(KNNSOS.Parameterizer.KNN_ID, 150).build().run(db);
testAUC(db, "Noise", result, 0.94435185);
testSingleScore(result, 945, 0.05163418);
}
Aggregations