-
Notifications
You must be signed in to change notification settings - Fork 0
/
integrateMatern.R
52 lines (42 loc) · 1.44 KB
/
integrateMatern.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
integrateMatern = function(xlim=c(0,1), ylim=c(0,1), n=50, ranges=seq(.01, .1, l=100), nsim=100) {
xs = seq(xlim[1], xlim[2], l=n)
ys = seq(ylim[1], ylim[2], l=n)
pts = make.surface.grid(list(x=xs, y=ys))
integrals = numeric(length(ranges))
for(i in 1:length(ranges)) {
print(paste0("i: ", i))
range = ranges[i]
cov = stationary.cov(pts, theta=range)
L = t(chol(cov))
zsims = matrix(rnorm(nrow(pts)*nsim), nrow=nrow(pts), ncol=nsim)
sims = L %*% zsims
integrals[i] = mean(colSums(sims))
}
integrals
}
integrateMatern2 = function(xlim=c(0,1), ylim=c(0,1), n=50, ranges=seq(.01, .1, l=100)) {
xs = seq(xlim[1], xlim[2], l=n)
ys = seq(ylim[1], ylim[2], l=n)
pts = make.surface.grid(list(x=xs, y=ys))
integrals = numeric(length(ranges))
for(i in 1:length(ranges)) {
print(paste0("i: ", i))
range = ranges[i]
cov = stationary.cov(pts, theta=range)
integrals[i] = mean(cov)
}
integrals
}
integrateExpitNugget = function(xlim=c(0,1), ylim=c(0,1), ns=c(10, 20, 30, 40, 50, 60), range=.05, nsim=1000, nuggetVar=.1^2) {
integrals = numeric(length(ns))
for(i in 1:length(ns)) {
n = ns[i]
print(paste0("n: ", n))
xs = seq(xlim[1], xlim[2], l=n)
ys = seq(ylim[1], ylim[2], l=n)
pts = make.surface.grid(list(x=xs, y=ys))
sims = expit(matrix(rnorm(nrow(pts)*nsim, sd=sqrt(nuggetVar)), nrow=nrow(pts), ncol=nsim))
integrals[i] = mean(colMeans(sims))
}
integrals
}