Skip to content
DeepForgeby svx
All problems
HardOptimizationop-050

Cross-Entropy Method Elite Mean

Problem

Run one iteration of the cross-entropy method for f(x) = (x - 2.5)^2.

After random.seed(seed), draw n_samples values from a Gaussian with the given mean and sigma. Keep the k = max(1, int(n_samples * elite_frac)) samples with the smallest objective, then return [mean of elites, population standard deviation of elites].

Hint

Elite selection uses the objective, so samples closest to 2.5 are kept.

Test cases

case 1
in: [0,2,20,0.5,0]
expected: [1.423804366158908,1.5812932920080844]
case 2
in: [1,0.5,10,0.3,42]
expected: [1.191697809311239,0.12099218802590447]
case 3
in: [3,1,8,0.25,7]
expected: [2.714525644610607,0.029594066941792452]
Starter codePython
def cem_elite_mean(mean, sigma, n_samples, elite_frac, seed):
    # Returns [elite_mean, elite_std]
    # Your code here
    pass

3 test cases · run your code against them in the editor