draft r interface for dmi - #77
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR introduces the R interface for Delayed Mutual Information (DMI) analysis, providing a complete pipeline from R-level function calls to the underlying C++ implementation powered by the KSG (Kraskov–Stögbauer–Grassberger) estimator. The implementation supports parallel computation across multiple lag steps.
Background & Theory
Mutual Information
Mutual Information (MI) quantifies the statistical dependence between two random variables$X$ and $Y$ :
where$H(\cdot)$ denotes the Shannon entropy. Unlike Pearson correlation, MI captures both linear and nonlinear dependencies, making it a more general measure of association.
KSG Estimator
Estimating MI for continuous variables directly from the definition is intractable because the probability density function is typically unknown. The KSG estimator (Kraskov et al., 2004) addresses this by leveraging$k$ -nearest neighbor distances in the joint and marginal spaces:
where:
This estimator is asymptotically unbiased and does not require explicit density estimation or binning.
Delayed Mutual Information
Delayed Mutual Information extends MI to a time series context. Given a time series${x_t}$ , DMI measures the information shared between the present state $x_t$ and its past state $x_{t-\tau}$ at a given lag $\tau$ :
Computing DMI across a range of lags$\tau \in {\tau_1, \tau_2, \dots, \tau_m}$ reveals the temporal dependency structure of the series, which is widely used in:
Algorithm
Step 1: Construct the Lag Matrix
Given:
A matrix$\mathbf{M}$ of size $(m + 1) \times n$ is constructed:
Entries where$p_j - \tau_{i-1} < 0$ are filled with
NaNand excluded from estimation.Step 2: Input Validation & Preprocessing (R → C++)
NaNStep 3: Pairwise MI Estimation
For each lag$\tau_i$ ($i = 1, \dots, m$ ):
NaNR Interface
Function Signature
Return Value
A named
numericvector of lengthlength(tau), where each element is the estimated MI at the corresponding lag. Names follow the format"tau:<value>".References