<commit_before>import numpy as np
import matplotlib.pyplot as pl

import pygp
import pygp.plotting
import pybo.models
import pybo.policies


def run_model(model, policy, T):
    xmin = model.bounds[0,0]
    xmax = model.bounds[0,1]
    X = np.linspace(xmin, xmax, 200)[:, None]

    x = (xmax-xmin) / 2 + xmin
    y = model(x)
    policy.add_data(x, y)

    pl.figure(1)
    pl.show()

    for i in xrange(T):
        x, index = policy.get_next(return_index=True)

        # evaluate the index at the test points.
        index = np.log(index(X))
        index -= np.max(index)

        pl.clf()
        pl.plot(X, model.get_f(X), 'k--', lw=2, zorder=1)
        pl.plot(X, index, lw=2, zorder=2)
        pl.axvline(x, color='r', zorder=3)
        pl.axis('tight')
        pl.axis(ymin=-3.4, ymax=3.4, xmin=xmin, xmax=xmax)
        pl.draw()

        y = model(x)
        policy.add_data(x, y)


if __name__ == '__main__':
    T = 100
    sigma = 0.05
    model = pybo.models.Sinusoidal(sigma)
    policy = pybo.policies.GPPolicy(model.bounds, noise=sigma, policy='ei')

    run_model(model, policy, T)<commit_msg>Make the simple demo cleaner.<commit_after>import numpy as np
import matplotlib.pyplot as pl

import pygp
import pygp.plotting

import pybo.models
import pybo.policies


def run_model(model, policy, T):
    xmin = model.bounds[0,0]
    xmax = model.bounds[0,1]
    X = np.linspace(xmin, xmax, 200)[:, None]

    x = (xmax-xmin) / 2 + xmin
    y = model(x)
    policy.add_data(x, y)

    pl.figure(1)
    pl.show()

    for i in xrange(T):
        x, index = policy.get_next(return_index=True)

        pygp.plotting.plot(policy._model, xmin=xmin, xmax=xmax, subplot=211, draw=False)
        pl.plot(X, model.get_f(X), 'k--', lw=2)
        pl.axvline(x, color='r')
        pl.ylabel('posterior')
        pl.gca().set_xticklabels([])
        pl.gca().set_yticklabels([])

        pl.subplot(212)
        pl.cla()
        pl.plot(X, index(X), lw=2)
        pl.axvline(x, color='r')
        pl.axis(xmin=xmin, xmax=xmax)
        pl.ylabel('acquisition')
        pl.gca().set_xticklabels([])
        pl.gca().set_yticklabels([])
        pl.draw()

        y = model(x)
        policy.add_data(x, y)


if __name__ == '__main__':
    T = 100
    sigma = 0.05
    model = pybo.models.Sinusoidal(sigma)
    policy = pybo.policies.GPPolicy(model.bounds, noise=sigma, policy='ei')

    run_model(model, policy, T)
{'fraction_non_alphanumeric': 0.15279503105590062, 'fraction_numerical': 0.019461697722567287, 'mean_word_length': 2.5014492753623188, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1625380', 'n_tokens_mistral': 990, 'n_tokens_neox': 952, 'n_words': 192}