Skip to content

Commit

Permalink
Transpose the input to get_nr_primary_components in misfit preprocessor
Browse files Browse the repository at this point in the history
- Fixes bug that crept in when moving from Semeio.
- The singular values are invariant to transposition, however the
centering of the matrix depends upon the matrix orientation.
- np.mean(x, axis=0) will calculate mean for each column, and so we need
to ensure that the input is of dim (nr_realizations, nr_observations).
  • Loading branch information
larsevj committed Feb 3, 2025
1 parent ec3894d commit 805ed26
Show file tree
Hide file tree
Showing 4 changed files with 614 additions and 612 deletions.
6 changes: 4 additions & 2 deletions src/ert/analysis/misfit_preprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ def get_nr_primary_components(
"""
Calculate the number of principal components needed to achieve a cumulative
variance less than a specified threshold using Singular Value Decomposition (SVD).
responses should be on form (n_realizations, n_observations)
"""
data_matrix = responses - responses.mean(axis=0)
_, singulars, _ = np.linalg.svd(data_matrix.astype(float), full_matrices=False)
Expand Down Expand Up @@ -139,7 +141,7 @@ def main(
# each other
return scale_factors, np.ones(len(obs_errors), dtype=int), nr_components

prim_components = get_nr_primary_components(scaled_responses, threshold=0.95)
prim_components = get_nr_primary_components(scaled_responses.T, threshold=0.95)

clusters = cluster_responses(scaled_responses.T, nr_clusters=prim_components)

Expand All @@ -150,7 +152,7 @@ def main(
components = 1
else:
components = get_nr_primary_components(
scaled_responses[index], threshold=0.95
scaled_responses[index].T, threshold=0.95
)
components = 1 if components == 0 else components
scale_factor = get_scaling_factor(len(index), components)
Expand Down
Loading

0 comments on commit 805ed26

Please sign in to comment.