2
2
import gempy_engine
3
3
from gempy .modules .data_manipulation .engine_factory import interpolation_input_from_structural_frame
4
4
5
+ import pyro
6
+ import pyro .distributions as dist
7
+ import torch
8
+
5
9
6
10
def model (geo_model : gempy .core .data .GeoModel , sp_coords_copy , y_obs_list ):
7
11
"""
@@ -10,21 +14,34 @@ def model(geo_model: gempy.core.data.GeoModel, sp_coords_copy, y_obs_list):
10
14
computes the thickness of the geological layer as an observed variable.
11
15
"""
12
16
# Define prior for the top layer's location:
17
+ # region Prior definition
13
18
prior_mean = sp_coords_copy [0 , 2 ]
14
- import pyro
15
- import pyro .distributions as dist
16
- import torch
17
- mu_top = pyro .sample (r'$\mu_{top}$' , dist .Normal (prior_mean , torch .tensor (0.02 , dtype = torch .float64 )))
19
+ normal = dist .Normal (
20
+ loc = prior_mean ,
21
+ scale = torch .tensor (0.02 , dtype = torch .float64 )
22
+ )
23
+
24
+ mu_top = pyro .sample (
25
+ name = r'$\mu_{top}$' ,
26
+ fn = normal
27
+ )
28
+ # endregion
29
+
30
+ # region Prior injection into the gempy model
18
31
19
- # Update the model with the new top layer's location
32
+ # * Update the model with the new top layer's location
20
33
interpolation_input = interpolation_input_from_structural_frame (geo_model )
21
34
interpolation_input .surface_points .sp_coords = torch .index_put (
22
- interpolation_input .surface_points .sp_coords ,
23
- (torch .tensor ([0 ]), torch .tensor ([2 ])),
24
- mu_top
35
+ input = interpolation_input .surface_points .sp_coords ,
36
+ indices = (torch .tensor ([0 ]), torch .tensor ([2 ])),
37
+ values = mu_top
25
38
)
26
39
27
- # Compute the geological model
40
+ # endregion
41
+
42
+ # region Forward model computation
43
+
44
+ # * Compute the geological model
28
45
geo_model .solutions = gempy_engine .compute_model (
29
46
interpolation_input = interpolation_input ,
30
47
options = geo_model .interpolation_options ,
@@ -35,5 +52,15 @@ def model(geo_model: gempy.core.data.GeoModel, sp_coords_copy, y_obs_list):
35
52
# Compute and observe the thickness of the geological layer
36
53
simulated_well = geo_model .solutions .octrees_output [0 ].last_output_center .custom_grid_values
37
54
thickness = simulated_well .sum ()
38
- pyro .deterministic (r'$\mu_{thickness}$' , thickness .detach ())
39
- y_thickness = pyro .sample (r'$y_{thickness}$' , dist .Normal (thickness , 50 ), obs = y_obs_list )
55
+ pyro .deterministic (
56
+ name = r'$\mu_{thickness}$' ,
57
+ value = thickness .detach ()
58
+ )
59
+
60
+ # endregion
61
+
62
+ y_thickness = pyro .sample (
63
+ name = r'$y_{thickness}$' ,
64
+ fn = dist .Normal (thickness , 50 ),
65
+ obs = y_obs_list
66
+ )
0 commit comments