Skip to contents

Estimates the mutual information between every column of x and every column of y (of x itself when y is missing) by the B-spline estimator of Daub et al. (2004), on the GPU. Unlike a correlation it detects any kind of dependence, not only linear or monotone association.

Usage

gpuMi(x, y = NULL, bins = 10, splineOrder = 3,
    precision = getOption("gputools.precision", "single"))

Arguments

x

a numeric matrix, one variable per column, a sample per row, with no missing values. The values may lie in any range: each variable is scaled onto the spline domain by its own minimum and maximum.

y

an optional numeric matrix of further variables, the same samples in the same rows.

bins

the number of bins each variable's range is divided into (\(M\) in Daub et al., who find 10 to work well), at most 64.

splineOrder

the B-spline order (\(k\) in Daub et al.), from 1 to bins: 1 puts each value wholly in one bin (plain binning), 2 spreads it linearly over two, 3 (which Daub et al. recommend) quadratically over three, and so on. The polynomial degree is splineOrder - 1.

precision

"single" or "double": the floating point precision of the products on the GPU. The B-spline weights themselves are always computed in double from the data as given, since rounding a value on a knot (as discrete data put them) to single would move it into the neighbouring bin. Results are returned as doubles either way.

Details

Each variable is scaled linearly onto the spline domain \([0, M - k + 1]\), its minimum at 0 and its maximum at the far end, with the knot vector \(0, \ldots, 0, 1, 2, \ldots, M - k, M - k + 1, \ldots, M - k + 1\) (each end repeated \(k\) times), as in Daub et al.; each value then has B-spline weights over the \(M\) bins, non-negative and summing to 1. With \(w_i(s, a)\) the weight of sample \(s\) of variable \(i\) in bin \(a\), the bin probabilities are \(P_i(a) = \mathrm{mean}_s\, w_i(s, a)\) and the joint ones \(P_{ij}(a, b) = \mathrm{mean}_s\, w_i(s, a) w_j(s, b)\), so that \(MI = H_i + H_j - H_{ij}\) with \(H = -\sum P \log_2 P\).

On the GPU, the weights of many variables side by side make one matrix product hold the joint distribution of every pair, a \(M \times M\) block per pair. Since each sample's weights sum to 1, a block's row and column sums are the two marginals, and the information is computed from the block alone as \(\sum P_{ij} \log_2 (P_{ij} / (P_i P_j))\): the same quantity, without subtracting large entropies to get a small difference, and consistent with any rounding in the product. \(0 \log 0\) counts as 0, and an estimate that rounds just below 0 is 0.

Value

a numeric matrix with a row per column of y (of x when y is missing) and a column per column of x: entry \((j, i)\) is the mutual information of y[, j] with x[, i], in bits. A constant variable shares no information: 0. With y missing, the diagonal is each variable's information with itself: its entropy for splineOrder = 1, and less for higher orders, whose spread weights blur a variable's joint distribution with itself.

References

Daub, C. O., Steuer, R., Selbig, J. and Kloska, S. (2004). Estimating mutual information using B-spline functions – an improved similarity measure for analysing gene expression data. BMC Bioinformatics 5, 118. doi:10.1186/1471-2105-5-118

Examples

if (FALSE) { # gpuAvailable()
set.seed(1)
u <- runif(2000, -1, 1)
x <- cbind(u = u, usq = u^2, noise = runif(2000, -1, 1))
mi <- gpuMi(x)
mi["usq", "u"] > 10 * mi["noise", "u"]   # u and u^2: dependent, uncorrelated
abs(cor(u, u^2)) < 0.05
}