示例#1
0
文件: mcfit.py 项目: carkey/MarkovPy
def mcfit(logpost,bounds,args=(),sampler=None,proposal=None,N=10000,burnin=1000,seed=None,outfile=None):
    """
    Fit args using MCMC and return samples from the PDF.
    """
    
    if sampler == None:
        # sampler = MCSampler()
        sampler = EnsembleSampler(100)
    
    try:
        bounds = np.array(bounds)
        
        # if np.shape(bounds)[1] != 2:
        #     raise MCError("provide bounds on the parameter space")
        if proposal == None:
            proposal = (bounds[:,1]-bounds[:,0])/10.
        
        return sampler.sample_pdf(logpost,bounds,proposal,N,burnin,args,outfile=outfile,seed=None)
    except (MCError,ProposalErr): # as e:
        print "MCMC exception raised with message: "+e.value