<jupyter_start><jupyter_text>Data plots This example illustrates data plotting for summary statistics of observed vs. simulated data. This can be used for easy assessment of how good we can fit the data.Let’s start to import the necessary classes. We also set up matplotlib and we’re going to use numpy and pandas as well.<jupyter_code>from pyabc.visualization import plot_data
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt<jupyter_output>/home/yannik/anaconda3/lib/python3.7/site-packages/distributed/config.py:20: YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details.
  defaults = yaml.load(f)<jupyter_text>Define summary statistics First, we will define some arbitrary summary statistics to be used in this example. We will define different summary statistics with different data types. Data types of the value of the summary statistic can be 1d numpy array, 2d numpy array, pandas data frame.<jupyter_code>observed = {'data 1': np.array([1,1,2,2,3,3,4,4]),
            'data 2': pd.DataFrame({'measurement': [1,2,3,4,1,2,3,4]}),
            'data 3': pd.DataFrame({'measurement 1': [1,2,3,4,1,2,3,4],
                                    'measurement 2': [1,5,4,6,7,2,6,2]}),
            'data 4': np.array([[4,4,5,3,2,2,1,2],[4,3,4,3,1,1,2,1]]),
            'data 5': np.array([1,1,2,2,3,3,4,4]),
           }<jupyter_output><empty_output><jupyter_text>We do the same for the simulated data:<jupyter_code>simulated = {'data 1': np.array([1,2,4,6,8,10,12,14]),
             'data 2': pd.DataFrame({'measurement': [1,2,4,6,1,2,4,6]}),
             'data 3': pd.DataFrame({'measurement 1': [2,3,4,5,3,4,1,2],
                                     'measurement 2': [1,6,5,4,6,2,5,2]}),
             'data 4': np.array([[13,13,9,7,8,3,2,1],[14,12,10,9,6,4,3,2]]),
             'data 5': np.array([1,2,4,6,8,10,12,14]),
            }<jupyter_output><empty_output><jupyter_text>Plot Now that we have defined two dictionaries for both the observed and simulated summary statistics, we can call the plotting function from pyABC.visualization<jupyter_code>plot_data(observed, simulated)
plt.gcf().set_size_inches(9, 6)
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14573304157549233, 'fraction_numerical': 0.06389496717724288, 'mean_word_length': 3.980392156862745, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, 'https://': 1, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '304435', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 854, 'n_tokens_neox': 794, 'n_words': 211, 'path': 'doc/examples/data_plots.ipynb', 'repo_name': 'j-zimmermann/pyABC', 'size': '2285'}