q1ss.binalg.affine
Affine subspaces.
AffineSubspace
- final class AffineSubspace(generators, basepoint=None, *, copy=False)[source]
Bases:
objectA linear or affine subspace of a binary vector space, represened by:
a matrix whose rows span the (underlying) linear subspace
a basepoint vector
The subspace representation can be canonicalized: see
is_canonicalandcanonicalizefor details.Warning
For efficiency reasons, the internal representation of the affine subspace is not canonicalised at construction time. Many properties and methods automatically canonicalize the subspace as part of their inner workings, but the following properties and methods don’t do so:
The values returned by
num_generators,generatorsandbasepointchange when the space is canonicalized.- __add__(vec)[source]
Translates the affine subspace by the given vector.
- Parameters:
vec (
binvec)- Return type:
- __radd__(vec)[source]
Translates the affine subspace by the given vector.
- Parameters:
vec (
binvec)- Return type:
- __rmatmul__(mat)[source]
Transforms the affine subspace by the given matrix.
- Parameters:
mat (
binmat)- Return type:
- property basepoint
The value returned by this property is only guaranteed to be constant if the subspace
is_canonical, in which case:it is guaranteed to be zero at the pivot cols for the
basismatrix (which is in RREF when the subspace is canonical);it is the zero vector if and only if the subspace is linear
- Return type:
- property basis
A RREF matrix whose rows form a basis for the linear subspace.
The subspace is automatically canonicalised.
- Return type:
- canonicalize()[source]
Canonicalises the affine subspace’s internal data:
the generators are brought to RCEF, zero columns are dropped and the subspace dimension is obtained as the number of non-zero columns.
the basepoint vector is reduced according to the new generators, and the subspace is linear when the reduced basepoint is zero.
- Return type:
- copy(*, canonical=False)[source]
Returns a copy of this affine subspace. If
canonical=True, the copy is canonicalised.- Parameters:
canonical (
bool; default =False)- Return type:
- property dim
The dimension of the subspace.
The subspace is automatically canonicalised.
- Return type:
- draw(axes, *, color=None, label=None, **draw_networkx_kwargs)[source]
Draws this affine subspace using
draw_networkx.- Parameters:
axes (
HypercubeAxes)label (
BinvecLabelFun|None)draw_networkx_kwargs (
Any; variadic keyword)
- Return type:
- static draw_many(axes, subspaces, *, colors=None, label=None, subsp_kwargs=None, **draw_networkx_kwargs)[source]
Draws the given affine subspaces using
draw_networkx.- Parameters:
axes (
HypercubeAxes)subspaces (
Sequence[AffineSubspace])label (
BinvecLabelFun|None)draw_networkx_kwargs (
Any; variadic keyword)
- Return type:
- property generators
A matrix whose rows span the (underlying) linear subspace.
The value returned by this property is only guaranteed to be constant if the subspace
is_canonical, in which case it is the same as the subspacebasis.- Return type:
- property is_canonical
Whether the subspace is in canonical form:
the basis matrix is in RREF
the basepoint vector has been reduced to canonical form
A subspace can be put in canonical form by calling
canonicalize, and it henceforth remains in canonical form. The subspace is automatically canonicalized the first time that an operation is executed which requires canonical data.- Return type:
- is_disjoint(other)[source]
Whether this affine subspace is disjoint from the other given subspace.
- Parameters:
other (
AffineSubspace)- Return type:
- property is_linear
Whether the subspace is linear.
The subspace is automatically canonicalised.
- Return type:
- property iter_basis
Iterates over the basis vectors for the linear subspace.
The subspace is automatically canonicalised.
- property iter_points
Iterates over all the points in the affine subspace.
- property linspace
The linear subspace corresponding to this affine subspace.
- Return type:
- property num_generators
Returns the number of generators for the (underlying) linear subspace.
- Return type:
- property points
Returns a matrix whose columns are all points of this affine subspace.
- Return type:
- static random(subsp_dim, ambient_dim, *, linear=False, rng=None)[source]
Samples a random affine subspace with given subspace dimension, within a vector space with given ambient dimension. If
linearisTrue, only linear subspaces are sampled.Warning
This method relies on
random_rrefto sample the underlying linear subspace: currently, it does not result in a uniform sampling across all subspaces. This will change in future releases.
- random_points(num_samples, *, rng=None)[source]
Returns a matrix with the given number of random subspace points as its rows.
- residual(vec)[source]
Returns the canonical translation that must be applied to this affine subspace to obtain a coset which contains the given vector.
- select(coeffs)[source]
Returns a matrix whose columns are the affine subspace points obtained by linear combination of the basis vectors, using the columns of the input matrix as coefficient vectors.
- static std(subsp_dim, ambient_dim, basepoint=None)[source]
Returns the standard affine subspace of given dimension, using the first \(n\) standard basis vectors of the ambient space where \(n\) is the subspace dimension.
- Parameters:
- Return type:
- transform(matrices, *, partial=False)[source]
Transforms the subspace by the given matrices, applied in order left-to-right. If
partial=True, matrices are allowed to have dimension/sideksmaller than the ambient dimension of the subspace, in which case they are applied to the subspace spanned by the firstkstandard ambient vectors.- Parameters:
- Return type:
BinvecLabelFun
HypercubeAxes
- HypercubeAxes = numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[numpy.number[typing.Any]]] | collections.abc.Sequence[collections.abc.Sequence[int | float]]
Type alias for hypercube axes that can be passed to
AffineSubspace.draw, andAffineSubspace.draw_many.
draw_hypercube
- draw_hypercube(axes, *, label=None, **draw_networkx_kwargs)[source]
Draws a hypercube using
draw_networkx, plotting the generating directions along the given 2D axes.- Parameters:
axes (
HypercubeAxes)label (
BinvecLabelFun|None)draw_networkx_kwargs (
Any; variadic keyword)
- Return type: