/** * Tests iteration with null inputs. */ @Test( expected = NullPointerException.class ) public void testNulls() { final IterablePair< Integer, Integer > pair = new IterablePair< >( null, null ); pair.iterator().next(); }
@Override public Double calculate(final Iterable<T> image1, final Iterable<U> image2) { return fastPearsons(new IterablePair<>(image1, image2)); }
@Override public Double calculate(Iterable<T> image1, Iterable<U> image2) { final Iterable<Pair<T, U>> samples = new IterablePair<>(image1, image2); return calculateMergeSort(samples); }
/** * Tests iteration with empty inputs. */ @Test( expected = NoSuchElementException.class ) public void testEmpty() { final List< Integer > iter1 = Collections.emptyList(); final List< Integer > iter2 = Collections.emptyList(); final IterablePair< Integer, Integer > pair = new IterablePair< >( iter1, iter2 ); pair.iterator().next(); }
/** * Determines whether two polyshapes describe the same region. * <p> * Two polyshapes are equal iff they have the same mask type, boundary type, * dimensions and vertices. * </p> * * @param polyshape1 * The first polyshape to compare. * @param polyshape2 * The second polyshape to compare. * @return True iff the polyshapes describe the same region. */ static boolean equals( final Polyshape polyshape1, final Polyshape polyshape2 ) { if ( polyshape1 == null && polyshape2 == null ) return true; if ( polyshape1 == null || polyshape2 == null || !Masks.sameTypesAndDimensions( polyshape1, polyshape2 ) ) return false; // Ensure same vertices in same order. final List< RealLocalizable > vertices1 = polyshape1.vertices(); final List< RealLocalizable > vertices2 = polyshape2.vertices(); for ( final Pair< RealLocalizable, RealLocalizable > pair : new IterablePair<>( vertices1, vertices2 ) ) if ( !Util.locationsEqual( pair.getA(), pair.getB() ) ) return false; return true; } }
/** * Tests iteration when two inputs are the same reference. */ @Test public void testSameIterable() { final List< Integer > iter = Arrays.asList( 3, 5, 6, 1, 2, 3 ); final IterablePair< Integer, Integer > pair = new IterablePair< >( iter, iter ); final Iterator< Pair< Integer, Integer > > iterPair = pair.iterator(); assertNotNull( iterPair ); int count = 0; for ( final Integer i : iter ) { final Pair< Integer, Integer > p = iterPair.next(); assertEquals( i, p.getA() ); assertEquals( i, p.getB() ); count++; } assertEquals( iter.size(), count ); }
@Test public void exhaustiveKendallTauBRankTesting() { assumeTrue(exhaustive); final int n = 5, m = 10; final int[] values1 = new int[n], values2 = new int[n]; for (int i = 0; i < 100; i++) { for (int j = 0; j < n; j++) { values1[j] = Math.abs(pseudoRandom()) % m; values2[j] = Math.abs(pseudoRandom()) % m; } //final PairIterator<DoubleType> iter = pairIterator(values1, values2); final Iterable<Pair<IntType, IntType>> iter = new IterablePair<>(ArrayImgs.ints(values1, n), ArrayImgs.ints(values2, n)); double kendallValue1 = calculateNaive(iter.iterator()); double kendallValue2 = (Double) ops.run(KendallTauBRank.class, values1, values2); if (Double.isNaN(kendallValue1)) { assertTrue("i: " + i + ", value2: " + kendallValue2, Double.isInfinite(kendallValue2) || Double.isNaN(kendallValue2)); } else { assertEquals("i: " + i, kendallValue1, kendallValue2, 1e-10); } } }
/** * Tests {@link IterablePair#iterator()}. */ @Test public void testIterator() { final List< Integer > iter1 = Arrays.asList( 3, 5, 6, 1, 2, 3 ); final List< String > iter2 = Arrays.asList( "dog", "cat", "mouse", "fox" ); final IterablePair< Integer, String > pair = new IterablePair< >( iter1, iter2 ); final Iterator< Pair< Integer, String > > iterPair = pair.iterator(); assertNotNull( iterPair ); assertNextItems( iterPair, 3, "dog" ); assertNextItems( iterPair, 5, "cat" ); assertNextItems( iterPair, 6, "mouse" ); assertNextItems( iterPair, 1, "fox" ); assertFalse( iterPair.hasNext() ); try { final Pair< Integer, String > next = iterPair.next(); fail( "Next element not expected: " + next ); } catch ( final NoSuchElementException exc ) { // expected behavior } }
@Override public Double calculate(final Iterable<T> image1, final Iterable<U> image2) { final Iterable<Pair<T, U>> samples = new IterablePair<>(image1, image2); final double m1 = mean1 == null ? computeMeanOf(image1) : mean1.get(); final double m2 = mean2 == null ? computeMeanOf(image2) : mean2.get(); // variables to count the positive and negative results // of Li's product of the difference of means. long numPositiveProducts = 0; long numNegativeProducts = 0; // iterate over image for (final Pair<T, U> value : samples) { final double ch1 = value.getA().getRealDouble(); final double ch2 = value.getB().getRealDouble(); final double productOfDifferenceOfMeans = (m1 - ch1) * (m2 - ch2); // check for positive and negative values if (productOfDifferenceOfMeans < 0.0) ++numNegativeProducts; else ++numPositiveProducts; } /* * calculate Li's ICQ value by dividing the amount of "positive pixels" * to the total number of pixels. Then shift it in the -0.5,0.5 range. */ final double icqValue = ((double) numPositiveProducts / (double) (numNegativeProducts + numPositiveProducts)) - 0.5; return icqValue; }