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);
}
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);
}
}
}
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);
}
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);
}
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);
}
Aggregations