diff --git a/NAMESPACE b/NAMESPACE index 69178c8..1147e9d 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -5,6 +5,7 @@ S3method(plot,pc_single) S3method(print,pc_boot) S3method(print,pc_ops) S3method(print,pc_single) +exportMethods(dmi) exportMethods(fnn) exportMethods(ops) exportMethods(pc) diff --git a/NEWS.md b/NEWS.md index d434908..26fc1d0 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,9 @@ # pc 0.3 +## new + +* Provide `dmi` generic for *delayed mutual information* method (#77). + ### enhancements * Clarify output indexing and boundary handling in `fnn` generic (#69). diff --git a/R/Agenerics.R b/R/Agenerics.R index ccd1766..7945f0a 100644 --- a/R/Agenerics.R +++ b/R/Agenerics.R @@ -7,6 +7,6 @@ register_generic = \(name, def = NULL) { } } -for (gen in c("pc", "ops", "fnn")) { +for (gen in c("pc", "ops", "fnn", "dmi")) { register_generic(gen) } diff --git a/R/dmi.R b/R/dmi.R new file mode 100644 index 0000000..7112008 --- /dev/null +++ b/R/dmi.R @@ -0,0 +1,27 @@ +.dmi_ts = \(data, target, tau = 1:10, pred = NULL, k = 3, base = exp(1), + normalize = FALSE, threads = length(tau), ...) { + tv = .validate_var(data, target)[[1]] + if (is.null(pred)) pred = which(!is.na(tv)) + return(RcppDMI(tv, tau, pred, k, 0, base, normalize, threads)) +} + +#' Delayed Mutual Information +#' +#' @inheritParams fnn +#' @param base (optional) Logarithm base of the entropy. +#' @param normalize (optional) Whether to normalize MI values. +#' +#' @return A vector. +#' @export +#' @name dmi +#' @aliases dmi,data.frame-method +#' @references +#' Fraser, A.M., Swinney, H.L., 1986. Independent coordinates for strange attractors from mutual information. Physical Review A 33, 1134–1140. +#' +#' Kraskov, A., Stogbauer, H., Grassberger, P., 2004. Estimating mutual information. Physical Review E 69, 066138. +#' +#' @examples +#' abun = readr::read_csv(system.file("case/abundance.csv", package = "pc")) +#' pc::dmi(abun, 2) +#' +methods::setMethod("dmi", "data.frame", .dmi_ts) diff --git a/_pkgdown.yml b/_pkgdown.yml index 95ed274..9613b7c 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -27,8 +27,9 @@ reference: - title: Pattern Causality Analysis -- subtitle: embedding dimension choice +- subtitle: Phase Space Reconstruction contents: + - dmi - fnn - subtitle: optimal parameters search diff --git a/man/dmi.Rd b/man/dmi.Rd new file mode 100644 index 0000000..bb3bdd4 --- /dev/null +++ b/man/dmi.Rd @@ -0,0 +1,54 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/dmi.R +\name{dmi} +\alias{dmi} +\alias{dmi,data.frame-method} +\title{Delayed Mutual Information} +\usage{ +\S4method{dmi}{data.frame}( + data, + target, + tau = 1:10, + pred = NULL, + k = 3, + base = exp(1), + normalize = FALSE, + threads = length(tau), + ... +) +} +\arguments{ +\item{data}{Observation data.} + +\item{target}{Integer of column indice for the target variable.} + +\item{tau}{(optional) Step of lag.} + +\item{pred}{(optional) Predictions indices.} + +\item{k}{(optional) Number of nearest neighbors used for evaluation.} + +\item{base}{(optional) Logarithm base of the entropy.} + +\item{normalize}{(optional) Whether to normalize MI values.} + +\item{threads}{(optional) Number of threads used.} + +\item{...}{Additional arguments to absorb unused inputs in method dispatch.} +} +\value{ +A vector. +} +\description{ +Delayed Mutual Information +} +\examples{ +abun = readr::read_csv(system.file("case/abundance.csv", package = "pc")) +pc::dmi(abun, 2) + +} +\references{ +Fraser, A.M., Swinney, H.L., 1986. Independent coordinates for strange attractors from mutual information. Physical Review A 33, 1134–1140. + +Kraskov, A., Stogbauer, H., Grassberger, P., 2004. Estimating mutual information. Physical Review E 69, 066138. +}