def func_gp_prior(xdim, l, sigma, seed, name=''):
    np.random.seed(seed)
    filename = 'func_gp_prior_param_seed{}_{}.pkl'.format(seed, name)
    n_feats = 1000
    if os.path.isfile(filename):
        with open(filename, 'rb') as infile:
            data = pickle.load(infile)
            W = data['W']
            b = data['b']
            theta = data['theta']
    else:
        l = (np.ones([1, xdim]) * l)
        W = (np.random.randn(n_feats, xdim) * np.tile(np.sqrt(l), (n_feats, 1)))
        b = ((2.0 * np.pi) * np.random.rand(n_feats, 1))
        theta = np.random.randn(n_feats, 1)
        with open(filename, 'wb') as outfile:
            pickle.dump({'W': W, 'b': b, 'theta': theta}, outfile, protocol=pickle.HIGHEST_PROTOCOL)

    def f(x):
        x = np.array(x).reshape((- 1), xdim)
        return theta.T.dot(np.sqrt(((2.0 * sigma) / n_feats))).dot(np.cos((W.dot(x.T) + np.tile(b, (1, x.shape[0]))))).squeeze()
    return f
def func_gp_prior(xdim, l, sigma, seed, name=):
    np.random.seed(seed)
    filename = 'func_gp_prior_param_seed{}_{}.pkl'.format(seed, name)
    n_feats = 1000
    if os.path.isfile(filename):
        with open(filename, 'rb') as infile:
            data = pickle.load(infile)
            W = data['W']
            b = data['b']
            theta = data['theta']
    else:
        l = (np.ones([1, xdim]) * l)
        W = (np.random.randn(n_feats, xdim) * np.tile(np.sqrt(l), (n_feats, 1)))
        b = ((2.0 * np.pi) * np.random.rand(n_feats, 1))
        theta = np.random.randn(n_feats, 1)
        with open(filename, 'wb') as outfile:
            pickle.dump({'W': W, 'b': b, 'theta': theta}, outfile, protocol=pickle.HIGHEST_PROTOCOL)

    def f(x):
        x = np.array(x).reshape((- 1), xdim)
        return theta.T.dot(np.sqrt(((2.0 * sigma) / n_feats))).dot(np.cos((W.dot(x.T) + np.tile(b, (1, x.shape[0]))))).squeeze()
    return f