Skip to content

Commit 7bced3e

Browse files
committed
[ENH/CLN] Define the prior mean just from the original geomodel
1 parent 53dc76e commit 7bced3e

File tree

2 files changed

+11
-22
lines changed

2 files changed

+11
-22
lines changed

gempy_probability/modules/model_definition/model_examples.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,14 @@
77
import torch
88

99

10-
def model(geo_model: gempy.core.data.GeoModel, sp_coords_copy, y_obs_list):
10+
def model(geo_model: gempy.core.data.GeoModel, normal, y_obs_list):
1111
"""
1212
This Pyro model represents the probabilistic aspects of the geological model.
1313
It defines a prior distribution for the top layer's location and
1414
computes the thickness of the geological layer as an observed variable.
1515
"""
1616
# Define prior for the top layer's location:
1717
# region Prior definition
18-
prior_mean = sp_coords_copy[0, 2]
19-
normal = dist.Normal(
20-
loc=prior_mean,
21-
scale=torch.tensor(0.1, dtype=torch.float64)
22-
)
2318

2419
mu_top = pyro.sample(
2520
name=r'$\mu_{top}$',

tests/test_prob_model/test_prob_I.py

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,16 @@ def test_basic_gempy_I() -> None:
3535
engine_config=gp.data.GemPyEngineConfig(backend=gp.data.AvailableBackends.numpy)
3636
)
3737

38-
# TODO: This is the part that has to go to a function no question
39-
# Probabilistic Geomodeling with Pyro
40-
# -----------------------------------
41-
# In this section, we introduce a probabilistic approach to geological modeling.
42-
# By using Pyro, a probabilistic programming language, we define a model that integrates
43-
# geological data with uncertainty quantification.
44-
45-
from gempy_engine.core.data.interpolation_input import InterpolationInput
4638
from gempy_engine.core.backend_tensor import BackendTensor
47-
from gempy.modules.data_manipulation.engine_factory import interpolation_input_from_structural_frame
48-
49-
interpolation_input_copy: InterpolationInput = interpolation_input_from_structural_frame(geo_model)
50-
sp_coords_copy = interpolation_input_copy.surface_points.sp_coords
51-
# Change the backend to PyTorch for probabilistic modeling
5239
BackendTensor.change_backend_gempy(engine_backend=gp.data.AvailableBackends.PYTORCH)
40+
41+
import pyro.distributions as dist
42+
import torch
5343

44+
normal = dist.Normal(
45+
loc=(geo_model.surface_points_copy_transformed.xyz[0, 2]),
46+
scale=torch.tensor(0.1, dtype=torch.float64)
47+
)
5448
# %%
5549
# Running Prior Sampling and Visualization
5650
# ----------------------------------------
@@ -75,7 +69,7 @@ def test_basic_gempy_I() -> None:
7569
num_samples=50
7670
)
7771

78-
prior = predictive(geo_model, sp_coords_copy, y_obs_list)
72+
prior = predictive(geo_model, normal, y_obs_list)
7973

8074
data = az.from_pyro(prior=prior)
8175
az.plot_trace(data.prior)
@@ -100,7 +94,7 @@ def test_basic_gempy_I() -> None:
10094
warmup_steps=50,
10195
disable_validation=False
10296
)
103-
mcmc.run(geo_model, sp_coords_copy, y_obs_list)
97+
mcmc.run(geo_model, normal, y_obs_list)
10498

10599
posterior_samples = mcmc.get_samples()
106100

@@ -109,7 +103,7 @@ def test_basic_gempy_I() -> None:
109103
posterior_samples=posterior_samples
110104
)
111105

112-
posterior_predictive = posterior_predictive_fn(geo_model, sp_coords_copy, y_obs_list)
106+
posterior_predictive = posterior_predictive_fn(geo_model, normal, y_obs_list)
113107

114108
data = az.from_pyro(posterior=mcmc, prior=prior, posterior_predictive=posterior_predictive)
115109
az.plot_trace(data)

0 commit comments

Comments
 (0)