Bayesian Non-Parametric Evolutionary by precise Gradients in the Acquisition Function - TensorFlow Core v2.5.0

Viewed 50

The graph compiles but NaN output values in objective function (although, random generated data as input).

# reference https://www.tensorflow.org/probability/api_docs/python/tfp/math/ode/Solver
# reference https://www.tensorflow.org/probability/api_docs/python/tfp/optimizer/differential_evolution_minimize

import tensorflow as tf
import tensorflow_probability as tfp
from tensorflow_probability import distributions as tfd

tf.executing_eagerly()



population_size = 40



initial_population = (tf.random.normal([population_size]),
                    tf.random.normal([population_size]))


pi = tf.constant(3.14159)
t_init, t0, t1 = 0., 0.5, 1.

def ode_fn(t, x):
    x, y = initial_population
    return -(tf.math.cos(x) * tf.math.cos(y) *
             tf.math.exp(-(x-pi)**2 - (y-pi)**2))
             

def gradients(x):
    results = tfp.math.ode.BDF().solve(ode_fn, t_init, initial_population[0],
                                    solution_times=[t0, t1])

    return(results.states[0])                                



# The objective function and the gradient.

optim_results = tfp.optimizer.differential_evolution_minimize(
      gradients,
      initial_population=initial_population[0])

objective_value = optim_results[4] 
DirSampleNoise = tfd.Dirichlet([tf.math.reduce_mean(objective_value), tf.math.reduce_std(objective_value)])
print(DirSampleNoise.sample([2,]))
    

# Check that the argmin is close to the actual value.
# Print out the total number of function evaluations it took. Should be 5.

Current, developments - can be found in this link - https://gitlab.com/emmanuelnsanga/bayes-distil-model/-/blob/main/optimizer_non-parametric.py

0 Answers
Related