normal ( mmu, msigma, Nens ) # initial m points cmin = - 10. # standard deviation of the Gaussian prior mini = np. # mean of the Gaussian prior msigma = 10. # standard deviation of the Gaussian prior lp -= 0.5 * (( m - mmu ) / msigma ) ** 2 return lp Nens = 100 # number of ensemble points mmu = 0. # upper range of prior # set prior to 1 (log prior to 0) if in the range and zero (-inf) outside the range lp = 0. # unpack the model parameters from the tuple m, c = theta # uniform prior on c cmin = - 10. Args: theta (tuple): a sample containing individual parameter values Note: We can ignore the normalisations of the prior here. sum ((( md - data ) / sigma ) ** 2 ) def logprior ( theta ): """ The natural logarithm of the prior probability. """ # unpack the model parameters from the tuple m, c = theta # evaluate the model (assumes that the straight_line model is defined as above) md = straight_line ( x, m, c ) # return the log likelihood return - 0.5 * np. Args: theta (tuple): a sample containing individual parameter values data (list): the set of data/observations sigma (float): the standard deviation of the data points x (list): the abscissa values at which the data/model is defined Note: We do not include the normalisation constants (as discussed above).
#EMCEE MEANING PLUS#
inf # return the likeihood times the prior (log likelihood plus the log prior) return lp + loglikelihood ( theta, data, sigma, x ) def loglikelihood ( theta, data, sigma, x ): """ The natural logarithm of the joint likelihood. Args: theta (tuple): a sample containing individual parameter values data (list): the set of data/observations sigma (float): the standard deviation of the data points x (list): the abscissa values at which the data/model is defined """ lp = logprior ( theta ) # get the prior # if the prior is not finite return a probability of zero (log probability of -inf) if not np. """ from _future_ import print_function, division import os import sys import numpy as np # import emcee import emcee # import model and data from createdata import * def logposterior ( theta, data, sigma, x ): """ The natural logarithm of the joint posterior. #!/usr/bin/env python # -*- coding: utf-8 -*- """ Example of running emcee to fit the parameters of a straight line.