Add an easily-called interactive test for Coloc 2

This helps developing in an IDE tremendously.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Coloc 2: Add Kendall's Tau-b rank correlation

Kendall's Tau-b rank correlation is said to be a better measure than
Spearman's rank correlation, and the latter was only preferred for a long
time because the former needs substantially more computational resources.

This implementation is very dumb and inefficient -- O(n^2) -- and is here
only for correctness.

A subsequent commit will replace it by an efficient method.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Introduce the PairIterator

For many measures, it should actually not be necessary to localize the
position or know about the mask. Therefore, let's abstract out an
interface for an iterator that returns pairs of values, and nothing else.

This will also make it substantially easier to test things, as one does no
longer need to construct full-blown image data structures just to test
an algorithm.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Add some documentation to the implementation of Kendall's Tau-b

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Use better names than getChannel1 and getChannel2

We are not getting the whole channel, after all. Just one sample of it.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Make the TwinCursor a PairIterator

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Add a test for the Kendall Tau-b algorithm

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Test more conditions of Kendall's Tau-b

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Add the reset() method to the PairIterator

We will need that for extensive testing of different Kendall Tau
algorithms.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Add the IntArraySorter class

This class implements an introsort of an integer array given a custom
comparator. That allows users to sort index arrays, i.e. arrays
containing indexes into other arrays, and comparing the values the
indexes point to.

This is often more efficient than having full-blown Object arrays (with
the full runtime and space cost of constructing that many Objects).

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Add an efficient implementation of Kendall's Tau-b

This is supposedly the algorithm proposed by Knight (reference
in the source code comments), but really, this developer used the
description on Wikipedia (it is really strange how few scientists
understand what a big obstacle the current publishing system is to
proper scientific work).

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Use the fast Kendall Tau-b algorithm instead of the naive one

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Kendall-Tau: add an exhaustive test

It is always good to verify that a robust but slow algorithm is replaced
by a fast *and accurate* algorithm.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
wip

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Kendall Tau: avoid integer overflow

Large n values can easily lead to n * (n - 1) / 2 to be larger than a
31-bit integer.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Coloc 2: make it easier to apply interactive test to custom images

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Coloc 2: fix flawed bin width calculation

Math can be wonderful! And fun! And it can also be useful.

For example, when you want to determine a bin width such that, say,

	value * binWidth + 0.5 < binCount

for *every* value in a given channel, but optimize such that the bin
width is still as large as possible, mathematical treatment of the
problem will lead to the equation:

	maxValue * binWidth + 0.5 = binCount - eps

where eps is a small value (just small enough not to matter much, but
large enough to avoid falling into the machine precision's cracks).
Solving that equation for binWidth yields:

	binWidth = (binCount - 0.5 - eps) / maxValue

which is a far cry from the previous

	binWidth = binCount / (maxValue + 1)

It is even very easy to construct an example where the latter version
falls on its face: let binCount = 2^8 and maxValue = 2^16 - 1. Then the
flawed formula would yield binWidth = 2^8 and maxValue * binWidth + 0.5
would be exactly 2^-1 - 2^-8 *larger* than binCount.

This bug showed itself in the form of an ArrayOutOfBoundsException
reported by Ginger Pocock in the report at

	http://fiji.sc/bugzilla/show_bug.cgi?id=699

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>