arma-thesis

git clone https://git.igankevich.com/arma-thesis.git
Log | Files | Refs | LICENSE

commit 44f6b8d5132e91241c4224797879aded4d50b1e3
parent 7f3ce758b5c2491677f2e204a0b7df9c772fa234
Author: Ivan Gankevich <igankevich@ya.ru>
Date:   Wed, 20 Jun 2018 12:18:29 +0300

Add Stokes wave ACF.

Diffstat:
R/common.R | 47+++++++++++++++++++++++++++++++++++++----------
arma-slides.org | 15+++++++++------
2 files changed, 46 insertions(+), 16 deletions(-)

diff --git a/R/common.R b/R/common.R @@ -20,16 +20,7 @@ arma.qqplot_grid_adj <- function (dir, params, titles, adj, ...) { } } -arma.wavy_plot <- function (data, t, ...) { - slice <- data[data$t == t,] - x <- unique(slice$x) - y <- unique(slice$y) - z <- with(slice, { - n <- sqrt(length(z)) - out <- matrix(nrow=n, ncol=n) - out[cbind(x, y)] <- z - out - }) +arma.wavy_plot_matrix <- function (x, y, z, t, ...) { nrz <- nrow(z) ncz <- ncol(z) # Create a function interpolating colors in the range of specified colors @@ -44,6 +35,42 @@ arma.wavy_plot <- function (data, t, ...) { persp(x, y, z, phi=30, theta=30, col=color[facetcol], ...) } +arma.to_matrix <- function (data, t) { + slice <- data[data$t == t,] + x <- unique(slice$x) + y <- unique(slice$y) + z <- with(slice, { + n <- sqrt(length(z)) + out <- matrix(nrow=n, ncol=n) + out[cbind(x, y)] <- z + out + }) + list(x=x,y=y,z=z) +} + +arma.wavy_plot <- function (data, t, ...) { + with(arma.to_matrix(data, t), arma.wavy_plot_matrix(x, y, z, ...)) +} + +arma.acf_plot <- function (data, t, ...) { + ifft <- function (arr) { fft(arr, inverse=TRUE) } + with( + arma.to_matrix(data, t), + function () { + # compute ACF using Wiener---Khinchin theorem + n <- nrow(z)*ncol(z) + z <- Re(ifft(abs(fft(z))^2))/n/n + # slice 1/4th of the matrix + n1 <- floor(nrow(z)/2) + n2 <- floor(ncol(z)/2) + x <- x[1:n1] + y <- y[1:n2] + z <- z[1:n1,1:n2] + arma.wavy_plot_matrix(x, y, z, ...) + } + )() +} + arma.skew_normal_1_plot <- function(x, params) { data <- mapply( function (s, k) arma.skew_normal_1(x, s, k), diff --git a/arma-slides.org b/arma-slides.org @@ -282,20 +282,23 @@ arma.wavy_plot(df, 0, zlim=c(-0.05,0.05), expand=0.5, border=NA) source(file.path("R", "common.R")) par(mar=c(0,0.5,0,0)) df <- data.frame(t=rep(NA,0), x=rep(NA,0), y=rep(NA,0), z=rep(NA,0)) -n <- 20 +n <- 40 +alpha <- 0.5 grid <- seq(1, n) -alpha <- 2.31906 -beta <- -5.49873 -gamm <- 0.0680413 +k <- 0.77341 +t <- 0 +omega <- 0.3 +a <- 1.5 for (i in grid) { for (j in grid) { x <- i/(n-1) y <- j/(n-1) - z <- gamm * exp(-alpha*(x+y)) * cos(beta*x) * cos(beta*y) + theta <- k*(x + y) - omega*t + z <- a * exp(-alpha*(x+y)) * (cos(theta) + 0.5*k*a*cos(2*theta) + (3/8)*(k*a*k*a)*cos(3*theta)) df[nrow(df) + 1,] <- c(0,i,j,z) } } -arma.wavy_plot(df, 0, zlim=c(-0.05,0.05), expand=0.5, border=NA) +arma.acf_plot(df, 0, zlim=c(0,1.0), expand=0.5, border=NA) #+end_src #+caption: Волна Стокса