Ejemplo n.º 1
0
 def setup_logger(self, verbose=False):
     h = pd.read_pickle(self.hist_path) if os.path.exists(
         self.hist_path) else None
     if h is not None:
         print("Resuming from %s..." % self.hist_path)
     tasks = [
         opt_tools.tasks.DisplayOptimisation(opt_tools.seq_exp_lin(1.1,
                                                                   20)),
         opt_tools.tasks.GPflowLogOptimisation(
             opt_tools.seq_exp_lin(1.1, 20)),
         # Uncomment to keep track of exact lml bound. This causes problems with memory sometimes.
         # exp_tools.GPflowMultiClassificationTrackerLml(
         #     self.Xt[:, :], self.Yt[:, :], itertools.count(1800, 1800), trigger="time",
         #     verbose=True, store_x="final_only", store_x_columns=".*(variance|lengthscales)"),
         opt_tools.gpflow_tasks.GPflowMultiClassificationTracker(
             self.Xt[:, :],
             self.Yt[:, :],
             itertools.count(300, 1000),
             trigger="time",
             verbose=True,
             store_x="final_only",
             store_x_columns=".*(variance|lengthscales)",
             old_hist=h),
         opt_tools.tasks.StoreOptimisationHistory(self.hist_path,
                                                  opt_tools.seq_exp_lin(
                                                      1.5,
                                                      600,
                                                      start_jump=30),
                                                  trigger="time",
                                                  verbose=False),
         opt_tools.tasks.Timeout(self.run_settings.get("timeout", np.inf))
     ]
     tasks[2].pred_batch_size = self.pred_batch_size
     self.logger = opt_tools.GPflowOptimisationHelper(self.m, tasks)
Ejemplo n.º 2
0
 def setup_logger(self, verbose=None):
     h = pd.read_pickle(self.hist_path) if os.path.exists(self.hist_path) else None
     if h is not None:
         print("Resuming from %s..." % self.hist_path)
     tasks = [
         opt_tools.tasks.DisplayOptimisation(opt_tools.seq_exp_lin(1.1, 20)),
         opt_tools.tasks.GPflowLogOptimisation(opt_tools.seq_exp_lin(1.1, 20)),
         opt_tools.gpflow_tasks.GPflowBinClassTracker(self.Xt[self.test_slice, :], self.Yt[self.test_slice, :],
                                                      opt_tools.seq_exp_lin(1.1, 80, 3),
                                                      verbose=True, store_x="final_only",
                                                      store_x_columns='.*(variance|lengthscales)',
                                                      old_hist=h),
         opt_tools.tasks.StoreOptimisationHistory(self.hist_path, itertools.count(0, 60), verbose=False)
     ]
     self.logger = opt_tools.GPflowOptimisationHelper(self.m, tasks)
Ejemplo n.º 3
0
    def setUp(self):
        X = np.linspace(0, 5, 100)[:, None]
        Y = 0.3 * np.sin(2 * X) + 0.05 * rnd.randn(*X.shape)

        # model = GPflow.sgpr.SGPR(X, Y, GPflow.kernels.RBF(1), X[rnd.permutation(len(X))[:3], :])
        model = GPflow.sgpr.SGPR(X, Y, GPflow.kernels.RBF(1), X[:3, :].copy())
        model._compile()

        self.optlog = ot.GPflowOptimisationHelper(
            model,
            [
                ot.tasks.DisplayOptimisation(ot.seq_exp_lin(1.0, 1.0)),
                ot.tasks.GPflowLogOptimisation(ot.seq_exp_lin(1.0, 1.0), store_fullg=True, store_x=True),
                ot.tasks.StoreOptimisationHistory('./opthist.pkl', ot.seq_exp_lin(1.0, np.inf, 5.0, 5.0), verbose=True)
            ]
        )
Ejemplo n.º 4
0
 def setup_logger(self, verbose=False):
     h = pd.read_pickle(self.hist_path) if os.path.exists(self.hist_path) else None
     if h is not None:
         print("Resuming from %s..." % self.hist_path)
     tasks = [
         opt_tools.tasks.DisplayOptimisation(opt_tools.seq_exp_lin(1.1, 20)),
         opt_tools.tasks.GPflowLogOptimisation(opt_tools.seq_exp_lin(1.1, 20)),
         exp_tools.GPflowMultiClassificationTrackerLml(
             self.Xt[:, :], self.Yt[:, :], itertools.count(1800, 1800), trigger="time",
             verbose=True, store_x="final_only", store_x_columns=".*(variance|lengthscales)"),
         opt_tools.gpflow_tasks.GPflowMultiClassificationTracker(
             self.Xt[:, :], self.Yt[:, :], opt_tools.seq_exp_lin(1.5, 150, start_jump=30), trigger="time",
             verbose=True, store_x="final_only", store_x_columns=".*(variance|lengthscales)", old_hist=h),
         opt_tools.tasks.StoreOptimisationHistory(self.hist_path, opt_tools.seq_exp_lin(1.5, 600, start_jump=30),
                                                  trigger="time", verbose=False),
         opt_tools.tasks.Timeout(self.run_settings.get("timeout", np.inf))
     ]
     self.logger = opt_tools.GPflowOptimisationHelper(self.m, tasks)
Ejemplo n.º 5
0
sys.path.append('..')
import opt_tools as ot

rnd.seed(4)

X = np.linspace(0, 5, 100)[:, None]
Y = 0.3 * np.sin(2 * X) + 0.05 * rnd.randn(*X.shape)

# model = GPflow.sgpr.SGPR(X, Y, GPflow.kernels.RBF(1), X[rnd.permutation(len(X))[:3], :])
model = GPflow.sgpr.SGPR(X, Y, GPflow.kernels.RBF(1), X[:3, :].copy())
model._compile()

optlog = ot.GPflowOptimisationHelper(model, [
    ot.tasks.DisplayOptimisation(ot.seq_exp_lin(1.0, 1.0)),
    ot.tasks.GPflowLogOptimisation(
        ot.seq_exp_lin(1.0, 1.0), store_fullg=True, store_x=True),
    ot.tasks.StoreOptimisationHistory(
        './opthist.pkl', ot.seq_exp_lin(1.0, np.inf, 5.0, 5.0), verbose=True)
])
optlog.callback(model.get_free_state())

# Start optimisation
model.optimize(callback=optlog.callback, disp=False, maxiter=10)
optlog.finish(model.get_free_state())
print("Finished first optimisation run. %i iterations." % optlog.hist.i.max())
print("")

# Resume optimisation
hist = pd.read_pickle('./opthist.pkl')
time.sleep(3.0)
model._wrapped_objective = model._objective