Repository navigation
Expand file tree
/
Copy pathexample_lake_model.py
More file actions
64 lines (51 loc) · 1.76 KB
/
Copy pathexample_lake_model.py
File metadata and controls
64 lines (51 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
"""An example of the lake problem using the ema workbench.
The model itself is adapted from the Rhodium example by Dave Hadka,
see https://gist.github.com/dhadka/a8d7095c98130d8f73bc
"""
from lake_models import lake_problem_intertemporal
from ema_workbench import (
Constant,
Model,
MultiprocessingEvaluator,
RealParameter,
ScalarOutcome,
ema_logging,
)
from ema_workbench.em_framework.evaluators import Samplers
if __name__ == "__main__":
ema_logging.log_to_stderr(ema_logging.INFO)
# instantiate the model
lake_model = Model("lake_problem", function=lake_problem_intertemporal)
lake_model.time_horizon = 100
# specify uncertainties
lake_model.uncertainties = [
RealParameter("b", 0.1, 0.45),
RealParameter("q", 2.0, 4.5),
RealParameter("mean", 0.01, 0.05),
RealParameter("stdev", 0.001, 0.005),
RealParameter("delta", 0.93, 0.99),
]
# set levers, one for each time step
lake_model.levers = [
RealParameter("decisions", 0, 0.1, shape=(100,)),
]
# specify outcomes
lake_model.outcomes = [
ScalarOutcome("max_p"),
ScalarOutcome("utility"),
ScalarOutcome("inertia"),
ScalarOutcome("reliability"),
]
# override some of the defaults of the model
lake_model.constants = [Constant("alpha", 0.41), Constant("n_samples", 150)]
# generate some random policies by sampling over levers
n_scenarios = 100
n_policies = 4
with MultiprocessingEvaluator(lake_model) as evaluator:
res = evaluator.perform_experiments(
n_scenarios,
n_policies,
lever_sampling=Samplers.MC,
lever_sampling_kwargs={"rng": 42},
uncertainty_sampling_kwargs={"rng": 42},
)