stochastic programsprobabilityand statistics def showerrorbars(minexpmaxexpnumtrials)"""assumes minexp and maxexp positive intsminexp maxexp numtrials positive integer plots mean fraction of heads with error bars""meanssds [][xvals [for exp in range(minexpmaxexp )xvals append( **expfracheadsmeansd flipsim( **expnumtrialsmeans append(meansds append(sdpylab errorbar(xvalsmeansyerr= *pylab array(sds)pylab semilogx(pylab title('mean fraction of heads (str(numtrialstrials)'pylab xlabel('number of flips per trial'pylab ylabel('fraction of heads confidence'figure produce plot with error bars of coursefinding mathematically nice model is of no use if it provides bad model of the actual data fortunatelymany random variables have an approximately normal distribution for examplephysical properties of plants and animals ( heightweightbody temperaturetypically have approximately normal distributions importantlymany experimental setups have normally distributed measurement errors this assumption was used in the early by the german mathematician and physicist karl gausswho assumed normal distribution of measurement errors in his analysis of astronomical data (which led to the normal distribution becoming known as the gaussian distribution in much of the scientific communitynormal distributions can be easily generated by calling random gauss(musigma)which returns randomly chosen floating point number from normal distribution with mean mu and standard deviation sigma it is importanthoweverto remember that not all distributions are normal uniform distributions consider rolling single die each of the six outcomes is equally probable if one were to roll single die million times and create histogram showing how often each number came upeach column would be almost the same height if one were to plot the probability of each possible lottery number being chosenit would be flat line (at divided by the range of the lottery numberssuch distributions are called uniform one can fully characterize uniform distribution with single parameterits range ( minimum and maximum valueswhile uniform distributions are quite common in games of chancethey rarely occur in naturenor are they usually useful for modeling complex manmade systems uniform distributions can easily be generated by calling random uniform(minmaxwhich returns randomly chosen floating point number between min and max