<jupyter_start><jupyter_text>Lake model continuedIn the previous week you used the lake problem as a means of getting aquinted with the workbench. In this assignment we will continue with the lake problem, focussing explicitly on using it for open exploration. You can use the second part of [this tutoria]https://emaworkbench.readthedocs.io/en/latest/indepth_tutorial/open-exploration.html) for help.**It is paramount that you are using the lake problem with 100 decision variables, rather than the one found on the website with the seperate anthropogenic release decision** Apply sensitivity analysisThere is substantial support in the ema_workbench for global sensitivity. For this, the workbench relies on [SALib](https://salib.readthedocs.io/en/latest/) and feature scoring which is a machine learning alternative for global sensitivity analysis. 1. As a start, generate a release policy without any release *(hint: use a Policy instance)*2. use sobol sampling with the no release policy, and set n to 10.0003. calculate sobol indices for max_P and reliability based on 10, 100, 1000, and 10.000 experiments. *(hint: sobol is a deterministic sequence, so you can slice results from the data generated in stap 2)*<jupyter_code>from lakemodel_function import lake_problem

from ema_workbench import (Model, RealParameter, ScalarOutcome, Constant)

#instantiate the model
lake_model = Model('lakeproblem', function=lake_problem)
lake_model.time_horizon = 100 # used to specify the number of timesteps

#specify uncertainties
lake_model.uncertainties = [RealParameter('mean', 0.01, 0.05),
                            RealParameter('stdev', 0.001, 0.005),
                            RealParameter('b', 0.1, 0.45),
                            RealParameter('q', 2.0, 4.5),
                            RealParameter('delta', 0.93, 0.99)]

# set levers, one for each time step
lake_model.levers = [RealParameter(str(i), 0, 0.1) for i in 
                     range(lake_model.time_horizon)] # we use time_horizon here

#specify outcomes 
lake_model.outcomes = [ScalarOutcome('max_P'),
                       ScalarOutcome('utility'),
                       ScalarOutcome('inertia'),
                       ScalarOutcome('reliability')]
from ema_workbench import MultiprocessingEvaluator, ema_logging, Policy
from ema_workbench.em_framework.evaluators import SOBOL

ema_logging.log_to_stderr(ema_logging.INFO)

no_release = Policy("norelease", **{l.name:0 for l in lake_model.levers})

n_scenarios = int(1e4)

with MultiprocessingEvaluator(lake_model) as evaluator:
    experiments, outcomes = evaluator.perform_experiments(n_scenarios, policies=[no_release],
                                                          uncertainty_sampling=SOBOL)


from SALib.analyze import sobol
from ema_workbench.em_framework import get_SALib_problem

ooi = 'max_P'
data = outcomes[ooi]
problem = get_SALib_problem(lake_model.uncertainties)

SI = []
for i in [1e1, 1e2, 1e3, 1e4]:
    i = int(i) * (2*len(lake_model.uncertainties) + 2) 
    
    y = data[0:i]
    si = sobol.analyze(problem, y)
    SI.append(si)

def plot_si(Si):

    Si_filter = {k:Si[k] for k in ['ST','ST_conf','S1','S1_conf']}
    Si_df = pd.DataFrame(Si_filter, index=problem['names'])

    sns.set_style('white')
    fig, ax = plt.subplots(1)

    indices = Si_df[['S1','ST']]
    err = Si_df[['S1_conf','ST_conf']]

    indices.plot.bar(yerr=err.values.T,ax=ax)
    fig.set_size_inches(8,6)
    fig.subplots_adjust(bottom=0.3)


for Si in SI:
    plot_si(Si)
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09671071127354512, 'fraction_numerical': 0.023615406241214505, 'mean_word_length': 3.620779220779221, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '31624', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1204, 'n_tokens_neox': 1093, 'n_words': 328, 'path': 'assignment 3 - model answer.ipynb', 'repo_name': 'quaquel/ema_tutorial', 'size': '3557'}