7
7
8
8
logger = logging .getLogger (__name__ )
9
9
10
- class TTCCalculation (Enum ):
10
+ class ProbCalculationMethod (Enum ):
11
11
SAMPLE = 1
12
12
EXPECTED = 2
13
13
14
- def sample_ttc (probs_dict ):
15
- """Calculate the sampled value from a ttc distribution function
14
+ def sample_prob (probs_dict ):
15
+ """Calculate the sampled value from a probability distribution function
16
16
Arguments:
17
17
probs_dict - a dictionary containing the probability distribution
18
- function that is part of a TTC
18
+ function
19
19
20
20
Return:
21
21
The float value obtained from calculating the sampled value corresponding
22
22
to the function provided.
23
23
"""
24
24
if probs_dict ['type' ] != 'function' :
25
- raise ValueError ('Sample TTC function requires a function '
25
+ raise ValueError ('Sample probability method requires a function '
26
26
f'probability distribution, but got "{ probs_dict ["type" ]} "' )
27
27
28
28
match (probs_dict ['name' ]):
@@ -67,19 +67,20 @@ def sample_ttc(probs_dict):
67
67
f'function encountered { probs_dict ["name" ]} !' )
68
68
69
69
70
- def expected_ttc (probs_dict ):
71
- """Calculate the expected value from a ttc distribution function
70
+ def expected_prob (probs_dict ):
71
+ """Calculate the expected value from a probability distribution function
72
72
Arguments:
73
73
probs_dict - a dictionary containing the probability distribution
74
- function that is part of a TTC
74
+ function
75
75
76
76
Return:
77
77
The float value obtained from calculating the expected value corresponding
78
78
to the function provided.
79
79
"""
80
80
if probs_dict ['type' ] != 'function' :
81
- raise ValueError ('Expected value TTC function requires a function '
82
- f'probability distribution, but got "{ probs_dict ["type" ]} "' )
81
+ raise ValueError ('Expected value probability method requires a '
82
+ 'function probability distribution, but got '
83
+ f'"{ probs_dict ["type" ]} "' )
83
84
84
85
match (probs_dict ['name' ]):
85
86
case 'Bernoulli' :
@@ -122,16 +123,16 @@ def expected_ttc(probs_dict):
122
123
f'function encountered { probs_dict ["name" ]} !' )
123
124
124
125
125
- def calculate_ttc (probs_dict : dict , method : TTCCalculation ) -> float :
126
- """Calculate the value from a ttc distribution
126
+ def calculate_prob (probs_dict : dict , method : ProbCalculationMethod ) -> float :
127
+ """Calculate the value from a probability distribution
127
128
Arguments:
128
129
probs_dict - a dictionary containing the probability distribution
129
- corresponding to the TTC
130
- method - the method to use in calculating the TTC
130
+ function
131
+ method - the method to use in calculating the probability
131
132
values(currently supporting sampled or expected values)
132
133
133
134
Return:
134
- The float value obtained from calculating the TTC probability distribution.
135
+ The float value obtained from calculating the probability distribution.
135
136
136
137
TTC Distributions in MAL:
137
138
https://mal-lang.org/mal-langspec/apidocs/org.mal_lang.langspec/org/mal_lang/langspec/ttc/TtcDistribution.html
@@ -142,8 +143,8 @@ def calculate_ttc(probs_dict: dict, method: TTCCalculation) -> float:
142
143
match (probs_dict ['type' ]):
143
144
case 'addition' | 'subtraction' | 'multiplication' | \
144
145
'division' | 'exponentiation' :
145
- lv = calculate_ttc (probs_dict ['lhs' ], method )
146
- rv = calculate_ttc (probs_dict ['rhs' ], method )
146
+ lv = calculate_prob (probs_dict ['lhs' ], method )
147
+ rv = calculate_prob (probs_dict ['rhs' ], method )
147
148
match (probs_dict ['type' ]):
148
149
case 'addition' :
149
150
return lv + rv
@@ -161,12 +162,12 @@ def calculate_ttc(probs_dict: dict, method: TTCCalculation) -> float:
161
162
162
163
case 'function' :
163
164
match (method ):
164
- case TTCCalculation .SAMPLE :
165
- return sample_ttc (probs_dict )
166
- case TTCCalculation .EXPECTED :
167
- return expected_ttc (probs_dict )
165
+ case ProbCalculationMethod .SAMPLE :
166
+ return sample_prob (probs_dict )
167
+ case ProbCalculationMethod .EXPECTED :
168
+ return expected_prob (probs_dict )
168
169
case _:
169
- raise ValueError ('Unknown TTC Calculation method '
170
+ raise ValueError ('Unknown Probability Calculation method '
170
171
f'encountered { method } !' )
171
172
172
173
case _:
0 commit comments