Zero source rj - #14
Conversation
Signed-off-by: code_reformat <>
…into zero_source_rj
mattj89
left a comment
There was a problem hiding this comment.
Some docstring updates. I don't understand a lot of the code changes (e.g. returning the allocation matrix as a parameter vector from the MixtureParameter cases). Let's discuss next week.
| parameters that need to be created/removed as part of the dimension change. The default behaviour is to | ||
| sample the necessary additional values from the associated parameter prior distribution. Defaults to None. | ||
| n_max (int): upper limit on self.param (lower limit is assumed to be 1). | ||
| n_max (int): upper limit on self.param. |
There was a problem hiding this comment.
Added this for completeness but the fact is pretty much every input to RJ has None as default but is in actual fact required to make it run.
| """ | ||
| return sparse.diags(diagonals=state[self.param][state[self.allocation]].flatten(), offsets=0, format="csc") | ||
| if state[self.param].shape[0] == 0: | ||
| diagonals = state[self.allocation].flatten() |
There was a problem hiding this comment.
I think that self.allocation is an allocation index (i.e. index vector which determines the allocation of each element of the data to e.g. a kernel). I don't think this should just go on the diagonal of a precision matrix? Totally different to the functionality which is in the other case statement?
There was a problem hiding this comment.
have updated to zeros and looked at cases where this is used and it is not used anywhere but the unit tests
|
|
||
| """ | ||
| if state[self.param].shape[0] == 0: | ||
| return state[self.allocation] |
There was a problem hiding this comment.
As with the matrix case (lines 503-508), why would just just set the predictor to be the allocation vector?
There was a problem hiding this comment.
have updated to zeros and looked at cases where this is used and it is not used anywhere but the unit tests
mattj89
left a comment
There was a problem hiding this comment.
I am mostly fine with this- couple of points that we should discuss when I'm back, but then I think we can go ahead and merge.
| raise ValueError("Reversible jump MCMC: n_max must be specified.") | ||
|
|
||
| if self.n_max <= self.n_min: | ||
| raise ValueError("Reversible jump MCMC: n_max must be greater than n_min.") |
There was a problem hiding this comment.
Should we not check that n_max is strictly greater than n_min? In the case where they're equal, shouldn't be using the RJMCMC?
| if log_prop_density.shape[0] > 0: | ||
| logp_pr_g_cr += np.log(p_birth) + log_prop_density[-1] | ||
| else: | ||
| logp_pr_g_cr += np.log(p_birth) |
There was a problem hiding this comment.
We may have already discussed this, but what situation is this catching? And do we want to resolve it by imposing more requirements on the function calculating log_prop_density instead?
| else: | ||
| diagonals = state[self.param][state[self.allocation]].flatten() | ||
|
|
||
| return sparse.diags(diagonals=diagonals, offsets=0, format="csc") |
There was a problem hiding this comment.
Think I'm fine with these now- but might be helpful to spend a little time thinking through all potential consequences when I'm back to make sure we're not causing any problems by making this choice.
| """ | ||
| state, n, p = state_tuple | ||
|
|
||
| p = np.maximum(p, 1) |
There was a problem hiding this comment.
Feel like this needs explanation in the docstring- presumably it's been added to catch the zero-element case, but feels like a fudge. Would it not be better to just assert this case separately? At least explain what should happen in the docstring.
There was a problem hiding this comment.
No issue with the content of this, but as you mentioned, it takes way too long to run.... We should probably think of a solution before merging, sinc we can't realistically expect people to sit for that long when making PRs etc. Maybe just do the [0, 10] case?
Description
Extend reversible jump code to handle reversible jump cases with no components.
Type of change
Please delete options that are not relevant.
Jupyter Notebooks
No changes to existing notebooks
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce.
Please also list any relevant details for your test configuration
Checklist: