PieterjanRobbe / GaussianRandomFields.jl

A package for Gaussian random field generation in Julia
Other
66 stars 11 forks source link

Question for defining custom covariance function #64

Closed zkk960317 closed 3 months ago

zkk960317 commented 3 months ago

First, why the apply function of exponential apply(e::Exponential, x::Real) = e.σ * e.σ * exp(-x / e.λ) has two e.σ multiplied, this is different from the original definition. Then, if I have a custom function C(x, y) = σ * exp(-ρ / λ) + r, the apply function should be e.σ * e.σ * exp(-x / e.λ) +e.r or e.σ * (e.σ * exp(-x / e.λ) +e.r)? Looking forward to your answer. @PieterjanRobbe

zkk960317 commented 3 months ago
# a test
cov = CovarianceFunction(2, Exponential(1.0,σ = 100))
pts = range(0, stop=10, length=101)
@time grf = GaussianRandomField(cov, CirculantEmbedding(), pts, pts, minpadding=201)
fem = sample(grf)
var = mean((fem.-mean(fem)).^2) #about 10000

In theory, the variance of a discrete field should be equal to the covariance when ρ = 0, and should also be equal to σ. But the variance of the test is about the square of σ, which should also be caused by the problem mentioned as the first comment.

PieterjanRobbe commented 3 months ago

I'm wondering if this is due to #45?

zkk960317 commented 3 months ago

@PieterjanRobbe Thank you, I think I got it. The problem is that the description of function in the line 24 in exponential.jl should also be modified to match the source code. The same problem exists with other covariance functions. The tutorial document should also be correct at section Tutorial -> Examples -> 1D Exponential Covariance Function.

PieterjanRobbe commented 3 months ago

Thanks for pointing this out! I've updated the documentation and tutorial to reflect the changes.