ddg.geometry.subspaces module
- class ddg.geometry.subspaces.Subspace(*points, atol=None, rtol=None)[source]
Bases:
LinearTransformable,NonExactSubspace of a projective space. Represented by a number of vectors in homogeneous coordinates.
- Parameters:
- *pointsarray_like of list or numpy.ndarray of shape (n,)
Homogeneous coordinate vectors spanning the subspace. If the span is 1-dimensional, automatically casts to subspaces.Point
- atolfloat
- rtolfloat
See also
Notes
Subspaces can be empty. In this case, points are stored as an empty matrix with shape (n,0) if the ambient dimension is n-1. Empty spaces must be initialized with 0-vectors.
- Attributes:
Methods
affine_points([affine_component])List of points spanning the affine part of the subspace.
affine_matrix([affine_component])Matrix whose columns span the affine part of the subspace.
affine_point_and_directions([affine_component])Return point in the subspace and directions.
at_infinity([affine_component])Whether or not the subspace is at infinity.
- property points
List of points spanning the subspace in homogeneous coordinates.
- Returns:
- list of numpy.ndarray of shape (ambient_dimension+1,)
- property matrix
Matrix whose columns span the subspace in homogeneous coordinates.
- Returns:
- numpy.ndarray of shape (ambient_dimension+1, dimension+1)
- Raises:
- ValueError
If the subspace is at infinity.
- affine_points(affine_component=-1)[source]
List of points spanning the affine part of the subspace.
Computes points in affine coordinates that, when homogenized according to
affine_component, form a basis for the subspace.- Parameters:
- affine_componentint (default=-1)
- Returns:
- list of numpy.ndarray of shape (ambient_dimension,)
- affine_matrix(affine_component=-1)[source]
Matrix whose columns span the affine part of the subspace.
Computes points in affine coordinates that, when homogenized according to
affine_component, form a basis for the subspace. Returns them as the columns of a matrix.- Parameters:
- affine_componentint (default=-1)
- Returns:
- numpy.ndarray of shape (ambient_dimension, dimension+1)
- Raises:
- ValueError
If the subspace is at infinity.
- affine_point_and_directions(affine_component=-1)[source]
Return point in the subspace and directions.
Returns affine coordinate vectors p and d1, …, dk such that the original subspace is spanned by [p,1], [d1,0], …, [dk,0] where 1 or 0 are at position affine_component.
The point is the one that is closest to the zero vector in affine coordinates and the directions are orthonormal.
- Parameters:
- affine_componentint (default=-1)
- Returns:
- numpy.ndarray, list of numpy.ndarray
- at_infinity(affine_component=-1)[source]
Whether or not the subspace is at infinity.
Returns True if and only if p[affine_component] == 0 for all points p.
- Parameters:
- affine_componentint (default=-1)
- Returns:
- bool
- property dimension
- property ambient_dimension
- property codimension
- dualize(ambient_space=None)[source]
Return dual subspace.
- Parameters:
- ambient_spaceSubspace (default=None)
Other subspace containing this subspace that should be used as ambient space when dualizing. None means whole space.
- Returns:
- Subspace
- orthonormalize(affine_component=-1)[source]
- Parameters:
- affine_componentint (default=-1)
- Returns:
- Subspace
See also
- center(center, remove_index=None, insert_index=0, affine_component=-1)[source]
- Parameters:
- affine_componentint (default=-1)
- Returns:
- Subspace
See also
- dehomogenize(affine_component=-1)[source]
- Parameters:
- affine_componentint (default=-1)
- Returns:
- Subspace
See also
- property atol
- classmethod nonexact_function(f)
Decorator to use global tolerance defaults in functions.
If None is given to the wrapped function as the value for
atolorrtol, it will be replaced by the global default.
- pop_transformation()
Pop transformation from the trafo-stack.
- Returns:
- function
- push_transformation(f)
Add a transformation to the trafo-stack.
- Parameters:
- fnumpy.ndarray
- classmethod reset_tol_defaults()
- property rtol
- transform(f)
Wrapper for
push_transformation.See also
- property transformation
Product of all matrices on the stack.
- Returns:
- numpy.ndarray
- class ddg.geometry.subspaces.Point(point, atol=None, rtol=None)[source]
Bases:
SubspaceSubclass for points (0-dim. projective subspaces).
- Parameters:
- pointlist or numpy.ndarray of shape (n,)
- atolfloat
- rtolfloat
See also
- Attributes:
pointHomogeneous coordinate vector representing the point.
affine_pointAffine coordinate vector representing the point.
- property point
Homogeneous coordinate vector representing the point.
- Returns:
- numpy.ndarray (dimension+1,)
- affine_point(affine_component=-1)[source]
Affine coordinate vector representing the point.
- Parameters:
- affine_componentint (default=-1)
- Returns:
- numpy.ndarray of shape (dimension,)
- Raises:
- ValueError
If the point is at infinity.
- affine_matrix(affine_component=-1)
Matrix whose columns span the affine part of the subspace.
Computes points in affine coordinates that, when homogenized according to
affine_component, form a basis for the subspace. Returns them as the columns of a matrix.- Parameters:
- affine_componentint (default=-1)
- Returns:
- numpy.ndarray of shape (ambient_dimension, dimension+1)
- Raises:
- ValueError
If the subspace is at infinity.
- affine_point_and_directions(affine_component=-1)
Return point in the subspace and directions.
Returns affine coordinate vectors p and d1, …, dk such that the original subspace is spanned by [p,1], [d1,0], …, [dk,0] where 1 or 0 are at position affine_component.
The point is the one that is closest to the zero vector in affine coordinates and the directions are orthonormal.
- Parameters:
- affine_componentint (default=-1)
- Returns:
- numpy.ndarray, list of numpy.ndarray
- affine_points(affine_component=-1)
List of points spanning the affine part of the subspace.
Computes points in affine coordinates that, when homogenized according to
affine_component, form a basis for the subspace.- Parameters:
- affine_componentint (default=-1)
- Returns:
- list of numpy.ndarray of shape (ambient_dimension,)
- property ambient_dimension
- at_infinity(affine_component=-1)
Whether or not the subspace is at infinity.
Returns True if and only if p[affine_component] == 0 for all points p.
- Parameters:
- affine_componentint (default=-1)
- Returns:
- bool
- property atol
- center(center, remove_index=None, insert_index=0, affine_component=-1)
- Parameters:
- affine_componentint (default=-1)
- Returns:
- Subspace
See also
- property codimension
- dehomogenize(affine_component=-1)
- Parameters:
- affine_componentint (default=-1)
- Returns:
- Subspace
See also
- property dimension
- dualize(ambient_space=None)
Return dual subspace.
- Parameters:
- ambient_spaceSubspace (default=None)
Other subspace containing this subspace that should be used as ambient space when dualizing. None means whole space.
- Returns:
- Subspace
- property matrix
Matrix whose columns span the subspace in homogeneous coordinates.
- Returns:
- numpy.ndarray of shape (ambient_dimension+1, dimension+1)
- Raises:
- ValueError
If the subspace is at infinity.
- classmethod nonexact_function(f)
Decorator to use global tolerance defaults in functions.
If None is given to the wrapped function as the value for
atolorrtol, it will be replaced by the global default.
- orthonormalize(affine_component=-1)
- Parameters:
- affine_componentint (default=-1)
- Returns:
- Subspace
See also
- property points
List of points spanning the subspace in homogeneous coordinates.
- Returns:
- list of numpy.ndarray of shape (ambient_dimension+1,)
- pop_transformation()
Pop transformation from the trafo-stack.
- Returns:
- function
- push_transformation(f)
Add a transformation to the trafo-stack.
- Parameters:
- fnumpy.ndarray
- classmethod reset_tol_defaults()
- property rtol
- transform(f)
Wrapper for
push_transformation.See also
- property transformation
Product of all matrices on the stack.
- Returns:
- numpy.ndarray
- ddg.geometry.subspaces.subspace_from_rows(matrix, **kwargs)[source]
Create subspace using the rows of a matrix as points.
- Parameters:
- matrixnumpy.ndarray of shape (k+1,n+1)
- **kwargsdict
Other arguments to be passed to the Subspace.
- Returns:
- ddg.geometry.subspaces.Subspace
Notes
An empty subspace can be created by giving a 0-matrix or a matrix with shape (0,n+1).
- ddg.geometry.subspaces.subspace_from_columns(matrix, **kwargs)[source]
Create subspace using the columns of a matrix as points.
- Parameters:
- matrixnumpy.ndarray of shape (n+1,k+1)
- **kwargsdict
Other arguments to be passed to the Subspace.
- Returns:
- ddg.geometry.subspaces.Subspace
Notes
An empty subspace can be created by giving a 0-matrix or a matrix with shape (n,0).
- ddg.geometry.subspaces.hyperplane_from_normal(normal, level=None, point=None, **kwargs)[source]
An affine hyperplane defined by either <x, normal> == level, or the normal and a point (given in affine coordinates) on the plane.
- ddg.geometry.subspaces.normals(subspace, affine_component=-1)[source]
Return all normal directions of a subspace.
If p1, p2 are two points in the subspace in affine coordinates and n is a normal direction, then
<p1 - p2, n> = 0.
- Parameters:
- subspaceSubspace
- affine_componentint (default=-1)
- Returns:
- list of numpy.ndarray of shape (subspace.ambient_dimension,)
Normals in affine coordinates.
- ddg.geometry.subspaces.subspace_from_affine_points(*points, affine_component=-1, **kwargs)[source]
Create a subspace from affine points.
- Parameters:
- *pointsiterable of numpy.ndarray or list
Affine coordinate vectors
- affine_componentint (optional, default=-1)
Where to insert the affine_component for the subspace. The default -1 will append to the end.
- **kwargsdict
Other keyword arguments to be passed to the subspace.
- Returns:
- ddg.geometry.subspaces.Subspace
Subspace spanned by the given points
- ddg.geometry.subspaces.subspace_from_affine_rows(matrix, affine_component=-1, **kwargs)[source]
Create a subspace from the rows of a matrix, interpreted as affine coordinates.
- Parameters:
- matrixnumpy.ndarray
Array whichs columns describe the affine points
- affine_componentint (optional, default=-1)
Where to insert the affine_component for the subspace. The default -1 will append to the end.
- **kwargsdict
Other keyword arguments to be passed to the subspace.
- Returns:
- ddg.geometry.subspaces.Subspace
Subspace spanned by the given points
- ddg.geometry.subspaces.subspace_from_affine_columns(matrix, affine_component=-1, **kwargs)[source]
Create a subspace from the columns of a matrix, interpreted as affine coordinates.
- Parameters:
- matrixnumpy.ndarray
Array whichs columns describe the affine points
- affine_componentint (optional, default=-1)
Where to insert the affine_component for the subspace. The default -1 will append to the end.
- **kwargsdict
Other keyword arguments to be passed to the subspace.
- Returns:
- ddg.geometry.subspaces.Subspace
Subspace spanned by the given points
- ddg.geometry.subspaces.subspace_from_affine_points_and_directions(points, directions, affine_component=-1, **kwargs)[source]
Create a subspace from affine points and directions.
- Parameters:
- points(list of numpy.array) or numpy.array
List of points or a single point
- directions(list of numpy.array) or numpy.array
List of directions or a single direction
- affine_componentint (optional, default=-1)
Where to insert the affine_component for the subspace. The default -1 will append to the end.
- **kwargsdict
Other keyword arguments to be passed to the subspace.
- Returns:
- ddg.geometry.subspaces.Subspace
Subspace spanned by the given points and directions
- Raises:
- ValueError
If both points and directions are empty lists.
- ddg.geometry.subspaces.orthonormalize_subspace(subspace, affine_component=-1)[source]
Regularize the basis of a subspace.
Takes a subspace and returns another subspace with a regularized basis based on
subspace.affine_point_and_directions(). Useful in preparation for visualization.- Parameters:
- subspaceSubspace
- affine_componentint (default=-1)
- Returns:
- Subspace
- ddg.geometry.subspaces.center_subspace(subspace, center, remove_index=None, insert_index=0, affine_component=-1)[source]
Insert a specific point into the basis of a subspace.
This is especially useful in preparation for visualization: When applying this function and then using the “convex” parametrization in
to_smooth_net, the parametrization will be centered around the newcenter, if it is a point not at infinity.- Parameters:
- subspaceSubspace
- centerPoint or numpy.ndarray of shape (k,) or (k+1,)
Where k is the ambient dimension of the subspace. Point must lie in subspace. Can be given as Point object or as array containing affine or homogeneous coordinates.
- remove_indexint (default=None)
Index of vector that should be removed in favor of center. If None, we search for one.
- insert_indexint (default=0)
Index where center should be inserted.
- affine_componentint (default=-1)
- Returns:
- Subspace
The same subspace with a basis that has
centerat position insert_index.
- Raises:
- ValueError
If center does not lie in the subspace.
If the vector at
remove_indexcould not be replaced withcenterwhile still having a basis.
- ddg.geometry.subspaces.dehomogenize_subspace(subspace, affine_component=-1)[source]
Normalize affine_component entries to 1 if possible.
Useful for visualization.
- Parameters:
- Subspace
- affine_componentint (default=-1)
- Returns:
- Subspace
- ddg.geometry.subspaces.whole_space(dimension, **kwargs)[source]
Create whole space of a certain dimension as a trivial subspace.
- Parameters:
- Dimensionint
Dimension of the space.
- **kwargs
Keyword arguments other than points to be passed to Subspace.
- Returns:
- ddg.geometry.subspaces.Subspace
See also
- ddg.geometry.subspaces.join(*subspaces)[source]
Construct the join of linear subspaces.
- Parameters:
- *subspacesddg.geometry.subspaces.Subspace
- Returns:
- resultddg.geometry.subspaces.Subspace
Join of the subspaces
Notes
For the tolerances, we use the maximum of the tolerances of the subspaces.
- ddg.geometry.subspaces.meet(*subspaces)[source]
Construct the meet of projective subspaces.
- Parameters:
- *subspacesddg.geometry.subspaces.Subspace
- Returns:
- resultddg.geometry.subspaces.Subspace
Meet of the subspaces
Notes
For the tolerances, we use the maximum of the tolerances of the subspaces.
- ddg.geometry.subspaces.intersect(*subspaces)[source]
Construct intersection of projective subspaces. This is an alias for meet.
- ddg.geometry.subspaces.least_square_subspace(points, k, affine_component=-1)[source]
Computes the k-dimensional subspace closest to N projective points. See below for more details.
- Parameters:
- pointslist of ddg.Point or numpy.ndarray, each of shape (n+1,)
The given N projective points.
- kint
Required dimension of the subspace.
- affine_componentint (default=-1)
Index of affine component normalized to one.
- Returns:
- subspaceddg.Subspace
k-dimensional projective subspace.
- Raises:
- ValueError
if no points are given.
- TypeError
if points are not given as a list of ddg.Points nor as a list of numpy.ndarray.
- ValueError
if the given points (of type numpy.ndarray) are not one-dimensional numpy.ndarray.
- ValueError
if k is strictly greater than the ambient projective dimension n.
- ValueError
if the points do not all lie in the n-dimensional copy of affine space defined by x_j != 0 where j is the coordinate given by affine_component.
Notes
The resulting subspace is ‘best-fitting’ or ‘closest’ k-dimensional subspace to the N points in the sense that it minimizes the sum of the squares of the Euclidean distances of the points to it.
For an appropriate k << N, the subspace is computed in the following steps: - First, dehomogenize the N points and define a (N x n)-matrix ‘A’ whoes rows are their chosen affine coordinates. - Second, compute the matrix ‘B’ with rank k+1 that is closest to A in the Frobenius norm. This is done by first decomposing A using SVD into A = U * np.diag(s) * Vh where U and Vh are unitary matrices of shape (N x N) and (n x n) respectively and s is 1D array of singular values of A. Then defining B as the sum of the (N x n)-matrices, each of rank 1, given by product ‘(u * s) * vh’ truncated after the first k+1 terms. - Finally, return the projectivization of the (k+1)-dimensional subspace defined by the matrix B.