Skip to content
Merged
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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).
Expand Down
2 changes: 1 addition & 1 deletion R/Agenerics.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
27 changes: 27 additions & 0 deletions R/dmi.R
Original file line number Diff line number Diff line change
@@ -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)
3 changes: 2 additions & 1 deletion _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ reference:

- title: Pattern Causality Analysis

- subtitle: embedding dimension choice
- subtitle: Phase Space Reconstruction
contents:
- dmi
- fnn

- subtitle: optimal parameters search
Expand Down
54 changes: 54 additions & 0 deletions man/dmi.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.