def extend(self, keys=None, lower=True, upper=True, algorithm='linear'): # default algorithm if algorithm is None: algorithm = 'linear' # other algorithms? if algorithm != 'linear': LinVac.extend(self, keys, lower, upper, algorithm) return # number of undefined singletons? num_undefined = len(self.pspace) - len(self) if num_undefined == 0: # nothing to do return # sum probabilities over all defined singletons mass = sum( self.get(({ omega: 1 }, True), (0, 0))[0] for omega in self.pspace) # distribute remaining probability over remaining events remaining_mass = (1 - mass) / num_undefined value = (remaining_mass, remaining_mass) for omega in self.pspace: key = ({omega: 1}, True) if key not in self: self[key] = value
def get_linvac(self, epsilon): """Convert probability into a linear vacuous mixture: .. math:: \underline{E}(f)=(1-\epsilon)E(f)+\epsilon\inf f""" epsilon = self.make_number(epsilon) return LinVac(self.pspace, lprob=[(1 - epsilon) * self[{ omega: 1 }, True][0] for omega in self.pspace], number_type=self.number_type)
def extend(self, keys=None, lower=True, upper=True, algorithm='linear'): # default algorithm if algorithm is None: algorithm = 'linear' # other algorithms? if algorithm != 'linear': LinVac.extend(self, keys, lower, upper, algorithm) return # number of undefined singletons? num_undefined = len(self.pspace) - len(self) if num_undefined == 0: # nothing to do return # sum probabilities over all defined singletons mass = sum(self.get(({omega: 1}, True), (0, 0))[0] for omega in self.pspace) # distribute remaining probability over remaining events remaining_mass = (1 - mass) / num_undefined value = (remaining_mass, remaining_mass) for omega in self.pspace: key = ({omega: 1}, True) if key not in self: self[key] = value
def get_precise(self, gamble, event=True, algorithm='linear'): r"""Calculate the conditional expectation, .. math:: E(f|A)= \frac{ \sum_{\omega\in A}p(\omega)f(\omega) }{ \sum_{\omega\in A}p(\omega) } where :math:`p(\omega)` is simply the probability of the singleton :math:`\omega`:: self[{omega: 1}, True][0] """ # default algorithm if algorithm is None: algorithm = 'linear' # other algorithms? if algorithm != 'linear': return LinVac.get_lower(self, gamble, event, algorithm) self.is_valid(raise_error=True) gamble = self.make_gamble(gamble) if event is True or (isinstance(event, Event) and event.is_true()): # self[{omega: 1}, True][0] is the lower probability ([0]) # of the indicator gamble of omega ({omega: 1}), # unconditionally (True). return sum(self[{ omega: 1 }, True][0] * gamble[omega] for omega in self.pspace) else: event = self.pspace.make_event(event) event_prob = self.get_precise(event.indicator(self.number_type)) if event_prob == 0: raise ZeroDivisionError( "cannot condition on event with zero probability") return self.get_precise(gamble * event) / event_prob
def get_precise(self, gamble, event=True, algorithm='linear'): r"""Calculate the conditional expectation, .. math:: E(f|A)= \frac{ \sum_{\omega\in A}p(\omega)f(\omega) }{ \sum_{\omega\in A}p(\omega) } where :math:`p(\omega)` is simply the probability of the singleton :math:`\omega`:: self[{omega: 1}, True][0] """ # default algorithm if algorithm is None: algorithm = 'linear' # other algorithms? if algorithm != 'linear': return LinVac.get_lower(self, gamble, event, algorithm) self.is_valid(raise_error=True) gamble = self.make_gamble(gamble) if event is True or (isinstance(event, Event) and event.is_true()): # self[{omega: 1}, True][0] is the lower probability ([0]) # of the indicator gamble of omega ({omega: 1}), # unconditionally (True). return sum(self[{omega: 1}, True][0] * gamble[omega] for omega in self.pspace) else: event = self.pspace.make_event(event) event_prob = self.get_precise(event.indicator(self.number_type)) if event_prob == 0: raise ZeroDivisionError( "cannot condition on event with zero probability") return self.get_precise(gamble * event) / event_prob