def negative_portfolio_optimization_gaussian(dtype=tf.float64):
    xdim = 3
    zdim = 2
    input_dim = (xdim + zdim)
    xmin = 0.0
    xmax = 1.0
    zmin = 0.0
    zmax = 1.0
    xs = get_meshgrid(xmin, xmax, 5, xdim)
    with open('portfolio_data/data.pkl', 'rb') as readfile:
        data = pickle.load(readfile)
        X = data['X'].astype(np.float64)
        Y = data['Y'].astype(np.float64)
    with open('portfolio_data/GP_params.pkl', 'rb') as readfile:
        params = pickle.load(readfile)
        lengthscales = params['lengthscales']
        kern_var = params['kern_variance']
        noise_var = params['noise_variance']
        mean_constant = params['mean_constant']
        invKmm = params['invKmm']
    print(Y)
    print('**PARAMS:', params)
    invKmm_tf = tf.constant(invKmm, dtype=dtype)
    mean_constant_tf = tf.constant(mean_constant, dtype=dtype)
    Y_tf = tf.constant(Y, dtype=dtype)

    def f(x):
        x = x.reshape((- 1), input_dim)
        Knm = portfolio_computeKnm_np(x, X, lengthscales, kern_var)
        val = (mean_constant + ((Knm @ invKmm) @ (Y - mean_constant)))
        return (- val.reshape(x.shape[0]))

    def f_tf(x):
        x = tf.reshape(x, shape=((- 1), input_dim))
        Knm = portfolio_computeKnm(x, X, lengthscales, kern_var)
        val = (mean_constant_tf + ((Knm @ invKmm_tf) @ (Y_tf - mean_constant_tf)))
        return (- tf.reshape(val, shape=(tf.shape(x)[0],)))

    def z_tnorm_generator(n):
        return tf.random.uniform(shape=(n, zdim), minval=0.0, maxval=1.0, dtype=dtype)

    def z_lpdf(z):
        return tf.reduce_sum(tf.ones_like(z, dtype=dtype), axis=1)
    zmid = ((zmin + zmax) / 2.0)
    z_values = get_meshgrid((zmid - 0.25), (zmid + 0.25), 5, zdim)
    z_lprobs = ((- np.sum(((z_values - (np.ones(zdim) * zmid)) ** 2), axis=1)) / (0.15 ** 2))
    z_lprobs = np.squeeze((z_lprobs - scsp.logsumexp(z_lprobs)))
    z_probs = np.exp(z_lprobs)
    return {'function': f, 'function_tf': f_tf, 'name': 'negative_portfolio_optimization_gaussian', 'xdim': xdim, 'zdim': zdim, 'xmin': xmin, 'xmax': xmax, 'zmin': zmin, 'zmax': zmax, 'z_generator': z_tnorm_generator, 'z_lpdf': z_lpdf, 'zvalues': z_values, 'zlprobs': z_lprobs, 'zprobs': z_probs, 'lengthscale': lengthscales, 'signal_variance': kern_var, 'likelihood_variance': 0.0001, 'rand_opt_init_x': xs, 'max_var_discrete': 17.835917287050652, 'max_var_continuous': 17.835917287050652, 'max_cvar_X': [0.0, 1.0, 0.08484073], 'max_cvar_discrete': 21.21}
def negative_portfolio_optimization_gaussian(dtype=tf.float64):
    xdim = 3
    zdim = 2
    input_dim = (xdim + zdim)
    xmin = 0.0
    xmax = 1.0
    zmin = 0.0
    zmax = 1.0
    xs = get_meshgrid(xmin, xmax, 5, xdim)
    with open('portfolio_data/data.pkl', 'rb') as readfile:
        data = pickle.load(readfile)
        X = data['X'].astype(np.float64)
        Y = data['Y'].astype(np.float64)
    with open('portfolio_data/GP_params.pkl', 'rb') as readfile:
        params = pickle.load(readfile)
        lengthscales = params['lengthscales']
        kern_var = params['kern_variance']
        noise_var = params['noise_variance']
        mean_constant = params['mean_constant']
        invKmm = params['invKmm']
    print(Y)
    print('**PARAMS:', params)
    invKmm_tf = tf.constant(invKmm, dtype=dtype)
    mean_constant_tf = tf.constant(mean_constant, dtype=dtype)
    Y_tf = tf.constant(Y, dtype=dtype)

    def f(x):
        x = x.reshape((- 1), input_dim)
        Knm = portfolio_computeKnm_np(x, X, lengthscales, kern_var)
        val = (mean_constant + ((Knm @ invKmm) @ (Y - mean_constant)))
        return (- val.reshape(x.shape[0]))

    def f_tf(x):
        x = tf.reshape(x, shape=((- 1), input_dim))
        Knm = portfolio_computeKnm(x, X, lengthscales, kern_var)
        val = (mean_constant_tf + ((Knm @ invKmm_tf) @ (Y_tf - mean_constant_tf)))
        return (- tf.reshape(val, shape=(tf.shape(x)[0],)))

    def z_tnorm_generator(n):
        return tf.random.uniform(shape=(n, zdim), minval=0.0, maxval=1.0, dtype=dtype)

    def z_lpdf(z):
        return tf.reduce_sum(tf.ones_like(z, dtype=dtype), axis=1)
    zmid = ((zmin + zmax) / 2.0)
    z_values = get_meshgrid((zmid - 0.25), (zmid + 0.25), 5, zdim)
    z_lprobs = ((- np.sum(((z_values - (np.ones(zdim) * zmid)) ** 2), axis=1)) / (0.15 ** 2))
    z_lprobs = np.squeeze((z_lprobs - scsp.logsumexp(z_lprobs)))
    z_probs = np.exp(z_lprobs)
    return {'function': f, 'function_tf': f_tf, 'name': 'negative_portfolio_optimization_gaussian', 'xdim': xdim, 'zdim': zdim, 'xmin': xmin, 'xmax': xmax, 'zmin': zmin, 'zmax': zmax, 'z_generator': z_tnorm_generator, 'z_lpdf': z_lpdf, 'zvalues': z_values, 'zlprobs': z_lprobs, 'zprobs': z_probs, 'lengthscale': lengthscales, 'signal_variance': kern_var, 'likelihood_variance': 0.0001, 'rand_opt_init_x': xs, 'max_var_discrete': 17.835917287050652, 'max_var_continuous': 17.835917287050652, 'max_cvar_X': [0.0, 1.0, 0.08484073], 'max_cvar_discrete': 21.21}