# Simulate 1000 exponential Hawkes processes on \eqn{[0, 100]},
# and average the periodogram of the count sequences with bin size 1
# at each frequency.
I = rep(0, 100)
for (k in 1:1e3) {
x = hawkes(100, fun = 1, repr = .5, family = "exp", rate = 2)
y = discrete(x, binsize = 1)
I = I + Mod(fft(y - mean(y)))^2 / length(y)
}
# Check that the averaged periodogram correctly approximates the spectral
# density function of the count sequence
model = new(Exponential)
model$param = c(1, .5, 2)
model$binsize = 1
z = 2 * pi * 0:99 / 100 # Frequencies of the periodogram
plot(z, I / 1e3, type = "l") # Averaged periodogram
lines(z, model$f1(xi = z, trunc = 10L), col = "red")
Run the code above in your browser using DataLab