In [1]:
# comment out this import if you would like to see warnings
import warnings; warnings.filterwarnings('ignore')
import copy
from bokeh.plotting import show, output_notebook
import os.path as op
import os
import savvy.data_processing as dp
import savvy.interactive_plots as ip
from savvy.plotting import make_plot, make_second_order_heatmap
import savvy.network_tools as nt
output_notebook()
# read the sensitivity analysis files from sample data loaded on github:
datapath = op.join(os.getcwd(),'savvy/sample_data_files/')
sa_dict = dp.get_sa_data(datapath)
Pass a dictionary (generated with dp.get_sa_data()
) to this function to visualize the first and total order sensitivity indices.
Tweak the plots you would like to see by specifying the following arguments:
When ready to plot, click "Run plot_all_outputs". Hover over the plotted bars to get more information.
In [2]:
# Plot the first and total order indices for all files in "datapath"
ip.interact_with_plot_all_outputs(sa_dict)
In [11]:
# If you do not want to use the widget interactivity, but still want the ability
# to explore the outputs on tabs, you can use this function and manually pass
# all the arguments to makeplot
# ip.plot_all_outputs(sa_dict, min_val=0.01, top=30)
Pass a dictionary (generated with dp.get_sa_data()) to this function to visualize the second order sensitivities for interacting parameters.
Note that this plot is computationally expensive if you choose a large value for top
. If you are choosing a large top
then at least set mirror=False
to ease the computational burden.
Hover over the resulting plot for more information.
In [5]:
# Plot the second order plots with tabs for all the options
ip.plot_all_second_order(sa_dict, top=5, mirror=True)
Out[5]:
For a given output measure, plot a graph whose vertices are the first ('S1') or total ('ST') order indices and the edges are the second order interaction indices.
Choose the number of vertices to include in the plot (top
), and the minimum value of their sensitivities (min_sens
). You can also specify the minimim value of 'S2' from second order interactions (edge_cutoff
).
Change inline=True
to False
and the plot will display in a new window where you can interact with it.
NOTE: build_graph()
changes the structure of the dataframes it acts on. This causes problems if you re-run any of the other functions that assume standard SALib structure for those dataframes. To address this issue we just copy sa_dict to a new object to use here.
In [5]:
sa_dict_net = copy.deepcopy(sa_dict)
g = nt.build_graph(sa_dict_net['sample-output1'], sens='ST', top=10, min_sens=0.01,
edge_cutoff=0.0)
nt.plot_network_circle(g, inline=True, scale=200)
# test = nt.plot_network_random(g, scale=200)
The parameters identified here have sensitivity indices (and confidence intervals) of exactly 0.0, so they do not contribute anything to the variance of any of the model outputs you chose to analyze. This doesn't necessarily indicate these parameters can be removed from your model, only that they are unimportant for any of the measures you've chosen to examine.
In [7]:
dp.find_unimportant_params('S1', 'savvy/sample_data_files/')
dp.find_unimportant_params('ST', 'savvy/sample_data_files/');
In [8]:
# demo of making the 1st and total order sensitivity index plot
df = sa_dict['sample-output1'][0]
p = make_plot(df, lgaxis=True, minvalues=0.0, top=30, stacked=True,
errorbar=True, showS1=True, showST=True)
show(p)
Out[8]:
In [9]:
# demo of the basic second order sensitivity index heat map
df2 = sa_dict['sample-output1'][1]
incl_lst = ['Tmax', 'Carbon', 'Hydrogen', 'k38', 'k48', 'k34']
s = make_second_order_heatmap(df2, top=3, mirror=True, name='demo',
include=incl_lst)
show(s)
Out[9]:
In [ ]: