def get_sim(sim_name):
    """
    Returns the simulator object for a given simulator name.
    """

    if sim_name == 'lv':
        return misc.get_simulator('lotka_volterra')

    elif sim_name == 'hh':
        return misc.get_simulator('hodgkin_huxley')

    else:
        return misc.get_simulator(sim_name)
Esempio n. 2
0
def plot_results(sim_name):
    """
    Plots all results for a given simulator and kind of error.
    """

    global sim
    sim = misc.get_simulator(translate_sim_name(sim_name))

    # gaussian
    err_gauss = get_err_gaussian(sim_name)
    err_gauss = max(err_gauss, 0.0)

    # NDE
    all_err_nde = []
    all_n_sims_nde = []
    for exp_desc in ed.parse(
            util.io.load_txt('exps/{0}_nl.txt'.format(sim_name))):
        all_err_nde.append(get_err_nde(exp_desc))
        all_n_sims_nde.append(exp_desc.inf.n_samples)

    all_err_snl = None
    all_n_sims_snl = None

    for exp_desc in ed.parse(
            util.io.load_txt('exps/{0}_seq.txt'.format(sim_name))):

        # SNL
        if isinstance(exp_desc.inf, ed.SNL_Descriptor):
            all_err_snl = get_err_snl(exp_desc)
            all_n_sims_snl = [(i + 1) * exp_desc.inf.n_samples
                              for i in xrange(exp_desc.inf.n_rounds)]

    matplotlib.rc('text', usetex=True)
    matplotlib.rc('font', size=16)

    all_n_sims = np.concatenate([all_n_sims_nde, all_n_sims_snl])
    min_n_sims = np.min(all_n_sims)
    max_n_sims = np.max(all_n_sims)

    fig, ax = plt.subplots(1, 1)
    ax.semilogx(all_n_sims_nde,
                np.sqrt(all_err_nde),
                's:',
                color='b',
                label='NL')
    ax.semilogx(all_n_sims_snl,
                np.sqrt(all_err_snl),
                'o:',
                color='r',
                label='SNL')
    ax.axhline(np.sqrt(err_gauss), linestyle='--', color='k', label='Gaussian')
    ax.set_xlabel('Number of simulations (log scale)')
    ax.set_ylabel('MMD')
    ax.set_xlim([min_n_sims * 10**(-0.2), max_n_sims * 10**0.2])
    ax.set_ylim([-0.1 if sim_name == 'gauss' else 0.0, ax.get_ylim()[1]])
    ax.legend(fontsize=14,
              loc='upper right' if sim_name == 'gauss' else 'lower right')

    plt.show()
Esempio n. 3
0
    def __init__(self, exp_desc):
        """
        :param exp_desc: an experiment descriptor object
        """

        assert isinstance(exp_desc, ed.ExperimentDescriptor)

        self.exp_desc = exp_desc
        self.exp_dir = os.path.join(misc.get_root(), 'experiments', exp_desc.get_dir())
        self.sim = misc.get_simulator(exp_desc.sim)