## Store graphical parameters:
tmp <- par(no.readonly = TRUE)
par(las=1)
## Case 1: one-dimensional symmetrical
n <- 11
x <- (n - 1)*seq(0, 1, length.out=n)
xx <- (n - 1)*seq(0, 1, 0.01)
sefSym <- genSEF(x, genDistMetric(), genDWF("Gaussian",3))
plot(y = predict(sefSym, xx, wh=1), x = xx, type = "l", ylab = "PMEM_1",
xlab = "x")
points(y = as.matrix(sefSym, wh=1), x = x)
plot(y = predict(sefSym, xx, wh=2), x = xx, type = "l", ylab = "PMEM_2",
xlab = "x")
points(y = as.matrix(sefSym, wh=2), x = x)
plot(y = predict(sefSym, xx, wh=5), x = xx, type = "l", ylab = "PMEM_5",
xlab = "x")
points(y = as.matrix(sefSym, wh=5), x = x)
## Case 2: one-dimensional asymmetrical (each has a real and imaginary parts)
sefAsy <- genSEF(x, genDistMetric(delta = pi/8), genDWF("Gaussian",3))
plot(y = Re(predict(sefAsy, xx, wh=1)), x = xx, type = "l", ylab = "PMEM_1",
xlab = "x", ylim=c(-0.35,0.35))
lines(y = Im(predict(sefAsy, xx, wh=1)), x = xx, col="red")
points(y = Re(as.matrix(sefAsy, wh=1)), x = x)
points(y = Im(as.matrix(sefAsy, wh=1)), x = x, col="red")
plot(y = Re(predict(sefAsy, xx, wh=2)), x = xx, type = "l", ylab = "PMEM_2",
xlab = "x", ylim=c(-0.45,0.35))
lines(y = Im(predict(sefAsy, xx, wh=2)), x = xx, col="red")
points(y = Re(as.matrix(sefAsy, wh=2)), x = x)
points(y = Im(as.matrix(sefAsy, wh=2)), x = x, col="red")
plot(y = Re(predict(sefAsy, xx, wh=5)), x = xx, type = "l", ylab = "PMEM_5",
xlab = "x", ylim=c(-0.45,0.35))
lines(y = Im(predict(sefAsy, xx, wh=5)), x = xx, col="red")
points(y = Re(as.matrix(sefAsy, wh=5)), x = x)
points(y = Im(as.matrix(sefAsy, wh=5)), x = x, col="red")
## A function to display combinations of the real and imaginary parts:
plotAsy <- function(object, xx, wh, a, ylim) {
pp <- predict(object, xx, wh=wh)
plot(y = cos(a)*Re(pp) + sin(a)*Im(pp), x = xx, type = "l",
ylab = "PMEM_5", xlab = "x", ylim=ylim, col="green")
invisible(NULL)
}
## Display combinations at an angle of 45° (pMEM_5):
plotAsy(sefAsy, xx, 5, pi/4, ylim=c(-0.45,0.45))
## Display combinations for other angles:
for(i in 0:15) {
plotAsy(sefAsy, xx, 5, i*pi/8, ylim=c(-0.45,0.45))
if(is.null(locator(1))) break
}
## Case 3: two-dimensional symmetrical
cbind(
x = c(-0.5,0.5,-1,0,1,-0.5,0.5),
y = c(rep(sqrt(3)/2,2L),rep(0,3L),rep(-sqrt(3)/2,2L))
) -> x2
seq(min(x2[,1L]) - 0.3, max(x2[,1L]) + 0.3, 0.05) -> xx
seq(min(x2[,2L]) - 0.3, max(x2[,2L]) + 0.3, 0.05) -> yy
list(
x = xx,
y = yy,
coords = cbind(
x = rep(xx, length(yy)),
y = rep(yy, each = length(xx))
)
) -> ss
cc <- seq(0,1,0.01)
cc <- c(rgb(cc,cc,1),rgb(1,1-cc,1-cc))
sefSym2D <- genSEF(x2, genDistMetric(), genDWF("Gaussian",3))
scr <- predict(sefSym2D, ss$coords)
par(mfrow = c(2,3), mar=0.5*c(1,1,1,1))
for(i in 1L:6) {
image(z=matrix(scr[,i],length(ss$x),length(ss$y)), x=ss$x, y=ss$y, asp=1,
zlim=max(abs(scr[,i]))*c(-1,1), col=cc, axes=FALSE)
points(x = x2[,1L], y = x2[,2L])
}
## Case 4: two-dimensional asymmetrical
sefAsy2D0 <- genSEF(x2, genDistMetric(delta=pi/8), genDWF("Gaussian",1))
## Note: default influence angle is 0 (with respect to the abscissa)
## A function to display combinations of the real and imaginary parts (2D):
plotAsy2 <- function(object, ss, a) {
pp <- predict(object, ss$coords)
for(i in 1:6) {
z <- cos(a)*Re(pp[,i]) + sin(a)*Im(pp[,i])
image(z=matrix(z,length(ss$x),length(ss$y)), x=ss$x, y=ss$y, asp=1,
zlim=max(abs(z))*c(-1,1), col=cc, axes=FALSE)
}
invisible(NULL)
}
## Display combinations at an angle of 22°:
plotAsy2(sefAsy2D0, ss, pi/8)
## Display combinations at other angles:
for(i in 0:23) {
plotAsy2(sefAsy2D0, ss, i*pi/12)
if(is.null(locator(1))) break
}
## With an influence of +45° (with respect to the abscissa)
sefAsy2D1 <- genSEF(x2, genDistMetric(delta=pi/8, theta = pi/4),
genDWF("Gaussian",1))
for(i in 0:23) {
plotAsy2(sefAsy2D1, ss, i*pi/12)
if(is.null(locator(1))) break
}
## With an influence of +90° (with respect to the abscissa)
sefAsy2D2 <- genSEF(x2, genDistMetric(delta=pi/8, theta = pi/2),
genDWF("Gaussian",1))
for(i in 0:23) {
plotAsy2(sefAsy2D2, ss, i*pi/12)
if(is.null(locator(1))) break
}
## With an influence of -45° (with respect to the abscissa)
sefAsy2D3 <- genSEF(x2, genDistMetric(delta=pi/8, theta = -pi/4),
genDWF("Gaussian",1))
for(i in 0:23) {
plotAsy2(sefAsy2D3, ss, i*pi/12)
if(is.null(locator(1))) break
}
## Reverting to initial graphical parameters:
par(tmp)
Run the code above in your browser using DataLab