Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add method or free function to combine VectorSpaces #229

Open
pjb236 opened this issue Aug 21, 2024 · 1 comment
Open

Add method or free function to combine VectorSpaces #229

pjb236 opened this issue Aug 21, 2024 · 1 comment
Assignees

Comments

@pjb236
Copy link
Contributor

pjb236 commented Aug 21, 2024

We should provide a method or a free function to allow someone to append modes to an existing vector space. This is needed for optimization, where some methods require combining the forward and adjoint bases to form one basis.

If this is implemented as a method, the call should:

  1. take the vector space to append as an argument
  2. take in an orthogonalizer, unless we have the vector space own this going forward
  3. perhaps include some ability to overwrite the shift vector.

If this is implemented as a free function, the function should:

  1. take both vector spaces as inputs, and perhaps modified one in place
  2. take in an orthogonalizer, unless we have the vector space own this going forward
  3. we might need an argument specifying which shift vector to use for the combined vector space
@pjb236
Copy link
Contributor Author

pjb236 commented Aug 21, 2024

Here's a hacky implementation I've gotten to work with existing code. The new version will need to be more eloquent that this in my opinion. Also, it will need to use an orthonormalizer.

forward_basis_tensor = forward_basis.get_basis()
adjoint_basis_tensor = adjoint_basis.get_basis()

forward_basis_matrix = _tensor_to_matrix(forward_basis_tensor)
adjoint_basis_matrix = _tensor_to_matrix(adjoint_basis_tensor)

adjoint_complement = adjoint_basis_matrix - forward_basis_matrix @ forward_basis_matrix.T @ adjoint_basis_matrix
adjoint_modes,_ = np.linalg.qr(adjoint_complement)

basis_matrix = np.concatenate([forward_basis_matrix, adjoint_modes],axis=1)
basis_tensor = _matrix_to_tensor(forward_basis.extents()[0],basis_matrix)

forward_combined_basis = DictionaryVectorSpace(basis_tensor)
forward_shift = forward_combined_basis.get_shift_vector()
forward_shift[:] = forward_basis.get_shift_vector()
adjoint_combined_basis = DictionaryVectorSpace(basis_tensor)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants