def ppf_phi ( x ): return sin2x.ppf( x )
''' Created on 27.03.2012 @author: Axel ''' from stats.pdistrib.sin2x_distr import sin2x print sin2x.ppf(1)
# joint probability density function of embedded lengths and inclination angles #e = make_ogrid([l, phi]) #m.surf(e[0], e[1], l*np.cos(phi[:,np.newaxis])) #m.surf(e[0], e[1], 1./2*np.ones_like(l)*np.sin(2.*phi[:,np.newaxis])) #m.show() # exact solution of number of fibers with distance from crack sim = 10000. def mc(z, uhel, delka): return np.sum(delka * np.cos(uhel) > z)/sim n_list = [] z_arr = np.linspace(0,1,50) for z in z_arr: n_list.append(mc(z,sin2x.ppf(np.random.rand(sim)), uniform(loc = 0, scale = 1).ppf(np.random.rand(sim)))) def exact(lf, z): return (lf-2*z)**2/lf**2 def power(z): return np.ones_like(z) - 2*z + z**2 plt.plot(z_arr,n_list, color = 'red', lw = 3, ls = 'dashed', label = 'MC') plt.plot(z_arr,exact(2.,z_arr), color = 'black', lw = 1, label = 'analytical') plt.plot(z_arr,power(z_arr), color = 'green', lw = 2, label = 'power series') plt.legend(loc = 'best') plt.ylim(0,1.1) plt.show()
import numpy as np from math import pi as Pi from matplotlib import pyplot as plt x = np.linspace( 0, Pi / 2 , 10000 ) pdf = sin2x.pdf( x ) sin2stats = sin2x.stats() #plt.plot( x, y2 ) plt.fill( x, pdf, facecolor = 'red', alpha = 0.2 , hatch = '\\' ) plt.axvline( x = sin2stats[0] , linewidth = 2.0, color = 'red' ) plt.xlabel( '$\phi$ in [$Rad$]', fontsize = 20 ) plt.ylabel( '$f_\phi (\phi)$', fontsize = 22 ) plt.title( 'Dichtefunktion PDF $sin(2\phi)$' , fontsize = 20 ) plt.xlim( 0, Pi / 2 ) legend_names = ['Erwartungswert $E_\phi(\phi)$', 'Dichtefunktion $sin(x)$'] plt.legend( legend_names, 'upper left' ) plt.show() ppf_x = np.linspace( 0, 1 , 10000 ) ppf = sin2x.ppf( ppf_x ) ppf[-1] = 0 nulls = np.zeros( len( ppf ) ) #plt.fill( x, ppf, facecolor = 'red', alpha = 0.2 , hatch = '/' ) plt.fill( ppf_x , ppf, facecolor = 'red', alpha = 0.2 , hatch = '\\' ) plt.title( 'Inverse Verteilungsfunktion PPF $sin(2\phi)$' , fontsize = 20 ) plt.xlabel( '$F_\phi(\phi)$', fontsize = 20 ) plt.ylabel( '$\phi$ in [$Rad$]', fontsize = 22 ) plt.axhline( y = sin2stats[0] , linewidth = 2.0, color = 'red' ) legend_names2 = ['Erwartungswert $E_\phi(\phi)$', 'Inverse Verteilungsfunktion $F_\phi^{-1}(\phi)$'] plt.legend( legend_names2, 'upper left' ) plt.show()