Assume I have a set \mathcal{S}. My parameter is possible subsets of \mathcal{S}, i.e. \{0,1\}^{|\mathcal{S}|}. I want to define a prior over this space, such that the probability of choosing any element of this set is Bernoulli(p). Trying to implement this as a custom distribution, I have this,
class Subset(Discrete):
"""Distribution for subset prior"""
_superset = None
_bernoulli = None
_p = None
def __init__(self, superset, p, *args, **kwargs):
super(Subset, self).__init__(*args, **kwargs)
self._superset = superset
self._bernoulli = Bernoulli("bernoulli", p=p)
self._p = p
def logp(self, value):
total = 0;
for i in value:
total += self._bernoulli.logp(value[i])
return total;
def random(self, point=None, size=None):
random_samples = [] # list of tuples
if size is None: size=1;
for i in range(size):
sample = []
for element in self._superset:
if self._bernoulli.random(): sample.append(1)
else: sample.append(0)
random_samples.append(sample)
return random_samples
logp should be evaluated over a subset, i.e. \{0,1\}^{|\mathcal{S}|}. However, in def logp(self, value)
I get an error saying that I cannot iterate over value. Am I looking at this incorrectly?