"## Here we create arbitrary jump proposals. This will highlight the necessary features of a jump proposal in ptmcmc. That is it takes the current position, x, then outputs a new position , q, and the jump probability i.e. p(x -> q). These will then be passed to the standard metropolis hastings condition. \n",
"## The two proposals below are probably not very good ones, ideally we would use proposals based upon our kmowledge of the problem/parameter space. In general for these proposals lqxy will certainly not be 0 "
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"class UniformJump(object):\n",
" def __init__(self, pmin, pmax):\n",
" \"\"\"Draw random parameters from pmin, pmax\"\"\"\n",
" self.pmin = pmin\n",
" self.pmax = pmax\n",
" \n",
" def unjump(self, x, it, beta):\n",
" \"\"\" \n",
" Function prototype must read in parameter vector x,\n",
" sampler iteration number it, and inverse temperature beta\n",
"### Below we create a dictionary containing our jump proposals and the relative weight of that proposal in the proposal cycle, these are then passed to bilby.run_sampler under the keyword argument custom_proposals = "
"### PTMCMC produces the acceptance rate for each of the proposals (including the ones built in). This is taken as an average at a specified checkpoint. This is one (acceptnace rate is certainly not the only/even the best metric here. Think exploration v exploitation problem ) indicators of whether our jump proposal is a good one"
## Here we create arbitrary jump proposals. This will highlight the necessary features of a jump proposal in ptmcmc. That is it takes the current position, x, then outputs a new position , q, and the jump probability i.e. p(x -> q). These will then be passed to the standard metropolis hastings condition.
## The two proposals below are probably not very good ones, ideally we would use proposals based upon our kmowledge of the problem/parameter space. In general for these proposals lqxy will certainly not be 0
%% Cell type:code id: tags:
``` python
classUniformJump(object):
def__init__(self,pmin,pmax):
"""Draw random parameters from pmin, pmax"""
self.pmin=pmin
self.pmax=pmax
defunjump(self,x,it,beta):
"""
Function prototype must read in parameter vector x,
sampler iteration number it, and inverse temperature beta
"""
# log of forward-backward jump probability
lqxy=0
# uniformly drawm parameters
q=np.random.uniform(self.pmin,self.pmax,len(x))
returnq,lqxy
```
%% Cell type:code id: tags:
``` python
classNormJump(object):
def__init__(self,step_size):
"""Draw random parameters from pmin, pmax"""
self.step_size=step_size
defnormjump(self,x,it,beta):
"""
Function prototype must read in parameter vector x,
sampler iteration number it, and inverse temperature beta
"""
# log of forward-backward jump probability. this is only zero for simple examples.
### Below we create a dictionary containing our jump proposals and the relative weight of that proposal in the proposal cycle, these are then passed to bilby.run_sampler under the keyword argument custom_proposals =
%% Cell type:code id: tags:
``` python
normjump=NormJump(1)
normweight=5
ujump=UniformJump(20,40)
uweight=1
custom={'uniform':[ujump.unjump,uweight],
'normal':[normjump.normjump,normweight]}
```
%% Cell type:code id: tags:
``` python
# Initialise the likelihood by passing in the interferometer data (ifos) and
### PTMCMC produces the acceptance rate for each of the proposals (including the ones built in). This is taken as an average at a specified checkpoint. This is one (acceptnace rate is certainly not the only/even the best metric here. Think exploration v exploitation problem ) indicators of whether our jump proposal is a good one
%% Cell type:code id: tags:
``` python
sampler_meta=result.meta_data['sampler_meta']
jumps=sampler_meta['proposals']
```
%% Cell type:code id: tags:
``` python
plt.figure()
plt.xlabel('epoch')
plt.ylabel('acceptance rate')
fori,proposalinenumerate(jumps):
plt.plot(jumps[proposal],label=proposal)
plt.legend(loc='best',frameon=True)
```
%% Output
<matplotlib.legend.Legend at 0x7f2ed97a0f50>
%% Cell type:markdown id: tags:
## We can generate the 1d chains for each of the parameters too and the likelihood of those points on the chain