use of org.ddogleg.struct.DogArray_F32 in project BoofCV by lessthanoptimal.
the class GenericTupleMapDistanceNormChecks method distanceUpdate_CompareToManual.
/**
* Compare the normalization to the same method computed other ways
*/
@Test
void distanceUpdate_CompareToManual() {
TupleMapDistanceNorm alg = createAlg();
for (int i = 0; i < 20; i++) {
DogArray_F32 descA = new DogArray_F32();
DogArray_F32 descB = new DogArray_F32();
descA.resize(10);
descB.resize(10);
int uniqueA = rand.nextInt(3);
int uniqueB = rand.nextInt(3);
// these might be unique
for (int idx = 0; idx < uniqueA; idx++) {
descA.set(rand.nextInt(10), rand.nextFloat());
}
for (int idx = 0; idx < uniqueB; idx++) {
descB.set(rand.nextInt(10), rand.nextFloat());
}
// these will be common
for (int commonI = 0; commonI < 5; commonI++) {
int index = rand.nextInt(10);
descA.set(index, rand.nextFloat());
descB.set(index, rand.nextFloat());
}
// Need to normalize for distance functions to work correctly
alg.normalize(descA);
alg.normalize(descB);
float found = 2.0f;
for (int j = 0; j < 10; j++) {
if (descA.get(j) != 0 && descB.get(j) != 0)
found += alg.distanceUpdate(descA.get(j), descB.get(j));
}
assertEquals(computeError(descA, descB), found, UtilEjml.TEST_F32);
}
}
use of org.ddogleg.struct.DogArray_F32 in project BoofCV by lessthanoptimal.
the class GenericTupleMapDistanceNormChecks method normalize_CompareToManual.
/**
* Compare the normalization to the same method computed other ways
*/
@Test
void normalize_CompareToManual() {
TupleMapDistanceNorm alg = createAlg();
for (int i = 0; i < 20; i++) {
DogArray_F32 weights = new DogArray_F32();
DogArray_F32 copy = new DogArray_F32();
for (int j = 0; j < 5; j++) {
float value = rand.nextFloat();
weights.add(value);
copy.add(value);
}
float norm = computeNorm(weights);
alg.normalize(weights);
for (int weightIdx = 0; weightIdx < weights.size; weightIdx++) {
assertEquals(copy.get(weightIdx) / norm, weights.get(weightIdx), UtilEjml.TEST_F32);
}
}
}
use of org.ddogleg.struct.DogArray_F32 in project BoofCV by lessthanoptimal.
the class GenericTupleMapDistanceNormChecks method newInstanceThread_SameAnswer.
/**
* Basic check to makes sure the returned function produces
* the same results as the original
*/
@Test
void newInstanceThread_SameAnswer() {
TupleMapDistanceNorm alg1 = createAlg();
TupleMapDistanceNorm alg2 = alg1.newInstanceThread();
DogArray_F32 descA = new DogArray_F32();
DogArray_F32 descB = new DogArray_F32();
for (int j = 0; j < 20; j++) {
float value = rand.nextFloat();
descA.add(value);
descB.add(value);
}
// Need to normalize for distance functions to work correctly
alg1.normalize(descA);
alg2.normalize(descB);
for (int i = 0; i < descA.size; i++) {
assertEquals(descA.get(i), descB.get(i), UtilEjml.TEST_F32);
}
}
Aggregations