.. note: Shortcut method to the *specificquery* method in :doc:`tablecpdfactorization` Eliminate all variables except for the ones specified by *query*. Adjust all distributions to reflect *evidence*. Return the entry that matches the exact probability of a specific event, as speci
(self, query, evidence)
| 106 | self.Vdata = j["Vdata"] |
| 107 | |
| 108 | def specificquery(self, query, evidence): |
| 109 | ''' |
| 110 | .. note: Shortcut method to the *specificquery* method in :doc:`tablecpdfactorization` |
| 111 | |
| 112 | Eliminate all variables except for the ones specified by *query*. Adjust all distributions to reflect *evidence*. Return the entry that matches the exact probability of a specific event, as specified by *query*. |
| 113 | |
| 114 | Arguments: |
| 115 | 1. *query* -- A dict containing (key: value) pairs reflecting (variable: value) that represents what outcome to calculate the probability of. The value of the query is a list of one or more values that can be taken by the variable. |
| 116 | 2. *evidence* -- A dict containing (key: value) pairs reflecting (variable: value) evidence that is known about the system. |
| 117 | |
| 118 | Returns: |
| 119 | - the probability that the event (or events) specified will occur, represented as a float between 0 and 1. |
| 120 | |
| 121 | Note that in this function, queries of the type P((x=A or x=B) and (y=C or y=D)) are permitted. They are executed by formatting the *query* dictionary like so:: |
| 122 | |
| 123 | { |
| 124 | "x": ["A", "B"], |
| 125 | "y": ["C", "D"] |
| 126 | } |
| 127 | |
| 128 | ''' |
| 129 | # validate |
| 130 | if not (hasattr(self, "V") and hasattr(self, "E") and hasattr(self, "Vdata")): |
| 131 | raise notloadedError("Bayesian network is missing essential attributes") |
| 132 | assert isinstance(query, dict) and isinstance(evidence, dict), "query and evidence must be dicts" |
| 133 | for k in query.keys(): |
| 134 | assert isinstance(query[k], list), "the values of your query must be lists, even if singletons" |
| 135 | |
| 136 | # calculate |
| 137 | fn = TableCPDFactorization(self) |
| 138 | return fn.specificquery(query, evidence) |
| 139 | |
| 140 | def randomsample(self, n, evidence=None): |
| 141 | ''' |
nothing calls this directly
no test coverage detected