Exemplo n.º 1
0
require_once '/core.php';
$arm1 = new BernoulliArm(0.7);
$arm2 = new NormalArm(10.0, 1.0);
$arm3 = new BernoulliArm(0.2);
$arms = [$arm1, $arm2, $arm3];
// $algo1 = new EpsilonGreedy(0.1, [], []); # not implemented yet
// $algo2 = new Softmax(1.0, [], []); # not implemented yet
$algo3 = new UCB1([], []);
// $algo4 = new Exp3(0.2, []); # not implemented yet
$algo5 = new UCB2(0.1, [], []);
$num_sims = 1000;
$horizon = 10;
$algos = [$algo3];
$rows = '';
foreach ($algos as $algo) {
    $results = test_algorithm($algo, $arms, $num_sims, $horizon);
    for ($i = 0; $i < $num_sims * $horizon; $i++) {
        $rows .= '<tr><td>' . $results[0][$i] . '</td><td>' . $results[1][$i] . '</td><td>' . $results[2][$i] . '</td><td>' . $results[3][$i] . '</td><td>' . $results[4][$i] . '</td></tr>';
    }
}
$table = <<<EOD
<pre>
<table style="width: 100%">
    <thead>
        <tr>
            <td>sim_nums</td>
            <td>times</td>
            <td>chosen_arms</td>
            <td>rewards</td>
            <td>cumulative_rewards</td>
        </tr>
Exemplo n.º 2
0
/**
 * Tests the algorithms
 *
 * @return array
 */
function test_algorithms()
{
    require_once ROOT . '/api/aa-get-algorithms.php';
    $algorithms = aa_get_algorithms();
    $results = array();
    $successes = 0;
    $failures = 0;
    $missing = 0;
    foreach (array_keys($algorithms) as $algorithm) {
        list($algorithm_filename, $example_filename) = make_file_names($algorithm);
        $result = test_algorithm($algorithm);
        if (empty($result)) {
            $missing++;
        } else {
            $successes += $result['successes'];
            $failures += $result['failures'];
        }
        $results[$algorithm] = $result;
    }
    return array('successes' => $successes, 'failures' => $failures, 'missing' => $missing, 'results' => $results);
}
/**
 * Runs the test of the algorithm
 */
function process_test_action()
{
    global $_filename, $_examples, $_source_code, $_docblock, $_algorithm;
    global $_posted_params, $_test;
    list($_filename, $_examples, $_source_code, $_docblock) = get_algorithm_details($_algorithm);
    if (!empty($_posted_params['run'])) {
        $_test = test_algorithm($_algorithm, $_examples);
    }
}