gym-csle-stopping-game 0.6.4__tar.gz → 0.6.5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of gym-csle-stopping-game might be problematic. Click here for more details.

Files changed (31) hide show
  1. {gym_csle_stopping_game-0.6.4 → gym_csle_stopping_game-0.6.5}/PKG-INFO +1 -1
  2. {gym_csle_stopping_game-0.6.4 → gym_csle_stopping_game-0.6.5}/setup.cfg +5 -5
  3. gym_csle_stopping_game-0.6.5/src/gym_csle_stopping_game/__version__.py +1 -0
  4. {gym_csle_stopping_game-0.6.4 → gym_csle_stopping_game-0.6.5}/src/gym_csle_stopping_game/dao/stopping_game_config.py +1 -1
  5. {gym_csle_stopping_game-0.6.4 → gym_csle_stopping_game-0.6.5}/src/gym_csle_stopping_game/dao/stopping_game_state.py +1 -1
  6. {gym_csle_stopping_game-0.6.4 → gym_csle_stopping_game-0.6.5}/src/gym_csle_stopping_game/envs/stopping_game_mdp_attacker_env.py +1 -1
  7. {gym_csle_stopping_game-0.6.4 → gym_csle_stopping_game-0.6.5}/src/gym_csle_stopping_game/util/stopping_game_util.py +54 -5
  8. {gym_csle_stopping_game-0.6.4 → gym_csle_stopping_game-0.6.5}/src/gym_csle_stopping_game.egg-info/PKG-INFO +1 -1
  9. {gym_csle_stopping_game-0.6.4 → gym_csle_stopping_game-0.6.5}/src/gym_csle_stopping_game.egg-info/requires.txt +5 -5
  10. {gym_csle_stopping_game-0.6.4 → gym_csle_stopping_game-0.6.5}/tests/test_stopping_game_env.py +1 -1
  11. gym_csle_stopping_game-0.6.4/src/gym_csle_stopping_game/__version__.py +0 -1
  12. {gym_csle_stopping_game-0.6.4 → gym_csle_stopping_game-0.6.5}/pyproject.toml +0 -0
  13. {gym_csle_stopping_game-0.6.4 → gym_csle_stopping_game-0.6.5}/setup.py +0 -0
  14. {gym_csle_stopping_game-0.6.4 → gym_csle_stopping_game-0.6.5}/src/gym_csle_stopping_game/__init__.py +0 -0
  15. {gym_csle_stopping_game-0.6.4 → gym_csle_stopping_game-0.6.5}/src/gym_csle_stopping_game/constants/__init__.py +0 -0
  16. {gym_csle_stopping_game-0.6.4 → gym_csle_stopping_game-0.6.5}/src/gym_csle_stopping_game/constants/constants.py +0 -0
  17. {gym_csle_stopping_game-0.6.4 → gym_csle_stopping_game-0.6.5}/src/gym_csle_stopping_game/dao/__init__.py +0 -0
  18. {gym_csle_stopping_game-0.6.4 → gym_csle_stopping_game-0.6.5}/src/gym_csle_stopping_game/dao/stopping_game_attacker_mdp_config.py +0 -0
  19. {gym_csle_stopping_game-0.6.4 → gym_csle_stopping_game-0.6.5}/src/gym_csle_stopping_game/dao/stopping_game_defender_pomdp_config.py +0 -0
  20. {gym_csle_stopping_game-0.6.4 → gym_csle_stopping_game-0.6.5}/src/gym_csle_stopping_game/envs/__init__.py +0 -0
  21. {gym_csle_stopping_game-0.6.4 → gym_csle_stopping_game-0.6.5}/src/gym_csle_stopping_game/envs/stopping_game_env.py +0 -0
  22. {gym_csle_stopping_game-0.6.4 → gym_csle_stopping_game-0.6.5}/src/gym_csle_stopping_game/envs/stopping_game_pomdp_defender_env.py +0 -0
  23. {gym_csle_stopping_game-0.6.4 → gym_csle_stopping_game-0.6.5}/src/gym_csle_stopping_game/util/__init__.py +0 -0
  24. {gym_csle_stopping_game-0.6.4 → gym_csle_stopping_game-0.6.5}/src/gym_csle_stopping_game.egg-info/SOURCES.txt +0 -0
  25. {gym_csle_stopping_game-0.6.4 → gym_csle_stopping_game-0.6.5}/src/gym_csle_stopping_game.egg-info/dependency_links.txt +0 -0
  26. {gym_csle_stopping_game-0.6.4 → gym_csle_stopping_game-0.6.5}/src/gym_csle_stopping_game.egg-info/not-zip-safe +0 -0
  27. {gym_csle_stopping_game-0.6.4 → gym_csle_stopping_game-0.6.5}/src/gym_csle_stopping_game.egg-info/top_level.txt +0 -0
  28. {gym_csle_stopping_game-0.6.4 → gym_csle_stopping_game-0.6.5}/tests/test_stopping_game_dao.py +0 -0
  29. {gym_csle_stopping_game-0.6.4 → gym_csle_stopping_game-0.6.5}/tests/test_stopping_game_mdp_attacker_env.py +0 -0
  30. {gym_csle_stopping_game-0.6.4 → gym_csle_stopping_game-0.6.5}/tests/test_stopping_game_pomdp_defender_env.py +0 -0
  31. {gym_csle_stopping_game-0.6.4 → gym_csle_stopping_game-0.6.5}/tests/test_stopping_game_util.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: gym_csle_stopping_game
3
- Version: 0.6.4
3
+ Version: 0.6.5
4
4
  Summary: OpenAI gym reinforcement learning environment of a Dynkin (Optimal stopping) game in CSLE
5
5
  Author: Kim Hammar
6
6
  Author-email: hammar.kim@gmail.com
@@ -20,11 +20,11 @@ classifiers =
20
20
  [options]
21
21
  install_requires =
22
22
  gymnasium>=0.27.1
23
- csle-base>=0.6.4
24
- csle-common>=0.6.4
25
- csle-attacker>=0.6.4
26
- csle-defender>=0.6.4
27
- csle-collector>=0.6.4
23
+ csle-base>=0.6.5
24
+ csle-common>=0.6.5
25
+ csle-attacker>=0.6.5
26
+ csle-defender>=0.6.5
27
+ csle-collector>=0.6.5
28
28
  python_requires = >=3.8
29
29
  package_dir =
30
30
  =src
@@ -0,0 +1 @@
1
+ __version__ = '0.6.5'
@@ -14,7 +14,7 @@ class StoppingGameConfig(SimulationEnvInputConfig):
14
14
  T: npt.NDArray[Any], O: npt.NDArray[np.int_], Z: npt.NDArray[Any],
15
15
  R: npt.NDArray[Any], S: npt.NDArray[np.int_], A1: npt.NDArray[np.int_],
16
16
  A2: npt.NDArray[np.int_], L: int, R_INT: int, R_COST: int, R_SLA: int, R_ST: int,
17
- b1: npt.NDArray[np.float_],
17
+ b1: npt.NDArray[np.float64],
18
18
  save_dir: str, checkpoint_traces_freq: int, gamma: float = 1, compute_beliefs: bool = True,
19
19
  save_trace: bool = True) -> None:
20
20
  """
@@ -10,7 +10,7 @@ class StoppingGameState(JSONSerializable):
10
10
  Represents the state of the optimal stopping game
11
11
  """
12
12
 
13
- def __init__(self, b1: npt.NDArray[np.float_], L: int) -> None:
13
+ def __init__(self, b1: npt.NDArray[np.float64], L: int) -> None:
14
14
  """
15
15
  Intializes the state
16
16
 
@@ -48,7 +48,7 @@ class StoppingGameMdpAttackerEnv(BaseEnv):
48
48
  self.reset()
49
49
  super().__init__()
50
50
 
51
- def step(self, pi2: Union[npt.NDArray[Any], int, float, np.int_, np.float_]) \
51
+ def step(self, pi2: Union[npt.NDArray[Any], int, float, np.int_, np.float64]) \
52
52
  -> Tuple[npt.NDArray[Any], int, bool, bool, Dict[str, Any]]:
53
53
  """
54
54
  Takes a step in the environment by executing the given action
@@ -11,7 +11,7 @@ class StoppingGameUtil:
11
11
  """
12
12
 
13
13
  @staticmethod
14
- def b1() -> npt.NDArray[np.float_]:
14
+ def b1() -> npt.NDArray[np.float64]:
15
15
  """
16
16
  Gets the initial belief
17
17
 
@@ -233,7 +233,7 @@ class StoppingGameUtil:
233
233
  return int(np.random.choice(np.arange(0, len(S)), p=state_probs))
234
234
 
235
235
  @staticmethod
236
- def sample_initial_state(b1: npt.NDArray[np.float_]) -> int:
236
+ def sample_initial_state(b1: npt.NDArray[np.float64]) -> int:
237
237
  """
238
238
  Samples the initial state
239
239
 
@@ -264,7 +264,7 @@ class StoppingGameUtil:
264
264
  return int(o)
265
265
 
266
266
  @staticmethod
267
- def bayes_filter(s_prime: int, o: int, a1: int, b: npt.NDArray[np.float_], pi2: npt.NDArray[Any], l: int,
267
+ def bayes_filter(s_prime: int, o: int, a1: int, b: npt.NDArray[np.float64], pi2: npt.NDArray[Any], l: int,
268
268
  config: StoppingGameConfig) -> float:
269
269
  """
270
270
  A Bayesian filter to compute the belief of player 1
@@ -302,8 +302,8 @@ class StoppingGameUtil:
302
302
  return float(b_prime_s_prime)
303
303
 
304
304
  @staticmethod
305
- def next_belief(o: int, a1: int, b: npt.NDArray[np.float_], pi2: npt.NDArray[Any],
306
- config: StoppingGameConfig, l: int, a2: int = 0, s: int = 0) -> npt.NDArray[np.float_]:
305
+ def next_belief(o: int, a1: int, b: npt.NDArray[np.float64], pi2: npt.NDArray[Any],
306
+ config: StoppingGameConfig, l: int, a2: int = 0, s: int = 0) -> npt.NDArray[np.float64]:
307
307
  """
308
308
  Computes the next belief using a Bayesian filter
309
309
 
@@ -337,3 +337,52 @@ class StoppingGameUtil:
337
337
  :return: a2 is the attacker action
338
338
  """
339
339
  return int(np.random.choice(np.arange(0, len(pi2[s])), p=pi2[s]))
340
+
341
+ @staticmethod
342
+ def pomdp_solver_file(config: StoppingGameConfig, discount_factor: float, pi2: npt.NDArray[Any]) -> str:
343
+ """
344
+ Gets the POMDP environment specification based on the format at http://www.pomdp.org/code/index.html,
345
+ for the defender's local problem against a static attacker
346
+
347
+ :param config: the POMDP config
348
+ :param discount_factor: the discount factor
349
+ :param pi2: the attacker strategy
350
+ :return: the file content as a string
351
+ """
352
+ file_str = ""
353
+ file_str = file_str + f"discount: {discount_factor}\n\n"
354
+ file_str = file_str + "values: reward\n\n"
355
+ file_str = file_str + f"states: {len(config.S)}\n\n"
356
+ file_str = file_str + f"actions: {len(config.A1)}\n\n"
357
+ file_str = file_str + f"observations: {len(config.O)}\n\n"
358
+ initial_belief_str = " ".join(list(map(lambda x: str(x), config.b1)))
359
+ file_str = file_str + f"start: {initial_belief_str}\n\n\n"
360
+ num_transitions = 0
361
+ for s in config.S:
362
+ for a1 in config.A1:
363
+ probs = []
364
+ for s_prime in range(len(config.S)):
365
+ num_transitions += 1
366
+ prob = 0
367
+ for a2 in config.A2:
368
+ prob += config.T[0][a1][a2][s][s_prime] * pi2[s][a2]
369
+ file_str = file_str + f"T: {a1} : {s} : {s_prime} {prob:.80f}\n"
370
+ probs.append(prob)
371
+ assert round(sum(probs), 3) == 1
372
+ file_str = file_str + "\n\n"
373
+ for a1 in config.A1:
374
+ for s_prime in config.S:
375
+ probs = []
376
+ for o in range(len(config.O)):
377
+ prob = config.Z[0][0][s_prime][o]
378
+ file_str = file_str + f"O : {a1} : {s_prime} : {o} {prob:.80f}\n"
379
+ probs.append(prob)
380
+ assert round(sum(probs), 3) == 1
381
+ file_str = file_str + "\n\n"
382
+ for s in config.S:
383
+ for a1 in config.A1:
384
+ for s_prime in config.S:
385
+ for o in config.O:
386
+ r = config.R[0][a1][0][s]
387
+ file_str = file_str + f"R: {a1} : {s} : {s_prime} : {o} {r:.80f}\n"
388
+ return file_str
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: gym-csle-stopping-game
3
- Version: 0.6.4
3
+ Version: 0.6.5
4
4
  Summary: OpenAI gym reinforcement learning environment of a Dynkin (Optimal stopping) game in CSLE
5
5
  Author: Kim Hammar
6
6
  Author-email: hammar.kim@gmail.com
@@ -1,9 +1,9 @@
1
1
  gymnasium>=0.27.1
2
- csle-base>=0.6.4
3
- csle-common>=0.6.4
4
- csle-attacker>=0.6.4
5
- csle-defender>=0.6.4
6
- csle-collector>=0.6.4
2
+ csle-base>=0.6.5
3
+ csle-common>=0.6.5
4
+ csle-attacker>=0.6.5
5
+ csle-defender>=0.6.5
6
+ csle-collector>=0.6.5
7
7
 
8
8
  [testing]
9
9
  pytest>=6.0
@@ -357,7 +357,7 @@ class TestStoppingGameEnvSuite:
357
357
  1,
358
358
  (
359
359
  np.array(
360
- [[0.2, 0.8], [0.6, 0.4], [0.5, 0.5], [0.5, 0.5]]
360
+ [[0.2, 0.8], [0.6, 0.4], [0.5, 0.5]]
361
361
  ),
362
362
  2,
363
363
  ),
@@ -1 +0,0 @@
1
- __version__ = '0.6.4'