def test_from_linear_synthetic(self): envs = Environments.from_linear_synthetic(100, 2, 3, 4, ["xa"], 5) env = envs[0] self.assertIsInstance(env, LinearSyntheticSimulation) interactions = list(env.read()) self.assertEqual(1, len(envs)) self.assertEqual(100, len(interactions)) self.assertEqual(2, len(interactions[0].actions)) self.assertEqual(3, len(interactions[0].context)) self.assertEqual(4, len(interactions[0].actions[0])) self.assertEqual(['xa'], env.params['reward_features']) self.assertEqual(5, env.params['seed'])
#this line is required by Python in order to use multi-processing if __name__ == '__main__': # These configuration changes aren't ever required. # They are simply here to serve as an example. # These can also be set automatically by creating a .coba file your project root. CobaContext.cacher.cache_directory = './.coba_cache' CobaContext.experiment.processes = 2 CobaContext.experiment.chunk_by = 'task' #First, we define the learners that we want to test learners = [ RandomLearner(), EpsilonBanditLearner(), VowpalEpsilonLearner(), ] #Next we create the environments we'd like evaluate against environments = Environments.from_linear_synthetic( 1000, n_action_features=0).shuffle([0, 1, 2, 3]) #We then create and evaluate our experiment from our environments and learners result = Experiment(environments, learners).evaluate() #After evaluating can create a quick summary plot to get a sense of how the learners performed result.plot_learners(err='sd') #We can also create a plot examining how specific learners did across each shuffle of our environments result.filter_lrn(full_name="vw").plot_learners(err='sd', each=True)