France
In this notebook we demonstrate the use of the Debiased Spatial Whittle for a simulated random field on an incomplete grid, where the sampling region follows the shape of the territory of France.
Imports¶
In [1]:
Copied!
import matplotlib.pyplot as plt
import debiased_spatial_whittle.grids as grids
from debiased_spatial_whittle.models.spectral import SpectralMatern
from debiased_spatial_whittle.grids.base import RectangularGrid
from debiased_spatial_whittle.sampling.simulation import SamplerOnRectangularGrid
from debiased_spatial_whittle.inference.periodogram import Periodogram, ExpectedPeriodogram
from debiased_spatial_whittle.inference.likelihood import Estimator, DebiasedWhittle
from debiased_spatial_whittle.grids.old import ImgGrid
import matplotlib.pyplot as plt
import debiased_spatial_whittle.grids as grids
from debiased_spatial_whittle.models.spectral import SpectralMatern
from debiased_spatial_whittle.grids.base import RectangularGrid
from debiased_spatial_whittle.sampling.simulation import SamplerOnRectangularGrid
from debiased_spatial_whittle.inference.periodogram import Periodogram, ExpectedPeriodogram
from debiased_spatial_whittle.inference.likelihood import Estimator, DebiasedWhittle
from debiased_spatial_whittle.grids.old import ImgGrid
Model specification¶
In [2]:
Copied!
model = SpectralMatern(rho=15, nu=2.0)
model = SpectralMatern(rho=15, nu=2.0)
Grid specification¶
In [3]:
Copied!
shape = (512, 512)
mask_france = ImgGrid(shape).get_new()
grid_france = RectangularGrid(shape)
grid_france.mask = mask_france
sampler = SamplerOnRectangularGrid(model, grid_france)
shape = (512, 512)
mask_france = ImgGrid(shape).get_new()
grid_france = RectangularGrid(shape)
grid_france.mask = mask_france
sampler = SamplerOnRectangularGrid(model, grid_france)
Sample generation¶
In [4]:
Copied!
z = sampler()
plt.figure()
plt.imshow(z, origin="lower", cmap="RdBu")
plt.show()
z = sampler()
plt.figure()
plt.imshow(z, origin="lower", cmap="RdBu")
plt.show()
Inference¶
In [5]:
Copied!
periodogram = Periodogram()
expected_periodogram = ExpectedPeriodogram(grid_france, periodogram)
debiased_whittle = DebiasedWhittle(periodogram, expected_periodogram)
estimator = Estimator(debiased_whittle)
periodogram = Periodogram()
expected_periodogram = ExpectedPeriodogram(grid_france, periodogram)
debiased_whittle = DebiasedWhittle(periodogram, expected_periodogram)
estimator = Estimator(debiased_whittle)
In [6]:
Copied!
model_est = SpectralMatern()
model_est.set_param_bounds(dict(rho=(3, 50), nu=(0.5, 5)))
estimate = estimator(model_est, z, opt_callback=lambda *args, **kwargs: print(*args))
print(estimate.rho)
model_est = SpectralMatern()
model_est.set_param_bounds(dict(rho=(3, 50), nu=(0.5, 5)))
estimate = estimator(model_est, z, opt_callback=lambda *args, **kwargs: print(*args))
print(estimate.rho)
[3.24592493 1.36757938]
[4.74157839 3.04834872]
[5.20055131 3.32504723]
[6.56919315 4.09007361]
[7.51437093 4.5659791 ]
[8.36777361 4.94441327]
[8.81423446 5. ]
[9.22093231 4.97680015]
[9.42353583 4.87206681]
[9.9745532 4.39907896]
[10.01102647 4.38519129]
[10.11990392 4.33835129]
[11.5052515 2.7119285]
[12.44472509 2.63883863]
[13.68623083 2.03775649]
[14.40644008 1.90505653]
[14.8940292 1.92169151]
[15.21248266 1.86917589]
[15.48589249 1.82989631]
[15.4850677 1.83311326] 15.485067703949477