class Agent(agents.random.RandomAgent(epochs)): def __init__(self, *args): super().__init__(*args) self.model = SparseGaussianProcess(encoder=self.encode, dim=dim, shape=self.shape, beta=beta, M=M) def act(self, seqs): choices = [] t = 1 + len(self.seen) // self.batch D = len(seqs) + len(self.seen) beta = lambda t: 2 * np.log(D * t**2 * np.pi**2 / 3) mu, sigma = self.model.interpolate(seqs) seqs = np.array(seqs) ucb = mu + 2 * np.sqrt(beta(t + 1)) * sigma selected = np.argsort(ucb)[-int(k * self.batch):] if k != 1.: idx = utils.mcmc.mcmc(self.batch, self.model.embed(seqs[selected]), iters=1000) selected = selected[idx] return seqs[selected] def observe(self, data): super().observe(data) self.model.fit(*zip(*self.seen.items()), epochs=epochs)
def __init__(self, *args): super().__init__(*args) self.model = SparseGaussianProcess(encoder=self.encode, dim=dim, shape=self.shape, beta=beta, M=M)
def __init__(self, *args): super().__init__(*args) self.model = SparseGaussianProcess(encoder=self.encode, dim=dim, shape=self.shape, beta=beta, M=M) if len(self.prior): self.model.embed.fit(*zip(*self.prior.items()), epochs=initial_epochs)