Interface#
Interface creates a separate interface with its own broadcasting rules. It provides the same
model-building functions as the default interface, without changing that default interface or
any other instance.
The default interface uses simple broadcasting, which rejects these different array shapes:
>>> from pangolin import interface as pi
>>> pi.normal([[0], [1]], [1, 2, 3])
Traceback (most recent call last):
...
ValueError: Can't broadcast shapes (2, 1) and (3,) with broadcasting=SIMPLE
Instead of importing the default interface as pi, create one with NumPy broadcasting:
>>> import pangolin
>>> pi = pangolin.interface.Interface(broadcasting="numpy")
>>> x = pi.normal([[0], [1]], [1, 2, 3])
>>> x.shape
(2, 3)
Use this pi in the same way as the default interface. Here NumPy broadcasting combines
shapes (2, 1) and (3,) to produce shape (2, 3).
Note
Array operations and distributions with non-scalar parameters use the IR’s shape rules without implicit broadcasting, regardless of this interface’s scalar broadcasting configuration.
Combinators work the same way as in the default interface.
Use pi.overload(...) for a temporary, context-local change. Saved functions observe the active
configuration when called:
>>> normal = pi.normal
>>> with pi.overload(broadcasting="off"):
... y = normal(0, 1)
... y.shape
()
>>> normal([0, 1], [[1, 1], [2, 2]]).shape
(2, 2)
See overload() for the full behavior of temporary overrides.
Interface#
- class pangolin.interface.Interface(*, broadcasting='simple')[source]#
Own one configuration and the graph-building functions that use it.
- Parameters:
broadcasting (Literal['off', 'simple', 'rank', 'numpy']) – Broadcasting policy used outside temporary overrides:
"off","simple"(the default),"rank", or"numpy".
Notes
Scalar functions follow the configured broadcasting policy. Non-scalar primitive operations use the IR’s shape rules without implicit broadcasting. Both preserve existing parent RVs and attach this interface to newly created outputs.
|
A combinator building log probabilities, accepting an RV-like evaluation value. |
|
A combinator building CDFs, accepting an RV-like evaluation value. |
|
A combinator building quantiles, accepting an RV-like probability. |
|
A combinator restricting continuous scalar distributions to a shared interval. |
|
A gradient combinator that also accepts a selected numeric scalar. |
|
A combinator that returns a function building a vector-Jacobian product. |
|
A combinator that broadcasts a scalar graph-building function. |
|
Provide vectorized indexing and summation as additional RV conveniences. |
|
Temporarily change this interface's configuration in the current context. |
|
Negate a scalar value. |
|
Create an RV by applying |
|
Create an RV by applying |
|
Create an RV by applying |
|
Create an RV by applying |
|
Create an RV by applying |
Create an RV by applying |
|
Create an RV by applying |
|
Create an RV by applying |
|
Create an RV by applying |
|
Create an RV by applying |
|
Create an RV by applying |
|
Create an RV by applying |
|
Create an RV by applying |
|
Create an RV by applying |
|
Create an RV by applying |
|
Create an RV by applying |
|
Create an RV by applying |
|
Create an RV by applying |
|
|
Create an RV by applying |
|
Create an RV by applying |
Create an RV by applying |
|
Create an RV by applying |
|
Create an RV by applying |
|
Create an RV by applying |
|
Create an RV by applying |
|
Create an RV by applying |
|
|
|
|
Create a |
|
|
|
|
|
Create a |
|
|
|
|
|
|
|
|
|
Create a |
|
|
|
|
|
Create a |
|
|
An alias for |
|
An alias for |
|
Take a square root. |
|
|
Multiply two vectors or matrices. |
Transpose a matrix. |
|
Extract the diagonal of a square matrix as a vector. |
|
Construct a square diagonal matrix from a vector. |
|
Invert a square matrix. |
|
Compute the lower-triangular Cholesky factor of a square matrix. |
|
Apply the softmax function to a vector. |
|
|
Sum an array along one axis, removing that axis from the result. |
|
Concatenate arrays along an existing axis without broadcasting. |
|
Fill a lower-triangular matrix row by row from a vector. |
Extract the lower-triangular entries of a square matrix row by row. |
|
|
Create a multivariate normal RV. |
|
Create a scalar categorical RV (Wikipedia). |
|
Create a multinomial RV (Wikipedia). |
|
Create a simplex-valued Dirichlet RV (Wikipedia). |
|
Create a matrix-valued Wishart RV (Wikipedia). |
|
Implement bracket indexing using this interface's orthogonal indexing rules. |
|
Index an RV using fully orthogonal indexing. |
|
Index an RV using fully vectorized indexing. |
|
Build an RV over named vectorized and sequential axes, in function-parameter order. |
|
Specify a sequential axis for |
|
Vectorize a function over named integer ranges. |
|
Build a state sequence with named sequential and parallel coordinates. |
|
Create an interface RV representing a fixed numeric value. |
|
Preserve an RV or create a constant owned by this interface. |