valanga 0.1.5__py3-none-any.whl → 0.1.7__py3-none-any.whl
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.
- valanga/evaluations.py +5 -1
- valanga/representation_factory.py +30 -42
- valanga/represention_for_evaluation.py +11 -5
- {valanga-0.1.5.dist-info → valanga-0.1.7.dist-info}/METADATA +1 -1
- {valanga-0.1.5.dist-info → valanga-0.1.7.dist-info}/RECORD +8 -8
- {valanga-0.1.5.dist-info → valanga-0.1.7.dist-info}/WHEEL +0 -0
- {valanga-0.1.5.dist-info → valanga-0.1.7.dist-info}/licenses/LICENSE +0 -0
- {valanga-0.1.5.dist-info → valanga-0.1.7.dist-info}/top_level.txt +0 -0
valanga/evaluations.py
CHANGED
|
@@ -5,6 +5,8 @@ Evaluation-related classes and types.
|
|
|
5
5
|
from dataclasses import dataclass
|
|
6
6
|
from typing import Protocol
|
|
7
7
|
|
|
8
|
+
from valanga.evaluator_types import EvaluatorInput
|
|
9
|
+
|
|
8
10
|
from .game import BranchKey, State
|
|
9
11
|
from .over_event import OverEvent
|
|
10
12
|
from .represention_for_evaluation import ContentRepresentation
|
|
@@ -22,7 +24,9 @@ class EvalItem[StateT: State](Protocol):
|
|
|
22
24
|
...
|
|
23
25
|
|
|
24
26
|
@property
|
|
25
|
-
def state_representation(
|
|
27
|
+
def state_representation(
|
|
28
|
+
self,
|
|
29
|
+
) -> ContentRepresentation[StateT, EvaluatorInput] | None:
|
|
26
30
|
"""The representation of the state associated with this evaluation item, if available."""
|
|
27
31
|
...
|
|
28
32
|
|
|
@@ -1,25 +1,23 @@
|
|
|
1
1
|
"""
|
|
2
|
-
Factory
|
|
2
|
+
Factory for creating content representations from game states and state modifications.
|
|
3
3
|
"""
|
|
4
4
|
|
|
5
5
|
from dataclasses import dataclass
|
|
6
6
|
from typing import Protocol
|
|
7
7
|
|
|
8
|
-
from .game import State
|
|
8
|
+
from .game import State
|
|
9
9
|
from .represention_for_evaluation import ContentRepresentation
|
|
10
10
|
|
|
11
11
|
|
|
12
|
-
class CreateFromState[StateT: State,
|
|
12
|
+
class CreateFromState[StateT: State, EvalIn](Protocol):
|
|
13
13
|
"""
|
|
14
14
|
Protocol for creating a state representation from a state.
|
|
15
15
|
"""
|
|
16
16
|
|
|
17
|
-
def __call__(self, state: StateT) ->
|
|
17
|
+
def __call__(self, state: StateT) -> ContentRepresentation[StateT, EvalIn]: ...
|
|
18
18
|
|
|
19
19
|
|
|
20
|
-
class CreateFromStateAndModifications[StateT: State,
|
|
21
|
-
Protocol
|
|
22
|
-
):
|
|
20
|
+
class CreateFromStateAndModifications[StateT: State, EvalIn, StateModT](Protocol):
|
|
23
21
|
"""
|
|
24
22
|
Protocol for creating a state representation from a state and modifications.
|
|
25
23
|
"""
|
|
@@ -27,50 +25,40 @@ class CreateFromStateAndModifications[StateT: State, RepT: ContentRepresentation
|
|
|
27
25
|
def __call__(
|
|
28
26
|
self,
|
|
29
27
|
state: StateT,
|
|
30
|
-
state_modifications:
|
|
31
|
-
previous_state_representation:
|
|
32
|
-
) ->
|
|
28
|
+
state_modifications: StateModT,
|
|
29
|
+
previous_state_representation: ContentRepresentation[StateT, EvalIn],
|
|
30
|
+
) -> ContentRepresentation[StateT, EvalIn]: ...
|
|
33
31
|
|
|
34
32
|
|
|
35
33
|
@dataclass
|
|
36
|
-
class RepresentationFactory[StateT: State,
|
|
37
|
-
"""
|
|
38
|
-
|
|
34
|
+
class RepresentationFactory[StateT: State, EvalIn, StateModT]:
|
|
35
|
+
"""Factory for creating content representations from states and state modifications.
|
|
36
|
+
Attributes:
|
|
37
|
+
create_from_state: Function to create a content representation from a state.
|
|
38
|
+
create_from_state_and_modifications: Function to create a content representation from a state and state modifications.
|
|
39
39
|
"""
|
|
40
40
|
|
|
41
|
-
create_from_state: CreateFromState[StateT,
|
|
42
|
-
create_from_state_and_modifications: CreateFromStateAndModifications[
|
|
41
|
+
create_from_state: CreateFromState[StateT, EvalIn]
|
|
42
|
+
create_from_state_and_modifications: CreateFromStateAndModifications[
|
|
43
|
+
StateT, EvalIn, StateModT
|
|
44
|
+
]
|
|
43
45
|
|
|
44
46
|
def create_from_transition(
|
|
45
47
|
self,
|
|
46
48
|
state: StateT,
|
|
47
|
-
previous_state_representation:
|
|
48
|
-
modifications:
|
|
49
|
-
) ->
|
|
50
|
-
"""
|
|
51
|
-
Create a Generic T_StateRepresentation object from a transition.
|
|
52
|
-
|
|
49
|
+
previous_state_representation: ContentRepresentation[StateT, EvalIn] | None,
|
|
50
|
+
modifications: StateModT | None,
|
|
51
|
+
) -> ContentRepresentation[StateT, EvalIn]:
|
|
52
|
+
"""Creates a content representation from a state transition.
|
|
53
53
|
Args:
|
|
54
|
-
state
|
|
55
|
-
previous_state_representation
|
|
56
|
-
modifications
|
|
57
|
-
|
|
54
|
+
state: The current state of the game.
|
|
55
|
+
previous_state_representation: The content representation of the previous state, or None if not available.
|
|
56
|
+
modifications: The modifications applied to the previous state to reach the current state, or None if not available.
|
|
58
57
|
Returns:
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
This version is supposed to be faster as it only modifies the previous state
|
|
62
|
-
representation with the last modification
|
|
58
|
+
ContentRepresentation[StateT, EvalIn]: The content representation of the current state.
|
|
63
59
|
"""
|
|
64
|
-
if previous_state_representation is None
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
else:
|
|
70
|
-
representation = self.create_from_state_and_modifications(
|
|
71
|
-
state=state,
|
|
72
|
-
state_modifications=modifications,
|
|
73
|
-
previous_state_representation=previous_state_representation,
|
|
74
|
-
)
|
|
75
|
-
|
|
76
|
-
return representation
|
|
60
|
+
if previous_state_representation is None or modifications is None:
|
|
61
|
+
return self.create_from_state(state)
|
|
62
|
+
return self.create_from_state_and_modifications(
|
|
63
|
+
state, modifications, previous_state_representation
|
|
64
|
+
)
|
|
@@ -2,21 +2,26 @@
|
|
|
2
2
|
Contains the definition of the ContentRepresentation protocol for content representations used in evaluations.
|
|
3
3
|
"""
|
|
4
4
|
|
|
5
|
-
from typing import
|
|
5
|
+
from typing import Protocol, TypeVar
|
|
6
|
+
|
|
7
|
+
from valanga.evaluator_types import EvaluatorInput
|
|
6
8
|
|
|
7
|
-
from .evaluator_types import EvaluatorInput
|
|
8
9
|
from .game import State
|
|
9
10
|
|
|
10
|
-
StateT_contra = TypeVar("StateT_contra", bound=State, contravariant=True, default=
|
|
11
|
+
StateT_contra = TypeVar("StateT_contra", bound=State, contravariant=True, default=State)
|
|
12
|
+
|
|
13
|
+
EvalIn_co = TypeVar(
|
|
14
|
+
"EvalIn_co", covariant=True, bound=EvaluatorInput, default=EvaluatorInput
|
|
15
|
+
)
|
|
11
16
|
|
|
12
17
|
|
|
13
|
-
class ContentRepresentation
|
|
18
|
+
class ContentRepresentation[StateT_contra, EvalIn_co](Protocol):
|
|
14
19
|
"""
|
|
15
20
|
Protocol defining the interface for a content representation.
|
|
16
21
|
It is a function returning the proper input for evaluation by the content evaluator.
|
|
17
22
|
"""
|
|
18
23
|
|
|
19
|
-
def get_evaluator_input(self, state: StateT_contra) ->
|
|
24
|
+
def get_evaluator_input(self, state: StateT_contra) -> EvalIn_co:
|
|
20
25
|
"""
|
|
21
26
|
Returns the evaluator input tensor for the content. Content representations have generally a compressed view and complemetary view of state info so to avoid redundancy and have all the necessary info we also give the state as input.
|
|
22
27
|
|
|
@@ -26,3 +31,4 @@ class ContentRepresentation(Protocol[StateT_contra]):
|
|
|
26
31
|
Returns:
|
|
27
32
|
The evaluator input tensor.
|
|
28
33
|
"""
|
|
34
|
+
...
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
valanga/__init__.py,sha256=EFoB5P_lGQCXM1tLTc9ZvO5mt_Ui_MXStEpcPwptwd8,945
|
|
2
|
-
valanga/evaluations.py,sha256=
|
|
2
|
+
valanga/evaluations.py,sha256=kGq8oU6cV-dlMvX_lSU_AAAWCXlvEGhsXdRt_CmuYvc,1461
|
|
3
3
|
valanga/evaluator_types.py,sha256=dRNY297Up2BSIM2557jy6cz0cINzfUHOpqkr1T6SSQM,344
|
|
4
4
|
valanga/game.py,sha256=7vFLJL0AhG9EqG_Po0hpyFU685YVMWnKYXn-QR2yiOo,6086
|
|
5
5
|
valanga/over_event.py,sha256=jUqN3CXq3e55TvDZatZKFlEOzJfho7M1Zr7VjZUhP6M,7908
|
|
6
6
|
valanga/policy.py,sha256=TkqcOSePRhHqtuoMbCKe5qZbizvF5H9uG1_oEcIZsuA,1229
|
|
7
7
|
valanga/progress_messsage.py,sha256=3LnOXSgyU84UkwcpsakcbPt_d3el2ojRSUClAwoPyEk,361
|
|
8
8
|
valanga/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
9
|
-
valanga/representation_factory.py,sha256=
|
|
10
|
-
valanga/represention_for_evaluation.py,sha256=
|
|
11
|
-
valanga-0.1.
|
|
12
|
-
valanga-0.1.
|
|
13
|
-
valanga-0.1.
|
|
14
|
-
valanga-0.1.
|
|
15
|
-
valanga-0.1.
|
|
9
|
+
valanga/representation_factory.py,sha256=LAIfLCBKTMVPDCZbcRtMQs_VIJwIHeaEH86BWV8PgTc,2456
|
|
10
|
+
valanga/represention_for_evaluation.py,sha256=9yCCOuN-h9FnoLJrffKGQ-oXiiXzZT3rP4e5wwMYfys,1135
|
|
11
|
+
valanga-0.1.7.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
|
|
12
|
+
valanga-0.1.7.dist-info/METADATA,sha256=4qCW9MTi80M1_3RJSi2hNiQlqV70UbzaZ0_YbdRvjTU,44645
|
|
13
|
+
valanga-0.1.7.dist-info/WHEEL,sha256=qELbo2s1Yzl39ZmrAibXA2jjPLUYfnVhUNTlyF1rq0Y,92
|
|
14
|
+
valanga-0.1.7.dist-info/top_level.txt,sha256=cKFLhxKDTqygHnc0xc_L8jDx6oNu5hSHqZ4UExU4xPo,8
|
|
15
|
+
valanga-0.1.7.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|