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

Laplace approximation to posterior #20

Merged
merged 29 commits into from
Apr 24, 2024
Merged

Laplace approximation to posterior #20

merged 29 commits into from
Apr 24, 2024

Conversation

V-Rang
Copy link
Collaborator

@V-Rang V-Rang commented Apr 11, 2024

Adding modeling/laplaceApproximation.py and algorithms/lowRankOperator.py

hippylibX/algorithms/lowRankOperator.py Outdated Show resolved Hide resolved
hippylibX/algorithms/lowRankOperator.py Outdated Show resolved Hide resolved
hippylibX/algorithms/lowRankOperator.py Outdated Show resolved Hide resolved
hippylibX/algorithms/multivector.py Outdated Show resolved Hide resolved
hippylibX/algorithms/multivector.py Outdated Show resolved Hide resolved
hippylibX/modeling/laplaceApproximation.py Outdated Show resolved Hide resolved
hippylibX/modeling/laplaceApproximation.py Outdated Show resolved Hide resolved
hippylibX/modeling/laplaceApproximation.py Outdated Show resolved Hide resolved
example/poisson_dirichlet_example.py Outdated Show resolved Hide resolved
example/poisson_dirichlet_example.py Outdated Show resolved Hide resolved
example/sfsi_toy_gaussian.py Outdated Show resolved Hide resolved
example/sfsi_toy_gaussian.py Outdated Show resolved Hide resolved
example/poisson_dirichlet_example.py Outdated Show resolved Hide resolved

noise = prior.generate_parameter("noise")

######################################################
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment above (multiple samples in the same file)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modification made.

example/sfsi_toy_gaussian.py Outdated Show resolved Hide resolved
hippylibX/algorithms/multivector.py Outdated Show resolved Hide resolved
hippylibX/modeling/laplaceApproximation.py Outdated Show resolved Hide resolved
prior,
d: np.array,
U: MultiVector,
createVecLeft=None,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also here:

createVecLeft and createVecRight are not needed

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed both.

hippylibX/modeling/laplaceApproximation.py Outdated Show resolved Hide resolved
if len(args) == 2:
self._sample_given_prior(args[0], args[1])
if add_mean:
temp_petsc_vec_arg1 = dlx.la.create_petsc_vector_wrap(args[1])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very confusing. Should it just be:

args[1].array[:] += self.mean.array

Copy link
Collaborator Author

@V-Rang V-Rang Apr 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been fixed here. Thanks for pointing this out:

if len(args) == 2:
self._sample_given_prior(args[0], args[1])
if add_mean:
args[1].array[:] += self.mean.array
elif len(args) == 3:
self._sample_given_white_noise(args[0], args[1], args[2])
if add_mean:
args[1].array[:] += self.prior.mean.array
args[2].array[:] += self.mean.array
else:
raise NameError("Invalid number of parameters in Posterior::sample")

hippylibX/modeling/laplaceApproximation.py Outdated Show resolved Hide resolved
def createVecLeft(self) -> petsc4py.PETSc.Vec:
return self.prior.R.createVecLeft()

def sample(self, noise: dlx.la.Vector, s: dlx.la.Vector):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rename as mult

cd ./hippylibX/test &&
mpirun -n 2 python3 test_lowRankHessian.py

- name: low rank Hessian precondtioner testing
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spelling: preconditioner

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spelling changed. Thanks for pointing it out.

@V-Rang V-Rang merged commit 4ef37ef into main Apr 24, 2024
@V-Rang V-Rang deleted the laplace_approx branch April 24, 2024 13:33
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

Successfully merging this pull request may close these issues.

2 participants