Skip to content
DeepForgeby svx
All problems
EasyOptimizationop-093

CEM Elite Count

Problem

Compute the number of elite samples in a cross-entropy method iteration.

Return max(1, int(n_samples * elite_frac)), where int truncates toward zero. At least one elite sample is always kept.

Hint

int truncates, and the max with 1 prevents an empty elite set.

Test cases

case 1
in: [20,0.5]
expected: 10
case 2
in: [10,0.3]
expected: 3
case 3
in: [8,0.05]
expected: 1
case 4
in: [1,0.9]
expected: 1
case 5
in: [100,0.1]
expected: 10
Starter codePython
def cem_elite_count(n_samples, elite_frac):
    # Your code here
    pass

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