Skip to content
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

Minimal model updating case #172

Merged
merged 1 commit into from
Nov 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions test-data/local/poly_example/POLY_EVAL
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
EXECUTABLE poly_eval.py
55 changes: 55 additions & 0 deletions test-data/local/poly_example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
## Polynomial curve fitting - A minimal model updating case
A display of a truly minimal model updating case. It is done with a second
degree polynomial as the _true reality_. The model is `ax^2 + bx + c` where
`a`, `b` and `c` are the parameters.

### Observed data
The observed data was generated with the following _Python_ code:
```
def p(x):
return 0.5*x**2 + x + 3

[(p(x)+random.gauss(0, 0.25*x**2+0.1), 0.25*x**2+0.1) for x in [0, 2, 4, 6, 8]]
```

This gives us observations (both a value and an uncertainty) for even `x` less
than 10. These values appear in `poly_obs_data.txt`. Finally, these values are
represented as an observation in `observations`. Here we give the data a name.
And we specify that the values that should be used from the `forward_model` is only
the even ones (the `forward model` spits out the image of the polynomial on the
range `[0, 9]`). It also specifies that the time step to consider is `0`
(`RESTART`). We do not really have a time concept in this setup and hence we
only use `0` as a dummy value. We could of course have considered the values
feed to the polynomial as time; but that is left as an exercise for the reader.

### Parameters
As mentioned above `a`, `b` and `c` forms the parameters of the model `ax^2 + bx + c`.
They are all specified to be uniformly distributed over ranges in
`coeff_priors` and are sampled by `GEN_KW` and dumped to the forward model
following the `json`-template in `coeff.tmpl`.

### Forward model
After the parameters are dumped to the runpath, _forward model_'s are launched
for each of the realizations. The forward model consists of a single script
described in `poly_eval.py`, that loads the dumped parameters and outputs the
values of the polynomial (given the parameters) for integer `x in [0, 10]` to the
file `poly_0.out`.

The very minimal job description file `POLY_EVAL` just points to the script.

### Loading data
The configuration specifies a `GEN_DATA` that expects there to be a result file
`poly_%d.out` for report step `0`. In other words it expects to load data from
`poly_0.out`, the exact file that the forward model produces.

### Model update
Then the loaded data is compared to the observed data and the parameters are
updated accordingly.

### Time
Although we don't really have a clear concept of time in this case _ERT_
expects us to have so. Since we have specified that all of our data is for time
step `0`, we had to create an artificial time map `time_map` that specifies
that the very first and only report step corresponds to `1/10/2006`. This could
be any date, so we put it to the date of the first commit of the
`ensembles/ert` repository on _Github_.
5 changes: 5 additions & 0 deletions test-data/local/poly_example/coeff.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"a": <COEFF_A>,
"b": <COEFF_B>,
"c": <COEFF_C>
}
3 changes: 3 additions & 0 deletions test-data/local/poly_example/coeff_priors
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
COEFF_A UNIFORM 0 1
COEFF_B UNIFORM 0 2
COEFF_C UNIFORM 0 5
6 changes: 6 additions & 0 deletions test-data/local/poly_example/observations
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
GENERAL_OBSERVATION POLY_OBS {
DATA = POLY_RES;
INDEX_LIST = 0,2,4,6,8;
RESTART = 0;
OBS_FILE = poly_obs_data.txt;
};
17 changes: 17 additions & 0 deletions test-data/local/poly_example/poly.ert
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
JOBNAME poly_%d

QUEUE_SYSTEM LOCAL
QUEUE_OPTION LOCAL MAX_RUNNING 50

RUNPATH poly_out/real_%d/iter_%d

OBS_CONFIG observations
TIME_MAP time_map

NUM_REALIZATIONS 100

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
16 changes: 16 additions & 0 deletions test-data/local/poly_example/poly_eval.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env python

import json

def _load_coeffs(filename):
with open(filename) as f:
return json.load(f)

def _evaluate(coeffs, x):
return coeffs['a']*x**2 + coeffs['b']*x + coeffs['c']

if __name__ == '__main__':
coeffs = _load_coeffs('coeffs.json')
output = [_evaluate(coeffs, x) for x in range(10)]
with open('poly_0.out', 'w') as f:
f.write('\n'.join(map(str, output)))
5 changes: 5 additions & 0 deletions test-data/local/poly_example/poly_obs_data.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
2.8532509308 0.1
7.20311703432 1.1
21.3864899107 4.1
31.5145559347 9.1
53.5676660405 16.1
1 change: 1 addition & 0 deletions test-data/local/poly_example/time_map
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1/10/2006