Ejemplo n.º 1
0
def show_bandit_algo(self, trials, results, xlim_low=-5, xlim_high=5,
        n_candidates=5):
    ivls = self.idxs_vals_by_status(trials, results)
    X_IVLs = ivls['x_IVLs']
    Ys = ivls['losses']
    Ys_var = ivls['losses_variance']
    prepared_data = self.prepare_GP_training_data(ivls)
    x_all, y_all, y_mean, y_var, y_std = prepared_data
    self.fit_GP(*prepared_data)

    candidates = self._prior_sampler(n_candidates)
    EI = self.GP_EI(IdxsValsList.fromflattened(candidates))
    print ''
    print 'Candidates'
    print 'idxs', candidates[0]
    print 'vals', candidates[1]
    print 'EI', EI
    #print 'optimizing candidates'
    candidates_opt = self.GP_EI_optimize(
            IdxsValsList.fromflattened(candidates))
    self.post_refinement(candidates_opt)
    EI_opt = self.GP_EI(candidates_opt)
    print ''
    print 'Optimized candidates'
    print 'idxs', candidates_opt[0].idxs
    print 'vals', candidates_opt[0].vals
    print "EI", EI_opt

    num = len(candidates_opt)

    plt.scatter(x_all[0].vals,
            y_all * self._GP_y_std + self._GP_y_mean)
    plt.scatter(candidates[1], numpy.zeros_like(candidates[1]),
        c='y')
    plt.scatter(candidates_opt[0].vals,
            numpy.zeros_like(candidates[1]) - .1,
            c='k')

    plt.figure()

    plt.xlim([xlim_low, xlim_high])
    xmesh = numpy.linspace(xlim_low, xlim_high)
    N = len(xmesh)
    XmeshN = [numpy.arange(N) for _ind in range(num)]
    Xmesh = [numpy.linspace(xlim_low, xlim_high)
            for _ind in range(num)]

    print Xmesh

    IVL = IdxsValsList.fromlists(XmeshN, Xmesh)
    gp_mean, gp_var = self.GP_mean_variance(IVL)
    gp_EI = self.GP_EI(IVL)

    print "GP_VAR", gp_var
    plt.plot(xmesh, gp_mean)
    plt.plot(xmesh, gp_mean + numpy.sqrt(gp_var), c='g')
    plt.plot(xmesh, gp_mean - numpy.sqrt(gp_var), c='g')
    plt.plot(xmesh, gp_EI, c='r')
    plt.show()
Ejemplo n.º 2
0
    def setUp(self):
        self.TE = IndependentNullEstimator()
        self.bandit = NestedUniform()
        self.experiment = SerialExperiment(
            GM_BanditAlgo(self.bandit,
                    good_estimator=IndependentNullEstimator(),
                    bad_estimator=IndependentNullEstimator()))

        self.s_rng = montetheano.RandomStreams(123)
        prior_idxs, prior_vals, s_N = self.bandit.template.theano_sampler(self.s_rng)
        #print prior_idxs
        #print prior_vals
        self.prior = IdxsValsList.fromlists(
                [i for i in prior_idxs if i is not None],
                [v for v in prior_vals if v is not None])
        self.s_N = s_N
        self.observations = self.prior.new_like_self()
        for i, o in enumerate(self.observations):
            o.idxs.name = 'Obs_idxs{%i}' % i
            o.vals.name = 'Obs_vals{%i}' % i
Ejemplo n.º 3
0
def ivl_fl(ilist, vlist):
    return IdxsValsList.fromlists(ilist, vlist)