Skip to content

Commit 53853d1

Browse files
committed
[BUG] Fixed numpy implementation of activator
1 parent f311a33 commit 53853d1

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed

gempy_engine/modules/activator/activator_interface.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,11 @@ def _final_faults_segmentation(Z, edges, sigmoid_slope):
177177
def _lith_segmentation(Z, edges, ids, sigmoid_slope):
178178
# 1) per-edge temperatures τ_k = |Δ_k|/(4·m)
179179
jumps = np.abs(ids[1:] - ids[:-1]) # shape (K-1,)
180-
tau_k = jumps / (4 * sigmoid_slope) # shape (K-1,)
180+
tau_k = jumps / float(4 * sigmoid_slope) # shape (K-1,)
181181
# 2) first bin (-∞, e1) via σ((e1 - Z)/τ₁)
182182
first = _sigmoid(
183-
scalar_field=Z,
184-
edges=edges[0],
183+
scalar_field=-Z,
184+
edges=-edges[0],
185185
tau_k=tau_k[0]
186186
) # shape (...,)
187187
# 3) last bin [e_{K-1}, ∞) via σ((Z - e_{K-1})/τ_{K-1})
@@ -213,4 +213,4 @@ def _lith_segmentation(Z, edges, ids, sigmoid_slope):
213213

214214

215215
def _sigmoid(scalar_field, edges, tau_k):
216-
return 1.0 / (1.0 + np.exp((scalar_field - edges) / tau_k))
216+
return 1.0 / (1.0 + np.exp(-(scalar_field - edges) / tau_k))

tests/test_common/test_modules/test_activator_fns.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,46 @@ def test_activator_3_layers_segmentation_function(simple_model_3_layers, simple_
5656
_plot_continious(grid, ids_block, interpolation_input)
5757

5858

59+
def test_activator_3_layers_segmentation_function_II(simple_model_3_layers, simple_grid_3d_more_points_grid):
60+
interpolation_input = simple_model_3_layers[0]
61+
options = simple_model_3_layers[1]
62+
data_shape = simple_model_3_layers[2].tensors_structure
63+
grid = dataclasses.replace(simple_grid_3d_more_points_grid)
64+
interpolation_input.set_temp_grid(grid)
65+
66+
interp_input: SolverInput = input_preprocess(data_shape, interpolation_input)
67+
weights = _solve_interpolation(interp_input, options.kernel_options)
68+
69+
exported_fields = _evaluate_sys_eq(interp_input, weights, options)
70+
exported_fields.set_structure_values(
71+
reference_sp_position=data_shape.reference_sp_position,
72+
slice_feature=interpolation_input.slice_feature,
73+
grid_size=interpolation_input.grid.len_all_grids)
74+
75+
Z_x: np.ndarray = exported_fields.scalar_field
76+
sasp = exported_fields.scalar_field_at_surface_points
77+
ids = np.array([1, 2, 3, 4])
78+
79+
print(Z_x, Z_x.shape[0])
80+
print(sasp)
81+
82+
BackendTensor.change_backend_gempy(AvailableBackends.numpy)
83+
ids_block = activate_formation_block(
84+
exported_fields=exported_fields,
85+
ids=ids,
86+
sigmoid_slope=500 * 4
87+
)[0, :-7]
88+
89+
BackendTensor.change_backend_gempy(AvailableBackends.numpy)
90+
if BackendTensor.engine_backend == AvailableBackends.PYTORCH:
91+
ids_block = ids_block.detach().numpy()
92+
Z_x = Z_x.detach().numpy()
93+
interpolation_input.surface_points.sp_coords = interpolation_input.surface_points.sp_coords.detach().numpy()
94+
95+
if plot:
96+
_plot_continious(grid, ids_block, interpolation_input)
97+
98+
5999
def _plot_continious(grid, ids_block, interpolation_input):
60100
block__ = ids_block[grid.dense_grid_slice]
61101
unique = np.unique(block__)

0 commit comments

Comments
 (0)