Search in sources :

Example 11 with DogArray_F32

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);
    }
}
Also used : DogArray_F32(org.ddogleg.struct.DogArray_F32) Test(org.junit.jupiter.api.Test)

Example 12 with DogArray_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);
        }
    }
}
Also used : DogArray_F32(org.ddogleg.struct.DogArray_F32) Test(org.junit.jupiter.api.Test)

Example 13 with DogArray_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);
    }
}
Also used : DogArray_F32(org.ddogleg.struct.DogArray_F32) Test(org.junit.jupiter.api.Test)

Aggregations

DogArray_F32 (org.ddogleg.struct.DogArray_F32)13 Test (org.junit.jupiter.api.Test)7 GrayF32 (boofcv.struct.image.GrayF32)2 Point2D_F64 (georegression.struct.point.Point2D_F64)2 ArrayList (java.util.ArrayList)2 PointCloudWriter (boofcv.alg.cloud.PointCloudWriter)1 DoNothingPixelTransform_F64 (boofcv.alg.distort.DoNothingPixelTransform_F64)1 Point3D_F64 (georegression.struct.point.Point3D_F64)1 Se3_F64 (georegression.struct.se.Se3_F64)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 DogArray_I32 (org.ddogleg.struct.DogArray_I32)1 VerbosePrint (org.ddogleg.struct.VerbosePrint)1