Skip to content

Commit

Permalink
Rename "symbol" to "key" in the Product inclusion-exclusion computation.
Browse files Browse the repository at this point in the history
  • Loading branch information
Feras A. Saad committed Feb 17, 2020
1 parent 7a61648 commit baa521c
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/distributions.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,12 +294,12 @@ def logprob_inclusion_exclusion(self, event):
# Compute probabilities of all the conjunctions.
(logps_pos, logps_neg) = ([], [])
for J in subsets:
# Find symbols involved in clauses J.
symbols = set(chain.from_iterable(dnf_factor[j].keys() for j in J))
# Find indexes of distributions that are involved in clauses J.
keys = set(chain.from_iterable(dnf_factor[j].keys() for j in J))
# Factorize events across the product.
logprobs = [
self.get_clause_weight_subset(dnf_factor, J, symbol)
for symbol in symbols
self.get_clause_weight_subset(dnf_factor, J, key)
for key in keys
]
logprob = sum(logprobs)
# Add probability to either positive or negative sums.
Expand Down Expand Up @@ -376,14 +376,14 @@ def get_clause_weight(self, clause):
for k, dist in enumerate(self.distributions)
])

def get_clause_weight_subset(self, dnf_factor, J, symbol):
# Return probability of conjunction of |J| clauses, for given symbol.
events = [dnf_factor[j][symbol] for j in J if symbol in dnf_factor[j]]
def get_clause_weight_subset(self, dnf_factor, J, key):
# Return probability of conjunction of |J| clauses, for given key.
events = [dnf_factor[j][key] for j in J if key in dnf_factor[j]]
if not events:
return -inf
# Compute probability of events.
event = events[0] if (len(events) == 1) else EventAnd(events)
return self.distributions[symbol].logprob(event)
return self.distributions[key].logprob(event)

# ==============================================================================
# Basic Distribution base class.
Expand Down

0 comments on commit baa521c

Please sign in to comment.