2d random field with mean=0 at each row of numbers and precision #213
-
Hi, |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
Hey there, this is a tough one. Setting Only thing that we are providing is a transformation to force the generated field to have the given moments (mean, variance). But this will not help with each individual row: import gstools as gs
x = y = range(100)
model = gs.Exponential(dim=2, len_scale=5)
srf = gs.SRF(model=model, mean=0.0, seed=1234)
srf.structured([x, y])
print("mean:", srf.field.mean())
print("mean row 0:", srf.field[0].mean())
srf.transform("force_moments")
print("forced mean:", srf.field.mean())
print("forced mean row 0:", srf.field[0].mean()) Will give: mean: 0.14957193945128852
mean row 0: -0.32238566532970436
forced mean: 1.1368683772161604e-17
forced mean row 0: -0.533112638564582 So this got even worse for the first row. I don't see a possibility at the moment to force the given mean on each row/col of a field. Sebastian |
Beta Was this translation helpful? Give feedback.
-
Hi Mohammad, the interesting line in Sebastians code is this one: Regarding your second question, we provide quite a few ready to use transformations, but not for the beta distribution. If you want to add that transformation to GSTools, we would be happy about your contribution. If not, you can apply your own functions as a transformation, as documented here. I hope that helps! |
Beta Was this translation helpful? Give feedback.
-
Regarding transformation to different distributions: Using the uniform distribution as basis, it is really easy to convert the field to any distribution provided by scipy.stats using the import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import beta
import gstools as gs
x = y = range(100)
model = gs.Exponential(dim=2, len_scale=5)
srf = gs.SRF(model=model, mean=0.0, seed=1234)
srf.structured([x, y])
# transform to uniform distribution on [0, 1]
srf.transform("uniform")
# transform to beta distribution with ppf from uniform distribution
# 'a' and 'b' are kwargs forwarded to the function in use
srf.transform("function", function=beta.ppf, a=2.31, b=0.627)
srf.plot()
# see histogram
p = np.linspace(0, 1)
plt.figure(2)
plt.hist(srf.field.ravel(), density=True)
plt.plot(p, beta.pdf(p, a=2.31, b=0.627))
plt.show() |
Beta Was this translation helpful? Give feedback.
Hey there,
this is a tough one. Setting
mean=0.0
actually means, that the mean at each point for an ensemble of random fields converges to this given value. Under the assumption of ergodicity, the spatial mean should be near the given mean for a large enough realization.You are further constraining this by requiring each row to have the given mean. With increasing length of the field, this should converge.
Only thing that we are providing is a transformation to force the generated field to have the given moments (mean, variance). But this will not help with each individual row: