Skip to content

Commit a4bcb2e

Browse files
committed
Const method to convert to log. Initialization parameter defaults
1 parent b96a5b2 commit a4bcb2e

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

brml/prob_tables/const.py

+23-2
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,28 @@
44

55
class Const(Potential):
66

7-
def __init__(self, value):
7+
def __init__(self, value=np.array([]), variables=np.array([])):
88
"""
99
Initializes Constant Potential table. The difference between a Const
1010
potential and an array is that Const does not need variables. It
1111
just contains a value (instead of a table).
1212
13+
Notice that variables should never be set to anything different from []
14+
However, even if someone did set it to something different from [],
15+
_check_variables method would still set self.variables to [].
1316
:param value: for constant table
1417
:type value: float
1518
"""
1619
# Constant probability table has no variables
17-
super().__init__([], value)
20+
super().__init__(variables, value)
21+
22+
def to_logconst(self):
23+
"""
24+
Converts Const to a Const where the value stored in self.table is
25+
the logarithm of the initial value
26+
:return:
27+
"""
28+
return Const(np.log(self.table))
1829

1930
def _check_table(self, value):
2031
"""
@@ -45,6 +56,16 @@ def _check_table(self, value):
4556
"Table value can only be float, int, list or np.array."
4657
)
4758

59+
@staticmethod
60+
def _check_variables(variables):
61+
"""
62+
Overwrite this method so that even if they try to change variables,
63+
it will not be possible. This could happen in certain methods such as
64+
in sum()
65+
:return:
66+
"""
67+
return np.array([])
68+
4869
def evalpot(self, evvariables=0, evidence=0):
4970
"""
5071
Evaluates the table of a potential. Because this is a constant

0 commit comments

Comments
 (0)