use of org.ddogleg.struct.DogArray_I32 in project BoofCV by lessthanoptimal.
the class TestReedSolomonCodes_U16 method findErrors_BruteForce.
public void findErrors_BruteForce(ReedSolomonCodes_U16 alg, DogArray_I16 message, int numErrors, boolean expectedFail) {
var ecc = new DogArray_I16();
int nsyn = 10;
DogArray_I16 syndromes = DogArray_I16.zeros(nsyn);
DogArray_I16 errorLocator = new DogArray_I16();
DogArray_I32 locations = new DogArray_I32();
alg.generator(nsyn);
alg.computeECC(message, ecc);
DogArray_I16 cmessage = message.copy();
// corrupt the message and ecc
int N = message.size + ecc.size;
int[] corrupted = selectN(numErrors, N);
for (int i = 0; i < corrupted.length; i++) {
int w = corrupted[i];
if (w < message.size)
cmessage.data[w] ^= (short) 0x45;
else {
ecc.data[w - message.size] ^= (short) 0x45;
}
}
// compute needed info
alg.computeSyndromes(cmessage, ecc, syndromes);
alg.findErrorLocatorPolynomialBM(syndromes, errorLocator);
if (expectedFail) {
assertFalse(alg.findErrorLocations_BruteForce(errorLocator, N, locations));
} else {
// find the error locations
assertTrue(alg.findErrorLocations_BruteForce(errorLocator, N, locations));
// see if it found the expected number of errors and that the locations match
assertEquals(numErrors, locations.size);
for (int i = 0; i < locations.size; i++) {
int num = 0;
for (int j = 0; j < corrupted.length; j++) {
if (corrupted[j] == locations.data[i]) {
num++;
}
}
assertEquals(1, num);
}
DogArray_I16 hack = new DogArray_I16();
alg.findErrorLocatorPolynomial(N, locations, hack);
}
}
use of org.ddogleg.struct.DogArray_I32 in project BoofCV by lessthanoptimal.
the class TestAssociateThreeByPairs method failOnAtoB.
/**
* A->B is bad.
*/
@Test
void failOnAtoB() {
DogArray<TupleDesc_F64> featuresA = UtilFeature.createArrayF64(1);
DogArray<TupleDesc_F64> featuresB = UtilFeature.createArrayF64(1);
DogArray<TupleDesc_F64> featuresC = UtilFeature.createArrayF64(1);
DogArray_I32 featuresSetA = new DogArray_I32();
DogArray_I32 featuresSetB = new DogArray_I32();
DogArray_I32 featuresSetC = new DogArray_I32();
featuresB.grow().setTo(234234234);
featuresC.grow().setTo(2344234);
featuresC.grow().setTo(99234234);
for (int i = 0; i < 10; i++) {
featuresA.grow().setTo(i);
featuresB.grow().setTo(i + 0.12);
featuresC.grow().setTo(i + 0.3);
}
// there is only one set
featuresSetA.resize(featuresA.size);
featuresSetA.fill(0);
featuresSetB.resize(featuresB.size);
featuresSetB.fill(0);
featuresSetC.resize(featuresC.size);
featuresSetC.fill(0);
double maxError = 0.1 * 0.1 + 0.00000001;
ScoreAssociation<TupleDesc_F64> score = FactoryAssociation.defaultScore(TupleDesc_F64.class);
AssociateDescription<TupleDesc_F64> associate = FactoryAssociation.greedy(new ConfigAssociateGreedy(true, maxError), score);
AssociateThreeByPairs<TupleDesc_F64> alg = new AssociateThreeByPairs<>(associate);
alg.initialize(1);
alg.setFeaturesA(featuresA, featuresSetA);
alg.setFeaturesB(featuresB, featuresSetB);
alg.setFeaturesC(featuresC, featuresSetC);
alg.associate();
DogArray<AssociatedTripleIndex> matches = alg.getMatches();
assertEquals(0, matches.size);
}
use of org.ddogleg.struct.DogArray_I32 in project BoofCV by lessthanoptimal.
the class GenericAssociateGreedyChecks method basic.
@Test
void basic() {
DogArray<TupleDesc_F64> a = createData(1, 2, 3, 4);
DogArray<TupleDesc_F64> b = createData(3, 4, 1, 40);
AssociateGreedyBase<TupleDesc_F64> alg = createAlgorithm();
alg.setMaxFitError(0.5);
associate(alg, a, b);
DogArray_I32 pairs = alg.getPairs();
assertEquals(2, pairs.get(0));
assertEquals(-1, pairs.get(1));
assertEquals(0, pairs.get(2));
assertEquals(1, pairs.get(3));
DogArray_F64 fitScore = alg.getFitQuality();
assertEquals(0, fitScore.get(0), 1e-5);
assertEquals(0, fitScore.get(2), 1e-5);
assertEquals(0, fitScore.get(3), 1e-5);
}
use of org.ddogleg.struct.DogArray_I32 in project BoofCV by lessthanoptimal.
the class GenericAssociateGreedyChecks method backwards.
@Test
void backwards() {
DogArray<TupleDesc_F64> a = createData(1, 2, 3, 8);
DogArray<TupleDesc_F64> b = createData(3, 4, 1, 10);
AssociateGreedyBase<TupleDesc_F64> alg = createAlgorithm();
alg.backwardsValidation = true;
alg.setMaxFitError(10);
associate(alg, a, b);
DogArray_I32 pairs = alg.getPairs();
assertEquals(2, pairs.get(0));
assertEquals(-1, pairs.get(1));
assertEquals(0, pairs.get(2));
assertEquals(3, pairs.get(3));
DogArray_F64 fitScore = alg.getFitQuality();
assertEquals(0, fitScore.get(0), 1e-5);
assertEquals(0, fitScore.get(2), 1e-5);
assertEquals(2, fitScore.get(3), 1e-5);
}
use of org.ddogleg.struct.DogArray_I32 in project BoofCV by lessthanoptimal.
the class TestUtilFeature method setDestination_2D.
@Test
void setDestination_2D() {
var associate = new PAssociateDescriptionSets2D<>(new MockAssociateDescriptionSets2D());
var descriptors = new DogArray<>(() -> new TupleDesc_F64(1));
var locs = new DogArray<>(Point2D_F64::new);
var sets = new DogArray_I32();
for (int i = 0; i < 5; i++) {
descriptors.grow();
locs.grow();
}
sets.add(1);
sets.add(0);
sets.add(0);
sets.add(2);
sets.add(0);
associate.initializeSets(3);
UtilFeature.setDestination(descriptors, sets, locs, associate);
assertEquals(3, associate.getCountDst(0));
assertEquals(1, associate.getCountDst(1));
assertEquals(1, associate.getCountDst(2));
for (int i = 0; i < 3; i++) {
assertEquals(0, associate.getCountSrc(i));
}
}
Aggregations