Skip to content

Commit

Permalink
Add temporary test
Browse files Browse the repository at this point in the history
  • Loading branch information
dafeda authored and Feda Curic committed Apr 27, 2023
1 parent 60c0459 commit dec3eea
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/ert/analysis/_es_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ def analysis_ES(
Sigma_Y = np.diag(np.sqrt(np.diag(C_YY)))
batch_size = 1000
for parameter in update_step.parameters:
num_params = len(parameter)
num_params = temp_storage[parameter.name].shape[0]
correlation_threshold = module.localization_correlation_threshold(
ensemble_size
)
Expand All @@ -438,14 +438,9 @@ def analysis_ES(
for param_batch_idx in tqdm(batches):
X_local = temp_storage[parameter.name][param_batch_idx, :]
A = X_local - X_local.mean(axis=1, keepdims=True)
# A_prime = A[param_batch_idx, :] - A[param_batch_idx, :].mean(
# axis=1, keepdims=True
# )
# C_AA = A_prime @ A_prime.T / (ensemble_size - 1)
C_AA = A @ A.T / (ensemble_size - 1)

# State-measurement covariance matrix
# C_AY = A_prime @ Y_prime.T / (ensemble_size - 1)
C_AY = A @ Y_prime.T / (ensemble_size - 1)
Sigma_A = np.diag(np.sqrt(np.diag(C_AA)))

Expand All @@ -454,6 +449,10 @@ def analysis_ES(
np.linalg.inv(Sigma_A) @ C_AY @ np.linalg.inv(Sigma_Y)
)
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.
# We want to call the update only once per such parameter group
# to speed up computation.
param_groups = np.unique(c_bool, axis=0)

for grp in param_groups:
Expand All @@ -475,10 +474,9 @@ def analysis_ES(
inversion=ies.InversionType(module.inversion),
param_ensemble=param_ensemble,
)
# A[param_batch_idx[param_idx], :] = smoother.update(A_chunk)
temp_storage[parameter.name][
param_batch_idx[param_idx], :
] = smoother.udpate(X_chunk)
] = smoother.update(X_chunk)
else:
for parameter in update_step.parameters:
smoother.fit(
Expand Down
22 changes: 22 additions & 0 deletions test-data/poly_example/poly_loc.ert
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
JOBNAME poly_%d

RANDOM_SEED 1234

QUEUE_SYSTEM LOCAL
QUEUE_OPTION LOCAL MAX_RUNNING 50

RUNPATH runpath/es_loc/realization-<IENS>/iter-<ITER>

ANALYSIS_SET_VAR STD_ENKF LOCALIZATION True

OBS_CONFIG observations
TIME_MAP time_map

NUM_REALIZATIONS 100
MIN_REALIZATIONS 1

GEN_KW COEFFS coeff.tmpl coeffs.json coeff_priors
GEN_DATA POLY_RES RESULT_FILE:poly_%d.out REPORT_STEPS:0 INPUT_FORMAT:ASCII

INSTALL_JOB poly_eval POLY_EVAL
SIMULATION_JOB poly_eval
23 changes: 23 additions & 0 deletions test-data/poly_example/poly_loc_1.ert
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
JOBNAME poly_%d

RANDOM_SEED 1234

QUEUE_SYSTEM LOCAL
QUEUE_OPTION LOCAL MAX_RUNNING 50

RUNPATH runpath/es_loc_1/realization-<IENS>/iter-<ITER>

ANALYSIS_SET_VAR STD_ENKF LOCALIZATION True
ANALYSIS_SET_VAR STD_ENKF LOCALIZATION_CORRELATION_THRESHOLD 1.0

OBS_CONFIG observations
TIME_MAP time_map

NUM_REALIZATIONS 100
MIN_REALIZATIONS 1

GEN_KW COEFFS coeff.tmpl coeffs.json coeff_priors
GEN_DATA POLY_RES RESULT_FILE:poly_%d.out REPORT_STEPS:0 INPUT_FORMAT:ASCII

INSTALL_JOB poly_eval POLY_EVAL
SIMULATION_JOB poly_eval
20 changes: 20 additions & 0 deletions test-data/poly_example/poly_no_loc.ert
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
JOBNAME poly_%d

RANDOM_SEED 1234

QUEUE_SYSTEM LOCAL
QUEUE_OPTION LOCAL MAX_RUNNING 50

RUNPATH runpath/es_no_loc/realization-<IENS>/iter-<ITER>

OBS_CONFIG observations
TIME_MAP time_map

NUM_REALIZATIONS 100
MIN_REALIZATIONS 1

GEN_KW COEFFS coeff.tmpl coeffs.json coeff_priors
GEN_DATA POLY_RES RESULT_FILE:poly_%d.out REPORT_STEPS:0 INPUT_FORMAT:ASCII

INSTALL_JOB poly_eval POLY_EVAL
SIMULATION_JOB poly_eval
23 changes: 23 additions & 0 deletions test-data/poly_example/poly_zero_loc.ert
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
JOBNAME poly_%d

RANDOM_SEED 1234

QUEUE_SYSTEM LOCAL
QUEUE_OPTION LOCAL MAX_RUNNING 50

RUNPATH runpath/es_zero_loc/realization-<IENS>/iter-<ITER>

ANALYSIS_SET_VAR STD_ENKF LOCALIZATION True
ANALYSIS_SET_VAR STD_ENKF LOCALIZATION_CORRELATION_THRESHOLD 0.0

OBS_CONFIG observations
TIME_MAP time_map

NUM_REALIZATIONS 100
MIN_REALIZATIONS 1

GEN_KW COEFFS coeff.tmpl coeffs.json coeff_priors
GEN_DATA POLY_RES RESULT_FILE:poly_%d.out REPORT_STEPS:0 INPUT_FORMAT:ASCII

INSTALL_JOB poly_eval POLY_EVAL
SIMULATION_JOB poly_eval
9 changes: 9 additions & 0 deletions test-data/poly_example/test_localization.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

ert ensemble_smoother poly_no_loc.ert --target ES_no_loc

ert ensemble_smoother poly_zero_loc.ert --target ES_zero_loc

ert ensemble_smoother poly_loc.ert --target ES_loc

ert ensemble_smoother poly_loc_1.ert --target ES_loc_1

0 comments on commit dec3eea

Please sign in to comment.