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

Metropolis Algorithm for MCMC #1262

Merged
merged 36 commits into from
Jul 25, 2020
Merged

Metropolis Algorithm for MCMC #1262

merged 36 commits into from
Jul 25, 2020

Conversation

wangcj05
Copy link
Collaborator

@wangcj05 wangcj05 commented Jul 6, 2020


Pull Request Description

What issue does this change request address? (Use "#" before the issue to link it, i.e., #42.)

close #1260
This PR will also update the submodule ID of LOGOS. Recent changes in RAVEN dependencies file structure caused the failure of LOGOS regression test. This has been recently fixed in LOGOS. see issue #1114
In addition, this PR also make some improvement on the restart capability (see #1280), this is because metadata is required for several Samplers when restarted is requested.

Implementation of Markov Chain Monte Carlo algorithm, i.e. Metropolis Algorithm.

What are the significant changes in functionality due to this change request?

For Change Control Board: Change Request Review

The following review must be completed by an authorized member of the Change Control Board.

  • 1. Review all computer code.
  • 2. If any changes occur to the input syntax, there must be an accompanying change to the user manual and xsd schema. If the input syntax change deprecates existing input files, a conversion script needs to be added (see Conversion Scripts).
  • 3. Make sure the Python code and commenting standards are respected (camelBack, etc.) - See on the wiki for details.
  • 4. Automated Tests should pass, including run_tests, pylint, manual building and xsd tests. If there are changes to Simulation.py or JobHandler.py the qsub tests must pass.
  • 5. If significant functionality is added, there must be tests added to check this. Tests should cover all possible options. Multiple short tests are preferred over one large test. If new development on the internal JobHandler parallel system is performed, a cluster test must be added setting, in XML block, the node <internalParallel> to True.
  • 6. If the change modifies or adds a requirement or a requirement based test case, the Change Control Board's Chair or designee also needs to approve the change. The requirements and the requirements test shall be in sync.
  • 7. The merge request must reference an issue. If the issue is closed, the issue close checklist shall be done.
  • 8. If an analytic test is changed/added is the the analytic documentation updated/added?
  • 9. If any test used as a basis for documentation examples (currently found in raven/tests/framework/user_guide and raven/docs/workshop) have been changed, the associated documentation must be reviewed and assured the text matches the example.

@wangcj05 wangcj05 requested a review from alfoa July 6, 2020 22:34
@wangcj05 wangcj05 added the RAVENv2.1 All tasks and defects that will go in RAVEN v2.1 label Jul 6, 2020
@moosebuild
Copy link

Job Test CentOS 7 on 8f116ea : invalidated by @wangcj05

conda error when setting python environment


def localInputAndChecks(self, xmlNode, paramInput):
"""
unfortunately-named method that serves as a pass-through for input reading.
Copy link
Collaborator

Choose a reason for hiding this comment

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

unfortunately-named method? O_o

Copy link
Collaborator

Choose a reason for hiding this comment

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

10:1 says I wrote the original version this was copied from ... heh

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

else:
self._proposal[var] = None
# TargetEvaluation Node (Required)
targetEval = paramInput.findFirst('TargetEvaluation')
Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe the AdaptiveSampler does this for you, so it should not be needed here if you call the base class, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Currently, the adaptive sampler using following lines to define and retrieve TargetEvaluation:

 self.addAssemblerObject('TargetEvaluation', 'n')
...
self._targetEvaluation = self.assemblerDict['TargetEvaluation'][0][3]

Which in my opinion should be changed to use

self.retrieveObjectFromAssemblerDict

@alfoa
Copy link
Collaborator

alfoa commented Jul 10, 2020

@wangcj05 I like the generality of allowing the user to use any distribution for the proposal (following the general metropolis-hasting algo), but I am afraid that we will "pay" this generality in terms of convergence issues and/or unexpected behavior. For example, how do we handle the discrete distributions here? Multivariates?

@alfoa
Copy link
Collaborator

alfoa commented Jul 10, 2020

@wangcj05 as during our conversation, if we limit the usability of the proposal distributions and check the truncability, I am good for the merge

@@ -439,6 +439,15 @@ def pdf(self,x):
returnPdf = self._distribution.pdf(x)
return returnPdf

def logpdf(self,x):
Copy link
Collaborator

Choose a reason for hiding this comment

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

I am having my revenge here: should it be logPdf?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed.

"""
descr = r"""
\section{Markov Chain Monte Carlo} \label{sec:MCMC}
The Markov chain Monte Carlo (MCMC) is another important entity in the RAVEN framework.
Copy link
Collaborator

Choose a reason for hiding this comment

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

... is another important sampler ...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed


def localFinalizeActualSampling(self, jobObject, model, myInput):
"""
General function (available to all samplers) that finalize the sampling
Copy link
Collaborator

Choose a reason for hiding this comment

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

finalizes

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

@ In, externalSeeding, int, optional, external seed
@ In, solutionExport, DataObject, optional, a PointSet to hold the solution
@ Out, None
"""
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is a generic question: does this MCMC method allow the user to use a chain generated in the past that needs to be augmented?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think the answer for this question is No for current implementation. This seems to me similar to Restart option.

Copy link
Collaborator

Choose a reason for hiding this comment

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

No restart?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you try a test for it?

@mandd
Copy link
Collaborator

mandd commented Jul 10, 2020

I have completed a first round of comments; I need a bit more time to think more about it

@wangcj05
Copy link
Collaborator Author

@alfoa I have added the checks for Distributions. Only continuous distribution is allowed.

@wangcj05
Copy link
Collaborator Author

@mandd I have addressed your comments.

@ In, externalSeeding, int, optional, external seed
@ In, solutionExport, DataObject, optional, a PointSet to hold the solution
@ Out, None
"""
Copy link
Collaborator

Choose a reason for hiding this comment

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

No restart?

@ In, externalSeeding, int, optional, external seed
@ In, solutionExport, DataObject, optional, a PointSet to hold the solution
@ Out, None
"""
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you try a test for it?

mean: [5, 5], cov=[[1, 0.9], [0.9, 1]]
Both input parameters have the standard normal distribution as their prior distribution.
The proposal distributions for the input variables are also standard normal distribution.
"TargetEvaluation" is used to collect the inputs and outputs from the likelihood model.
Copy link
Collaborator

Choose a reason for hiding this comment

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

since this goes into a latex file, I would use the `` '' construct for the quotes

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

@wangcj05
Copy link
Collaborator Author

@alfoa I have opened an issue for the restart problem, see #1280. As we discussed, it is a basic issue for raven, and we need a discussion on this. I think a different PR need to be created to address the issue. Please let me know what you think.

@moosebuild
Copy link

All jobs on 87b7177 : invalidated by @alfoa

@alfoa
Copy link
Collaborator

alfoa commented Jul 23, 2020

@wangcj05 do you want to develop the restart here or in another PR?

@wangcj05
Copy link
Collaborator Author

@wangcj05 do you want to develop the restart here or in another PR?

I have updated the Metropolis Sampler with the restart capability. The original test has also been updated with the restart.

@wangcj05
Copy link
Collaborator Author

@alfoa I have addressed all your comments, restart is now tested, and the tests are green now.

@alfoa
Copy link
Collaborator

alfoa commented Jul 25, 2020

Checklist passed...

Comments have been addressed...

I approve this PR...

Merging...

@wangcj05 can you update the issue #1225 for the new release changelog?

@alfoa alfoa merged commit 2a94807 into devel Jul 25, 2020
@alfoa alfoa deleted the wangc/mcmc branch July 25, 2020 17:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RAVENv2.1 All tasks and defects that will go in RAVEN v2.1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[TASK] Markov Chain Monte Carlo: Metropolis Algorithm
5 participants