Skip to content

Commit

Permalink
Merge pull request #355 from Limmen/tolerance_tests
Browse files Browse the repository at this point in the history
csle tolerance tests
  • Loading branch information
Limmen authored May 15, 2024
2 parents 10c0cd4 + 36b2a72 commit 2ad9273
Show file tree
Hide file tree
Showing 14 changed files with 2,213 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def __str__(self) -> str:
"""
:return: a string representation of the DTO
"""
return (f"eta: {self.eta}, p_a: {self.p_a}, p_c_1: {self.p_c_1},"
return (f"eta: {self.eta}, p_a: {self.p_a}, p_c_1: {self.p_c_1}, "
f"BTR: {self.BTR}, negate_costs: {self.negate_costs}, seed: {self.seed}, "
f"discount_factor: {self.discount_factor}, states: {self.states}, actions: {self.actions}, "
f"observations: {self.observation_tensor}, cost_tensor: {self.cost_tensor}, "
Expand Down Expand Up @@ -105,7 +105,7 @@ def to_dict(self) -> Dict[str, Any]:
d["b1"] = self.b1
d["T"] = self.T
d["simulation_env_name"] = self.simulation_env_name
d["gym_env_name"] = self.simulation_env_name
d["gym_env_name"] = self.gym_env_name
return d

@staticmethod
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from typing import List, Dict, Any
import numpy as np
import logging
import io
import json
from csle_common.dao.simulation_config.simulation_env_input_config import SimulationEnvInputConfig


Expand Down Expand Up @@ -111,7 +114,7 @@ def to_dict(self) -> Dict[str, Any]:
d["b1"] = self.b1
d["T"] = self.T
d["simulation_env_name"] = self.simulation_env_name
d["gym_env_name"] = self.simulation_env_name
d["gym_env_name"] = self.gym_env_name
return d

@staticmethod
Expand All @@ -122,8 +125,8 @@ def from_json_file(json_file_path: str) -> "IntrusionRecoveryPomdpConfig":
:param json_file_path: the json file path
:return: the converted DTO
"""
import io
import json
logging.info(msg="msg")
with io.open(json_file_path, 'r') as f:
json_str = f.read()
print(json_str)
return IntrusionRecoveryPomdpConfig.from_dict(json.loads(json_str))
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from typing import List
from gymnasium.envs.registration import register
import math
import numpy as np

Expand All @@ -22,9 +21,14 @@ def threshold_probability(b1: float, threshold: float, k=-20) -> float:
return 1.0
if round(b1, 2) == 0:
return 0.0
if (threshold * (1 - b1)) > 0 and (b1 * (1 - threshold)) / (threshold * (1 - b1)) > 0:
if (threshold * (1 - b1)) > 0 and (b1 * (1 - threshold)) / (
threshold * (1 - b1)
) > 0:
try:
return math.pow(1 + math.pow(((b1 * (1 - threshold)) / (threshold * (1 - b1))), k), -1)
return math.pow(
1 + math.pow(((b1 * (1 - threshold)) / (threshold * (1 - b1))), k),
-1,
)
except Exception:
return 0.0
else:
Expand All @@ -51,7 +55,9 @@ def inverse_sigmoid(y) -> float:
return math.log(y / (1 - y), math.e)

@staticmethod
def sample_next_state(transition_tensor: List[List[List[float]]], s: int, a: int, states: List[int]) -> int:
def sample_next_state(
transition_tensor: List[List[List[float]]], s: int, a: int, states: List[int]
) -> int:
"""
Samples the next state of a MDP or POMDP
Expand All @@ -73,13 +79,15 @@ def register_envs() -> None:
:return: None
"""
from gymnasium.envs.registration import register

register(
id='csle-tolerance-intrusion-recovery-pomdp-v1',
entry_point='csle_tolerance.envs.intrusion_recovery_pomdp_env:IntrusionRecoveryPomdpEnv',
kwargs={'config': None}
id="csle-tolerance-intrusion-recovery-pomdp-v1",
entry_point="csle_tolerance.envs.intrusion_recovery_pomdp_env:IntrusionRecoveryPomdpEnv",
kwargs={"config": None},
)
register(
id='csle-tolerance-intrusion-response-cmdp-v1',
entry_point='csle_tolerance.envs.intrusion_response_cmdp_env:IntrusionResponseCmdpEnv',
kwargs={'config': None}
id="csle-tolerance-intrusion-response-cmdp-v1",
entry_point="csle_tolerance.envs.intrusion_response_cmdp_env:IntrusionResponseCmdpEnv",
kwargs={"config": None},
)
Loading

0 comments on commit 2ad9273

Please sign in to comment.