Search in sources :

Example 1 with ListAccessor

use of org.ddogleg.clustering.misc.ListAccessor in project BoofCV by lessthanoptimal.

the class TestComputeMedianTuple_MT_B method compare.

@Test
void compare() {
    int DOF = 510;
    int numClusters = 4;
    // Create a list of random points
    List<TupleDesc_B> list = new ArrayList<>();
    var assignments = new DogArray_I32(1000);
    for (int i = 0; i < 1000; i++) {
        assignments.add(rand.nextInt(numClusters));
        var t = new TupleDesc_B(DOF);
        for (int j = 0; j < t.data.length; j++) {
            t.data[j] = rand.nextInt();
        }
        list.add(t);
    }
    var points = new ListAccessor<>(list, (src, dst) -> dst.setTo(src), TupleDesc_B.class);
    var clustersSingle = new DogArray<>(() -> new TupleDesc_B(DOF));
    var clustersMulti = new DogArray<>(() -> new TupleDesc_B(DOF));
    clustersSingle.resize(numClusters);
    clustersMulti.resize(numClusters);
    var single = new ComputeMedianTuple_B(DOF);
    var multi = new ComputeMedianTuple_MT_B(DOF);
    single.process(points, assignments, clustersSingle);
    multi.process(points, assignments, clustersMulti);
    assertEquals(clustersSingle.size, clustersMulti.size);
    for (int i = 0; i < numClusters; i++) {
        assertArrayEquals(clustersSingle.get(i).data, clustersMulti.get(i).data);
    }
}
Also used : ListAccessor(org.ddogleg.clustering.misc.ListAccessor) TupleDesc_B(boofcv.struct.feature.TupleDesc_B) ArrayList(java.util.ArrayList) DogArray_I32(org.ddogleg.struct.DogArray_I32) DogArray(org.ddogleg.struct.DogArray) Test(org.junit.jupiter.api.Test)

Example 2 with ListAccessor

use of org.ddogleg.clustering.misc.ListAccessor in project BoofCV by lessthanoptimal.

the class TestComputeMeanTuple_MT_F64 method compare.

@Test
void compare() {
    int DOF = 31;
    int numClusters = 4;
    // Create a list of random points
    List<TupleDesc_F64> list = new ArrayList<>();
    var assignments = new DogArray_I32(1000);
    for (int i = 0; i < 1000; i++) {
        assignments.add(rand.nextInt(numClusters));
        var t = new TupleDesc_F64(DOF);
        for (int j = 0; j < DOF; j++) {
            t.data[j] = rand.nextDouble();
        }
        list.add(t);
    }
    var points = new ListAccessor<>(list, (src, dst) -> dst.setTo(src), TupleDesc_F64.class);
    var clustersSingle = new DogArray<>(() -> new TupleDesc_F64(DOF));
    var clustersMulti = new DogArray<>(() -> new TupleDesc_F64(DOF));
    clustersSingle.resize(numClusters);
    clustersMulti.resize(numClusters);
    var single = new ComputeMeanTuple_F64();
    var multi = new ComputeMeanTuple_MT_F64(DOF);
    single.process(points, assignments, clustersSingle);
    multi.process(points, assignments, clustersMulti);
    assertEquals(clustersSingle.size, clustersMulti.size);
    for (int i = 0; i < numClusters; i++) {
        assertArrayEquals(clustersSingle.get(i).data, clustersMulti.get(i).data, UtilEjml.TEST_F64);
    }
}
Also used : ListAccessor(org.ddogleg.clustering.misc.ListAccessor) TupleDesc_F64(boofcv.struct.feature.TupleDesc_F64) ArrayList(java.util.ArrayList) DogArray_I32(org.ddogleg.struct.DogArray_I32) DogArray(org.ddogleg.struct.DogArray) Test(org.junit.jupiter.api.Test)

Example 3 with ListAccessor

use of org.ddogleg.clustering.misc.ListAccessor in project BoofCV by lessthanoptimal.

the class TestComputeMeanTuple_MT_U8 method compare.

@Test
void compare() {
    int DOF = 31;
    int numClusters = 4;
    // Create a list of random points
    List<TupleDesc_U8> list = new ArrayList<>();
    var assignments = new DogArray_I32(1000);
    for (int i = 0; i < 1000; i++) {
        assignments.add(rand.nextInt(numClusters));
        var t = new TupleDesc_U8(DOF);
        for (int j = 0; j < DOF; j++) {
            t.data[j] = (byte) rand.nextInt();
        }
        list.add(t);
    }
    var points = new ListAccessor<>(list, (src, dst) -> dst.setTo(src), TupleDesc_U8.class);
    var clustersSingle = new DogArray<>(() -> new TupleDesc_U8(DOF));
    var clustersMulti = new DogArray<>(() -> new TupleDesc_U8(DOF));
    clustersSingle.resize(numClusters);
    clustersMulti.resize(numClusters);
    var single = new ComputeMeanTuple_U8(DOF);
    var multi = new ComputeMeanTuple_MT_U8(DOF);
    single.process(points, assignments, clustersSingle);
    multi.process(points, assignments, clustersMulti);
    assertEquals(clustersSingle.size, clustersMulti.size);
    for (int i = 0; i < numClusters; i++) {
        assertArrayEquals(clustersSingle.get(i).data, clustersMulti.get(i).data);
    }
}
Also used : ListAccessor(org.ddogleg.clustering.misc.ListAccessor) TupleDesc_U8(boofcv.struct.feature.TupleDesc_U8) ArrayList(java.util.ArrayList) DogArray_I32(org.ddogleg.struct.DogArray_I32) DogArray(org.ddogleg.struct.DogArray) Test(org.junit.jupiter.api.Test)

Aggregations

ArrayList (java.util.ArrayList)3 ListAccessor (org.ddogleg.clustering.misc.ListAccessor)3 DogArray (org.ddogleg.struct.DogArray)3 DogArray_I32 (org.ddogleg.struct.DogArray_I32)3 Test (org.junit.jupiter.api.Test)3 TupleDesc_B (boofcv.struct.feature.TupleDesc_B)1 TupleDesc_F64 (boofcv.struct.feature.TupleDesc_F64)1 TupleDesc_U8 (boofcv.struct.feature.TupleDesc_U8)1