Search in sources :

Example 61 with DoubleVector

use of de.lmu.ifi.dbs.elki.data.DoubleVector in project elki by elki-project.

the class WeightedUncertainSplitFilter method filterSingleObject.

@Override
protected WeightedDiscreteUncertainObject filterSingleObject(NumberVector vec) {
    final int dim = vec.getDimensionality();
    if (dim % mod != 0) {
        throw new AbortException("Vector length " + dim + " not divisible by the number of dimensions + 1 (for probability): " + mod);
    }
    final int num = dim / mod;
    final DoubleVector[] samples = new DoubleVector[num];
    final double[] weights = new double[dims];
    final double[] buf = new double[dims];
    for (int i = 0, j = 0, k = 0, l = 0; i < mod; i++) {
        if (l++ == probcol) {
            weights[k] = vec.doubleValue(i);
        } else {
            buf[j++] = vec.doubleValue(i);
        }
        if (l == mod) {
            samples[k] = DoubleVector.copy(buf);
            j = 0;
            l = 0;
            k++;
        }
    }
    return new WeightedDiscreteUncertainObject(samples, weights);
}
Also used : DoubleVector(de.lmu.ifi.dbs.elki.data.DoubleVector) LessConstraint(de.lmu.ifi.dbs.elki.utilities.optionhandling.constraints.LessConstraint) GreaterEqualConstraint(de.lmu.ifi.dbs.elki.utilities.optionhandling.constraints.GreaterEqualConstraint) WeightedDiscreteUncertainObject(de.lmu.ifi.dbs.elki.data.uncertain.WeightedDiscreteUncertainObject) AbortException(de.lmu.ifi.dbs.elki.utilities.exceptions.AbortException)

Example 62 with DoubleVector

use of de.lmu.ifi.dbs.elki.data.DoubleVector in project elki by elki-project.

the class SpatialPrimitiveDistanceFunctionTest method testSpatialDistanceConsistency.

@Test
public void testSpatialDistanceConsistency() {
    final Random rnd = new Random(0);
    final int dim = 7;
    final int iters = 10000;
    List<SpatialPrimitiveDistanceFunction<? super NumberVector>> dists = new ArrayList<>();
    dists.add(EuclideanDistanceFunction.STATIC);
    dists.add(ManhattanDistanceFunction.STATIC);
    dists.add(MaximumDistanceFunction.STATIC);
    dists.add(MinimumDistanceFunction.STATIC);
    dists.add(new LPNormDistanceFunction(3));
    dists.add(new LPNormDistanceFunction(.5));
    dists.add(CanberraDistanceFunction.STATIC);
    // Histogram intersection distance isn't proper for negative values
    // dists.add(HistogramIntersectionDistanceFunction.STATIC);
    dists.add(SquaredEuclideanDistanceFunction.STATIC);
    dists.add(ArcCosineDistanceFunction.STATIC);
    dists.add(CosineDistanceFunction.STATIC);
    double[] d1 = new double[dim];
    double[] d2 = new double[dim];
    double[] d3 = new double[dim];
    double[] d4 = new double[dim];
    DoubleVector v1 = DoubleVector.wrap(d1);
    ModifiableHyperBoundingBox mbr = new ModifiableHyperBoundingBox(d2, d3);
    DoubleVector v2 = DoubleVector.wrap(d4);
    for (int i = 0; i < iters; i++) {
        for (int d = 0; d < dim; d++) {
            d1[d] = (rnd.nextDouble() - .5) * 2E4;
            d2[d] = (rnd.nextDouble() - .5) * 2E4;
            d3[d] = (rnd.nextDouble() - .5) * 2E4;
            if (d2[d] > d3[d]) {
                double t = d2[d];
                d2[d] = d3[d];
                d3[d] = t;
            }
            double m = rnd.nextDouble();
            d4[d] = m * d2[d] + (1 - m) * d3[d];
        }
        for (SpatialPrimitiveDistanceFunction<? super NumberVector> dis : dists) {
            compareDistances(v1, mbr, v2, dis);
        }
    }
}
Also used : LPNormDistanceFunction(de.lmu.ifi.dbs.elki.distance.distancefunction.minkowski.LPNormDistanceFunction) Random(java.util.Random) NumberVector(de.lmu.ifi.dbs.elki.data.NumberVector) ArrayList(java.util.ArrayList) DoubleVector(de.lmu.ifi.dbs.elki.data.DoubleVector) ModifiableHyperBoundingBox(de.lmu.ifi.dbs.elki.data.ModifiableHyperBoundingBox) Test(org.junit.Test)

Example 63 with DoubleVector

use of de.lmu.ifi.dbs.elki.data.DoubleVector in project elki by elki-project.

the class PolynomialKernelFunctionTest method testToyExamplesPoly2.

@Test
public void testToyExamplesPoly2() {
    DoubleVector v1 = DoubleVector.wrap(new double[] { 1, 0, 0 });
    DoubleVector v2 = DoubleVector.wrap(new double[] { 0, 1, 0 });
    DoubleVector v3 = DoubleVector.wrap(new double[] { 1, 1, 1 });
    DoubleVector v4 = DoubleVector.wrap(new double[] { .1, .2, .3 });
    PolynomialKernelFunction kernel = new PolynomialKernelFunction(2);
    assertEquals("Linear kernel not correct.", 0., kernel.similarity(v1, v2), 0.);
    assertEquals("Linear kernel not correct.", 1., kernel.similarity(v1, v3), 0.);
    assertEquals("Linear kernel not correct.", .01, kernel.similarity(v1, v4), 1e-13);
    assertEquals("Linear kernel not correct.", 1., kernel.similarity(v2, v3), 0.);
    assertEquals("Linear kernel not correct.", .04, kernel.similarity(v2, v4), 1e-13);
    assertEquals("Linear kernel not correct.", .36, kernel.similarity(v3, v4), 1e-13);
}
Also used : DoubleVector(de.lmu.ifi.dbs.elki.data.DoubleVector) Test(org.junit.Test)

Example 64 with DoubleVector

use of de.lmu.ifi.dbs.elki.data.DoubleVector in project elki by elki-project.

the class PolynomialKernelFunctionTest method testToyExamplesPoly3.

@Test
public void testToyExamplesPoly3() {
    DoubleVector v1 = DoubleVector.wrap(new double[] { 1, 0, 0 });
    DoubleVector v2 = DoubleVector.wrap(new double[] { 0, 1, 0 });
    DoubleVector v3 = DoubleVector.wrap(new double[] { 1, 1, 1 });
    DoubleVector v4 = DoubleVector.wrap(new double[] { .1, .2, .3 });
    PolynomialKernelFunction kernel = new PolynomialKernelFunction(3);
    assertEquals("Linear kernel not correct.", 0., kernel.similarity(v1, v2), 0.);
    assertEquals("Linear kernel not correct.", 1., kernel.similarity(v1, v3), 0.);
    assertEquals("Linear kernel not correct.", .001, kernel.similarity(v1, v4), 1e-13);
    assertEquals("Linear kernel not correct.", 1., kernel.similarity(v2, v3), 0.);
    assertEquals("Linear kernel not correct.", .008, kernel.similarity(v2, v4), 1e-13);
    assertEquals("Linear kernel not correct.", .216, kernel.similarity(v3, v4), 1e-13);
}
Also used : DoubleVector(de.lmu.ifi.dbs.elki.data.DoubleVector) Test(org.junit.Test)

Example 65 with DoubleVector

use of de.lmu.ifi.dbs.elki.data.DoubleVector in project elki by elki-project.

the class LinearKernelFunctionTest method testToyExamples.

@Test
public void testToyExamples() {
    DoubleVector v1 = DoubleVector.wrap(new double[] { 1, 0, 0 });
    DoubleVector v2 = DoubleVector.wrap(new double[] { 0, 1, 0 });
    DoubleVector v3 = DoubleVector.wrap(new double[] { 1, 1, 1 });
    DoubleVector v4 = DoubleVector.wrap(new double[] { .1, .2, .3 });
    LinearKernelFunction kernel = LinearKernelFunction.STATIC;
    assertEquals("Linear kernel not correct.", 0., kernel.similarity(v1, v2), 0.);
    assertEquals("Linear kernel not correct.", 1., kernel.similarity(v1, v3), 0.);
    assertEquals("Linear kernel not correct.", .1, kernel.similarity(v1, v4), 0.);
    assertEquals("Linear kernel not correct.", 1., kernel.similarity(v2, v3), 0.);
    assertEquals("Linear kernel not correct.", .2, kernel.similarity(v2, v4), 0.);
    assertEquals("Linear kernel not correct.", .6, kernel.similarity(v3, v4), 1e-13);
}
Also used : DoubleVector(de.lmu.ifi.dbs.elki.data.DoubleVector) Test(org.junit.Test)

Aggregations

DoubleVector (de.lmu.ifi.dbs.elki.data.DoubleVector)147 Test (org.junit.Test)112 Database (de.lmu.ifi.dbs.elki.database.Database)85 ELKIBuilder (de.lmu.ifi.dbs.elki.utilities.ELKIBuilder)75 AbstractClusterAlgorithmTest (de.lmu.ifi.dbs.elki.algorithm.clustering.AbstractClusterAlgorithmTest)50 MultipleObjectsBundle (de.lmu.ifi.dbs.elki.datasource.bundle.MultipleObjectsBundle)26 AbstractDataSourceTest (de.lmu.ifi.dbs.elki.datasource.AbstractDataSourceTest)24 OutlierResult (de.lmu.ifi.dbs.elki.result.outlier.OutlierResult)22 AbstractOutlierAlgorithmTest (de.lmu.ifi.dbs.elki.algorithm.outlier.AbstractOutlierAlgorithmTest)16 ArrayList (java.util.ArrayList)14 DBIDs (de.lmu.ifi.dbs.elki.database.ids.DBIDs)12 NumberVector (de.lmu.ifi.dbs.elki.data.NumberVector)11 DBIDIter (de.lmu.ifi.dbs.elki.database.ids.DBIDIter)10 VectorFieldTypeInformation (de.lmu.ifi.dbs.elki.data.type.VectorFieldTypeInformation)9 ListParameterization (de.lmu.ifi.dbs.elki.utilities.optionhandling.parameterization.ListParameterization)9 Random (java.util.Random)9 AbstractSimpleAlgorithmTest (de.lmu.ifi.dbs.elki.algorithm.AbstractSimpleAlgorithmTest)8 Model (de.lmu.ifi.dbs.elki.data.model.Model)8 LinearScanDistanceKNNQuery (de.lmu.ifi.dbs.elki.database.query.knn.LinearScanDistanceKNNQuery)8 MedoidModel (de.lmu.ifi.dbs.elki.data.model.MedoidModel)7