# 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 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 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. bool

## RealDomain - (A subset of) Real Numbers¶

### Class Reference¶

class qinfer.RealDomain(min=None, max=None)[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. If left as None, negative infinity is assumed. max (float) – A number specifying the largest possible value of the domain. If left as None, positive infinity is assumed.
min

Returns the minimum value of the domain. The outcome None is interpreted as negative infinity.

Return type: float
max

Returns the maximum value of the domain. The outcome None is interpreted as positive infinity.

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: 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
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. bool

## IntegerDomain - (A subset of) Integers¶

This is the default domain for FiniteOutcomeModel.

### Class Reference¶

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

Bases: qinfer.domains.Domain

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

Parameters: min (int) – A number specifying the lowest possible value of the domain. If None, negative infinity is assumed. max (int) – A number specifying the largest possible value of the domain. If left as None, positive infinity is assumed.

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

min

Returns the minimum value of the domain. The outcome None is interpreted as negative infinity.

Return type: float
max

Returns the maximum value of the domain. The outcome None is interpreted as positive infinity.

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: 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
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. 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. 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. 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. bool