def plot_param_matrix( plotter: StreamlitPlotter, calib_dir_path: str, mcmc_tables: List[pd.DataFrame], mcmc_params: List[pd.DataFrame], targets: dict, app_name: str, region: str, show_ticks=False, ): parameters = mcmc_params[0]["name"].unique().tolist() chain_length = find_shortest_chain_length(mcmc_tables) burn_in = st.sidebar.slider("Burn in", 0, chain_length, 0) label_font_size = st.sidebar.slider("Label font size", 1, 15, 8) label_chars = st.sidebar.slider("Label characters", 1, 10, 2) bins = st.sidebar.slider("Bins", 4, 50, 20) style = st.sidebar.selectbox("Style", ["Shade", "Scatter", "KDE"]) dpi_request = st.sidebar.slider("DPI", 50, 2000, 300) plots.calibration.plots.plot_param_vs_param( plotter, mcmc_params, parameters, burn_in, style, bins, label_font_size, label_chars, dpi_request, show_ticks=show_ticks, ) st.write(parameters)
def plot_posterior( plotter: StreamlitPlotter, calib_dir_path: str, mcmc_tables: List[pd.DataFrame], mcmc_params: List[pd.DataFrame], targets: dict, app_name: str, region: str, ): chosen_param = selectors.parameter(mcmc_params[0]) chain_length = find_shortest_chain_length(mcmc_tables) burn_in = st.sidebar.slider("Burn in", 0, chain_length, 0) num_bins = st.sidebar.slider("Number of bins", 1, 50, 16) prior = None priors = [] try: priors_path = os.path.join(calib_dir_path, "priors-1.yml") with open(priors_path) as file: priors = yaml.load(file, Loader=yaml.FullLoader) except: st.write("Check if priors-1.yml exists in the output folder") for i, prior in enumerate(priors): if prior["param_name"] == chosen_param: prior = priors[i] break plots.calibration.plots.plot_posterior(plotter, mcmc_params, mcmc_tables, burn_in, chosen_param, num_bins, prior)
def plot_loglike_vs_all_params( plotter: StreamlitPlotter, calib_dir_path: str, mcmc_tables: List[pd.DataFrame], mcmc_params: List[pd.DataFrame], targets: dict, app_name: str, region: str, ): ( title_font_size, label_font_size, dpi_request, capitalise_first_letter, ) = selectors.create_standard_plotting_sidebar() chain_length = find_shortest_chain_length(mcmc_tables) burn_in = st.sidebar.slider("Burn in", 0, chain_length, 0) plots.calibration.plots.plot_all_params_vs_loglike( plotter, mcmc_tables, mcmc_params, burn_in, title_font_size, label_font_size, capitalise_first_letter, dpi_request, )
def plot_calibration_fit( plotter: StreamlitPlotter, calib_dir_path: str, mcmc_tables: List[pd.DataFrame], mcmc_params: List[pd.DataFrame], targets: dict, app_name: str, region: str, ): # Set up interface available_outputs = [o["output_key"] for o in targets.values()] chain_length = find_shortest_chain_length(mcmc_tables) burn_in = st.sidebar.slider( "Burn in (select 0 for default behaviour of discarding first half)", 0, chain_length, 0) chosen_output = st.sidebar.selectbox("Select calibration target", available_outputs) is_logscale = st.sidebar.checkbox("Log scale") # Get data for plotting outputs = get_uncertainty_data(calib_dir_path, mcmc_tables, chosen_output, burn_in) # Call main plotting function plots.calibration.plots.plot_calibration_fit(plotter, chosen_output, outputs, targets, is_logscale)
def plot_mcmc_parameter_trace( plotter: StreamlitPlotter, calib_dir_path: str, mcmc_tables: List[pd.DataFrame], mcmc_params: List[pd.DataFrame], targets: dict, app_name: str, region: str, ): chosen_param = selectors.parameter(mcmc_params[0]) chain_length = find_shortest_chain_length(mcmc_tables) burn_in = st.sidebar.slider("Burn in", 0, chain_length, 0) plots.calibration.plots.plot_mcmc_parameter_trace(plotter, mcmc_params, burn_in, chosen_param)
def plot_all_posteriors( plotter: StreamlitPlotter, calib_dir_path: str, mcmc_tables: List[pd.DataFrame], mcmc_params: List[pd.DataFrame], targets: dict, app_name: str, region: str, ): priors = [] try: priors_path = os.path.join(calib_dir_path, "priors-1.yml") with open(priors_path) as file: priors = yaml.load(file, Loader=yaml.FullLoader) except: st.write("Check if priors-1.yml exists in the output folder") ( title_font_size, label_font_size, dpi_request, capitalise_first_letter, ) = selectors.create_standard_plotting_sidebar() chain_length = find_shortest_chain_length(mcmc_tables) burn_in = st.sidebar.slider("Burn in", 0, chain_length, 0) num_bins = st.sidebar.slider("Number of bins", 1, 50, 16) sig_figs = st.sidebar.slider("Significant figures", 0, 6, 3) plots.calibration.plots.plot_multiple_posteriors( plotter, mcmc_params, mcmc_tables, burn_in, num_bins, title_font_size, label_font_size, capitalise_first_letter, dpi_request, priors, parameters=get_epi_params(mcmc_params), ) write_mcmc_centiles(mcmc_params, mcmc_tables, burn_in, sig_figs, [2.5, 50, 97.5])
def plot_multi_output_fit( plotter: StreamlitPlotter, calib_dir_path: str, mcmc_tables: List[pd.DataFrame], mcmc_params: List[pd.DataFrame], targets: dict, app_name: str, region: str, ): # Set up interface available_outputs = [o["output_key"] for o in targets.values()] ( title_font_size, label_font_size, dpi_request, capitalise_first_letter, ) = selectors.create_standard_plotting_sidebar() is_logscale = st.sidebar.checkbox("Log scale") chain_length = find_shortest_chain_length(mcmc_tables) burn_in = st.sidebar.slider( "Burn in (select 0 for default behaviour of discarding first half)", 0, chain_length, 0) # Get data for plotting outputs = { output: get_uncertainty_data(calib_dir_path, mcmc_tables, output, burn_in) for output in available_outputs } # Call main plotting function plots.calibration.plots.plot_multi_fit( plotter, available_outputs, outputs, targets, is_logscale, title_font_size, label_font_size, dpi_request, capitalise_first_letter, )
def plot_acceptance_ratio( plotter: StreamlitPlotter, calib_dir_path: str, mcmc_tables: List[pd.DataFrame], mcmc_params: List[pd.DataFrame], targets: dict, app_name: str, region: str, ): label_font_size = st.sidebar.slider("Label font size", 1, 15, 10) burn_in = st.sidebar.slider("Burn in", 0, find_shortest_chain_length(mcmc_tables), 0) dpi_request = st.sidebar.slider("DPI", 50, 2000, 300) plots.calibration.plots.plot_acceptance_ratio( plotter, mcmc_tables, burn_in, label_font_size=label_font_size, dpi_request=dpi_request)