toggle all code blocks

Examples of physical measurements

...
import numpy from pylab import * from pacal import *
.
Using compiled interpolation routine
...
from pacal.distr import demo_distr
.

coefficient of thermal expansion

...
L0 = UniformDistr(9,10) L1 = UniformDistr(11,12) dT = NormalDistr(1,2) k = (L1/L0 - 1)/dT k.plot(linewidth=3, color = "k") k.hist(xmin=-1,xmax=1,color="0.75") k.summary()
.
============= summary =============
  ((U(11,12)/U(9,10))-1)/N(1,2)
                mean  =  0.00778444188329
                 std  =  inf
                 var  =  inf
              median  =  0.0746995786027
            medianad  =  0.126533522192
      iqrange(0.025)  =  2.97731719835
               range  =  (-inf, inf)
            ci(0.05)  =  (-1.4608136836263554, 1.5165035147281165)
             int_err  =  8.79296635503e-14
...
print "P(K<0) - NormalDistr(1,2).cdf(0) =", k.cdf(0)[0] - NormalDistr(1,2).cdf(0)[0]
.
P(K<0) - NormalDistr(1,2).cdf(0) = -4.14113188185e-14
...
xlim(-1,1) ylim(ymin=0) title("Distribution of thermal expansion coefficient") show()
.
measurements_pyreport_0.png
...
.

combining two independent measurements

...
from scipy.optimize.optimize import fminbound # E1 = UniformDistr(0,2) # E2 = BetaDistr(2,2) # E2 = BetaDistr(0.5,0.5) E1 = UniformDistr(-1,1) E2 = NormalDistr() E1.summary()
.
============= summary =============
  U(-1,1)
                mean  =  3.51164110413e-16
                 std  =  0.57735026919
                 var  =  0.333333333333
              median  =  0.0
            medianad  =  0.5
      iqrange(0.025)  =  1.9
               range  =  (-1.0, 1.0)
            ci(0.05)  =  (-0.94999999999999996, 0.94999999999999996)
             int_err  =  0.0
...
E2.summary()
.
============= summary =============
  N(0.0,1.0)
                mean  =  1.94289029309e-16
                 std  =  1.0
                 var  =  1.0
              median  =  -7.77156117238e-16
            medianad  =  0.674489750196
      iqrange(0.025)  =  3.91992796908
               range  =  (-inf, inf)
            ci(0.05)  =  (-1.9599639845398045, 1.9599639845400472)
             int_err  =  -4.4408920985e-16
...
def E(alpha): alpha = numpy.squeeze(alpha) return alpha*E1 + (1 - alpha)*E2 print
.
...
print "Combining measurements for optimal variance"
.
Combining measurements for optimal variance
...
alphaOptVar = fminbound(lambda alpha: E(alpha).var(), 0, 1, xtol = 1e-16) print "alphaOptVar = ", alphaOptVar
.
alphaOptVar =  [ 0.75]
...
dopt = E(alphaOptVar) dopt.summary()
.
============= summary =============
  0.75*U(-1,1)+0.25*N(0.0,1.0)
                mean  =  1.56125112838e-16
                 std  =  0.5
                 var  =  0.25
              median  =  0.0
            medianad  =  0.382868515015
      iqrange(0.025)  =  1.83555677038
               range  =  (-inf, inf)
            ci(0.05)  =  (-0.91777838519074428, 0.91777838519074428)
             int_err  =  0.0
...
print
.
...
print "Combining measurements for optimal Median Absolute Deviance"
.
Combining measurements for optimal Median Absolute Deviance
...
alphaOptMad = fminbound(lambda alpha: E(alpha).medianad(), 0, 1, xtol = 1e-16) print "alphaOptMAD = ", alphaOptMad
.
alphaOptMAD =  [ 0.64492105]
...
dopt = E(alphaOptMad) dopt.summary()
.
============= summary =============
  0.644921052358*U(-1,1)+0.355078947642*N(0.0,1.0)
                mean  =  1.49186218934e-16
                 std  =  0.514511529171
                 var  =  0.26472211365
              median  =  -5.55111512313e-17
            medianad  =  0.366016941933
      iqrange(0.025)  =  1.96758060444
               range  =  (-inf, inf)
            ci(0.05)  =  (-0.98379030222134256, 0.98379030222134167)
             int_err  =  -2.22044604925e-16
...
print
.
...
print "Combining measurements for optimal 95% confidence interval"
.
Combining measurements for optimal 95% confidence interval
...
alphaOptIQrange = fminbound(lambda alpha: E(alpha).iqrange(0.025), 0, 1, xtol = 1e-16) print "alphaOptIQrange = ", alphaOptIQrange
.
alphaOptIQrange =  [ 0.86972011]
...
dopt = E(alphaOptIQrange) dopt.summary()
.
============= summary =============
  0.869720113907*U(-1,1)+0.130279886093*N(0.0,1.0)
                mean  =  2.65412691824e-16
                 std  =  0.518758653806
                 var  =  0.269110540899
              median  =  -2.22044604925e-16
            medianad  =  0.434874411821
      iqrange(0.025)  =  1.77536580577
               range  =  (-inf, inf)
            ci(0.05)  =  (-0.88768290288250762, 0.88768290288250618)
             int_err  =  -4.4408920985e-16
...
print "-----------------------"
.
-----------------------
...
figure() E1.plot(color='k') E2.plot(color='k') E(alphaOptVar).plot(color='r') E(alphaOptMad).plot(color='g') E(alphaOptIQrange).plot(color='b') show()
.
measurements_pyreport_1.png
...
figure() E(alphaOptVar).get_piecewise_cdf().plot(color='r') E(alphaOptMad).get_piecewise_cdf().plot(color='g') E(alphaOptIQrange).get_piecewise_cdf().plot(color='b') show()
.
measurements_pyreport_2.png