use of de.lmu.ifi.dbs.elki.data.NumberVector in project elki by elki-project.
the class TriangularDistanceFunctionTest method testTriganular.
@Test
public void testTriganular() {
DoubleVector v0 = DoubleVector.wrap(new double[] { 0.8, 0.1, 0.1 });
DoubleVector v1 = DoubleVector.wrap(new double[] { 0.1, 0.8, 0.1 });
DoubleVector v2 = DoubleVector.wrap(new double[] { 0.1, 0.1, 0.8 });
DoubleVector v3 = DoubleVector.wrap(new double[] { 1. / 3, 1. / 3, 1. / 3 });
DoubleVector v4 = DoubleVector.wrap(new double[] { 0.6, 0.2, 0.2 });
DoubleVector[] vecs = { v0, v1, v2, v3, v4 };
// Manual computation of correct distances:
double d10 = .49 / .9 + .49 / .9 + 0.;
double d30 = //
(.8 - 1. / 3) * (.8 - 1. / 3) / (.8 + 1. / 3) + 2 * (.1 - 1. / 3) * (.1 - 1. / 3) / (.1 + 1. / 3);
double d40 = .04 / 1.4 + .01 / .3 + .01 / .3;
double d41 = .25 / 0.7 + .36 / 1. + .01 / .3;
double d43 = //
(.6 - 1. / 3) * (.6 - 1. / 3) / (.6 + 1. / 3) + 2 * (.2 - 1. / 3) * (.2 - 1. / 3) / (.2 + 1. / 3);
double[][] distances = { //
{ 0., d10, d10, d30, d40 }, //
{ d10, 0., d10, d30, d41 }, //
{ d10, d10, 0., d30, d41 }, //
{ d30, d30, d30, 0., d43 }, //
{ d40, d41, d41, d43, 0. } };
PrimitiveDistanceFunction<NumberVector> df = TriangularDistanceFunction.STATIC;
for (int i = 0; i < vecs.length; i++) {
for (int j = 0; j < vecs.length; j++) {
assertEquals("Distance " + i + "," + j + " incorrect.", Math.sqrt(distances[i][j]), df.distance(vecs[i], vecs[j]), 1e-15);
}
}
}
use of de.lmu.ifi.dbs.elki.data.NumberVector in project elki by elki-project.
the class ManhattanDistanceFunction method minDist.
@Override
public double minDist(SpatialComparable mbr1, SpatialComparable mbr2) {
final int dim1 = mbr1.getDimensionality(), dim2 = mbr2.getDimensionality();
final int mindim = (dim1 < dim2) ? dim1 : dim2;
final NumberVector v1 = (mbr1 instanceof NumberVector) ? (NumberVector) mbr1 : null;
final NumberVector v2 = (mbr2 instanceof NumberVector) ? (NumberVector) mbr2 : null;
double agg = //
(v1 != null) ? //
(v2 != null) ? preDistance(v1, v2, 0, mindim) : preDistanceVM(v1, mbr2, 0, mindim) : (v2 != null) ? preDistanceVM(v2, mbr1, 0, mindim) : preDistanceMBR(mbr1, mbr2, 0, mindim);
// first object has more dimensions.
if (dim1 > mindim) {
agg += (v1 != null) ? preNorm(v1, mindim, dim1) : preNormMBR(mbr1, mindim, dim1);
}
// second object has more dimensions.
if (dim2 > mindim) {
agg += (v2 != null) ? preNorm(v2, mindim, dim2) : preNormMBR(mbr2, mindim, dim2);
}
return agg;
}
use of de.lmu.ifi.dbs.elki.data.NumberVector in project elki by elki-project.
the class WeightedManhattanDistanceFunction method minDist.
@Override
public double minDist(SpatialComparable mbr1, SpatialComparable mbr2) {
final int dim1 = mbr1.getDimensionality(), dim2 = mbr2.getDimensionality();
final int mindim = (dim1 < dim2) ? dim1 : dim2;
final NumberVector v1 = (mbr1 instanceof NumberVector) ? (NumberVector) mbr1 : null;
final NumberVector v2 = (mbr2 instanceof NumberVector) ? (NumberVector) mbr2 : null;
double agg = //
(v1 != null) ? //
(v2 != null) ? preDistance(v1, v2, 0, mindim) : preDistanceVM(v1, mbr2, 0, mindim) : (v2 != null) ? preDistanceVM(v2, mbr1, 0, mindim) : preDistanceMBR(mbr1, mbr2, 0, mindim);
// first object has more dimensions.
if (dim1 > mindim) {
agg += (v1 != null) ? preNorm(v1, mindim, dim1) : preNormMBR(mbr1, mindim, dim1);
}
// second object has more dimensions.
if (dim2 > mindim) {
agg += (v2 != null) ? preNorm(v2, mindim, dim2) : preNormMBR(mbr2, mindim, dim2);
}
return agg;
}
use of de.lmu.ifi.dbs.elki.data.NumberVector in project elki by elki-project.
the class TrivialAverageCoordinateOutlier method run.
/**
* Run the actual algorithm.
*
* @param relation Relation
* @return Result
*/
public OutlierResult run(Relation<? extends NumberVector> relation) {
WritableDoubleDataStore scores = DataStoreUtil.makeDoubleStorage(relation.getDBIDs(), DataStoreFactory.HINT_HOT);
DoubleMinMax minmax = new DoubleMinMax();
Mean m = new Mean();
for (DBIDIter iditer = relation.iterDBIDs(); iditer.valid(); iditer.advance()) {
m.reset();
NumberVector nv = relation.get(iditer);
for (int i = 0; i < nv.getDimensionality(); i++) {
m.put(nv.doubleValue(i));
}
final double score = m.getMean();
scores.putDouble(iditer, score);
minmax.put(score);
}
DoubleRelation scoreres = new MaterializedDoubleRelation("Trivial mean score", "mean-outlier", scores, relation.getDBIDs());
OutlierScoreMeta meta = new BasicOutlierScoreMeta(minmax.getMin(), minmax.getMax());
return new OutlierResult(meta, scoreres);
}
use of de.lmu.ifi.dbs.elki.data.NumberVector in project elki by elki-project.
the class UncertainifyFilter method filter.
@Override
public MultipleObjectsBundle filter(MultipleObjectsBundle objects) {
if (objects.dataLength() == 0) {
return objects;
}
MultipleObjectsBundle bundle = new MultipleObjectsBundle();
for (int r = 0; r < objects.metaLength(); r++) {
SimpleTypeInformation<?> type = objects.meta(r);
@SuppressWarnings("unchecked") final List<Object> column = (List<Object>) objects.getColumn(r);
if (!TypeUtil.NUMBER_VECTOR_FIELD.isAssignableFromType(type)) {
bundle.appendColumn(type, column);
continue;
}
// Get the replacement type information
@SuppressWarnings("unchecked") final VectorFieldTypeInformation<NumberVector> castType = (VectorFieldTypeInformation<NumberVector>) type;
final int dim = castType.getDimensionality();
if (keep) {
bundle.appendColumn(type, column);
}
// Uncertain objects produced
final List<UO> uos = new ArrayList<>(column.size());
// Normalization scan
FiniteProgress nprog = LOG.isVerbose() ? new FiniteProgress("Derive uncertain objects", objects.dataLength(), LOG) : null;
for (int i = 0; i < objects.dataLength(); i++) {
final NumberVector obj = (NumberVector) column.get(i);
final UO normalizedObj = generator.newFeatureVector(rand, obj, ArrayLikeUtil.NUMBERVECTORADAPTER);
uos.add(normalizedObj);
LOG.incrementProcessed(nprog);
}
LOG.ensureCompleted(nprog);
// Add column with uncertain objects
bundle.appendColumn(new VectorFieldTypeInformation<UO>(generator.getFactory(), dim), uos);
}
return bundle;
}
Aggregations