Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2aa7d9c

Browse files
authored
Merge pull request#609 from SpatLyu/v2.0
implement s4 generic `slm` for spatial logistic map method
2 parentsbae257f +4cb4107 commit2aa7d9c

File tree

6 files changed

+172
-1
lines changed

6 files changed

+172
-1
lines changed

‎NAMESPACE‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ exportMethods(gcmc)
1515
exportMethods(multiview)
1616
exportMethods(sc.test)
1717
exportMethods(simplex)
18+
exportMethods(slm)
1819
exportMethods(smap)
1920
importFrom(methods,setGeneric)
2021
importFrom(methods,setMethod)

‎R/slm.R‎

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
methods::setGeneric("slm", function(data, ...) standardGeneric("slm"))
2+
3+
.slm_sf_method= \(data,x,y=NULL,z=NULL,
4+
k=4,step=20,alpha_x=0.77,alpha_y=0,alpha_z=0,
5+
beta_xy=0,beta_xz=0,beta_yx=0,beta_yz=0,beta_zx=0,beta_zy=0,
6+
threshold=1e10,nb=NULL){
7+
vx= .uni_lattice(data,x,FALSE)
8+
vy= .uni_lattice(data,y,FALSE)
9+
vz= .uni_lattice(data,z,FALSE)
10+
if (is.null(nb))nb= .internal_lattice_nb(data)
11+
return(.bind_slm(RcppSLMTri4Lattice(vx,vy,vz,nb,k,step,alpha_x,alpha_y,alpha_z,beta_xy,beta_xz,beta_yx,beta_yz,beta_zx,beta_zy,threshold),y,z))
12+
}
13+
14+
.slm_spatraster_method= \(data,x,y=NULL,z=NULL,
15+
k=4,step=20,alpha_x=0.77,alpha_y=0,alpha_z=0,
16+
beta_xy=0,beta_xz=0,beta_yx=0,beta_yz=0,beta_zx=0,beta_zy=0,
17+
threshold=1e10){
18+
mx= .uni_grid(data,x,FALSE)
19+
my= .uni_grid(data,y,FALSE)
20+
mz= .uni_grid(data,z,FALSE)
21+
return(.bind_slm(RcppSLMTri4Grid(mx,my,mz,k,step,alpha_x,alpha_y,alpha_z,beta_xy,beta_xz,beta_yx,beta_yz,beta_zx,beta_zy,threshold),y,z))
22+
}
23+
24+
#' spatial logistic map
25+
#'
26+
#' @param data observation data.
27+
#' @param x first spatial variable.
28+
#' @param y (optional) second spatial variable.
29+
#' @param z (optional) third spatial variable.
30+
#' @param k (optional) number of neighbors to used.
31+
#' @param step (optional) number of simulation time steps.
32+
#' @param alpha_x (optional) growth parameter for x.
33+
#' @param alpha_y (optional) growth parameter for y.
34+
#' @param alpha_z (optional) growth parameter for y.
35+
#' @param beta_xy (optional) cross-inhibition from x to y.
36+
#' @param beta_xz (optional) cross-inhibition from x to z.
37+
#' @param beta_yx (optional) cross-inhibition from y to x.
38+
#' @param beta_yz (optional) cross-inhibition from y to z.
39+
#' @param beta_zx (optional) cross-inhibition from z to x.
40+
#' @param beta_zy (optional) cross-inhibition from z to y.
41+
#' @param threshold (optional) set to `NaN` if the absolute value exceeds this threshold.
42+
#' @param nb (optional) neighbours list.
43+
#'
44+
#' @return A list
45+
#' @export
46+
#'
47+
#' @name slm
48+
#' @rdname slm
49+
#' @aliases slm,sf-method
50+
#' @references
51+
#' Willeboordse, F.H., The spatial logistic map as a simple prototype for spatiotemporal chaos, Chaos, 533–540 (2003).
52+
#'
53+
#' @examples
54+
#' columbus = sf::read_sf(system.file("case/columbus.gpkg", package="spEDM"))
55+
#' columbus$inc = sdsfun::normalize_vector(columbus$inc)
56+
#' slm(columbus,"inc")
57+
#'
58+
methods::setMethod("slm", "sf", .slm_sf_method)
59+
60+
#' @rdname slm
61+
methods::setMethod("slm", "SpatRaster", .slm_spatraster_method)

‎R/variable_check_prepare.R‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
}
6666

6767
.uni_lattice= \(data,target,detrend=FALSE){
68+
if (is.null(target))return(rep(0,nrow(data)))
6869
target= .check_character(target)
6970
coords= as.data.frame(sdsfun::sf_coordinates(data))
7071
data=sf::st_drop_geometry(data)
@@ -78,6 +79,7 @@
7879
}
7980

8081
.uni_grid= \(data,target,detrend=FALSE){
82+
if (is.null(target))return(matrix(0,terra::nrow(data),terra::ncol(data)))
8183
target= .check_character(target)
8284
data=data[[target]]
8385
names(data)="target"

‎R/xmapdf.R‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,10 @@
6363
class(res)="sc_res"
6464
return(res)
6565
}
66+
67+
.bind_slm= \(mat_list,y,z){
68+
res= lapply(mat_list, \(.x) apply(.x,1,mean,na.rm=TRUE))
69+
if (is.null(y))res$y=NULL
70+
if (is.null(z))res$z=NULL
71+
return(res)
72+
}

‎_pkgdown.yml‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,14 @@ reference:
5151
-gccm
5252
-gcmc
5353

54+
-subtitle:Spatiotemporal Chaos
55+
contents:
56+
-slm
57+
5458
-title:Causality in Information Flux (for Comparison)
5559
contents:
5660
-sc.test
5761

5862
-title:Miscellaneous Utility Functions
5963
contents:
6064
-detectThreads
61-

‎man/slm.Rd‎

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp