-
Notifications
You must be signed in to change notification settings - Fork 104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Test obs_data_allocE #2530
Test obs_data_allocE #2530
Conversation
libres/lib/enkf/obs_data.cpp
Outdated
@@ -274,8 +273,8 @@ static void obs_block_initR(const obs_block_type *obs_block, matrix_type *R, | |||
matrix_free(obs_block->error_covar); | |||
} | |||
|
|||
static void obs_block_initE(const obs_block_type *obs_block, matrix_type *E, | |||
const double *pert_var, int *__obs_offset) { | |||
void obs_block_initE(const obs_block_type *obs_block, matrix_type *E, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The details of the obs_block
was originally meant to be an internal implementation detail of obs_data
- I would recommend doing the testing fully through the obs_data
api.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean that I should not test the obs_block_initE
function directly, but instead just test obs_data_allocE
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would do that yes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense, thanks!
I've pushed a fix.
adcbef2
to
3d38575
Compare
Codecov Report
@@ Coverage Diff @@
## main #2530 +/- ##
==========================================
+ Coverage 64.33% 64.37% +0.04%
==========================================
Files 645 645
Lines 54318 54323 +5
Branches 4538 4538
==========================================
+ Hits 34947 34973 +26
+ Misses 18001 17967 -34
- Partials 1370 1383 +13
Continue to review full report at Codecov.
|
3679519
to
56d2690
Compare
An observation: The differences btw linux and mac in this example is surprisingly symmetric. Could it be caused by some indexing-issue instead of actual difference in sequences? |
Looks like it's because of the way the elements of the matrix Each element of E is multiplied by a factor. Does that make sense? Here are the admittedly poorly formatted numbers that go into the calculation of Linux: E[i, j]: -0.937757 factor: 0.319912 E[i, j] * factor: -0.3 MacOS: E[i, j]: 0.914876 factor: 0.327913 E[i, j] * factor: 0.3 |
0c71514
to
2338873
Compare
The "symmetry" is a consequence of centering the matrix with only two realizations. Here's the first part of the calculations done in nens = 2 # Size of ensemble
nobs = 5 # Number of observations
E = rng.normal(0, 1, size=(nobs, nens))
E - E.mean(axis=1).reshape(nobs, 1) This results in: array([[-0.14346748, 0.14346748], This "symmetry" goes away when using more than two realizations, so I've updated my tests. |
2338873
to
3a0bf8d
Compare
For completeness, here's the rest of the calculation that produces the same results as were used in the test before increasing the number of realizations: I will put this in the documentation of the test. E = rng.normal(0, 1, size=(5, 2))
nens = E.shape[1]
nobs = E.shape[0]
E_centered = E - E.mean(axis=1).reshape(nobs, 1)
# Estimate of variance
pert_var = (E_centered * E_centered).sum(axis=1)
obs_block_std = np.array([0.3, 0.5, 0.3, 0.5, 0.6])
factor = obs_block_std.reshape(nobs, 1) * np.sqrt(
nens / pert_var.reshape(nobs, 1)
)
E_final = E_centered * factor
E_final array([[ 0.3, -0.3], |
3a0bf8d
to
e0749e4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apart for the nits, this LGTM.
e0749e4
to
1c222b2
Compare
Issue
Resolves #2529
Approach
Short description of the approach