def mcmc_advance(start, stdevs, logp, nsteps = <NUM_LIT>, adapt=True, callback=None):
import scipy<EOL>from numpy import log<EOL>import progressbar<EOL>prob = logp(start)<EOL>chain = [start]<EOL>accepts = [True]<EOL>probs = [prob]<EOL>assert not numpy.isnan(start).any()<EOL>assert not numpy.isnan(stdevs).any()<EOL>i = <NUM_LIT:0><EOL>widgets=['<STR_LIT>', progressbar.Percentage(), progressbar.Counter('<STR_LIT>'),<EOL>progressbar.Bar(), progressbar.ETA()]<EOL>pbar = progressbar.ProgressBar(widgets=widgets,<EOL>maxval=nsteps).start()<EOL>prev = start<EOL>prev_prob = prob<EOL>print('<STR_LIT>', prob)<EOL>stepchange = <NUM_LIT:0.1><EOL>while len(chain) < nsteps:<EOL><INDENT>i = i + <NUM_LIT:1><EOL>next = scipy.random.normal(prev, stdevs)<EOL>next[next > <NUM_LIT:1>] = <NUM_LIT:1><EOL>next[next < <NUM_LIT:0>] = <NUM_LIT:0><EOL>next_prob = logp(next)<EOL>assert not numpy.isnan(next).any()<EOL>assert not numpy.isnan(next_prob).any()<EOL>delta = next_prob - prev_prob<EOL>dice = log(scipy.random.uniform(<NUM_LIT:0>, <NUM_LIT:1>))<EOL>accept = delta > dice<EOL>if accept:<EOL><INDENT>prev = next<EOL>prev_prob = next_prob<EOL>if adapt: stdevs *= (<NUM_LIT:1> + stepchange)<EOL><DEDENT>else:<EOL><INDENT>if adapt: stdevs *= (<NUM_LIT:1> + stepchange)**(-<NUM_LIT>) <EOL><DEDENT>if callback: callback(prev_prob, prev, accept)<EOL>chain.append(prev)<EOL>accepts.append(accept)<EOL>probs.append(prev_prob)<EOL>if adapt: stepchange = min(<NUM_LIT:0.1>, <NUM_LIT> / i)<EOL>widgets[<NUM_LIT:0>] = '<STR_LIT>' % numpy.mean(numpy.array(accepts[len(accepts)/<NUM_LIT:3>:])+<NUM_LIT:0>)<EOL>pbar.update(pbar.currval + <NUM_LIT:1>)<EOL><DEDENT>pbar.finish()<EOL>return chain, probs, accepts, stdevs<EOL>
Generic Metropolis MCMC. Advances the chain by nsteps.
Called by :func:`mcmc`

:param adapt: enables adaptive stepwidth alteration (converges).