Beispiel #1
0
        @deterministic
        def y_plus_gen(gamma=gamma, deltaB=deltaB, rB=rB):
            return commons.y_plus(gamma, deltaB, rB)
        @deterministic
        def x_minus_gen(gamma=gamma, deltaB=deltaB, rB=rB):
            return commons.x_minus(gamma, deltaB, rB)
        @deterministic
        def y_minus_gen(gamma=gamma, deltaB=deltaB, rB=rB):
            return commons.y_minus(gamma, deltaB, rB)

        #Averaged experiments
        @stochastic
        def vars(x_plus_gen=x_plus_gen, y_plus_gen=y_plus_gen, x_minus_gen=x_minus_gen, y_minus_gen=y_minus_gen, value=0):
            return pymc.mv_normal_like([x_plus_gen, y_plus_gen, x_minus_gen, y_minus_gen], experiment['y_exp'], experiment['y_covar_inv'])

        # Model
        if load_last_model:
            mcmc = pymc.database.pickle.load('mcmc-{}.pickle'.format(name))
        else:
            mcmc = MCMC([vars, gamma, deltaB, rB],
                        db='pickle',
                        dbmode='w',
                        dbname='mcmc-{}.pickle'.format(name))
            mcmc.sample(iter = N, burn = min(5000, int(N/10)), thin = 1)

        for v in var_list:
            commons.plot(mcmc.trace(v.__name__)[:], v.__doc__, "pics/{}_{}.png".format(name, v.__name__))

        for x,y in combinations(var_list, 2):
           commons.plot_2d_hist(mcmc.trace(x.__name__)[:], mcmc.trace(y.__name__)[:],
                         "pics/{}_{}-{}_hist.png".format(name, x.__name__, y.__name__))
Beispiel #2
0
        #Averaged experiments
        @stochastic
        def vars(x_plus_gen=x_plus_gen,
                 y_plus_gen=y_plus_gen,
                 x_minus_gen=x_minus_gen,
                 y_minus_gen=y_minus_gen,
                 value=0):
            return pymc.mv_normal_like(
                [x_plus_gen, y_plus_gen, x_minus_gen, y_minus_gen],
                experiment['y_exp'], experiment['y_covar_inv'])

        # Model
        if load_last_model:
            mcmc = pymc.database.pickle.load('mcmc-{}.pickle'.format(name))
        else:
            mcmc = MCMC([vars, gamma, deltaB, rB],
                        db='pickle',
                        dbmode='w',
                        dbname='mcmc-{}.pickle'.format(name))
            mcmc.sample(iter=N, burn=min(5000, int(N / 10)), thin=1)

        for v in var_list:
            commons.plot(
                mcmc.trace(v.__name__)[:], v.__doc__,
                "pics/{}_{}.png".format(name, v.__name__))

        for x, y in combinations(var_list, 2):
            commons.plot_2d_hist(
                mcmc.trace(x.__name__)[:],
                mcmc.trace(y.__name__)[:],
                "pics/{}_{}-{}_hist.png".format(name, x.__name__, y.__name__))
Beispiel #3
0
                data_to_save = {}
                for v in data:
                    data_to_save[v] = np.histogram(data[v], bins=edges[v])
                pickle.dump({'data': data_to_save}, file, protocol=2)
        else:
            with gzip.open('output/raw.dat.gz', 'w') as file:
                pickle.dump({'data': data}, file, protocol=2)
    else: #not MCMC
        var_dict = {}
        weights = []
        data = {v: [] for v in desired_variables}
        for i in range(N):
            for i, p in enumerate(desired_variables):
                rval = np.random.uniform(lower_bounds[i], upper_bounds[i])
                data[p].append(rval)
                parameters.setRealValue(p, rval)
            weights.append(pdf.getVal())
        if bins:
            with gzip.open('output/bins.dat.gz', 'w') as file:
                data_to_save = {}
                for v in data:
                    data_to_save[v] = np.histogram(data[v], bins=edges[v], weights=weights)
                pickle.dump({'data': data_to_save}, file, protocol=2)
        else:
            with gzip.open('output/raw.dat.gz', 'w') as file:
                pickle.dump({'data': data, 'weights': weights}, file, protocol=2)
    if plot_graph:
        for v in desired_variables:
            commons.plot(np.array(data[v]), combination, v, weights=weights)

    print("Total time: {}".format(time.time() - start_time))