From 942d6e2fb613b93c984010510b5ab5f4c600e951 Mon Sep 17 00:00:00 2001 From: Feda Curic Date: Wed, 12 Apr 2023 14:04:41 +0200 Subject: [PATCH] Drop row with all False to avoid grp.sum() > 0 --- src/ert/analysis/_es_update.py | 49 +++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/src/ert/analysis/_es_update.py b/src/ert/analysis/_es_update.py index 4d72c885246..cdabe05206a 100644 --- a/src/ert/analysis/_es_update.py +++ b/src/ert/analysis/_es_update.py @@ -450,33 +450,38 @@ def analysis_ES( ) c_bool = c_AY > correlation_threshold # Some parameters might be significantly correlated to the exact same - # responses, making up what we cann a parameter group. + # responses, making up what we call a `parameter group``. # We want to call the update only once per such parameter group # to speed up computation. param_groups = np.unique(c_bool, axis=0) + # Drop the parameter group that does not correlate to any responses. + row_with_all_false = np.all(param_groups == False, axis=1) + param_groups = param_groups[~row_with_all_false] + for grp in param_groups: - if grp.sum() > 0: - param_idx = np.where((c_bool == grp).all(axis=1))[0] - # A_chunk = A[param_batch_idx, :][param_idx, :] - X_chunk = temp_storage[parameter.name][param_batch_idx, :][ - param_idx, : - ] - Y_chunk = Y[grp, :] - observation_errors_loc = observation_errors[grp] - observation_values_loc = observation_values[grp] - smoother.fit( - Y_chunk, - observation_errors_loc, - observation_values_loc, - noise=noise[grp], - truncation=truncation, - inversion=ies.InversionType(module.inversion), - param_ensemble=param_ensemble, - ) - temp_storage[parameter.name][ - param_batch_idx[param_idx], : - ] = smoother.update(X_chunk) + # Find the rows matching the parameter group + matching_rows = np.all(c_bool == grp, axis=1) + # Get the indices of the matching rows + row_indices = np.where(matching_rows)[0] + X_chunk = temp_storage[parameter.name][param_batch_idx, :][ + row_indices, : + ] + Y_chunk = Y[grp, :] + observation_errors_loc = observation_errors[grp] + observation_values_loc = observation_values[grp] + smoother.fit( + Y_chunk, + observation_errors_loc, + observation_values_loc, + noise=noise[grp], + truncation=truncation, + inversion=ies.InversionType(module.inversion), + param_ensemble=param_ensemble, + ) + temp_storage[parameter.name][ + param_batch_idx[row_indices], : + ] = smoother.update(X_chunk) else: for parameter in update_step.parameters: smoother.fit(