Esempio n. 1
0
def make_sigmoid(config):
    bench = SigmoidBenchmark()
    for k in config.keys():
        if k == "action_values":
            bench.set_action_values(config[k])
        else:
            bench.config[k] = config[k]
    return bench.get_environment()
Esempio n. 2
0
 def test_init(self):
     bench = SigmoidBenchmark()
     bench.set_action_values((3, ))
     env = bench.get_environment()
     wrapped = PolicyProgressWrapper(env, compute_optimal_sigmoid)
     self.assertTrue(len(wrapped.policy_progress) == 0)
     self.assertTrue(len(wrapped.episode) == 0)
     self.assertFalse(wrapped.compute_optimal is None)
Esempio n. 3
0
 def test_render(self, mock_plt):
     bench = SigmoidBenchmark()
     bench.set_action_values((3, ))
     env = bench.get_environment()
     env = PolicyProgressWrapper(env, compute_optimal_sigmoid)
     for _ in range(2):
         done = False
         env.reset()
         while not done:
             _, _, done, _ = env.step(1)
     env.render_policy_progress()
     self.assertTrue(mock_plt.show.called)
Esempio n. 4
0
    def test_step(self):
        bench = SigmoidBenchmark()
        bench.set_action_values((3, ))
        bench.config.instance_set = [[0, 0], [1, 1], [3, 4], [5, 6]]
        env = bench.get_environment()
        wrapped = PolicyProgressWrapper(env, compute_optimal_sigmoid)

        wrapped.reset()
        _, _, done, _ = wrapped.step(1)
        self.assertTrue(len(wrapped.episode) == 1)
        while not done:
            _, _, done, _ = wrapped.step(1)
        self.assertTrue(len(wrapped.episode) == 0)
        self.assertTrue(len(wrapped.policy_progress) == 1)
Esempio n. 5
0
    return instances


# Helper method to print current set


def print_instance_set(instance_set):
    c = 1
    for i in instance_set:
        print(f"Instance {c}: {i[0]}, {i[1]}")
        c += 1


# Make Sigmoid benchmark
bench = SigmoidBenchmark()
bench.set_action_values([3])

# First example: read instances from default instance set path
instances_from_file = bench.get_environment()
print("Instance set read from file")
print_instance_set(instances_from_file.instance_set)
print("\n")

# Second example: Sample instance set before training
instance_set = sample_instance(20)
bench.config.instance_set = instance_set
instances_sampled_beforehand = bench.get_environment()
print("Instance set sampled before env creation")
print_instance_set(instances_sampled_beforehand.instance_set)
print("\n")
Esempio n. 6
0
 def test_action_value_setting(self):
     bench = SigmoidBenchmark()
     bench.set_action_values([1, 2, 3])
     self.assertTrue(bench.config.action_values == [1, 2, 3])
     self.assertTrue(bench.config.action_space_args == [6])
     self.assertTrue(len(bench.config.observation_space_args[0]) == 10)