|
4 | 4 |
|
5 | 5 | class Const(Potential):
|
6 | 6 |
|
7 |
| - def __init__(self, value): |
| 7 | + def __init__(self, value=np.array([]), variables=np.array([])): |
8 | 8 | """
|
9 | 9 | Initializes Constant Potential table. The difference between a Const
|
10 | 10 | potential and an array is that Const does not need variables. It
|
11 | 11 | just contains a value (instead of a table).
|
12 | 12 |
|
| 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 []. |
13 | 16 | :param value: for constant table
|
14 | 17 | :type value: float
|
15 | 18 | """
|
16 | 19 | # 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)) |
18 | 29 |
|
19 | 30 | def _check_table(self, value):
|
20 | 31 | """
|
@@ -45,6 +56,16 @@ def _check_table(self, value):
|
45 | 56 | "Table value can only be float, int, list or np.array."
|
46 | 57 | )
|
47 | 58 |
|
| 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 | + |
48 | 69 | def evalpot(self, evvariables=0, evidence=0):
|
49 | 70 | """
|
50 | 71 | Evaluates the table of a potential. Because this is a constant
|
|
0 commit comments