# -*- coding: utf-8 -*- # diese Zeile legt die Codierung von Umlauten fest ################################################################## # script Likelihood-pdf.py ''' Illustration Likelihood .. author:: Günter Quast für den Kurs Computergestützte Datenauswertung (CgDA) ''' #-------------------------------------------------------------- import numpy as np, matplotlib.pyplot as plt import scipy.integrate as integrate # Beispiele für Funktionsdefinitionen # Funktionen aus numpy verwenden, da sie auf array angewendet werden können # define a function (Gauss distribution) def fgauss(x,mu,sigma): return np.exp(-(x-mu)**2/2./sigma**2)/np.sqrt(2.*np.pi)/sigma def npdf(x, a, b): def f(x): return x**3 * np.exp(-x) norm=integrate.quad(f, a, b)[0] return f(x)/norm ##### ---- main Program starts here ----- # create figure object fig = plt.figure('Likelihood', figsize=(10., 5.) ) ## numpy-array(s) fuer Stuetzstellen und axis-Objekt(e) erzeugen xmin,xmax=0., 10. npoints=256 X=np.linspace( xmin, xmax, npoints, endpoint=True) ax1 = fig.add_subplot(1, 2, 1) ax2 = fig.add_subplot(1, 2, 2) ## Plot(s) der Funktion(en) erzeugen mu = 5 sig = 1.5 ax1.plot(X, fgauss(X, mu, sig ), '-', color='darkblue', linewidth=3) ax2.plot(X, npdf(X, xmin, xmax), '-', color='darkblue', linewidth=3) xm=[0.7, 1.1, 1.9, 2.7, 4.5, 5.9, 6.5] L1=1. L2=1. for x in xm: ax1.plot( [x,x], [0., fgauss(x, mu, sig)], 'r-', lw=2) L1*=fgauss(x, mu, sig) ax2.plot( [x,x], [0., npdf(x, xmin, xmax)], 'r-', lw=2) L2*=npdf(x,xmin, xmax) ax1.text(0.1,0.93, 'L1=%.2g'%L1, transform=ax1.transAxes,size='x-large', color='blue') ax2.text(0.5,0.93, 'L2=%.2g'%L2, transform=ax2.transAxes,size='x-large', color='blue') #plt.legend() plt.show() # show on screen #fig.savefig('MyFig.pdf')