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