@@ -44,57 +44,13 @@ def test_basic_gempy_I():
44
44
45
45
from gempy_engine .core .data .interpolation_input import InterpolationInput
46
46
from gempy_engine .core .backend_tensor import BackendTensor
47
-
48
47
from gempy .modules .data_manipulation .engine_factory import interpolation_input_from_structural_frame
49
48
50
49
interpolation_input_copy : InterpolationInput = interpolation_input_from_structural_frame (geo_model )
51
50
sp_coords_copy = interpolation_input_copy .surface_points .sp_coords
52
51
# Change the backend to PyTorch for probabilistic modeling
53
52
BackendTensor .change_backend_gempy (engine_backend = gp .data .AvailableBackends .PYTORCH )
54
53
55
- # Defining the Probabilistic Model
56
- # --------------------------------
57
- # The Pyro model represents the probabilistic aspects of the geological model.
58
- # It defines a prior distribution for the top layer's location and computes the thickness
59
- # of the geological layer as an observed variable.
60
-
61
- def model (y_obs_list ):
62
- """
63
- This Pyro model represents the probabilistic aspects of the geological model.
64
- It defines a prior distribution for the top layer's location and
65
- computes the thickness of the geological layer as an observed variable.
66
- """
67
- # Define prior for the top layer's location:
68
- prior_mean = sp_coords_copy [0 , 2 ]
69
- import pyro
70
- import pyro .distributions as dist
71
- import torch
72
- mu_top = pyro .sample (r'$\mu_{top}$' , dist .Normal (prior_mean , torch .tensor (0.02 , dtype = torch .float64 )))
73
-
74
- # Update the model with the new top layer's location
75
- interpolation_input = interpolation_input_from_structural_frame (geo_model )
76
- interpolation_input .surface_points .sp_coords = torch .index_put (
77
- interpolation_input .surface_points .sp_coords ,
78
- (torch .tensor ([0 ]), torch .tensor ([2 ])),
79
- mu_top
80
- )
81
-
82
- # Compute the geological model
83
- geo_model .solutions = gempy_engine .compute_model (
84
- interpolation_input = interpolation_input ,
85
- options = geo_model .interpolation_options ,
86
- data_descriptor = geo_model .input_data_descriptor ,
87
- geophysics_input = geo_model .geophysics_input ,
88
- )
89
-
90
- # Compute and observe the thickness of the geological layer
91
- simulated_well = geo_model .solutions .octrees_output [0 ].last_output_center .custom_grid_values
92
- thickness = simulated_well .sum ()
93
- pyro .deterministic (r'$\mu_{thickness}$' , thickness .detach ())
94
- y_thickness = pyro .sample (r'$y_{thickness}$' , dist .Normal (thickness , 50 ), obs = y_obs_list )
95
-
96
-
97
-
98
54
# %%
99
55
# Running Prior Sampling and Visualization
100
56
# ----------------------------------------
@@ -112,8 +68,9 @@ def model(y_obs_list):
112
68
import pyro
113
69
import arviz as az
114
70
import matplotlib .pyplot as plt
115
-
116
- prior = Predictive (model , num_samples = 50 )(y_obs_list )
71
+
72
+ from gempy_probability .modules .model_definition .model_examples import model
73
+ prior = Predictive (model , num_samples = 50 )(geo_model , sp_coords_copy , y_obs_list )
117
74
118
75
data = az .from_pyro (prior = prior )
119
76
az .plot_trace (data .prior )
@@ -133,11 +90,11 @@ def model(y_obs_list):
133
90
init_strategy = init_to_mean
134
91
)
135
92
mcmc = MCMC (nuts_kernel , num_samples = 200 , warmup_steps = 50 , disable_validation = False )
136
- mcmc .run (y_obs_list )
93
+ mcmc .run (geo_model , sp_coords_copy , y_obs_list )
137
94
138
95
139
96
posterior_samples = mcmc .get_samples ()
140
- posterior_predictive = Predictive (model , posterior_samples )(y_obs_list )
97
+ posterior_predictive = Predictive (model , posterior_samples )(geo_model , sp_coords_copy , y_obs_list )
141
98
data = az .from_pyro (posterior = mcmc , prior = prior , posterior_predictive = posterior_predictive )
142
99
az .plot_trace (data )
143
100
plt .show ()
0 commit comments