RtsigntrighttleftR*(RRRrRuR>RsR+RtRqRvR(((Rt __embraceRsL " cCs|o |}nd}d}x'|djo|d|d}}q Wx'|djo|d|d}}qJWtd|d|}t||djod|Sn|S(s2Returns a suitable power of 10 for examining what.iii f10.0N(thattwhattdecadeReR5tint(RRxRyR5Rz((Rt__units cCs|djo<y|i}WqIttfj o|i}qIXnt|djo | Sn|o|d|jo | Snd|i}|djpt d||if|i||\}} |djod\}}n d\}}d\}}}|itt|| }| djo.d t|i} |td | d}nd}|djo d} nTt|} | d d jo(d| jod| idd} nd|d} x|| jp ||jobt||||}|||||| }}t!|||d|}|djo$hdd<dd<|d}n|djo |}n|||}|ot|||joK| o-| ddjp t | d| d} nt|dj}Pnt|| jod}Pq$n|i$|d||d|}d |}qWt|djp| djp ||j}yx|djo|d}|d }ychdd<dd<dd<dd<dd<dd<dd<dd<dd<|| } Wnt&j od| } qXd}qWWnt'j o|d}nX|| }|o!|o|d d|d}n||S( s?Returns a rounding-string for estim. Argument, estim, is optional: if omitted, the distribution's median (if available) or mean (likewise) will be used. Result is a string representing this value to some accuracy, in %e-style format. This implicity represents an interval, given by `plus or minus a half in the last digit'. This interval will contain estim. Normally, the interval denoted by the result string will contain less than half the weight of self's distribution and is the shortest such representation. E.g. if self.between(3.05, 3.15) >= .5 > self.between(3.135, 3.145) then self.round(pi) will return '3.14'. That's impossible if half (or more) of self's weight sits at estim, i.e. self's half-width about estim is zero. In this case, the result string will only give estim to as many significant digits as eight more than the number of sample-points of self; and if the next five digits would all have been 0, any trailing zeros will be elided from the ones given [for various sanity reasons]. Sugar: in this `exact' case, any exponent used will employ E rather than e (thus 1.2E1 for 12); and if no digits appear after the '.' in an exact representation, the '.' is omitted. if10.0f0.5is2Weights need to be positive for rounding algorithmt-itif0.10000000000000001iis1.tes%.0etEt0t1t2t3t4t5t6t7t8t9t.N(R}i(R~i(R~ii((testimR RtmedianRRnR-RRt thresholdR*Rdt_repWeighted__embraceR>twidththeadRttbodyttweaktaimt_repWeighted__unitRtabstunitRRARettinyttailtstrR:R{tdigtcmpRotadddotRjR?tKeyErrorR@(RRR>RRtRRRoRRRRRRAR?RRR((Rtrounds & $ ", c (RR R R2R RjRmRpRRR(((RRis 4 tjoinWeightedcBsttZdZdZdeddZdZddZedd Zd Z edZ dZRS( sInterface-class defining how to stick distributions together. Provides apparatus for adding data to a distribution, re-sampling a distribution, obtaining a canonical distribution (i.e. one whose weights' neighbourhoods don't overlap) and for performing `cartesion product' operations (i.e. taking two distributions and obtaining the joint distribution for some combination of their parameters), including comparison. cCs ||_dS(N(tdetailRt_joinWeighted__detail(RR((RR#<sicCs |dfS(Ni(R&(R&((RR?scCs#y|i}WnRtj oFyt||}Wqettfj o|dfg}qeXnXx|D]\}}||}|djot d|||fnt|to |i }nt|to|i|||ql|dj o||}n|||||d<Z?d=Z@d>ZAd?ZBd@dAZCedBZDRS(Ds(Models numeric values by distributions. t_strt_reprtbestcCs|djoy |WnEtj o9yt|i}Wqjtj o d}qjXnXt|}|djo d}nd}||djo |}qx+||djo||d}}qWn|||S(Niif-1.0f1.0f0.5(R3R R2RRRdttotRRR'tklaz(RR2R3RRR'((RR<s$ cOs,y|d}Wn tj o|i|d |i|io d}n|i|io d}qn[t|to|i|o d}qn-|d|df|i|o d}ny|iWn6tj o*|pt|i|i|_nX|o.y |`Wntj onX|indS(sCImplements the .observe() functionality of quantity.Quantity (q.v.)iif2.2999999999999998f1.7N(R RRRRRRRR9RRRRCRt_Sample__updateRRRRR*Rtsimplify(RRCRRR((RRsL cCs#|ii||_|idS(sSimplifies the distribution describing self. Argument, count, is optional (default: None). If count is omitted or None, the distribution's view of how many sample points it should be using is used as count. Otherwise, it specifies the number of sample points to retain in the simplification; if it exceeds the number of sample points in use, nothing changes. N(RRRRt_lazy_reset_(RR((RR scCs|ii|_dS(N(RRR(R((RRscCs|ii|_dS(N(RRRf(R((RRfscCs|ii}x@|iD]2}|ddjp|i|o||=qqW|o||i|d >> gr = (1 + Sample({5.**.5: 1, -(5.**.5): 1}))/2 >>> gr 0. >>> gr+1 2. >>> gr**2 0. >>> gr**2 > gr+1 1 in which gr's weighs are the roots to x*x=x+1 (and its .best is .5). Notice that gr.copy(lambda x: x**2-x-1) and gr**2-gr-1 will have quite different weight dictionaries ! RiR s$Unit width zero-centred error bar. Also known as 0 +/- .5, which can readily be used as a simple way to implement a+/-b as a + 2*b*tophat. For asymmetric error bars, use Sample.upward, which has best estimate zero, like tophat, but is uniformly distributed on the interval from zero to one.f-0.5f0.5(R RR_tstudy.snake.lazyRhRRiRRtobjectRRRRRRRt _surpriseRgtupward(RhRRRRRRRRRRRiRER_R((Rt?s." ( t