h$k<      !"#$%&'()*+,-./0123456789:;None #'(-/<=>?mealyA rough Median. The average absolute value of the stat is used to callibrate estimate drift towards the medianmealyMost common statistics are averages, which are some sort of aggregation of values (sum) and some sort of sample size (count). mealyA   is a triple of functions (a -> b) inject& Convert an input into the state type.(b -> a -> b) step0 Update state given prior state and (new) input. (c -> b) extract" Convert state to the output type./By adopting this order, a Mealy sum looks like:  M id (+) idwhere the first id is the initial injection to a contravariant position, and the second id is the covariant extraction.inject kicks off state on the initial element of the Foldable, but is otherwise be independent of step. 1scan (M e s i) (x : xs) = e <$> scanl' s (i x) xs mealyPattern for an .  A sum count mealyConvenience pattern for a  . M extract step injectmealyFold a list through a  . cosieve == foldmealyRun a list through a  + and return a list of values for every step length (scan _ xs) == length xsmealyextract the average from an av gives NaN on zero dividemealy)substitute a default value on zero-divide av_ (Averager (0,0)) x == xmealy online f g is a   where f is a transformation of the data and g is a decay function (usually convergent to zero) applied at each step. online id id == avonline is best understood by examining usage to produce a moving average and standard deviation:An exponentially-weighted moving average with a decay rate of 0.9 ma r == online id (*r)7An exponentially-weighted moving average of the square. #sqma r = online (\x -> x * x) (* r)Applicative-style exponentially-weighted standard deviation computation: 9std r = (\s ss -> sqrt (ss - s ** 2)) <$> ma r <*> sqma rmealyA moving average using a decay rate of r. r=1 represents the simple average, and r=0 represents the latest value.fold (ma 0) ([1..100])100.0fold (ma 1) ([1..100])50.5fold (ma 0.99) xs09.713356299018187e-2mealyabsolute averagefold (absma 1) xs00.8075705557429647mealyaverage square )fold (ma r) . fmap (**2) == fold (sqma r)mealystandard deviationThe construction of standard deviation, using the Applicative instance of a  : 9(\s ss -> sqrt (ss - s ** (one+one))) <$> ma r <*> sqma rThe average deviation of the numbers 1..1000 is about 1 / sqrt 12 * 1000 https://en.wikipedia.org/wiki/Uniform_distribution_(continuous)#Standard_uniformfold (std 1) [0..1000]288.9636655359978*The average deviation with a decay of 0.99fold (std 0.99) [0..1000]99.28328803163829fold (std 1) xs01.0126438036262801mealyThe covariance of a tuple given an underlying central tendency fold.fold (cov (ma 1)) xsp0.7818936662586868mealy/correlation of a tuple, specialised to Guassianfold (corrGauss 1) xsp0.7978347126677433mealy/a generalised version of correlation of a tuplefold (corr (ma 1) (std 1)) xsp0.7978347126677433 "corr (ma r) (std r) == corrGauss rmealyThe beta in a simple linear regression of an (independent variable, single dependent variable) tuple given an underlying central tendency fold.This is a generalisation of the classical regression formula, where averages are replaced by   statistics. \begin{align} \beta & = \frac{n\sum xy - \sum x \sum y}{n\sum x^2 - (\sum x)^2} \\ & = \frac{n^2 \overline{xy} - n^2 \bar{x} \bar{y}}{n^2 \overline{x^2} - n^2 \bar{x}^2} \\ & = \frac{\overline{xy} - \bar{x} \bar{y}}{\overline{x^2} - \bar{x}^2} \\ \end{align} :fold (beta1 (ma 1)) $ zipWith (\x y -> (y, x + y)) xs0 xs10.999747321294513mealyThe alpha in a simple linear regression of an (independent variable, single dependent variable) tuple given an underlying central tendency fold. \begin{align} \alpha & = \frac{\sum y \sum x^2 - \sum x \sum xy}{n\sum x^2 - (\sum x)^2} \\ & = \frac{n^2 \bar{y} \overline{x^2} - n^2 \bar{x} \overline{xy}}{n^2 \overline{x^2} - n^2 \bar{x}^2} \\ & = \frac{\bar{y} \overline{x^2} - \bar{x} \overline{xy}}{\overline{x^2} - \bar{x}^2} \\ \end{align} fold (alpha1 (ma 1)) $ zipWith (\x y -> ((3+y), x + 0.5 * (3 + y))) xs0 xs11.3680496627365146e-2mealyThe (alpha, beta) tuple in a simple linear regression of an (independent variable, single dependent variable) tuple given an underlying central tendency fold.fold (reg1 (ma 1)) $ zipWith (\x y -> ((3+y), x + 0.5 * (3 + y))) xs0 xs1*(1.3680496627365146e-2,0.4997473212944953)mealyaccumulated summealyconstant Mealymealymost recent value mealy9most recent value if it exists, previous value otherwise.!mealydelay input values by 1"mealydelays values by n stepsdelay [0] == delay1 0delay [] == id!delay [1,2] = delay1 2 . delay1 1scan (delay [-2,-1]) [0..3] [-2,-1,0,1]Autocorrelation example: 8scan (((,) <$> id <*> delay [0]) >>> beta (ma 0.99)) xs0#mealy/onlineL1' takes a function and turns it into a   where the step is an incremental update of an (isomorphic) median statistic.$mealymoving median > L.fold (maL1 inc d r) [1..n] 93.92822312742108%mealya window of a's-mealy av mempty == nan"mealy/initial statistical values, delay equals length%  !"#$%%   !"#$%None,/6mealy,Mealy quantiles based on the tdigest library7mealyMealy median using <The tdigest algorithm works best at extremes and can be unreliable in the centre.8mealyA mealy that computes the running quantile bucket. For example, in a scan, digitize 0.9 [0,0.5,1] returns:=0 if the current value is less than the current mealy median.1 if the current value is greater than the current mealy median.678768None /?a:mealy6rvs creates a list of standard normal random variates.import Data.Mealyimport Data.Mealy.Simulate gen <- create rvs gen 3?[1.8005943761746166e-2,0.36444481359059255,-1.2939898115295387]rs <- rvs gen 10000fold (ma 1) rs1.29805301109162e-2fold (std 1) rs1.0126527176272948;mealy?@A"mealy-0.3.0-J6NMauxgyQrIVvIQ3tMQL7Data.Mealy.Simulate Data.MealyData.Mealy.Quantiles*mwc-random-0.15.0.2-K3oHKq2e3XxDNvUIrivTD7System.Random.MWCcreateMedianer$sel:medAbsSum:Medianer$sel:medCount:Medianer$sel:medianEst:MedianerAverager$sel:sumCount:AveragerMealyAMdipurefoldscanavav_onlinemaabsmasqmastdcov corrGausscorrbeta1alpha1reg1asumaconstlast maybeLastdelay1delayonlineL1maL1window$fExceptionMealyError$fProfunctorMealy$fFunctorMealy$fCategoryTYPEMealy$fApplicativeMealy $fMonoidPair'$fSemigroupPair'$fMonoidAverager$fSemigroupAverager $fEqAverager$fShowAverager $fEqPair' $fOrdPair' $fShowPair' $fReadPair'$fShowMealyError quantilesmediandigitize$fShowOnlineTDigestrvsrvsp&tdigest-0.2.1.1-EyT508ZiPm51AM9DrFxky4Data.TDigest.Tree.Internaltdigest