0

Can't get the trace to converge in my simple polynomial fitting program. I will include an example of the 'a' parameter below. They only thing I can think of is that because I'm using logarithmic data, and the log-likelihood is causing a problem? I'm quite new to this, and I'm unsure. Hence I'm directing my question here.

This is the code I'm running:

  y=vc
  x=vt
  y=np.asarray(y)
  x=np.asarray(x)
  z = np.polyfit(x, y, 2) # the traditional chi-square fit
  print 'The chi-square result: ', z

  #The chi-square result: [ -0.63802271 5.83847593 -13.24021273]

  #priors
  sig = pymc.Uniform('sig', 0, 100, value=1)

  a = pymc.Uniform('a', -100, 100,value=0)
  b = pymc.Uniform('b', -100, 100,value=0)
  c = pymc.Uniform('c', -100, 100,value=0)


  #model
  @pymc.deterministic(plot=False)
  def mod_quadratic(x=x, a=a, b=b, c=c):
      return a*x**2 + b*x + c

  #likelihood
  y = pymc.Normal('y', mu=mod_quadratic, tau=1.0/sig**2, value=y, observed=True)

I have logarithmic x and y values as the input, and I fit a simple x**2 polynomial.

I keep the input file modest:

  import pymc,v
  # load the model file
  import numpy as np
  import matplotlib.pyplot as plt

  R = pymc.MCMC(v) # build the model
  R.sample(iter=100000,burn=20000,thin=100) # populate and run it
  print 'a ', R.a.value # print outputs
  print 'b ', R.b.value
  print 'c ', R.c.value
  print 'a ', R.a.stats()
  print 'b ', R.b.stats()
  print 'c ', R.c.stats()

The trace does not converge. If I use non-logarithmic data the trace converges, however the fit is not acceptable as a polynomial does not fit the non-logarithmic data.

sig trace window b trace window

To save space I have only include the b trace, but they are show the same non-convergance.

Does anyone see my flaw? I'm sure I'm doing something wrong here..

Thanks

Till Hoffmann
  • 9,479
  • 6
  • 46
  • 64
Akerfeldt
  • 31
  • 1
  • 7
  • What is your proposal distribution? The second trace looks like your proposal is too narrow. – Till Hoffmann Oct 10 '16 at 23:10
  • @TillHoffmann - I think in this case my proposal distribution is my priors. And yes I agree it does look narrow. – Akerfeldt Oct 11 '16 at 09:56
  • Hm, this may be my ignorance of `pymc`: if `pymc.MCMC` is a Metropolis Hastings sampler, then the proposal is unlikely to be the prior (it would just be an [independence sampler](https://www.lancaster.ac.uk/pg/jamest/Group/stats4.html) in that case). You may find this question to be more suitable on [stats.stackexchange.com](http://stats.stackexchange.com). – Till Hoffmann Oct 11 '16 at 16:47
  • @TillHoffmann I think that by default it uses the priors as the proposal. I've moved my question to the thread you recommended, it does seem more appropriate there- thanks. – Akerfeldt Oct 11 '16 at 20:02

0 Answers0