Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Limmen committed Feb 4, 2024
1 parent 8abe241 commit 900bf2b
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion examples/eval/cyborg_scenario_two/evaluate_on_base_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from gym_csle_cyborg.envs.cyborg_scenario_two_defender import CyborgScenarioTwoDefender

if __name__ == '__main__':
ppo_policy = MetastoreFacade.get_ppo_policy(id=58)
ppo_policy = MetastoreFacade.get_ppo_policy(id=3)
config = CSLECyborgConfig(
gym_env_name="csle-cyborg-scenario-two-v1", scenario=2, baseline_red_agents=[RedAgentType.B_LINE_AGENT],
maximum_steps=100, red_agent_distribution=[1.0], reduced_action_space=True, decoy_state=True,
Expand Down
2 changes: 2 additions & 0 deletions examples/plotting/backup_orlando.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# experiment_apple_bline_256.to_json_file("/home/kim/orlando_results/15_jan/apple_b_line_256.json")
# experiment_apple_meander_256.to_json_file("/home/kim/orlando_results/15_jan/apple_meander_256.json")
# experiment_cardiff_b_line_64.to_json_file("/home/kim/orlando_results/16_jan/cardiff_b_line_64.json")
experiment_cardiff_b_line_64.to_json_file("/home/kim/orlando_results/16_jan/cardiff_b_line_64_2.json")
# experiment_cardiff_meander_64.to_json_file("/home/kim/orlando_results/16_jan/cardiff_meander_64.json")

metric = "average_return"
Expand Down Expand Up @@ -41,6 +42,7 @@
# print(avg_returns_means.shape)
# avg_returns_stds = np.array(list(map(lambda x: PlottingUtil.mean_confidence_interval(
# data=x, confidence=confidence)[1], returns)))
b_line_opt = -13.73
for i in range(len(avg_returns_means)):
print(f"{i + 1} {avg_returns_means[i]} {avg_returns_means[i] + avg_returns_stds[i]} "
f"{avg_returns_means[i] - avg_returns_stds[i]}")
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,6 @@
player_type=PlayerType.DEFENDER, player_idx=0
)
agent = POMCPAgent(emulation_env_config=emulation_env_config, simulation_env_config=simulation_env_config,
experiment_config=experiment_config, save_to_metastore=True)
experiment_config=experiment_config, save_to_metastore=False)
experiment_execution = agent.train()
MetastoreFacade.save_experiment_execution(experiment_execution)
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,9 @@ def update_tree_with_new_samples(self, action_sequence: List[int], observation:
count = 0
else:
count += 1
if count >= 20000:
raise ValueError(f"Invalid observation: {o} given state: {root.sample_state()}")
if count >= 80000:
raise ValueError(f"Invalid observation: {o} given state: {root.sample_state()}, "
f"{root.sample_state()}, {root.sample_state()}")
new_root.particles += particles

# We now prune the old root from the tree
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,11 +275,14 @@ def pomcp(self, exp_result: ExperimentResult, seed: int,
action_sequence.append(action)
s_prime = info[agents_constants.COMMON.STATE]
obs_id = info[agents_constants.COMMON.OBSERVATION]
print(eval_env.get_true_table())
print(eval_env.get_table())
from gym_csle_cyborg.util.cyborg_env_util import CyborgEnvUtil
print(CyborgEnvUtil.state_id_to_state_vector(state_id=s_prime))
print(CyborgEnvUtil.state_id_to_state_vector(state_id=obs_id, observation=True))
pomcp.update_tree_with_new_samples(action_sequence=action_sequence, observation=obs_id)
R += r
t += 1
print(eval_env.get_true_table())
print(eval_env.get_table())
if t % log_steps_frequency == 0:
rollout_action = -1
if rollout_policy is not None:
Expand Down

0 comments on commit 900bf2b

Please sign in to comment.