Exemplo n.º 1
0
def gp_quick_condition(lenscale,
                       obs=None,
                       hidfcn=None,
                       domain=linspace(0, 1, 1028),
                       sigvar=1.,
                       noisevar2=1e-7):

    obs_huh = check_obs(obs)

    mu_prior = zeros_like(domain)
    covmat_prior = jbgp.K_se(domain, domain, lenscale, sigvar)

    if obs_huh:
        if isscalar(obs) and obs>0:
            if hidfcn is None:
                hidfcn = jbgp.sample(domain, mu_prior, covmat_prior, noisevar2)
            iobs = rng.randint(len(domain), size=obs)
            xobs = domain[iobs]
            yobs = hidfcn[iobs]
        elif type(obs) is ndarray:
            if hidfcn is None:
                hidfcn = jbgp.sample(domain, mu_prior, covmat_prior, noisevar2)
            iobs = obs
            xobs = domain[iobs]
            yobs = hidfcn[iobs]
        elif type(obs) is list:
            assert len(obs)==2, 'if list, must be list of two ndarrays w x and y vals'
            assert not hidfcn, 'cannot provide yvals if passing a hidfcn'
            iobs = None
            xobs = obs[0]
            yobs = obs[1]
        else:
            raise ValueError('obs must be an integer, a nparray, or a list of two nparrays')

        post_mu = jbgp.conditioned_mu(domain, xobs, yobs, lenscale, sigvar, noisevar2)
        post_covmat = jbgp.conditioned_covmat(domain, covmat_prior, xobs, lenscale, sigvar, noisevar2)
    else:
        post_mu = mu_prior
        post_covmat = covmat_prior
        xobs = None
        yobs = None
        iobs = None

    return {'mu': post_mu,
            'covmat': post_covmat,
            'xobs': xobs,
            'yobs': yobs,
            'iobs': iobs}
Exemplo n.º 2
0
def gp_quick_sample(lenscale,
                    obs=None,
                    nsam=1,
                    hidfcn=None,
                    domain=linspace(0, 1, 1028),
                    sigvar=1.,
                    noisevar2=1e-7):

    mu_prior = zeros_like(domain)
    covmat_prior = jbgp.K_se(domain, domain, lenscale, sigvar)

    post = gp_quick_condition(lenscale, obs, hidfcn, domain, sigvar, noisevar2)

    samples = [jbgp.sample(domain, post['mu'], post['covmat'], noisevar2)
               for _ in xrange(nsam)]

    return {'samples': samples,
            'xobs': post['xobs'],
            'yobs': post['yobs'],
            'iobs': post['iobs']}