Domains

Introduction

A Domain represents a collection of objects. They are used by Simulatable (and subclasses like Model and FiniteOutcomeModel) to store relevant information about the possible outcomes of a given experiment. This includes properties like whether or not there are a finite number of possibilities, if so how many, and what their data types are.

Domain - Base Class for Domains

All domains should inherit from this base class.

Class Reference

class qinfer.Domain[source]

Bases: object

Abstract base class for domains of outcomes of models.

is_continuous

Whether or not the domain has an uncountable number of values.

Type:bool
is_finite

Whether or not the domain contains a finite number of points.

Type:bool
dtype

The numpy dtype of a single element of the domain.

Type:np.dtype
n_members

Returns the number of members in the domain if it is_finite, otherwise, returns np.inf.

Type:int or np.inf
example_point

Returns any single point guaranteed to be in the domain, but no other guarantees; useful for testing purposes. This is given as a size 1 np.array of type dtype.

Type:np.ndarray
values

Returns an np.array of type dtype containing some values from the domain. For domains where is_finite is True, all elements of the domain will be yielded exactly once.

Return type:np.ndarray
is_discrete

Whether or not the domain has a countable number of values.

Type:bool
in_domain(points)[source]

Returns True if all of the given points are in the domain, False otherwise.

Parameters:points (np.ndarray) – An np.ndarray of type self.dtype.
Return type:bool

ProductDomain - Cartesian product of multiple domains

Class Reference

class qinfer.ProductDomain(*domains)[source]

Bases: qinfer.domains.Domain

A domain made from the cartesian product of other domains.

Parameters:domains (Domain) – Domain instances as separate arguments, or as a singe list of Domain instances.
is_continuous

Whether or not the domain has an uncountable number of values.

Type:bool
is_finite

Whether or not the domain contains a finite number of points.

Type:bool
dtype

The numpy dtype of a single element of the domain.

Type:np.dtype
n_members

Returns the number of members in the domain if it is_finite, otherwise, returns np.inf.

Type:int or np.inf
example_point

Returns any single point guaranteed to be in the domain, but no other guarantees; useful for testing purposes. This is given as a size 1 np.array of type dtype.

Type:np.ndarray
values

Returns an np.array of type dtype containing some values from the domain. For domains where is_finite is True, all elements of the domain will be yielded exactly once.

Return type:np.ndarray
to_regular_arrays(array)[source]

Expands from an array of type self.dtype into a list of arrays with dtypes corresponding to the factor domains.

Parameters:array (np.ndarray) – An np.array of type self.dtype.
Return type:list
from_regular_arrays(arrays)[source]

Merges a list of arrays (of the same shape) of dtypes corresponding to the factor domains into a single array with the dtype of the ProductDomain.

Parameters:array (list) – A list with each element of type np.ndarray
Return type:np.ndarray
in_domain(points)[source]

Returns True if all of the given points are in the domain, False otherwise.

Parameters:points (np.ndarray) – An np.ndarray of type self.dtype.
Return type:bool

RealDomain - (A subset of) Real Numbers

Class Reference

class qinfer.RealDomain(min=-inf, max=inf)[source]

Bases: qinfer.domains.Domain

A domain specifying a contiguous (and possibly open ended) subset of the real numbers.

Parameters:
  • min (float) – A number specifying the lowest possible value of the domain.
  • max (float) – A number specifying the largest possible value of the domain.
min

Returns the minimum value of the domain.

Return type:float
max

Returns the maximum value of the domain.

Return type:float
is_continuous

Whether or not the domain has an uncountable number of values.

Type:bool
is_finite

Whether or not the domain contains a finite number of points.

Type:bool
dtype

The numpy dtype of a single element of the domain.

Type:np.dtype
n_members

Returns the number of members in the domain if it is_finite, otherwise, returns None.

Type:np.inf
example_point

Returns any single point guaranteed to be in the domain, but no other guarantees; useful for testing purposes. This is given as a size 1 np.array of type dtype.

Type:np.ndarray
values

Returns an np.array of type self.dtype containing some values from the domain. For domains where is_finite is True, all elements of the domain will be yielded exactly once.

Return type:np.ndarray
in_domain(points)[source]

Returns True if all of the given points are in the domain, False otherwise.

Parameters:points (np.ndarray) – An np.ndarray of type self.dtype.
Return type:bool

IntegerDomain - (A subset of) Integers

This is the default domain for FiniteOutcomeModel.

Class Reference

class qinfer.IntegerDomain(min=0, max=inf)[source]

Bases: qinfer.domains.Domain

A domain specifying a contiguous (and possibly open ended) subset of the integers.

Internally minimum and maximum are represented as floats in order to handle the case of infinite maximum, and minimums. The integer conversion function will be applied to the min and max values.

Parameters:
  • min (int) – A number specifying the lowest possible value of the domain.
  • max (int) – A number specifying the largest possible value of the domain.

Note: Yes, it is slightly unpythonic to specify max instead of `max`+1.

min

Returns the minimum value of the domain.

Return type:float or np.inf
max

Returns the maximum value of the domain.

Return type:float or np.inf
is_continuous

Whether or not the domain has an uncountable number of values.

Type:bool
is_finite

Whether or not the domain contains a finite number of points.

Type:bool
dtype

The numpy dtype of a single element of the domain.

Type:np.dtype
n_members

Returns the number of members in the domain if it is_finite, otherwise, returns np.inf.

Type:int or np.inf
example_point

Returns any single point guaranteed to be in the domain, but no other guarantees; useful for testing purposes. This is given as a size 1 np.array of type dtype.

Type:np.ndarray
values

Returns an np.array of type self.dtype containing some values from the domain. For domains where is_finite is True, all elements of the domain will be yielded exactly once.

Return type:np.ndarray
in_domain(points)[source]

Returns True if all of the given points are in the domain, False otherwise.

Parameters:points (np.ndarray) – An np.ndarray of type self.dtype.
Return type:bool

MultinomialDomain - Tuples of Integers with a Constant Sum

This domain is used by MultinomialModel.

Class Reference

class qinfer.MultinomialDomain(n_meas, n_elements=2)[source]

Bases: qinfer.domains.Domain

A domain specifying k-tuples of non-negative integers which sum to a specific value.

Parameters:
  • n_meas (int) – The sum of any tuple in the domain.
  • n_elements (int) – The number of elements in a tuple.
n_meas

Returns the sum of any tuple in the domain.

Return type:int
n_elements

Returns the number of elements of a tuple in the domain.

Return type:int
is_continuous

Whether or not the domain has an uncountable number of values.

Type:bool
is_finite

Whether or not the domain contains a finite number of points.

Type:bool
dtype

The numpy dtype of a single element of the domain.

Type:np.dtype
n_members

Returns the number of members in the domain if it is_finite, otherwise, returns None.

Type:int
example_point

Returns any single point guaranteed to be in the domain, but no other guarantees; useful for testing purposes. This is given as a size 1 np.array of type dtype.

Type:np.ndarray
values

Returns an np.array of type self.dtype containing some values from the domain. For domains where is_finite is True, all elements of the domain will be yielded exactly once.

Return type:np.ndarray
to_regular_array(A)[source]

Converts from an array of type self.dtype to an array of type int with an additional index labeling the tuple indeces.

Parameters:A (np.ndarray) – An np.array of type self.dtype.
Return type:np.ndarray
from_regular_array(A)[source]

Converts from an array of type int where the last index is assumed to have length self.n_elements to an array of type self.d_type with one fewer index.

Parameters:A (np.ndarray) – An np.array of type int.
Return type:np.ndarray
in_domain(points)[source]

Returns True if all of the given points are in the domain, False otherwise.

Parameters:points (np.ndarray) – An np.ndarray of type self.dtype.
Return type:bool