inferi.probability¶
Contains probability concept classes.

class
inferi.probability.
EventSpace
[source]¶ An abstract class for objects which are a container of simple events.
Any class inheriting from this class should ensure its instances have a
_simple_events
property which is a set ofSimple Event
objects.
simple_events
¶ The set of simple events in this space.
Return type: set


class
inferi.probability.
Event
(*events, name='E')[source]¶ Base class:
EventSpace
An occurance that is made up of multiple simple events.
Events are containers both of their simple events, and the outcomes of those simple events.
Parameters:  *events – The
Event
objects within this set.  name (str) – The name of the event (default is ‘E’).
Raises:  TypeError – if nonevents are given.
 TypeError – if the name is not a string.

sample_space
¶ The sample space that the event is part of.
Return type: SampleSpace

name
¶ Returns the name of the Event.
Return type: str

complement
¶ Returns the complement of the event  the event that this event does not happen.
Return type: Event

probability
(given=None, fraction=False)[source]¶ Returns the probability of the event happening.
Parameters:  given (Event) – an optional precondition to consider.
 fraction (bool) – If
True
, the result will be returned as aFraction
.
Raises: TypeError – if the given event is not an
Event
Return type: float

mutually_exclusive_with
(event)[source]¶ Looks at some other event and checks if this event is mutually exclusive with the other event. That is, whether it is impossible for them both to happen in a given statistical experiment.
Parameters: event (Event) – the other event to check with. Raises: TypeError – if a nonEvent is given. Return type: bool

independent_of
(event)[source]¶ Checks to see if this event is independent of some other event  that is, whether its probability is unaffacted by the occurence of the other event.
Parameters: event (Event) – the other event to check with. Raises: TypeError – if a nonEvent is given. Return type: bool

dependent_on
(event)[source]¶ Checks to see if this event is dependent of some other event  that is, whether its probability is affacted by the occurence of the other event.
Parameters: event (Event) – the other event to check with. Raises: TypeError – if a nonEvent is given. Return type: bool

outcomes
(p=False)¶ The set of outcomes that the event space’s simple events can produce.
Parameters: p (bool) – if True
, the results will be returned as a dict with probabilities associated.Return type: set
ordict

simple_events
¶ The set of simple events in this space.
Return type: set
 *events – The

class
inferi.probability.
SimpleEvent
(outcome, probability, space)[source]¶ Base class: py:class:.Event
A simple event  a single outcome of a statistical experiment.
Parameters:  outcome – The result of this event occuring.
 probability (float) – The probability of this event occuring.
Raises:  TypeError – if probability isn’t numeric.
 ValueError – if probability is not between 0 and 1.

outcome
¶ The result of this event occuring.

complement
¶ Returns the complement of the event  the event that this event does not happen.
Return type: Event

dependent_on
(event)¶ Checks to see if this event is dependent of some other event  that is, whether its probability is affacted by the occurence of the other event.
Parameters: event (Event) – the other event to check with. Raises: TypeError – if a nonEvent is given. Return type: bool

independent_of
(event)¶ Checks to see if this event is independent of some other event  that is, whether its probability is unaffacted by the occurence of the other event.
Parameters: event (Event) – the other event to check with. Raises: TypeError – if a nonEvent is given. Return type: bool

mutually_exclusive_with
(event)¶ Looks at some other event and checks if this event is mutually exclusive with the other event. That is, whether it is impossible for them both to happen in a given statistical experiment.
Parameters: event (Event) – the other event to check with. Raises: TypeError – if a nonEvent is given. Return type: bool

name
¶ Returns the name of the Event.
Return type: str

outcomes
(p=False)¶ The set of outcomes that the event space’s simple events can produce.
Parameters: p (bool) – if True
, the results will be returned as a dict with probabilities associated.Return type: set
ordict

probability
(given=None, fraction=False)¶ Returns the probability of the event happening.
Parameters:  given (Event) – an optional precondition to consider.
 fraction (bool) – If
True
, the result will be returned as aFraction
.
Raises: TypeError – if the given event is not an
Event
Return type: float

sample_space
¶ The sample space that the event is part of.
Return type: SampleSpace

simple_events
¶ The set of simple events in this space.
Return type: set

class
inferi.probability.
SampleSpace
(*outcomes, p=None)[source]¶ Base class:
EventSpace
The set of all possible things that can result from a statistical experiment.
Parameters:  *outcomes – All the possible outcomes.
 p (dict) – The probabilities for the supplied outcomes. If not given, these will be weighted equally.
Raises: ValueError – if you supply probabilities that don’t add up to 1.

event
(*outcomes, name=None)[source]¶ If a single outcome is given, this function will return the
SimpleEvent
corresponding to that outcome.If multiple outcomes are given, the function will return the
Event
corresponding to one of those outcomes occuring.If a callable is provided, the function will return the
Event
of all the simple events that returnTrue
when the callable is applied to their outcome.Parameters:  *outcomes – The outcome(s) to look for.
 name (str) – The name to apply if a
Event
is returned.
Return type: SimpleEvent
orEvent

chances_of
(*outcomes)[source]¶ Returns the probability of the given outcome or outcomes occuring in a single statistical experiment.
If multiple outcomes are given, the function will return the
Event
corresponding to one of those outcomes occuring.If a callable is provided, the function will return the
Event
of all the simple events that returnTrue
when the callable is applied to their outcome.Parameters: *outcomes – The outcome(s) to look for. Return type: float

outcomes
(p=False)¶ The set of outcomes that the event space’s simple events can produce.
Parameters: p (bool) – if True
, the results will be returned as a dict with probabilities associated.Return type: set
ordict

simple_events
¶ The set of simple events in this space.
Return type: set