2

I have a function with three parameters a,b and c and I want to define different priors for each of these parameters. I am using the emcee package.

I started with the simple uniform (non-informative) prior:

def lnprior(theta):
    m, b, c = theta
    if 1.0 < m < 2.0 and 1.0 < b < 2.0 and 1.0 < c < 2.0:
        return 0.0
    return -np.inf

I would like to have for each parameter a different prior. For instance for a I would like to have a Normal(mu,sigma) prior, while for b an uniform and for c a Jeffreys prior (1/c). Up to now I come out with the following:

def lnprior(theta):
    a, b, c = theta

    mu = 0.5 # mean of the Normal prior
    sigma = 0.1 # standard deviation of the Normal prior

if not (1.0 < b < 2.0): # the bound on the uniform
    return -np.inf
if c < 0.0:             # the bound on the Jeffreys
    return -np.inf
return .... # total log-prior to be determined

As far as I understood in log-scale I have to add together all the probabilities to define the total one (the return value of lnprior). So let's start with the Normal on a:

log_Pr(a) = np.log( 1.0 / (np.sqrt(2*np.pi)*sigma) ) - 0.5*(a - mu)**2/sigma**2;

then the prior on c:

log_Pr(c) = -log(c).

Thus the total log-prior should be: Pr(a)+Pr(c). My question, is this approach correct?

Thanks

Stefan Zobel
  • 3,182
  • 7
  • 28
  • 38

1 Answers1

3

Try the following one:

def lnprior(theta):
    a, b, c = theta
    #flat priors on b, c
    if not 1.0 < b < 2.0 and c > 0:
        return -np.inf
    #gaussian prior on a and c
    mu = 0.5
    sigma = 0.1
    ### your prior is gaussian * (1/c), take natural log is the following:
    return np.log(1.0/(np.sqrt(2*np.pi)*sigma))-0.5*(a-mu)**2/sigma**2 - np.log(c)
Huanian Zhang
  • 830
  • 3
  • 16
  • 37
  • are you still here? I would like to ask a question – Ma Y Mar 05 '19 at 22:03
  • Yes, what is your question? – Huanian Zhang Mar 07 '19 at 22:59
  • how to guess mean (`mu`) for a n unknown parameter? – Ma Y Mar 07 '19 at 23:20
  • What I do is: 1) guess the parameters from literature. 2) I guess by knowledge and run a small mcmc set to see what range of those parameters, and then set the mu or sigma from this small running. Hope it helps. – Huanian Zhang Mar 08 '19 at 16:04
  • Do you know what the problem is? consider for `b` I guess an initial point equal to `5` and for `mu` I guess it is `4.3` the final results after `n` steps of MCMC is very close to `4.3` which could not be reasonable. – Ma Y Mar 09 '19 at 21:23