(f, th_mean, batch_size, n_iter, eps = 0.1, lr=0.01)
implementation of the evolution strategy method for maximizing a black-box function

    f: a function mapping from vector -> scalar
    th_mean: initial mean over input distribution
    batch_size: number of samples of theta to evaluate per batch
    n_iter: number of batches
implementation of the evolution strategy method for maximizing a black-box function
implementation of the evolution strategy method for maximizing a black - box function
def es(f, th_mean, batch_size, n_iter, eps = 0.1, lr=0.01):
    """
    implementation of the evolution strategy method for maximizing a black-box function

    f: a function mapping from vector -> scalar
    th_mean: initial mean over input distribution
    batch_size: number of samples of theta to evaluate per batch
    n_iter: number of batches
    """
    for _ in range(n_iter):
        ds = np.array([dth for dth in np.random.randn(batch_size, th_mean.size)]) # perturbations
        ths = np.array([th_mean + eps *dth for dth in ds]) # perturbed parameters
        ys = np.array([f(th) for th in ths]) # here is the reward for each episode
        delta_ths = np.array([ds[i]*ys[i] for i in range(len(ys))])
        th_mean = th_mean + lr * delta_ths.mean(axis=0)
        yield {'ys' : ys, 'theta_mean' : th_mean, 'y_mean' : ys.mean()}
def es ( f , th_mean , batch_size , n_iter , eps = 0.1 , lr = 0.01 ) : for _ in range ( n_iter ) : ds = np . array ( [ dth for dth in np . random . randn ( batch_size , th_mean . size ) ] ) # perturbations ths = np . array ( [ th_mean + eps * dth for dth in ds ] ) # perturbed parameters ys = np . array ( [ f ( th ) for th in ths ] ) # here is the reward for each episode delta_ths = np . array ( [ ds [ i ] * ys [ i ] for i in range ( len ( ys ) ) ] ) th_mean = th_mean + lr * delta_ths . mean ( axis = 0 ) yield { 'ys' : ys , 'theta_mean' : th_mean , 'y_mean' : ys . mean ( ) }