regpy.hilbert.base¶
Classes¶
Base class for Hilbert spaces. Subclasses must at least implement the gram property, which |
|
Makes the domain of a given (positive, self-adjoint) operator a Hilbert space with the operator as Gram matrix. |
|
Pullback of a Hilbert space on the codomain of an operator to its domain. |
|
The direct sum of an arbitrary number of hilbert spaces, with optional |
|
The Tensor product of an arbitrary number of hilbert spaces, with optional |
|
L2 implementation on a generic regpy.vecsps.VectorSpaceBase. |
|
An abstract Hilbert space that can be called on a vector space to get the corresponding |
Module Contents¶
- class regpy.hilbert.base.HilbertSpace(vecsp)[source]¶
Base class for Hilbert spaces. Subclasses must at least implement the gram property, which should return a linear regpy.operators.Operator instance. To avoid recomputing it, regpy.util.memoized_property can be used.
Hilbert spaces can be added, producing DirectSum instances on the direct sums of the underlying disretizations (see regpy.vecsps.DirectSum in the regpy.vecsps module).
They can also be multiplied by scalars to scale the norm. Note that the Gram matrix will scale by the square of the factor. This is for consistency with the (not yet implemented) Banach space case.
- Parameters:
vecsp (regpy.vecsps.VectorSpaceBase) – The underlying vector space. Should be the domain and codomain of the Gram matrix.
- log¶
- vecsp¶
The underlying vector space.
- abstract property gram¶
The gram matrix as an regpy.operators.Operator instance.
- property gram_inv¶
The inverse of the gram matrix as an regpy.operators.Operator instance. Needs only to be implemented if the gram property does not return an invertible operator (i.e. one that implements regpy.operators.Operator.inverse).
- inner(x, y)[source]¶
Compute the inner product between to elements.
This is a convenience wrapper around gram.
- Parameters:
x (array-like) – The elements for which the inner product should be computed.
y (array-like) – The elements for which the inner product should be computed.
- Returns:
The inner product.
- Return type:
float
- norm(x)[source]¶
Compute the norm of an element.
This is a convenience wrapper around norm.
- Parameters:
x (array-like) – The elements for which the norm should be computed.
- Returns:
The norm.
- Return type:
float
- class regpy.hilbert.base.GramHilbertSpace(gram, gram_inv=None)[source]¶
Bases:
HilbertSpaceMakes the domain of a given (positive, self-adjoint) operator a Hilbert space with the operator as Gram matrix.
- Parameters:
gram (operator) – The Gram matrix of the discrete Hilbert space.
gram_inv (operator, default =None) – Inverse of the Gram matrix
- property gram¶
The gram matrix as an regpy.operators.Operator instance.
- property gram_inv¶
The inverse of the gram matrix as an regpy.operators.Operator instance. Needs only to be implemented if the gram property does not return an invertible operator (i.e. one that implements regpy.operators.Operator.inverse).
- class regpy.hilbert.base.HilbertPullBack(space, op, inverse=None)[source]¶
Bases:
HilbertSpacePullback of a Hilbert space on the codomain of an operator to its domain.
For op : X -> Y with Y a Hilbert space, the inner product on X is defined as
<a, b> := <op(x), op(b)>
(This really only works in finite dimensions due to completeness). The gram matrix of the pullback space is simply G_X = op.adjoint * G_Y * op.
Note that computation of the inverse of G_X is not trivial.
- Parameters:
space (regpy.hilbert.HilbertSpace) – Hilbert space on the codomain of op.
op (regpy.operators.Operator) – The operator along which to pull back space
inverse ('conjugate', 'cholesky' or None) –
How to compute the inverse gram matrix.
’conjugate’: the inverse will be computed as op.adjoint * G_Y.inverse * op. This is in general not correct, but may in some cases be an efficient approximation.
’cholesky’: Implement the inverse via Cholesky decomposition. This requires assembling the full matrix.
None: no inverse will be implemented.
- op¶
The operator.
- space¶
The codomain Hilbert space.
- property gram_inv¶
The inverse of the gram matrix as an regpy.operators.Operator instance. Needs only to be implemented if the gram property does not return an invertible operator (i.e. one that implements regpy.operators.Operator.inverse).
- class regpy.hilbert.base.DirectSum(*args, flatten=False, vecsp=None)[source]¶
Bases:
HilbertSpaceThe direct sum of an arbitrary number of hilbert spaces, with optional scaling of the respective norms. The underlying vector space will be the regpy.vecsps.DirectSum of the underlying vector spaces of the summands.
Note that constructing DirectSum instances can be done more comfortably simply by adding regpy.hilbert.HilbertSpace instances and by multiplying them with scalars, but see the documentation for regpy.vecsps.DirectSum for the flatten parameter.
- Parameters:
*summands (HilbertSpace tuple) – The Hilbert spaces to be summed. Alternatively, summands can be given as tuples (scalar, HilbertSpace), which will scale the norm the respective summand. The gram matrices and hence the inner products will be scaled by scalar**2.
flatten (bool, optional) – Whether summands that are themselves DirectSums should be merged into this instance. Default: False.
vecsp (vecsps.VectorSpaceBase or callable, optional) – Either the underlying vector space or a factory function that will be called with all summands’ vector spaces passed as arguments and should return a vecsps.DirectSum instance. Default: vecsps.DirectSum.
- summands = []¶
- weights = []¶
- class regpy.hilbert.base.TensorProd(*args, flatten=False, vecsp=None)[source]¶
Bases:
HilbertSpaceThe Tensor product of an arbitrary number of hilbert spaces, with optional scaling of the respective norms. The underlying vector space will be the regpy.vecsps.Prod of the underlying discretizations of the factors.
Important note! The implementation of the Gram operator makes use of the BasisTransform Operator from regpy.operators.bases_transform in the sense, that the Gram matrix of the Tensor Product of discretised Hilbert spaces would be given as the Kronecker-product of all Gram matrices. Which is exactly given by the BasisTransform operator given that we interpret the Gram matrices as basis changes in each discretised Hilbert space.
Therefore, please pay attention that to do that we have to actually evaluate the Gram-matrix for each Hilbert and store it.
We want \(H_1 \otimes \dots H_l\) and each \(H_i\) is discretised by a basis of size \(n_i\) then we get a memory consumption for the Gram matrices of \(O(\sum_{i=1}^l n_i)<=O(l\cdot n)\) with \(n = \max(n_i)\).
Computing the Gram property itself can be easily seen to have the complexity \(O(\sum_{i=1}^l n_i\phi_i(n_i))<=O(l\cdot n\phi(n)))\). with \(\phi_i\) being the complexity for evaluation the Gram operator of the Hilbert space \(H_i\). Note that in the case that each Gram operator is a dense matrix this would be given by \(\phi_i(n_i)=n_i^2\) leading to a complexity of \(O(l\cdot n^3)\).
- Parameters:
*args (HilbertSpace or (scalar, HilbertSpace)) – The Hilbert spaces to be tensored. Alternatively, factors can be given as tuples (scalar, HilbertSpace), which will scale the norm of the respective factor. The gram matrices and hence the inner products will be scaled by scalar**2.
flatten (bool, optional) – Whether factors that are themselves TensorProds should be merged into this instance. Default: False.
vecsp (vecsps.VectorSpaceBase or callable, optional) – Either the underlying vector space or a factory function that will be called with all factors’ vector spaces passed as arguments and should return a vecsps.Prod instance. Default: vecsps.Prod.
- factors = []¶
- weights = []¶
- class regpy.hilbert.base.L2Generic(vecsp, weights=None)[source]¶
Bases:
HilbertSpaceL2 implementation on a generic regpy.vecsps.VectorSpaceBase.
- Parameters:
vecsp (regpy.vecsps.VectorSpaceBase) – Underlying discretization
weights (array-like) – Weight in the norm.
- weights = None¶
- class regpy.hilbert.base.AbstractSpace(name)[source]¶
Bases:
AbstractSpaceBaseAn abstract Hilbert space that can be called on a vector space to get the corresponding concrete implementation.
AbstractSpaces provide two kinds of functionality:
A decorator method register(vecsp_type) that can be used to declare some class or function as the concrete implementation of this abstract space for vector spaces of type vecsp_type or subclasses thereof, e.g.:
@Sobolev.register(vecsps.UniformGridFcts) class SobolevUniformGridFcts(HilbertSpace): ...
AbstractSpaces are callable. Calling them on a vector space and arbitrary optional keyword arguments finds the corresponding concrete regpy.hilbert.HilbertSpace among all registered implementations. If there are implementations for multiple base classes of the vector space type, the most specific one will be chosen. The chosen implementation will then be called with the vector space and the keyword arguments, and the result will be returned.
If called without a vector space as positional argument, it returns a new abstract space with all passed keyword arguments remembered as defaults. This allows one e.g. to write
H = Sobolev(index=2)
after which H(grid) is the same as Sobolev(grid, index=2) (which in turn will be the same as something like SobolevUniformGridFcts(grid, index=2), depending on the type of grid).
- Parameters:
name (str) – A name for this abstract space. Currently, this is only used in error messages, when no implementation was found for some vector space.
- name¶
- args¶