public function testShouldExploreIsTrueEvery3rdIterationWithExplorationEvery3()
 {
     $ex = $this->getTrafficExperiment();
     $ex->bandit->setStrategy(\MaBandit\Strategy\EpsilonGreedy::withExplorationEvery(3));
     $l = $ex->bandit->chooseLever($ex->ex);
     $ex->bandit->registerConversion($l);
     $this->assertEquals($l, $ex->bandit->chooseLever($ex->ex));
     $this->assertNotEquals($l, $ex->bandit->chooseLever($ex->ex));
     for ($i = 1; $i < 100; $i++) {
         if ($i % 3 === 0) {
             $this->assertNotEquals($l, $ex->bandit->chooseLever($ex->ex));
         } else {
             $this->assertEquals($l, $ex->bandit->chooseLever($ex->ex));
         }
     }
 }
Example #2
0
 /**
  * Start up the bandit.
  *
  * @since 0.4.0
  *
  * @access protected
  */
 protected function go()
 {
     $this->set_random();
     $strategy = \MaBandit\Strategy\EpsilonGreedy::withExplorationEvery(3);
     $persistor = $this->create_persistor();
     $this->bandit = \MaBandit\MaBandit::withStrategy($strategy)->withPersistor($persistor);
     try {
         $this->experiment = $this->bandit->getExperiment((string) $this->ID);
     } catch (\MaBandit\Exception\ExperimentNotFoundException $e) {
         $this->create_experiment();
     }
 }
 /**
  * @expectedException \PHPUnit_Framework_Error
  */
 public function testWithPersistorRaisesOnInvalidStrategy()
 {
     $s = \MaBandit\Strategy\EpsilonGreedy::withExplorationEvery(10);
     $p = new \stdClass();
     $bandit = \MaBandit\MaBandit::withStrategy($s)->withPersistor($p);
 }