Skip to content

Commit cbc04fc

Browse files
authored
Merge pull request #77 from SpatLyu/dev
draft r interface for dmi
2 parents 8a24b17 + 4694093 commit cbc04fc

6 files changed

Lines changed: 89 additions & 2 deletions

File tree

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ S3method(plot,pc_single)
55
S3method(print,pc_boot)
66
S3method(print,pc_ops)
77
S3method(print,pc_single)
8+
exportMethods(dmi)
89
exportMethods(fnn)
910
exportMethods(ops)
1011
exportMethods(pc)

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# pc 0.3
22

3+
## new
4+
5+
* Provide `dmi` generic for *delayed mutual information* method (#77).
6+
37
### enhancements
48

59
* Clarify output indexing and boundary handling in `fnn` generic (#69).

R/Agenerics.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ register_generic = \(name, def = NULL) {
77
}
88
}
99

10-
for (gen in c("pc", "ops", "fnn")) {
10+
for (gen in c("pc", "ops", "fnn", "dmi")) {
1111
register_generic(gen)
1212
}

R/dmi.R

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
.dmi_ts = \(data, target, tau = 1:10, pred = NULL, k = 3, base = exp(1),
2+
normalize = FALSE, threads = length(tau), ...) {
3+
tv = .validate_var(data, target)[[1]]
4+
if (is.null(pred)) pred = which(!is.na(tv))
5+
return(RcppDMI(tv, tau, pred, k, 0, base, normalize, threads))
6+
}
7+
8+
#' Delayed Mutual Information
9+
#'
10+
#' @inheritParams fnn
11+
#' @param base (optional) Logarithm base of the entropy.
12+
#' @param normalize (optional) Whether to normalize MI values.
13+
#'
14+
#' @return A vector.
15+
#' @export
16+
#' @name dmi
17+
#' @aliases dmi,data.frame-method
18+
#' @references
19+
#' Fraser, A.M., Swinney, H.L., 1986. Independent coordinates for strange attractors from mutual information. Physical Review A 33, 1134–1140.
20+
#'
21+
#' Kraskov, A., Stogbauer, H., Grassberger, P., 2004. Estimating mutual information. Physical Review E 69, 066138.
22+
#'
23+
#' @examples
24+
#' abun = readr::read_csv(system.file("case/abundance.csv", package = "pc"))
25+
#' pc::dmi(abun, 2)
26+
#'
27+
methods::setMethod("dmi", "data.frame", .dmi_ts)

_pkgdown.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ reference:
2727

2828
- title: Pattern Causality Analysis
2929

30-
- subtitle: embedding dimension choice
30+
- subtitle: Phase Space Reconstruction
3131
contents:
32+
- dmi
3233
- fnn
3334

3435
- subtitle: optimal parameters search

man/dmi.Rd

Lines changed: 54 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)