human
I am working on the file "Guided_Evolutionary_Strategies_Demo.ipynb".
The first task is:
Vanilla ES
Vanilla ES is the standard evolutionary strategies algorithm. It uses a diagonal covariance matrix for perturbing parameters.
Can you write Python program for it?
assistant
#Here is the Python program you requested.

def vanilla_es(loss_fn, grads_and_vars, sigma=0.1, beta=1.0):
  
  def vardist(v):
    n = v.shape[0]
    scale_diag = (sigma / tf.sqrt(tf.cast(n, tf.float32))) * tf.ones(n)
    return mvn_diag(scale_diag=scale_diag)
  
  # build distributions
  dists = {v.op.name: vardist(v) for _, v in grads_and_vars}
  
  updates_and_vars = evostrat_update(loss_fn, dists, grads_and_vars, beta, sigma)
  
  return updates_and_vars