accumulators.qbk 177 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180
  1. [library Boost.Accumulators
  2. [quickbook 1.3]
  3. [authors [Niebler, Eric]]
  4. [copyright 2005 2006 Eric Niebler]
  5. [category math]
  6. [id accumulators]
  7. [dirname accumulators]
  8. [purpose
  9. Incremental accumulation framework and statistical accumulator library.
  10. ]
  11. [license
  12. Distributed under the Boost Software License, Version 1.0.
  13. (See accompanying file LICENSE_1_0.txt or copy at
  14. [@http://www.boost.org/LICENSE_1_0.txt])
  15. ]
  16. ]
  17. [/ Images ]
  18. [def _note_ [$images/note.png]]
  19. [def _alert_ [$images/caution.png]]
  20. [def _detail_ [$images/note.png]]
  21. [def _tip_ [$images/tip.png]]
  22. [/ Links ]
  23. [def _sample_type_ '''<replaceable>sample-type</replaceable>''']
  24. [def _weight_type_ '''<replaceable>weight-type</replaceable>''']
  25. [def _variate_type_ '''<replaceable>variate-type</replaceable>''']
  26. [def _variate_tag_ '''<replaceable>variate-tag</replaceable>''']
  27. [def _left_or_right_ '''<replaceable>left-or-right</replaceable>''']
  28. [def _implementation_defined_ '''<replaceable>implementation-defined</replaceable>''']
  29. [def _boost_ [@http://www.boost.org Boost]]
  30. [def _mpl_ [@../../libs/mpl/index.html MPL]]
  31. [def _mpl_lambda_expression_ [@../../libs/mpl/doc/refmanual/lambda-expression.html MPL Lambda Expression]]
  32. [def _parameter_ [@../../libs/parameter/index.html Boost.Parameter]]
  33. [def _accumulator_set_ [classref boost::accumulators::accumulator_set `accumulator_set<>`]]
  34. [def _accumulator_base_ [classref boost::accumulators::accumulator_base `accumulator_base`]]
  35. [def _depends_on_ [classref boost::accumulators::depends_on `depends_on<>`]]
  36. [def _feature_of_ [classref boost::accumulators::feature_of `feature_of<>`]]
  37. [def _as_feature_ [classref boost::accumulators::as_feature `as_feature<>`]]
  38. [def _features_ [classref boost::accumulators::features `features<>`]]
  39. [def _external_ [classref boost::accumulators::external `external<>`]]
  40. [def _droppable_ [classref boost::accumulators::droppable `droppable<>`]]
  41. [def _droppable_accumulator_ [classref boost::accumulators::droppable_accumulator `droppable_accumulator<>`]]
  42. [def _extractor_ [classref boost::accumulators::tag::extractor `extractor<>`]]
  43. [def _tail_ [classref boost::accumulators::tag::tail `tail`]]
  44. [def _tail_variate_ [classref boost::accumulators::tag::tail_variate `tail_variate<>`]]
  45. [def _extract_result_ [funcref boost::accumulators::extract_result `extract_result()`]]
  46. [def _ZKB_ [@http://www.zkb.com Z'''&uuml;'''rcher Kantonalbank]]
  47. [section Preface]
  48. [:["It is better to be approximately right than exactly wrong.]\n['-- Old adage]]
  49. [h2 Description]
  50. Boost.Accumulators is both a library for incremental statistical computation as
  51. well as an extensible framework for incremental calculation in general. The library
  52. deals primarily with the concept of an ['accumulator], which is a primitive
  53. computational entity that accepts data one sample at a time and maintains some
  54. internal state. These accumulators may offload some of their computations on other
  55. accumulators, on which they depend. Accumulators are grouped within an ['accumulator
  56. set]. Boost.Accumulators resolves the inter-dependencies between accumulators in a
  57. set and ensures that accumulators are processed in the proper order.
  58. [endsect]
  59. [section User's Guide]
  60. This section describes how to use the Boost.Accumulators framework to create new
  61. accumulators and how to use the existing statistical accumulators to perform incremental
  62. statistical computation. For detailed information regarding specific components in
  63. Boost.Accumulators, check the [link accumulators_framework_reference Reference] section.
  64. [h2 Hello, World!]
  65. Below is a complete example of how to use the Accumulators Framework and the
  66. Statistical Accumulators to perform an incremental statistical calculation. It
  67. calculates the mean and 2nd moment of a sequence of doubles.
  68. #include <iostream>
  69. #include <boost/accumulators/accumulators.hpp>
  70. #include <boost/accumulators/statistics/stats.hpp>
  71. #include <boost/accumulators/statistics/mean.hpp>
  72. #include <boost/accumulators/statistics/moment.hpp>
  73. using namespace boost::accumulators;
  74. int main()
  75. {
  76. // Define an accumulator set for calculating the mean and the
  77. // 2nd moment ...
  78. accumulator_set<double, stats<tag::mean, tag::moment<2> > > acc;
  79. // push in some data ...
  80. acc(1.2);
  81. acc(2.3);
  82. acc(3.4);
  83. acc(4.5);
  84. // Display the results ...
  85. std::cout << "Mean: " << mean(acc) << std::endl;
  86. std::cout << "Moment: " << moment<2>(acc) << std::endl;
  87. return 0;
  88. }
  89. This program displays the following:
  90. [pre
  91. Mean: 2.85
  92. Moment: 9.635
  93. ]
  94. [section The Accumulators Framework]
  95. The Accumulators Framework is framework for performing incremental calculations. Usage
  96. of the framework follows the following pattern:
  97. * Users build a computational object, called an ['_accumulator_set_], by selecting
  98. the computations in which they are interested, or authoring their own computational
  99. primitives which fit within the framework.
  100. * Users push data into the _accumulator_set_ object one sample at a time.
  101. * The _accumulator_set_ computes the requested quantities in the most efficient method
  102. possible, resolving dependencies between requested calculations, possibly caching
  103. intermediate results.
  104. The Accumulators Framework defines the utilities needed for defining primitive
  105. computational elements, called ['accumulators]. It also provides the _accumulator_set_
  106. type, described above.
  107. [h2 Terminology]
  108. The following terms are used in the rest of the documentation.
  109. [variablelist
  110. [[Sample] [[#sample_type] A datum that is pushed into an _accumulator_set_.
  111. The type of the sample is the ['sample type].]]
  112. [[Weight] [[#weight_type] An optional scalar value passed along with the
  113. sample specifying the weight of the sample. Conceptually, each
  114. sample is multiplied with its weight. The type of the weight is
  115. the ['weight type].]]
  116. [[Feature] [An abstract primitive computational entity. When defining an
  117. _accumulator_set_, users specify the features in which they are
  118. interested, and the _accumulator_set_ figures out which
  119. ['accumulators] would best provide those features. Features may
  120. depend on other features. If they do, the accumulator set figures
  121. out which accumulators to add to satisfy the dependencies.]]
  122. [[Accumulator] [A concrete primitive computational entity. An accumulator is a
  123. concrete implementation of a feature. It satisfies exactly one
  124. abstract feature. Several different accumulators may provide the
  125. same feature, but may represent different implementation strategies.]]
  126. [[Accumulator Set] [A collection of accumulators. An accumulator set is specified with
  127. a sample type and a list of features. The accumulator set uses this
  128. information to generate an ordered set of accumulators depending on
  129. the feature dependency graph. An accumulator set accepts samples one
  130. datum at a time, propagating them to each accumulator in order. At any
  131. point, results can be extracted from the accumulator set.]]
  132. [[Extractor] [A function or function object that can be used to extract a result
  133. from an _accumulator_set_.]]
  134. ]
  135. [h2 Overview]
  136. Here is a list of the important types and functions in the Accumulator Framework and
  137. a brief description of each.
  138. [table Accumulators Toolbox
  139. [[Tool] [Description]]
  140. [[_accumulator_set_] [This is the most important type in the Accumulators Framework.
  141. It is a collection of accumulators. A datum pushed into an
  142. _accumulator_set_ is forwarded to each accumulator, in an order
  143. determined by the dependency relationships between the
  144. accumulators. Computational results can be extracted from an
  145. accumulator at any time.]]
  146. [[_depends_on_ ] [Used to specify which other features a feature depends on.]]
  147. [[_feature_of_ ] [Trait used to tell the Accumulators Framework that, for the purpose
  148. of feature-based dependency resolution, one feature should be
  149. treated the same as another.]]
  150. [[_as_feature_ ] [Used to create an alias for a feature. For example, if there are
  151. two features, fast_X and accurate_X, they can be mapped to
  152. X(fast) and X(accurate) with _as_feature_. This is just syntactic
  153. sugar.]]
  154. [[_features_ ] [An _mpl_ sequence. We can use _features_ as the second template
  155. parameter when declaring an _accumulator_set_.]]
  156. [[_external_ ] [Used when declaring an _accumulator_set_. If the weight type is
  157. specified with _external_, then the weight accumulators are
  158. assumed to reside in a separate accumulator set which will be passed
  159. in with a named parameter.]]
  160. [[_extractor_ ] [A class template useful for creating an extractor function object.
  161. It is parameterized on a feature, and it has member functions for
  162. extracting from an _accumulator_set_ the result corresponding to
  163. that feature.]]
  164. ]
  165. [section Using [^accumulator_set<>]]
  166. Our tour of the _accumulator_set_ class template begins with the forward declaration:
  167. template< typename Sample, typename Features, typename Weight = void >
  168. struct accumulator_set;
  169. The template parameters have the following meaning:
  170. [variablelist
  171. [[`Sample`] [The type of the data that will be accumulated.]]
  172. [[`Features`] [An _mpl_ sequence of features to be calculated.]]
  173. [[`Weight`] [The type of the (optional) weight paramter.]]
  174. ]
  175. For example, the following line declares an _accumulator_set_ that will accept
  176. a sequence of doubles one at a time and calculate the min and mean:
  177. accumulator_set< double, features< tag::min, tag::mean > > acc;
  178. Notice that we use the _features_ template to specify a list of features to be calculated.
  179. _features_ is an MPL sequence of features.
  180. [note _features_ is a synonym of `mpl::vector<>`. In fact, we could use `mpl::vector<>`
  181. or any MPL sequence if we prefer, and the meaning would be the same.]
  182. Once we have defined an _accumulator_set_, we can then push data into it,
  183. and it will calculate the quantities you requested, as shown below.
  184. // push some data into the accumulator_set ...
  185. acc(1.2);
  186. acc(2.3);
  187. acc(3.4);
  188. Since _accumulator_set_ defines its accumulate function to be the function call operator,
  189. we might be tempted to use an _accumulator_set_ as a UnaryFunction to a standard
  190. algorithm such as `std::for_each`. That's fine as long as we keep in mind that the standard
  191. algorithms take UnaryFunction objects by value, which involves making a copy of the
  192. _accumulator_set_ object. Consider the following:
  193. // The data for which we wish to calculate statistical properties:
  194. std::vector< double > data( /* stuff */ );
  195. // The accumulator set which will calculate the properties for us:
  196. accumulator_set< double, features< tag::min, tag::mean > > acc;
  197. // Use std::for_each to accumulate the statistical properties:
  198. acc = std::for_each( data.begin(), data.end(), acc );
  199. Notice how we must assign the return value of `std::for_each` back to the _accumulator_set_.
  200. This works, but some accumulators are not cheap to copy. For
  201. example, the _tail_ and _tail_variate_ accumulators must store a `std::vector<>`, so copying
  202. these accumulators involves a dynamic allocation. We might be better off in this
  203. case passing the accumulator by reference, with the help of `boost::bind()` and
  204. `boost::ref()`. See below:
  205. // The data for which we wish to calculate statistical properties:
  206. std::vector< double > data( /* stuff */ );
  207. // The accumulator set which will calculate the properties for us:
  208. accumulator_set< double, features< tag::tail<left> > > acc(
  209. tag::tail<left>::cache_size = 4 );
  210. // Use std::for_each to accumulate the statistical properties:
  211. std::for_each( data.begin(), data.end(), bind<void>( ref(acc), _1 ) );
  212. Notice now that we don't care about the return value of `std::for_each()` anymore because
  213. `std::for_each()` is modifying `acc` directly.
  214. [note To use `boost::bind()` and `boost::ref()`, you must `#include` [^<boost/bind.hpp>]
  215. and [^<boost/ref.hpp>]]
  216. [endsect]
  217. [section Extracting Results]
  218. Once we have declared an _accumulator_set_ and pushed data into it, we need to be able
  219. to extract results from it. For each feature we can add to an _accumulator_set_, there
  220. is a corresponding extractor for fetching its result. Usually, the extractor has the
  221. same name as the feature, but in a different namespace. For example, if we accumulate
  222. the `tag::min` and `tag::max` features, we can extract the results with the `min` and `max`
  223. extractors, as follows:
  224. // Calculate the minimum and maximum for a sequence of integers.
  225. accumulator_set< int, features< tag::min, tag::max > > acc;
  226. acc( 2 );
  227. acc( -1 );
  228. acc( 1 );
  229. // This displays "(-1, 2)"
  230. std::cout << '(' << min( acc ) << ", " << max( acc ) << ")\n";
  231. The extractors are all declared in the `boost::accumulators::extract` namespace, but they
  232. are brought into the `boost::accumulators` namespace with a `using` declaration.
  233. [tip On the Windows platform, `min` and `max` are preprocessor macros defined in [^WinDef.h].
  234. To use the `min` and `max` extractors, you should either compile with `NOMINMAX` defined, or
  235. you should invoke the extractors like: `(min)( acc )` and `(max)( acc )`. The parentheses
  236. keep the macro from being invoked.]
  237. Another way to extract a result from an _accumulator_set_ is with the
  238. `extract_result()` function. This can be more convenient if there isn't an extractor
  239. object handy for a certain feature. The line above which displays results could
  240. equally be written as:
  241. // This displays "(-1, 2)"
  242. std::cout << '(' << extract_result< tag::min >( acc )
  243. << ", " << extract_result< tag::max >( acc ) << ")\n";
  244. Finally, we can define our own extractor using the _extractor_ class template. For
  245. instance, another way to avoid the `min` / `max` macro business would be to define
  246. extractors with names that don't conflict with the macros, like this:
  247. extractor< tag::min > min_;
  248. extractor< tag::min > max_;
  249. // This displays "(-1, 2)"
  250. std::cout << '(' << min_( acc ) << ", " << max_( acc ) << ")\n";
  251. [endsect]
  252. [section Passing Optional Parameters]
  253. Some accumulators need initialization parameters. In addition, perhaps some auxiliary
  254. information needs to be passed into the _accumulator_set_ along with each sample.
  255. Boost.Accumulators handles these cases with named parameters from the _parameter_
  256. library.
  257. For example, consider the _tail_ and _tail_variate_ features. _tail_ keeps
  258. an ordered list of the largest [^['N]] samples, where [^['N]] can be specified at
  259. construction time. Also, the _tail_variate_ feature, which depends on _tail_, keeps
  260. track of some data that is covariate with the [^['N]] samples tracked by _tail_. The
  261. code below shows how this all works, and is described in more detail below.
  262. // Define a feature for tracking covariate data
  263. typedef tag::tail_variate< int, tag::covariate1, left > my_tail_variate_tag;
  264. // This will calculate the left tail and my_tail_variate_tag for N == 2
  265. // using the tag::tail<left>::cache_size named parameter
  266. accumulator_set< double, features< my_tail_variate_tag > > acc(
  267. tag::tail<left>::cache_size = 2 );
  268. // push in some samples and some covariates by using
  269. // the covariate1 named parameter
  270. acc( 1.2, covariate1 = 12 );
  271. acc( 2.3, covariate1 = -23 );
  272. acc( 3.4, covariate1 = 34 );
  273. acc( 4.5, covariate1 = -45 );
  274. // Define an extractor for the my_tail_variate_tag feature
  275. extractor< my_tail_variate_tag > my_tail_variate;
  276. // Write the tail statistic to std::cout. This will print "4.5, 3.4, "
  277. std::ostream_iterator< double > dout( std::cout, ", " );
  278. std::copy( tail( acc ).begin(), tail( acc ).end(), dout );
  279. // Write the tail_variate statistic to std::cout. This will print "-45, 34, "
  280. std::ostream_iterator< int > iout( std::cout, ", " );
  281. std::copy( my_tail_variate( acc ).begin(), my_tail_variate( acc ).end(), iout );
  282. There are several things to note about the code above. First, notice that we didn't have
  283. to request that the _tail_ feature be calculated. That is implicit because the _tail_variate_
  284. feature depends on the _tail_ feature. Next, notice how the `acc` object
  285. is initialized: `acc( tag::tail<left>::cache_size = 2 )`. Here, `cache_size` is a named parameter.
  286. It is used to tell the _tail_ and _tail_variate_ accumulators how many samples and
  287. covariates to store. Conceptually, every construction parameter is made available to
  288. every accumulator in an accumulator set.
  289. We also use a named parameter to pass covariate data into the accumulator set along with
  290. the samples. As with the constructor parameters, all parameters to the accumulate function
  291. are made available to all the accumulators in the set. In this case, only the accumulator
  292. for the `my_tail_variate` feature would be interested in the value of the `covariate1` named
  293. parameter.
  294. We can make one final observation about the example above. Since _tail_ and _tail_variate_
  295. are multi-valued features, the result we extract for them is represented as an iterator
  296. range. That is why we can say `tail( acc ).begin()` and `tail( acc ).end()`.
  297. Even the extractors can accept named parameters. In a bit, we'll see a situation where that
  298. is useful.
  299. [endsect]
  300. [section Weighted Samples]
  301. Some accumulators, statistical accumulators in particular, deal with data that are
  302. ['weighted]. Each sample pushed into the accumulator has an associated weight, by which
  303. the sample is conceptually multiplied. The Statistical Accumulators Library provides an
  304. assortment of these weighted statistical accumulators. And many unweighted statistical
  305. accumulators have weighted variants. For instance, the weighted variant of the `sum`
  306. accumulator is called `weighted_sum`, and is calculated by accumulating all the
  307. samples multiplied by their weights.
  308. To declare an _accumulator_set_ that accepts weighted samples, you must specify the
  309. type of the weight parameter as the 3rd template parameter, as follows:
  310. // 3rd template parameter 'int' means this is a weighted
  311. // accumulator set where the weights have type 'int'
  312. accumulator_set< int, features< tag::sum >, int > acc;
  313. When you specify a weight, all the accumulators in the set are replaced with
  314. their weighted equivalents. For example, the above _accumulator_set_ declaration
  315. is equivalent to the following:
  316. // Since we specified a weight, tag::sum becomes tag::weighted_sum
  317. accumulator_set< int, features< tag::weighted_sum >, int > acc;
  318. When passing samples to the accumulator set, you must also specify the
  319. weight of each sample. You can do that with the `weight` named parameter,
  320. as follows:
  321. acc(1, weight = 2); // 1 * 2
  322. acc(2, weight = 4); // 2 * 4
  323. acc(3, weight = 6); // + 3 * 6
  324. // -------
  325. // = 28
  326. You can then extract the result with the `sum()` extractor, as follows:
  327. // This prints "28"
  328. std::cout << sum(acc) << std::endl;
  329. [note When working with weighted statistical accumulators from the Statistical
  330. Accumulators Library, be sure to include the appropriate header. For instance,
  331. `weighted_sum` is defined in `<boost/accumulators/statistics/weighted_sum.hpp>`.]
  332. [endsect]
  333. [section Numeric Operators Sub-Library]
  334. This section describes the function objects in the `boost::numeric` namespace, which
  335. is a sub-library that provides function objects and meta-functions corresponding
  336. to the infix operators in C++.
  337. In the `boost::numeric::operators` namespace are additional operator overloads for
  338. some useful operations not provided by the standard library, such as multiplication
  339. of a `std::complex<>` with a scalar.
  340. In the `boost::numeric::functional` namespace are function object equivalents of
  341. the infix operators. These function object types are heterogeneous, and so are more
  342. general than the standard ones found in the [^<functional>] header. They use the
  343. Boost.Typeof library to deduce the return types of the infix expressions they
  344. evaluate. In addition, they look within the `boost::numeric::operators` namespace
  345. to consider any additional overloads that might be defined there.
  346. In the `boost::numeric` namespace are global polymorphic function objects
  347. corresponding to the function object types defined in the `boost::numeric::functional`
  348. namespace. For example, `boost::numeric::plus(a, b)` is equivalent to
  349. `boost::numeric::functional::plus<A, B>()(a, b)`, and both are equivalent to
  350. `using namespace boost::numeric::operators; a + b;`.
  351. The Numeric Operators Sub-Library also gives several ways to sub-class and
  352. a way to sub-class and specialize operations. One way uses tag dispatching on
  353. the types of the operands. The other way is based on the compile-time
  354. properties of the operands.
  355. [endsect]
  356. [section Extending the Accumulators Framework]
  357. This section describes how to extend the Accumulators Framework by defining new accumulators,
  358. features and extractors. Also covered are how to control the dependency resolution of
  359. features within an accumulator set.
  360. [section Defining a New Accumulator]
  361. All new accumulators must satisfy the [link
  362. accumulators.user_s_guide.the_accumulators_framework.concepts.accumulator_concept Accumulator
  363. Concept]. Below is a sample class that satisfies the accumulator concept, which simply sums
  364. the values of all samples passed into it.
  365. #include <boost/accumulators/framework/accumulator_base.hpp>
  366. #include <boost/accumulators/framework/parameters/sample.hpp>
  367. namespace boost { // Putting your accumulators in the
  368. namespace accumulators { // impl namespace has some
  369. namespace impl { // advantages. See below.
  370. template<typename Sample>
  371. struct sum_accumulator // All accumulators should inherit from
  372. : accumulator_base // accumulator_base.
  373. {
  374. typedef Sample result_type; // The type returned by result() below.
  375. template<typename Args> // The constructor takes an argument pack.
  376. sum_accumulator(Args const & args)
  377. : sum(args[sample | Sample()]) // Maybe there is an initial value in the
  378. { // argument pack. ('sample' is defined in
  379. } // sample.hpp, included above.)
  380. template<typename Args> // The accumulate function is the function
  381. void operator ()(Args const & args) // call operator, and it also accepts an
  382. { // argument pack.
  383. this->sum += args[sample];
  384. }
  385. result_type result(dont_care) const // The result function will also be passed
  386. { // an argument pack, but we don't use it here,
  387. return this->sum; // so we use "dont_care" as the argument type.
  388. }
  389. private:
  390. Sample sum;
  391. };
  392. }}}
  393. Much of the above should be pretty self-explanatory, except for the use of argument packs
  394. which may be confusing if you have never used the _parameter_ library before. An argument
  395. pack is a cluster of values, each of which can be accessed with a key. So `args[sample]`
  396. extracts from the pack the value associated with the `sample` key. And the cryptic
  397. `args[sample | Sample()]` evaluates to the value associated with the `sample` key if it
  398. exists, or a default-constructed `Sample` if it doesn't.
  399. The example above demonstrates the most common attributes of an accumulator. There are
  400. other optional member functions that have special meaning. In particular:
  401. [variablelist Optional Accumulator Member Functions
  402. [[[^on_drop(Args)]] [Defines an action to be taken when this accumulator is
  403. dropped. See the section on
  404. [link accumulators.user_s_guide.the_accumulators_framework.extending_the_accumulators_framework.defining_a_new_accumulator.droppable_accumulators
  405. Droppable Accumulators].]]
  406. ]
  407. [h3 Accessing Other Accumulators in the Set]
  408. Some accumulators depend on other accumulators within the same accumulator set. In those
  409. cases, it is necessary to be able to access those other accumulators. To make this possible,
  410. the _accumulator_set_ passes a reference to itself when invoking the member functions of
  411. its contained accumulators. It can be accessed by using the special `accumulator` key with
  412. the argument pack. Consider how we might implement `mean_accumulator`:
  413. // Mean == (Sum / Count)
  414. template<typename Sample>
  415. struct mean_accumulator : accumulator_base
  416. {
  417. typedef Sample result_type;
  418. mean_accumulator(dont_care) {}
  419. template<typename Args>
  420. result_type result(Args const &args) const
  421. {
  422. return sum(args[accumulator]) / count(args[accumulator]);
  423. }
  424. };
  425. `mean` depends on the `sum` and `count` accumulators. (We'll see in the next section how
  426. to specify these dependencies.) The result of the mean accumulator is merely the result of
  427. the sum accumulator divided by the result of the count accumulator. Consider how we write
  428. that: `sum(args[accumulator]) / count(args[accumulator])`. The expression `args[accumulator]`
  429. evaluates to a reference to the _accumulator_set_ that contains this `mean_accumulator`. It
  430. also contains the `sum` and `count` accumulators, and we can access their results with the
  431. extractors defined for those features: `sum` and `count`.
  432. [note Accumulators that inherit from _accumulator_base_ get an empty `operator ()`, so
  433. accumulators like `mean_accumulator` above need not define one.]
  434. All the member functions that accept an argument pack have access to the enclosing
  435. _accumulator_set_ via the `accumulator` key, including the constructor. The
  436. accumulators within the set are constructed in an order determined by their interdependencies.
  437. As a result, it is safe for an accumulator to access one on which it depends during construction.
  438. [h3 Infix Notation and the Numeric Operators Sub-Library]
  439. Although not necessary, it can be a good idea to put your accumulator implementations in
  440. the `boost::accumulators::impl` namespace. This namespace pulls in any operators defined
  441. in the `boost::numeric::operators` namespace with a using directive. The Numeric Operators
  442. Sub-Library defines some additional overloads that will make your accumulators work with
  443. all sorts of data types.
  444. Consider `mean_accumulator` defined above. It divides the sum of the samples by the count.
  445. The type of the count is `std::size_t`. What if the sample type doesn't define division by
  446. `std::size_t`? That's the case for `std::complex<>`. You might think that if the sample type
  447. is `std::complex<>`, the code would not work, but in fact it does. That's because
  448. Numeric Operators Sub-Library defines an overloaded `operator/` for `std::complex<>`
  449. and `std::size_t`. This operator is defined in the `boost::numeric::operators` namespace and
  450. will be found within the `boost::accumulators::impl` namespace. That's why it's a good idea
  451. to put your accumulators there.
  452. [h3 Droppable Accumulators]
  453. The term "droppable" refers to an accumulator that can be removed from the _accumulator_set_.
  454. You can request that an accumulator be made droppable by using the _droppable_ class template.
  455. // calculate sum and count, make sum droppable:
  456. accumulator_set< double, features< tag::count, droppable<tag::sum> > > acc;
  457. // add some data
  458. acc(3.0);
  459. acc(2.0);
  460. // drop the sum (sum is 5 here)
  461. acc.drop<tag::sum>();
  462. // add more data
  463. acc(1.0);
  464. // This will display "3" and "5"
  465. std::cout << count(acc) << ' ' << sum(acc);
  466. Any accumulators that get added to an accumulator set in order to satisfy
  467. dependencies on droppable accumulators are themselves droppable. Consider
  468. the following accumulator:
  469. // Sum is not droppable. Mean is droppable. Count, brought in to
  470. // satisfy mean's dependencies, is implicitly droppable, too.
  471. accumulator_set< double, features< tag::sum, droppable<tag::mean> > > acc;
  472. `mean` depends on `sum` and `count`. Since `mean` is droppable, so too is `count`.
  473. However, we have explicitly requested that `sum` be not droppable, so it isn't. Had
  474. we left `tag::sum` out of the above declaration, the `sum` accumulator would have
  475. been implicitly droppable.
  476. A droppable accumulator is reference counted, and is only really dropped after all the
  477. accumulators that depend on it have been dropped. This can lead to some surprising
  478. behavior in some situations.
  479. // calculate sum and mean, make mean droppable.
  480. accumulator_set< double, features< tag::sum, droppable<tag::mean> > > acc;
  481. // add some data
  482. acc(1.0);
  483. acc(2.0);
  484. // drop the mean. mean's reference count
  485. // drops to 0, so it's really dropped. So
  486. // too, count's reference count drops to 0
  487. // and is really dropped.
  488. acc.drop<tag::mean>();
  489. // add more data. Sum continues to accumulate!
  490. acc(3.0);
  491. // This will display "6 2 3"
  492. std::cout << sum(acc) << ' '
  493. << count(acc) << ' '
  494. << mean(acc);
  495. Note that at the point at which `mean` is dropped, `sum` is 3, `count` is 2, and
  496. therefore `mean` is 1.5. But since `sum` continues to accumulate even after `mean`
  497. has been dropped, the value of `mean` continues to change. If you want to remember
  498. the value of `mean` at the point it is dropped, you should save its value into
  499. a local variable.
  500. The following rules more precisely specify how droppable and non-droppable
  501. accumulators behave within an accumulator set.
  502. * There are two types of accumulators: droppable and non-droppable.
  503. The default is non-droppable.
  504. * For any feature `X`, both `X` and `droppable<X>` satisfy the `X` dependency.
  505. * If feature `X` depends on `Y` and `Z`, then `droppable<X>` depends on
  506. `droppable<Y>` and `droppable<Z>`.
  507. * All accumulators have `add_ref()` and `drop()` member functions.
  508. * For non-droppable accumulators, `drop()` is a no-op, and `add_ref()`
  509. invokes `add_ref()` on all accumulators corresponding to the features
  510. upon which the current accumulator depends.
  511. * Droppable accumulators have a reference count and define `add_ref()`
  512. and `drop()` to manipulate the reference count.
  513. * For droppable accumulators, `add_ref()` increments the accumulator's
  514. reference count, and also `add_ref()`'s the accumulators corresponding
  515. to the features upon which the current accumulator depends.
  516. * For droppable accumulators, `drop()` decrements the accumulator's
  517. reference count, and also `drop()`'s the accumulators corresponding to
  518. the features upon which the current accumulator depends.
  519. * The accumulator_set constructor walks the list of *user-specified*
  520. features and `add_ref()`'s the accumulator that corresponds to each of
  521. them. (Note: that means that an accumulator that is not user-specified
  522. but in the set merely to satisfy a dependency will be dropped as soon
  523. as all its dependencies have been dropped. Ones that have been user
  524. specified are not dropped until their dependencies have been
  525. dropped *and* the user has explicitly dropped the accumulator.)
  526. * Droppable accumulators check their reference count in their
  527. accumulate member function. If the reference count is 0, the function
  528. is a no-op.
  529. * Users are not allowed to drop a feature that is not user-specified and
  530. marked as droppable.
  531. And as an optimization:
  532. * If the user specifies the non-droppable feature `X`, which depends on `Y`
  533. and `Z`, then the accumulators for `Y` and `Z` can be safely made
  534. non-droppable, as well as any accumulators on which they depend.
  535. [endsect]
  536. [section Defining a New Feature]
  537. Once we have implemented an accumulator, we must define a feature for it so
  538. that users can specify the feature when declaring an _accumulator_set_. We
  539. typically put the features into a nested namespace, so that later we can
  540. define an extractor of the same name. All features must satisfy the
  541. [link accumulators.user_s_guide.the_accumulators_framework.concepts.feature_concept
  542. Feature Concept]. Using _depends_on_ makes satisfying the concept simple.
  543. Below is an example of a feature definition.
  544. namespace boost { namespace accumulators { namespace tag {
  545. struct mean // Features should inherit from
  546. : depends_on< count, sum > // depends_on<> to specify dependencies
  547. {
  548. // Define a nested typedef called 'impl' that specifies which
  549. // accumulator implements this feature.
  550. typedef accumulators::impl::mean_accumulator< mpl::_1 > impl;
  551. };
  552. }}}
  553. The only two things we must do to define the `mean` feature is to specify the
  554. dependencies with _depends_on_ and define the nested `impl` typedef. Even features
  555. that have no dependencies should inherit from _depends_on_. The nested `impl` type
  556. must be an _mpl_lambda_expression_. The result of
  557. `mpl::apply< impl, _sample_type_, _weight_type_ >::type` must be
  558. be the type of the accumulator that implements this feature. The use of _mpl_
  559. placeholders like `mpl::_1` make it especially easy to make a template such
  560. as `mean_accumulator<>` an _mpl_lambda_expression_. Here, `mpl::_1` will be
  561. replaced with the sample type. Had we used `mpl::_2`, it would have been replaced
  562. with the weight type.
  563. What about accumulator types that are not templates? If you have a `foo_accumulator`
  564. which is a plain struct and not a template, you could turn it into an
  565. _mpl_lambda_expression_ using `mpl::always<>`, like this:
  566. // An MPL lambda expression that always evaluates to
  567. // foo_accumulator:
  568. typedef mpl::always< foo_accumulator > impl;
  569. If you are ever unsure, or if you are not comfortable with MPL lambda expressions,
  570. you could always define `impl` explicitly:
  571. // Same as 'typedef mpl::always< foo_accumulator > impl;'
  572. struct impl
  573. {
  574. template< typename Sample, typename Weight >
  575. struct apply
  576. {
  577. typedef foo_accumulator type;
  578. };
  579. };
  580. Here, `impl` is a binary [@../../libs/mpl/doc/refmanual/metafunction-class.html
  581. MPL Metafunction Class], which is a kind of _mpl_lambda_expression_. The nested
  582. `apply<>` template is part of the metafunction class protocol and tells MPL how
  583. to build the accumulator type given the sample and weight types.
  584. All features must also provide a nested `is_weight_accumulator` typedef. It must
  585. be either `mpl::true_` or `mpl::false_`. _depends_on_ provides a default of
  586. `mpl::false_` for all features that inherit from it, but that can be overridden
  587. (or hidden, technically speaking) in the derived type. When the feature represents
  588. an accumulation of information about the weights instead of the samples, we
  589. can mark this feature as such with `typedef mpl::true_ is_weight_accumulator;`.
  590. The weight accumulators are made external if the weight type is specified using
  591. the _external_ template.
  592. [endsect]
  593. [section Defining a New Extractor]
  594. Now that we have an accumulator and a feature, the only thing lacking is a way
  595. to get results from the accumulator set. The Accumulators Framework provides the
  596. _extractor_ class template to make it simple to define an extractor for your
  597. feature. Here's an extractor for the `mean` feature we defined above:
  598. namespace boost {
  599. namespace accumulators { // By convention, we put extractors
  600. namespace extract { // in the 'extract' namespace
  601. extractor< tag::mean > const mean = {}; // Simply define our extractor with
  602. // our feature tag, like this.
  603. }
  604. using extract::mean; // Pull the extractor into the
  605. // enclosing namespace.
  606. }}
  607. Once defined, the `mean` extractor can be used to extract the result of the
  608. `tag::mean` feature from an _accumulator_set_.
  609. Parameterized features complicate this simple picture. Consider the `moment`
  610. feature, for calculating the [^['N]]-th moment, where [^['N]] is specified as
  611. a template parameter:
  612. // An accumulator set for calculating the N-th moment, for N == 2 ...
  613. accumulator_set< double, features< tag::moment<2> > > acc;
  614. // ... add some data ...
  615. // Display the 2nd moment ...
  616. std::cout << "2nd moment is " << accumulators::moment<2>(acc) << std::endl;
  617. In the expression `accumulators::moment<2>(acc)`, what is `moment`? It cannot be an object --
  618. the syntax of C++ will not allow it. Clearly, if we want to provide this syntax,
  619. we must make `moment` a function template. Here's what the definition of the
  620. `moment` extractor looks like:
  621. namespace boost {
  622. namespace accumulators { // By convention, we put extractors
  623. namespace extract { // in the 'extract' namespace
  624. template<int N, typename AccumulatorSet>
  625. typename mpl::apply<AccumulatorSet, tag::moment<N> >::type::result_type
  626. moment(AccumulatorSet const &acc)
  627. {
  628. return extract_result<tag::moment<N> >(acc);
  629. }
  630. }
  631. using extract::moment; // Pull the extractor into the
  632. // enclosing namespace.
  633. }}
  634. The return type deserves some explanation. Every _accumulator_set_ type
  635. is actually a unary [@../../libs/mpl/doc/refmanual/metafunction-class.html
  636. MPL Metafunction Class]. When you `mpl::apply<>` an _accumulator_set_ and
  637. a feature, the result is the type of the accumulator within the set that
  638. implements that feature. And every accumulator provides a nested `result_type`
  639. typedef that tells what its return type is. The extractor simply delegates
  640. its work to the _extract_result_ function.
  641. [endsect]
  642. [section Controlling Dependencies]
  643. The feature-based dependency resolution of the Accumulators Framework is
  644. designed to allow multiple different implementation strategies for each
  645. feature. For instance, two different accumulators may calculate the same
  646. quantity with different rounding modes, or using different algorithms with
  647. different size/speed tradeoffs. Other accumulators that depend on that
  648. quantity shouldn't care how it's calculated. The Accumulators Framework
  649. handles this by allowing several different accumulators satisfy the same
  650. feature.
  651. [*Aliasing feature dependencies with [^feature_of<>]]
  652. Imagine that you would like to implement the hypothetical ['fubar] statistic,
  653. and that you know two ways to calculate fubar on a bunch of samples: an
  654. accurate but slow calculation and an approximate but fast calculation. You
  655. might opt to make the accurate calculation the default, so you implement
  656. two accumulators and call them `impl::fubar_impl` and `impl::fast_fubar_impl`.
  657. You would also define the `tag::fubar` and `tag::fast_fubar` features as described
  658. [link accumulators.user_s_guide.the_accumulators_framework.extending_the_accumulators_framework.defining_a_new_feature above].
  659. Now, you would like to inform the Accumulators Framework that these two features
  660. are the same from the point of view of dependency resolution. You can do that
  661. with _feature_of_, as follows:
  662. namespace boost { namespace accumulators
  663. {
  664. // For the purposes of feature-based dependency resolution,
  665. // fast_fubar provides the same feature as fubar
  666. template<>
  667. struct feature_of<tag::fast_fubar>
  668. : feature_of<tag::fubar>
  669. {
  670. };
  671. }}
  672. The above code instructs the Accumulators Framework that, if another accumulator
  673. in the set depends on the `tag::fubar` feature, the `tag::fast_fubar` feature
  674. is an acceptable substitute.
  675. [*Registering feature variants with [^as_feature<>]]
  676. You may have noticed that some feature variants in the Accumulators Framework can be
  677. specified with a nicer syntax. For instance, instead of `tag::mean` and `tag::immediate_mean`
  678. you can specify them with `tag::mean(lazy)` and `tag::mean(immediate)` respectively.
  679. These are merely aliases, but the syntax makes the relationship between the two clearer.
  680. You can create these feature aliases with the _as_feature_ trait. Given the fubar example
  681. above, you might decide to alias `tag::fubar(accurate)` with `tag::fubar` and
  682. `tag::fubar(fast)` with `tag::fast_fubar`. You would do that as follows:
  683. namespace boost { namespace accumulators
  684. {
  685. struct fast {}; // OK to leave these tags empty
  686. struct accurate {};
  687. template<>
  688. struct as_feature<tag::fubar(accurate)>
  689. {
  690. typedef tag::fubar type;
  691. };
  692. template<>
  693. struct as_feature<tag::fubar(fast)>
  694. {
  695. typedef tag::fast_fubar type;
  696. };
  697. }}
  698. Once you have done this, users of your fubar accumulator can request the `tag::fubar(fast)`
  699. and `tag::fubar(accurate)` features when defining their `accumulator_set`s and get the correct
  700. accumulator.
  701. [endsect]
  702. [section:operators_ex Specializing Numeric Operators]
  703. This section describes how to adapt third-party numeric types to work with the Accumulator
  704. Framework.
  705. Rather than relying on the built-in operators, the Accumulators Framework relies on functions
  706. and operator overloads defined in the
  707. [link accumulators.user_s_guide.the_accumulators_framework.numeric_operators_sub_library
  708. Numeric Operators Sub-Library] for many of its numeric operations. This is so that it
  709. is possible to assign non-standard meanings to arithmetic operations. For instance, when
  710. calculating an average by dividing two integers, the standard integer division behavior
  711. would be mathematically incorrect for most statistical quantities. So rather than use `x / y`,
  712. the Accumulators Framework uses `numeric::fdiv(x, y)`, which does floating-point division
  713. even if both `x` and `y` are integers.
  714. Another example where the Numeric Operators Sub-Library is useful is when a type does not
  715. define the operator overloads required to use it for some statistical calculations. For instance,
  716. `std::vector<>` does not overload any arithmetic operators, yet it may be useful to use
  717. `std::vector<>` as a sample or variate type. The Numeric Operators Sub-Library
  718. defines the necessary operator overloads in the `boost::numeric::operators` namespace,
  719. which is brought into scope by the Accumulators Framework with a using directive.
  720. [*Numeric Function Objects and Tag Dispatching]
  721. How are the numeric function object defined by the Numeric Operators Sub-Library made
  722. to work with types such as `std::vector<>`? The free functions in the `boost::numeric` namespace
  723. are implemented in terms of the function objects in the `boost::numeric::functional` namespace,
  724. so to make `boost::numeric::fdiv()` do something sensible with a `std::vector<>`, for instance,
  725. we'll need to partially specialize the `boost::numeric::functional::fdiv<>` function object.
  726. The functional objects make use of a technique known as
  727. [@http://www.boost.org/community/generic_programming.html#tag_dispatching ['tag dispatching]] to
  728. select the proper implementation for the given operands. It works as follows:
  729. namespace boost { namespace numeric { namespace functional
  730. {
  731. // Metafunction for looking up the tag associated with
  732. // a given numeric type T.
  733. template<typename T>
  734. struct tag
  735. {
  736. // by default, all types have void as a tag type
  737. typedef void type;
  738. };
  739. // Forward declaration looks up the tag types of each operand
  740. template<
  741. typename Left
  742. , typename Right
  743. , typename LeftTag = typename tag<Left>::type
  744. , typename RightTag = typename tag<Right>::type
  745. >
  746. struct fdiv;
  747. }}}
  748. If you have some user-defined type `MyDouble` for which you would like to customize the behavior
  749. of `numeric::fdiv()`, you would specialize `numeric::functional::fdiv<>` by
  750. first defining a tag type, as shown below:
  751. namespace boost { namespace numeric { namespace functional
  752. {
  753. // Tag type for MyDouble
  754. struct MyDoubleTag {};
  755. // Specialize tag<> for MyDouble.
  756. // This only needs to be done once.
  757. template<>
  758. struct tag<MyDouble>
  759. {
  760. typedef MyDoubleTag type;
  761. };
  762. // Specify how to divide a MyDouble by an integral count
  763. template<typename Left, typename Right>
  764. struct fdiv<Left, Right, MyDoubleTag, void>
  765. {
  766. // Define the type of the result
  767. typedef ... result_type;
  768. result_type operator()(Left & left, Right & right) const
  769. {
  770. return ...;
  771. }
  772. };
  773. }}}
  774. Once you have done this, `numeric::fdiv()` will use your specialization
  775. of `numeric::functional::fdiv<>` when the first argument is a `MyDouble`
  776. object. All of the function objects in the Numeric Operators Sub-Library can
  777. be customized in a similar fashion.
  778. [endsect]
  779. [endsect]
  780. [section Concepts]
  781. [h2 Accumulator Concept]
  782. In the following table, `Acc` is the type of an accumulator, `acc` and `acc2` are objects of type
  783. `Acc`, and `args` is the name of an argument pack from the _parameter_ library.
  784. [table Accumulator Requirements
  785. [[[*Expression]] [[*Return type]] [[*Assertion / Note /
  786. Pre- / Post-condition]]]
  787. [[`Acc::result_type`] [['implementation
  788. defined]] [The type returned by `Acc::result()`.]]
  789. [[`Acc acc(args)`] [none] [Construct from an argument pack.]]
  790. [[`Acc acc(acc2)`] [none] [Post: `acc.result(args)` is equivalent
  791. to `acc2.result(args)`]]
  792. [[`acc(args)`] [['unspecified]] []]
  793. [[`acc.on_drop(args)`] [['unspecified]] []]
  794. [[`acc.result(args)`] [`Acc::result_type`] []]
  795. ]
  796. [h2 Feature Concept]
  797. In the following table, `F` is the type of a feature and `S` is some scalar type.
  798. [table Feature Requirements
  799. [[[*Expression]] [[*Return type]] [[*Assertion / Note /
  800. Pre- / Post-condition]]]
  801. [[`F::dependencies`] [['unspecified]] [An MPL sequence of other features on
  802. which `F` depends.]]
  803. [[`F::is_weight_accumulator`] [`mpl::true_` or
  804. `mpl::false_`] [`mpl::true_` if the accumulator for
  805. this feature should be made external
  806. when the weight type for the accumulator
  807. set is `external<S>`, `mpl::false_`
  808. otherwise.]]
  809. [[`F::impl`] [['unspecified]] [An _mpl_lambda_expression_ that
  810. returns the type of the accumulator that
  811. implements this feature when passed a
  812. sample type and a weight type.]]
  813. ]
  814. [endsect]
  815. [endsect]
  816. [section The Statistical Accumulators Library]
  817. The Statistical Accumulators Library defines accumulators for incremental statistical
  818. computations. It is built on top of [link accumulators.user_s_guide.the_accumulators_framework
  819. The Accumulator Framework].
  820. [section:count count]
  821. The `count` feature is a simple counter that tracks the
  822. number of samples pushed into the accumulator set.
  823. [variablelist
  824. [[Result Type] [``
  825. std::size_t
  826. ``]]
  827. [[Depends On] [['none]]]
  828. [[Variants] [['none]]]
  829. [[Initialization Parameters] [['none]]]
  830. [[Accumulator Parameters] [['none]]]
  831. [[Extractor Parameters] [['none]]]
  832. [[Accumulator Complexity] [O(1)]]
  833. [[Extractor Complexity] [O(1)]]
  834. ]
  835. [*Header]
  836. [def _COUNT_HPP_ [headerref boost/accumulators/statistics/count.hpp]]
  837. #include <_COUNT_HPP_>
  838. [*Example]
  839. accumulator_set<int, features<tag::count> > acc;
  840. acc(0);
  841. acc(0);
  842. acc(0);
  843. assert(3 == count(acc));
  844. [*See also]
  845. * [classref boost::accumulators::impl::count_impl `count_impl`]
  846. [endsect]
  847. [section:covariance covariance]
  848. The `covariance` feature is an iterative Monte Carlo estimator for the covariance.
  849. It is specified as `tag::covariance<_variate_type_, _variate_tag_>`.
  850. [variablelist
  851. [[Result Type] [``
  852. numeric::functional::outer_product<
  853. numeric::functional::fdiv<_sample_type_, std::size_t>::result_type
  854. , numeric::functional::fdiv<_variate_type_, std::size_t>::result_type
  855. >::result_type
  856. ``]]
  857. [[Depends On] [`count` \n `mean` \n `mean_of_variates<_variate_type_, _variate_tag_>`]]
  858. [[Variants] [`abstract_covariance`]]
  859. [[Initialization Parameters] [['none]]]
  860. [[Accumulator Parameters] [[~variate-tag]]]
  861. [[Extractor Parameters] [['none]]]
  862. [[Accumulator Complexity] [TODO]]
  863. [[Extractor Complexity] [O(1)]]
  864. ]
  865. [*Headers]
  866. [def _COVARIANCE_HPP_ [headerref boost/accumulators/statistics/covariance.hpp]]
  867. [def _COVARIATE_HPP_ [headerref boost/accumulators/statistics/variates/covariate.hpp]]
  868. #include <_COVARIANCE_HPP_>
  869. #include <_COVARIATE_HPP_>
  870. [*Example]
  871. accumulator_set<double, stats<tag::covariance<double, tag::covariate1> > > acc;
  872. acc(1., covariate1 = 2.);
  873. acc(1., covariate1 = 4.);
  874. acc(2., covariate1 = 3.);
  875. acc(6., covariate1 = 1.);
  876. assert(covariance(acc) == -1.75);
  877. [*See also]
  878. * [classref boost::accumulators::impl::covariance_impl [^covariance_impl]]
  879. * [link accumulators.user_s_guide.the_statistical_accumulators_library.count [^count]]
  880. * [link accumulators.user_s_guide.the_statistical_accumulators_library.mean [^mean]]
  881. [endsect]
  882. [section:density density]
  883. The `tag::density` feature returns a histogram of the sample distribution. For more
  884. implementation details, see [classref boost::accumulators::impl::density_impl [^density_impl]].
  885. [variablelist
  886. [[Result Type] [``
  887. iterator_range<
  888. std::vector<
  889. std::pair<
  890. numeric::functional::fdiv<_sample_type_, std::size_t>::result_type
  891. , numeric::functional::fdiv<_sample_type_, std::size_t>::result_type
  892. >
  893. >::iterator
  894. >
  895. ``]]
  896. [[Depends On] [`count` \n `min` \n `max`]]
  897. [[Variants] [['none]]]
  898. [[Initialization Parameters] [`density::cache_size` \n `density::num_bins`]]
  899. [[Accumulator Parameters] [['none]]]
  900. [[Extractor Parameters] [['none]]]
  901. [[Accumulator Complexity] [TODO]]
  902. [[Extractor Complexity] [O(N), when N is `density::num_bins`]]
  903. ]
  904. [*Header]
  905. [def _DENSITY_HPP_ [headerref boost/accumulators/statistics/density.hpp]]
  906. #include <_DENSITY_HPP_>
  907. [*Note]
  908. Results from the `density` accumulator can only be extracted after the number of
  909. samples meets or exceeds the cache size.
  910. [/ TODO add example ]
  911. [*See also]
  912. * [classref boost::accumulators::impl::density_impl [^density_impl]]
  913. * [link accumulators.user_s_guide.the_statistical_accumulators_library.count [^count]]
  914. * [link accumulators.user_s_guide.the_statistical_accumulators_library.min [^min]]
  915. * [link accumulators.user_s_guide.the_statistical_accumulators_library.max [^max]]
  916. [endsect]
  917. [section:error_of_mean error_of<mean>]
  918. The `error_of<mean>` feature calculates the error of the mean feature. It is equal to
  919. `sqrt(variance / (count - 1))`.
  920. [variablelist
  921. [[Result Type] [``
  922. numeric::functional::fdiv<_sample_type_, std::size_t>::result_type
  923. ``]]
  924. [[Depends On] [`count` \n `variance`]]
  925. [[Variants] [`error_of<immediate_mean>`]]
  926. [[Initialization Parameters] [['none]]]
  927. [[Accumulator Parameters] [['none]]]
  928. [[Extractor Parameters] [['none]]]
  929. [[Accumulator Complexity] [TODO]]
  930. [[Extractor Complexity] [O(1)]]
  931. ]
  932. [*Header]
  933. [def _ERROR_OF_HPP_ [headerref boost/accumulators/statistics/error_of.hpp]]
  934. [def _ERROR_OF_MEAN_HPP_ [headerref boost/accumulators/statistics/error_of_mean.hpp]]
  935. #include <_ERROR_OF_HPP_>
  936. #include <_ERROR_OF_MEAN_HPP_>
  937. [*Example]
  938. accumulator_set<double, stats<tag::error_of<tag::mean> > > acc;
  939. acc(1.1);
  940. acc(1.2);
  941. acc(1.3);
  942. assert(0.057735 == error_of<tag::mean>(acc));
  943. [*See also]
  944. * [classref boost::accumulators::impl::error_of_mean_impl [^error_of_mean_impl]]
  945. * [link accumulators.user_s_guide.the_statistical_accumulators_library.count [^count]]
  946. * [link accumulators.user_s_guide.the_statistical_accumulators_library.variance [^variance]]
  947. [endsect]
  948. [section:extended_p_square extended_p_square]
  949. Multiple quantile estimation with the extended [^P^2] algorithm. For further
  950. details, see [classref boost::accumulators::impl::extended_p_square_impl [^extended_p_square_impl]].
  951. [variablelist
  952. [[Result Type] [``
  953. boost::iterator_range<
  954. _implementation_defined_
  955. >
  956. ``]]
  957. [[Depends On] [`count`]]
  958. [[Variants] [['none]]]
  959. [[Initialization Parameters] [`tag::extended_p_square::probabilities`]]
  960. [[Accumulator Parameters] [['none]]]
  961. [[Extractor Parameters] [['none]]]
  962. [[Accumulator Complexity] [TODO]]
  963. [[Extractor Complexity] [O(1)]]
  964. ]
  965. [*Header]
  966. [def _EXTENDED_P_SQUARE_HPP_ [headerref boost/accumulators/statistics/extended_p_square.hpp]]
  967. #include <_EXTENDED_P_SQUARE_HPP_>
  968. [*Example]
  969. boost::array<double> probs = {0.001,0.01,0.1,0.25,0.5,0.75,0.9,0.99,0.999};
  970. accumulator_set<double, stats<tag::extended_p_square> >
  971. acc(tag::extended_p_square::probabilities = probs);
  972. boost::lagged_fibonacci607 rng; // a random number generator
  973. for (int i=0; i<10000; ++i)
  974. acc(rng());
  975. BOOST_CHECK_CLOSE(extended_p_square(acc)[0], probs[0], 25);
  976. BOOST_CHECK_CLOSE(extended_p_square(acc)[1], probs[1], 10);
  977. BOOST_CHECK_CLOSE(extended_p_square(acc)[2], probs[2], 5);
  978. for (std::size_t i=3; i < probs.size(); ++i)
  979. {
  980. BOOST_CHECK_CLOSE(extended_p_square(acc)[i], probs[i], 2);
  981. }
  982. [*See also]
  983. * [classref boost::accumulators::impl::extended_p_square_impl [^extended_p_square_impl]]
  984. * [link accumulators.user_s_guide.the_statistical_accumulators_library.count [^count]]
  985. [endsect]
  986. [section:extended_p_square_quantile extended_p_square_quantile ['and variants]]
  987. Quantile estimation using the extended [^P^2] algorithm for weighted and unweighted samples.
  988. By default, the calculation is linear and unweighted, but quadratic and weighted variants
  989. are also provided. For further implementation details, see
  990. [classref boost::accumulators::impl::extended_p_square_quantile_impl [^extended_p_square_quantile_impl]].
  991. All the variants share the `tag::quantile` feature and can be extracted using the `quantile()`
  992. extractor.
  993. [variablelist
  994. [[Result Type] [``
  995. numeric::functional::fdiv<_sample_type_, std::size_t>::result_type
  996. ``]]
  997. [[Depends On] [weighted variants depend on `weighted_extended_p_square` \n
  998. unweighted variants depend on `extended_p_square`]]
  999. [[Variants] [`extended_p_square_quantile_quadratic` \n
  1000. `weighted_extended_p_square_quantile` \n
  1001. `weighted_extended_p_square_quantile_quadratic`]]
  1002. [[Initialization Parameters] [`tag::extended_p_square::probabilities`]]
  1003. [[Accumulator Parameters] [`weight` for the weighted variants]]
  1004. [[Extractor Parameters] [`quantile_probability`]]
  1005. [[Accumulator Complexity] [TODO]]
  1006. [[Extractor Complexity] [O(N) where N is the count of probabilities.]]
  1007. ]
  1008. [*Header]
  1009. [def _EXTENDED_P_SQUARE_QUANTILE_HPP_ [headerref boost/accumulators/statistics/extended_p_square_quantile.hpp]]
  1010. #include <_EXTENDED_P_SQUARE_QUANTILE_HPP_>
  1011. [*Example]
  1012. typedef accumulator_set<double, stats<tag::extended_p_square_quantile> >
  1013. accumulator_t;
  1014. typedef accumulator_set<double, stats<tag::weighted_extended_p_square_quantile>, double >
  1015. accumulator_t_weighted;
  1016. typedef accumulator_set<double, stats<tag::extended_p_square_quantile(quadratic)> >
  1017. accumulator_t_quadratic;
  1018. typedef accumulator_set<double, stats<tag::weighted_extended_p_square_quantile(quadratic)>, double >
  1019. accumulator_t_weighted_quadratic;
  1020. // tolerance
  1021. double epsilon = 1;
  1022. // a random number generator
  1023. boost::lagged_fibonacci607 rng;
  1024. boost::array<double> probs = { 0.990, 0.991, 0.992, 0.993, 0.994,
  1025. 0.995, 0.996, 0.997, 0.998, 0.999 };
  1026. accumulator_t acc(extended_p_square_probabilities = probs);
  1027. accumulator_t_weighted acc_weighted(extended_p_square_probabilities = probs);
  1028. accumulator_t_quadratic acc2(extended_p_square_probabilities = probs);
  1029. accumulator_t_weighted_quadratic acc_weighted2(extended_p_square_probabilities = probs);
  1030. for (int i=0; i<10000; ++i)
  1031. {
  1032. double sample = rng();
  1033. acc(sample);
  1034. acc2(sample);
  1035. acc_weighted(sample, weight = 1.);
  1036. acc_weighted2(sample, weight = 1.);
  1037. }
  1038. for (std::size_t i = 0; i < probs.size() - 1; ++i)
  1039. {
  1040. BOOST_CHECK_CLOSE(
  1041. quantile(acc, quantile_probability = 0.99025 + i*0.001)
  1042. , 0.99025 + i*0.001
  1043. , epsilon
  1044. );
  1045. BOOST_CHECK_CLOSE(
  1046. quantile(acc2, quantile_probability = 0.99025 + i*0.001)
  1047. , 0.99025 + i*0.001
  1048. , epsilon
  1049. );
  1050. BOOST_CHECK_CLOSE(
  1051. quantile(acc_weighted, quantile_probability = 0.99025 + i*0.001)
  1052. , 0.99025 + i*0.001
  1053. , epsilon
  1054. );
  1055. BOOST_CHECK_CLOSE(
  1056. quantile(acc_weighted2, quantile_probability = 0.99025 + i*0.001)
  1057. , 0.99025 + i*0.001
  1058. , epsilon
  1059. );
  1060. }
  1061. [*See also]
  1062. * [classref boost::accumulators::impl::extended_p_square_quantile_impl [^extended_p_square_quantile_impl]]
  1063. * [link accumulators.user_s_guide.the_statistical_accumulators_library.extended_p_square [^extended_p_square]]
  1064. * [link accumulators.user_s_guide.the_statistical_accumulators_library.weighted_extended_p_square [^weighted_extended_p_square]]
  1065. [endsect]
  1066. [section:kurtosis kurtosis]
  1067. The kurtosis of a sample distribution is defined as the ratio of the 4th central moment and the
  1068. square of the 2nd central moment (the variance) of the samples, minus 3. The term [^-3] is added
  1069. in order to ensure that the normal distribution has zero kurtosis. For more implementation
  1070. details, see [classref boost::accumulators::impl::kurtosis_impl [^kurtosis_impl]]
  1071. [variablelist
  1072. [[Result Type] [``
  1073. numeric::functional::fdiv<_sample_type_, _sample_type_>::result_type
  1074. ``]]
  1075. [[Depends On] [`mean` \n `moment<2>` \n `moment<3>` \n `moment<4>`]]
  1076. [[Variants] [['none]]]
  1077. [[Initialization Parameters] [['none]]]
  1078. [[Accumulator Parameters] [['none]]]
  1079. [[Extractor Parameters] [['none]]]
  1080. [[Accumulator Complexity] [O(1)]]
  1081. [[Extractor Complexity] [O(1)]]
  1082. ]
  1083. [*Header]
  1084. [def _KURTOSIS_HPP_ [headerref boost/accumulators/statistics/kurtosis.hpp]]
  1085. #include <_KURTOSIS_HPP_>
  1086. [*Example]
  1087. accumulator_set<int, stats<tag::kurtosis > > acc;
  1088. acc(2);
  1089. acc(7);
  1090. acc(4);
  1091. acc(9);
  1092. acc(3);
  1093. BOOST_CHECK_EQUAL( mean(acc), 5 );
  1094. BOOST_CHECK_EQUAL( accumulators::moment<2>(acc), 159./5. );
  1095. BOOST_CHECK_EQUAL( accumulators::moment<3>(acc), 1171./5. );
  1096. BOOST_CHECK_EQUAL( accumulators::moment<4>(acc), 1863 );
  1097. BOOST_CHECK_CLOSE( kurtosis(acc), -1.39965397924, 1e-6 );
  1098. [*See also]
  1099. * [classref boost::accumulators::impl::kurtosis_impl [^kurtosis_impl]]
  1100. * [link accumulators.user_s_guide.the_statistical_accumulators_library.mean [^mean]]
  1101. * [link accumulators.user_s_guide.the_statistical_accumulators_library.moment [^moment]]
  1102. [endsect]
  1103. [section:max max]
  1104. Calculates the maximum value of all the samples.
  1105. [variablelist
  1106. [[Result Type] [``
  1107. _sample_type_
  1108. ``]]
  1109. [[Depends On] [['none]]]
  1110. [[Variants] [['none]]]
  1111. [[Initialization Parameters] [['none]]]
  1112. [[Accumulator Parameters] [['none]]]
  1113. [[Extractor Parameters] [['none]]]
  1114. [[Accumulator Complexity] [O(1)]]
  1115. [[Extractor Complexity] [O(1)]]
  1116. ]
  1117. [*Header]
  1118. [def _MAX_HPP_ [headerref boost/accumulators/statistics/max.hpp]]
  1119. #include <_MAX_HPP_>
  1120. [*Example]
  1121. accumulator_set<int, stats<tag::max> > acc;
  1122. acc(1);
  1123. BOOST_CHECK_EQUAL(1, (max)(acc));
  1124. acc(0);
  1125. BOOST_CHECK_EQUAL(1, (max)(acc));
  1126. acc(2);
  1127. BOOST_CHECK_EQUAL(2, (max)(acc));
  1128. [*See also]
  1129. * [classref boost::accumulators::impl::max_impl [^max_impl]]
  1130. [endsect]
  1131. [section:mean mean ['and variants]]
  1132. Calculates the mean of samples, weights or variates. The calculation is either
  1133. lazy (in the result extractor), or immediate (in the accumulator). The lazy implementation
  1134. is the default. For more implementation details, see
  1135. [classref boost::accumulators::impl::mean_impl [^mean_impl]] or.
  1136. [classref boost::accumulators::impl::immediate_mean_impl [^immediate_mean_impl]]
  1137. [variablelist
  1138. [[Result Type] [For samples, `numeric::functional::fdiv<_sample_type_, std::size_t>::result_type` \n
  1139. For weights, `numeric::functional::fdiv<_weight_type_, std::size_t>::result_type` \n
  1140. For variates, `numeric::functional::fdiv<_variate_type_, std::size_t>::result_type`]]
  1141. [[Depends On] [`count` \n
  1142. The lazy mean of samples depends on `sum` \n
  1143. The lazy mean of weights depends on `sum_of_weights` \n
  1144. The lazy mean of variates depends on `sum_of_variates<>`]]
  1145. [[Variants] [`mean_of_weights` \n
  1146. `mean_of_variates<_variate_type_, _variate_tag_>` \n
  1147. `immediate_mean` \n
  1148. `immediate_mean_of_weights` \n
  1149. `immediate_mean_of_variates<_variate_type_, _variate_tag_>`]]
  1150. [[Initialization Parameters] [['none]]]
  1151. [[Accumulator Parameters] [['none]]]
  1152. [[Extractor Parameters] [['none]]]
  1153. [[Accumulator Complexity] [O(1)]]
  1154. [[Extractor Complexity] [O(1)]]
  1155. ]
  1156. [*Header]
  1157. [def _MEAN_HPP_ [headerref boost/accumulators/statistics/mean.hpp]]
  1158. #include <_MEAN_HPP_>
  1159. [*Example]
  1160. accumulator_set<
  1161. int
  1162. , stats<
  1163. tag::mean
  1164. , tag::mean_of_weights
  1165. , tag::mean_of_variates<int, tag::covariate1>
  1166. >
  1167. , int
  1168. > acc;
  1169. acc(1, weight = 2, covariate1 = 3);
  1170. BOOST_CHECK_CLOSE(1., mean(acc), 1e-5);
  1171. BOOST_CHECK_EQUAL(1u, count(acc));
  1172. BOOST_CHECK_EQUAL(2, sum(acc));
  1173. BOOST_CHECK_CLOSE(2., mean_of_weights(acc), 1e-5);
  1174. BOOST_CHECK_CLOSE(3., (accumulators::mean_of_variates<int, tag::covariate1>(acc)), 1e-5);
  1175. acc(0, weight = 4, covariate1 = 4);
  1176. BOOST_CHECK_CLOSE(0.33333333333333333, mean(acc), 1e-5);
  1177. BOOST_CHECK_EQUAL(2u, count(acc));
  1178. BOOST_CHECK_EQUAL(2, sum(acc));
  1179. BOOST_CHECK_CLOSE(3., mean_of_weights(acc), 1e-5);
  1180. BOOST_CHECK_CLOSE(3.5, (accumulators::mean_of_variates<int, tag::covariate1>(acc)), 1e-5);
  1181. acc(2, weight = 9, covariate1 = 8);
  1182. BOOST_CHECK_CLOSE(1.33333333333333333, mean(acc), 1e-5);
  1183. BOOST_CHECK_EQUAL(3u, count(acc));
  1184. BOOST_CHECK_EQUAL(20, sum(acc));
  1185. BOOST_CHECK_CLOSE(5., mean_of_weights(acc), 1e-5);
  1186. BOOST_CHECK_CLOSE(5., (accumulators::mean_of_variates<int, tag::covariate1>(acc)), 1e-5);
  1187. accumulator_set<
  1188. int
  1189. , stats<
  1190. tag::mean(immediate)
  1191. , tag::mean_of_weights(immediate)
  1192. , tag::mean_of_variates<int, tag::covariate1>(immediate)
  1193. >
  1194. , int
  1195. > acc2;
  1196. acc2(1, weight = 2, covariate1 = 3);
  1197. BOOST_CHECK_CLOSE(1., mean(acc2), 1e-5);
  1198. BOOST_CHECK_EQUAL(1u, count(acc2));
  1199. BOOST_CHECK_CLOSE(2., mean_of_weights(acc2), 1e-5);
  1200. BOOST_CHECK_CLOSE(3., (accumulators::mean_of_variates<int, tag::covariate1>(acc2)), 1e-5);
  1201. acc2(0, weight = 4, covariate1 = 4);
  1202. BOOST_CHECK_CLOSE(0.33333333333333333, mean(acc2), 1e-5);
  1203. BOOST_CHECK_EQUAL(2u, count(acc2));
  1204. BOOST_CHECK_CLOSE(3., mean_of_weights(acc2), 1e-5);
  1205. BOOST_CHECK_CLOSE(3.5, (accumulators::mean_of_variates<int, tag::covariate1>(acc2)), 1e-5);
  1206. acc2(2, weight = 9, covariate1 = 8);
  1207. BOOST_CHECK_CLOSE(1.33333333333333333, mean(acc2), 1e-5);
  1208. BOOST_CHECK_EQUAL(3u, count(acc2));
  1209. BOOST_CHECK_CLOSE(5., mean_of_weights(acc2), 1e-5);
  1210. BOOST_CHECK_CLOSE(5., (accumulators::mean_of_variates<int, tag::covariate1>(acc2)), 1e-5);
  1211. [*See also]
  1212. * [classref boost::accumulators::impl::mean_impl [^mean_impl]]
  1213. * [classref boost::accumulators::impl::immediate_mean_impl [^immediate_mean_impl]]
  1214. * [link accumulators.user_s_guide.the_statistical_accumulators_library.count [^count]]
  1215. * [link accumulators.user_s_guide.the_statistical_accumulators_library.sum [^sum]]
  1216. [endsect]
  1217. [section:median median ['and variants]]
  1218. Median estimation based on the [^P^2] quantile estimator, the density estimator, or
  1219. the [^P^2] cumulative distribution estimator. For more implementation details, see
  1220. [classref boost::accumulators::impl::median_impl [^median_impl]],
  1221. [classref boost::accumulators::impl::with_density_median_impl [^with_density_median_impl]],
  1222. and [classref boost::accumulators::impl::with_p_square_cumulative_distribution_median_impl [^with_p_square_cumulative_distribution_median_impl]].
  1223. The three median accumulators all satisfy the `tag::median` feature, and can all be
  1224. extracted with the `median()` extractor.
  1225. [variablelist
  1226. [[Result Type] [``
  1227. numeric::functional::fdiv<_sample_type_, std::size_t>::result_type
  1228. ``]]
  1229. [[Depends On] [`median` depends on `p_square_quantile_for_median` \n
  1230. `with_density_median` depends on `count` and `density` \n
  1231. `with_p_square_cumulative_distribution_median` depends on `p_square_cumulative_distribution`]]
  1232. [[Variants] [`with_density_median` \n
  1233. `with_p_square_cumulative_distribution_median`]]
  1234. [[Initialization Parameters] [`with_density_median` requires `tag::density::cache_size` and `tag::density::num_bins` \n
  1235. `with_p_square_cumulative_distribution_median` requires `tag::p_square_cumulative_distribution::num_cells`]]
  1236. [[Accumulator Parameters] [['none]]]
  1237. [[Extractor Parameters] [['none]]]
  1238. [[Accumulator Complexity] [TODO]]
  1239. [[Extractor Complexity] [TODO]]
  1240. ]
  1241. [*Header]
  1242. [def _MEDIAN_HPP_ [headerref boost/accumulators/statistics/median.hpp]]
  1243. #include <_MEDIAN_HPP_>
  1244. [*Example]
  1245. // two random number generators
  1246. double mu = 1.;
  1247. boost::lagged_fibonacci607 rng;
  1248. boost::normal_distribution<> mean_sigma(mu,1);
  1249. boost::variate_generator<boost::lagged_fibonacci607&, boost::normal_distribution<> >
  1250. normal(rng, mean_sigma);
  1251. accumulator_set<double, stats<tag::median(with_p_square_quantile) > > acc;
  1252. accumulator_set<double, stats<tag::median(with_density) > >
  1253. acc_dens( density_cache_size = 10000, density_num_bins = 1000 );
  1254. accumulator_set<double, stats<tag::median(with_p_square_cumulative_distribution) > >
  1255. acc_cdist( p_square_cumulative_distribution_num_cells = 100 );
  1256. for (std::size_t i=0; i<100000; ++i)
  1257. {
  1258. double sample = normal();
  1259. acc(sample);
  1260. acc_dens(sample);
  1261. acc_cdist(sample);
  1262. }
  1263. BOOST_CHECK_CLOSE(1., median(acc), 1.);
  1264. BOOST_CHECK_CLOSE(1., median(acc_dens), 1.);
  1265. BOOST_CHECK_CLOSE(1., median(acc_cdist), 3.);
  1266. [*See also]
  1267. * [classref boost::accumulators::impl::median_impl [^median_impl]]
  1268. * [classref boost::accumulators::impl::with_density_median_impl [^with_density_median_impl]]
  1269. * [classref boost::accumulators::impl::with_p_square_cumulative_distribution_median_impl [^with_p_square_cumulative_distribution_median_impl]]
  1270. * [link accumulators.user_s_guide.the_statistical_accumulators_library.count [^count]]
  1271. * [link accumulators.user_s_guide.the_statistical_accumulators_library.p_square_quantile [^p_square_quantile]]
  1272. * [link accumulators.user_s_guide.the_statistical_accumulators_library.p_square_cumulative_distribution [^p_square_cumulative_distribution]]
  1273. [endsect]
  1274. [section:min min]
  1275. Calculates the minimum value of all the samples.
  1276. [variablelist
  1277. [[Result Type] [``
  1278. _sample_type_
  1279. ``]]
  1280. [[Depends On] [['none]]]
  1281. [[Variants] [['none]]]
  1282. [[Initialization Parameters] [['none]]]
  1283. [[Accumulator Parameters] [['none]]]
  1284. [[Extractor Parameters] [['none]]]
  1285. [[Accumulator Complexity] [O(1)]]
  1286. [[Extractor Complexity] [O(1)]]
  1287. ]
  1288. [*Header]
  1289. [def _MIN_HPP_ [headerref boost/accumulators/statistics/min.hpp]]
  1290. #include <_MIN_HPP_>
  1291. [*Example]
  1292. accumulator_set<int, stats<tag::min> > acc;
  1293. acc(1);
  1294. BOOST_CHECK_EQUAL(1, (min)(acc));
  1295. acc(0);
  1296. BOOST_CHECK_EQUAL(0, (min)(acc));
  1297. acc(2);
  1298. BOOST_CHECK_EQUAL(0, (min)(acc));
  1299. [*See also]
  1300. * [classref boost::accumulators::impl::min_impl [^min_impl]]
  1301. [endsect]
  1302. [section:moment moment]
  1303. Calculates the N-th moment of the samples, which is defined as the sum of the N-th power of the
  1304. samples over the count of samples.
  1305. [variablelist
  1306. [[Result Type] [``
  1307. numeric::functional::fdiv<_sample_type_, std::size_t>::result_type
  1308. ``]]
  1309. [[Depends On] [`count`]]
  1310. [[Variants] [['none]]]
  1311. [[Initialization Parameters] [['none]]]
  1312. [[Accumulator Parameters] [['none]]]
  1313. [[Extractor Parameters] [['none]]]
  1314. [[Accumulator Complexity] [O(1)]]
  1315. [[Extractor Complexity] [O(1)]]
  1316. ]
  1317. [*Header]
  1318. [def _MOMENT_HPP_ [headerref boost/accumulators/statistics/moment.hpp]]
  1319. #include <_MOMENT_HPP_>
  1320. [*Example]
  1321. accumulator_set<int, stats<tag::moment<2> > > acc1;
  1322. acc1(2); // 4
  1323. acc1(4); // 16
  1324. acc1(5); // + 25
  1325. // = 45 / 3 = 15
  1326. BOOST_CHECK_CLOSE(15., accumulators::moment<2>(acc1), 1e-5);
  1327. accumulator_set<int, stats<tag::moment<5> > > acc2;
  1328. acc2(2); // 32
  1329. acc2(3); // 243
  1330. acc2(4); // 1024
  1331. acc2(5); // + 3125
  1332. // = 4424 / 4 = 1106
  1333. BOOST_CHECK_CLOSE(1106., accumulators::moment<5>(acc2), 1e-5);
  1334. [*See also]
  1335. * [classref boost::accumulators::impl::moment_impl [^moment_impl]]
  1336. * [link accumulators.user_s_guide.the_statistical_accumulators_library.count [^count]]
  1337. [endsect]
  1338. [section:p_square_cumulative_distribution p_square_cumulative_distribution]
  1339. Histogram calculation of the cumulative distribution with the [^P^2] algorithm.
  1340. For more implementation details, see
  1341. [classref boost::accumulators::impl::p_square_cumulative_distribution_impl [^p_square_cumulative_distribution_impl]]
  1342. [variablelist
  1343. [[Result Type] [``
  1344. iterator_range<
  1345. std::vector<
  1346. std::pair<
  1347. numeric::functional::fdiv<_sample_type_, std::size_t>::result_type
  1348. , numeric::functional::fdiv<_sample_type_, std::size_t>::result_type
  1349. >
  1350. >::iterator
  1351. >
  1352. ``]]
  1353. [[Depends On] [`count`]]
  1354. [[Variants] [['none]]]
  1355. [[Initialization Parameters] [`tag::p_square_cumulative_distribution::num_cells`]]
  1356. [[Accumulator Parameters] [['none]]]
  1357. [[Extractor Parameters] [['none]]]
  1358. [[Accumulator Complexity] [TODO]]
  1359. [[Extractor Complexity] [O(N) where N is `num_cells`]]
  1360. ]
  1361. [*Header]
  1362. [def _P_SQUARE_CUMULATIVE_DISTRIBUTION_HPP_ [headerref boost/accumulators/statistics/p_square_cumul_dist.hpp]]
  1363. #include <_P_SQUARE_CUMULATIVE_DISTRIBUTION_HPP_>
  1364. [*Example]
  1365. // tolerance in %
  1366. double epsilon = 3;
  1367. typedef accumulator_set<double, stats<tag::p_square_cumulative_distribution> > accumulator_t;
  1368. accumulator_t acc(tag::p_square_cumulative_distribution::num_cells = 100);
  1369. // two random number generators
  1370. boost::lagged_fibonacci607 rng;
  1371. boost::normal_distribution<> mean_sigma(0,1);
  1372. boost::variate_generator<boost::lagged_fibonacci607&, boost::normal_distribution<> > normal(rng, mean_sigma);
  1373. for (std::size_t i=0; i<100000; ++i)
  1374. {
  1375. acc(normal());
  1376. }
  1377. typedef iterator_range<std::vector<std::pair<double, double> >::iterator > histogram_type;
  1378. histogram_type histogram = p_square_cumulative_distribution(acc);
  1379. for (std::size_t i = 0; i < histogram.size(); ++i)
  1380. {
  1381. // problem with small results: epsilon is relative (in percent), not absolute!
  1382. if ( histogram[i].second > 0.001 )
  1383. BOOST_CHECK_CLOSE( 0.5 * (1.0 + erf( histogram[i].first / sqrt(2.0) )), histogram[i].second, epsilon );
  1384. }
  1385. [*See also]
  1386. * [classref boost::accumulators::impl::p_square_cumulative_distribution_impl [^p_square_cumulative_distribution_impl]]
  1387. * [link accumulators.user_s_guide.the_statistical_accumulators_library.count [^count]]
  1388. [endsect]
  1389. [section:p_square_quantile p_square_quantile ['and variants]]
  1390. Single quantile estimation with the [^P^2] algorithm. For more implementation details, see
  1391. [classref boost::accumulators::impl::p_square_quantile_impl [^p_square_quantile_impl]]
  1392. [variablelist
  1393. [[Result Type] [``
  1394. numeric::functional::fdiv<_sample_type_, std::size_t>::result_type
  1395. ``]]
  1396. [[Depends On] [`count`]]
  1397. [[Variants] [`p_square_quantile_for_median`]]
  1398. [[Initialization Parameters] [`quantile_probability`, which defaults to `0.5`.
  1399. (Note: for `p_square_quantile_for_median`, the `quantile_probability`
  1400. parameter is ignored and is always `0.5`.)]]
  1401. [[Accumulator Parameters] [['none]]]
  1402. [[Extractor Parameters] [['none]]]
  1403. [[Accumulator Complexity] [TODO]]
  1404. [[Extractor Complexity] [O(1)]]
  1405. ]
  1406. [*Header]
  1407. [def _P_SQUARE_QUANTILE_HPP_ [headerref boost/accumulators/statistics/p_square_quantile.hpp]]
  1408. #include <_P_SQUARE_QUANTILE_HPP_>
  1409. [*Example]
  1410. typedef accumulator_set<double, stats<tag::p_square_quantile> > accumulator_t;
  1411. // tolerance in %
  1412. double epsilon = 1;
  1413. // a random number generator
  1414. boost::lagged_fibonacci607 rng;
  1415. accumulator_t acc0(quantile_probability = 0.001);
  1416. accumulator_t acc1(quantile_probability = 0.01 );
  1417. accumulator_t acc2(quantile_probability = 0.1 );
  1418. accumulator_t acc3(quantile_probability = 0.25 );
  1419. accumulator_t acc4(quantile_probability = 0.5 );
  1420. accumulator_t acc5(quantile_probability = 0.75 );
  1421. accumulator_t acc6(quantile_probability = 0.9 );
  1422. accumulator_t acc7(quantile_probability = 0.99 );
  1423. accumulator_t acc8(quantile_probability = 0.999);
  1424. for (int i=0; i<100000; ++i)
  1425. {
  1426. double sample = rng();
  1427. acc0(sample);
  1428. acc1(sample);
  1429. acc2(sample);
  1430. acc3(sample);
  1431. acc4(sample);
  1432. acc5(sample);
  1433. acc6(sample);
  1434. acc7(sample);
  1435. acc8(sample);
  1436. }
  1437. BOOST_CHECK_CLOSE( p_square_quantile(acc0), 0.001, 15*epsilon );
  1438. BOOST_CHECK_CLOSE( p_square_quantile(acc1), 0.01 , 5*epsilon );
  1439. BOOST_CHECK_CLOSE( p_square_quantile(acc2), 0.1 , epsilon );
  1440. BOOST_CHECK_CLOSE( p_square_quantile(acc3), 0.25 , epsilon );
  1441. BOOST_CHECK_CLOSE( p_square_quantile(acc4), 0.5 , epsilon );
  1442. BOOST_CHECK_CLOSE( p_square_quantile(acc5), 0.75 , epsilon );
  1443. BOOST_CHECK_CLOSE( p_square_quantile(acc6), 0.9 , epsilon );
  1444. BOOST_CHECK_CLOSE( p_square_quantile(acc7), 0.99 , epsilon );
  1445. BOOST_CHECK_CLOSE( p_square_quantile(acc8), 0.999, epsilon );
  1446. [*See also]
  1447. * [classref boost::accumulators::impl::p_square_quantile_impl [^p_square_quantile_impl]]
  1448. * [link accumulators.user_s_guide.the_statistical_accumulators_library.count [^count]]
  1449. [endsect]
  1450. [section:peaks_over_threshold peaks_over_threshold ['and variants]]
  1451. Peaks Over Threshold method for quantile and tail mean estimation. For implementation
  1452. details, see [classref boost::accumulators::impl::peaks_over_threshold_impl [^peaks_over_threshold_impl]]
  1453. and [classref boost::accumulators::impl::peaks_over_threshold_prob_impl [^peaks_over_threshold_prob_impl]].
  1454. Both `tag::peaks_over_threshold` and `tag::peaks_over_threshold_prob<>` satisfy the `tag::abstract_peaks_over_threshold`
  1455. feature, and can be extracted with the `peaks_over_threshold()` extractor. The result is a 3-tuple representing
  1456. the fit parameters `u_bar`, `beta_bar` and `xi_hat`.
  1457. [variablelist
  1458. [[Result Type] [``
  1459. boost::tuple<
  1460. numeric::functional::fdiv<_sample_type_, std::size_t>::result_type // u_bar
  1461. , numeric::functional::fdiv<_sample_type_, std::size_t>::result_type // beta_bar
  1462. , numeric::functional::fdiv<_sample_type_, std::size_t>::result_type // xi_hat
  1463. >
  1464. ``]]
  1465. [[Depends On] [`count` \n
  1466. In addition, `tag::peaks_over_threshold_prob<>` depends on `tail<_left_or_right_>`]]
  1467. [[Variants] [`peaks_over_threshold_prob<_left_or_right_>`]]
  1468. [[Initialization Parameters] [ `tag::peaks_over_threshold::threshold_value` \n
  1469. `tag::peaks_over_threshold_prob::threshold_probability` \n
  1470. `tag::tail<_left_or_right_>::cache_size` ]]
  1471. [[Accumulator Parameters] [['none]]]
  1472. [[Extractor Parameters] [['none]]]
  1473. [[Accumulator Complexity] [TODO]]
  1474. [[Extractor Complexity] [TODO]]
  1475. ]
  1476. [*Header]
  1477. [def _PEAKS_OVER_THRESHOLD_HPP_ [headerref boost/accumulators/statistics/peaks_over_threshold.hpp]]
  1478. #include <_PEAKS_OVER_THRESHOLD_HPP_>
  1479. [*Example]
  1480. See example for [link accumulators.user_s_guide.the_statistical_accumulators_library.pot_quantile [^pot_quantile]].
  1481. [*See also]
  1482. * [classref boost::accumulators::impl::peaks_over_threshold_impl [^peaks_over_threshold_impl]]
  1483. * [classref boost::accumulators::impl::peaks_over_threshold_prob_impl [^peaks_over_threshold_prob_impl]]
  1484. * [link accumulators.user_s_guide.the_statistical_accumulators_library.count [^count]]
  1485. * [link accumulators.user_s_guide.the_statistical_accumulators_library.tail [^tail]]
  1486. * [link accumulators.user_s_guide.the_statistical_accumulators_library.pot_quantile [^pot_quantile]]
  1487. * [link accumulators.user_s_guide.the_statistical_accumulators_library.pot_tail_mean [^pot_tail_mean]]
  1488. [endsect]
  1489. [section:pot_quantile pot_quantile ['and variants]]
  1490. Quantile estimation based on Peaks over Threshold method (for both left and right tails). For
  1491. implementation details, see [classref boost::accumulators::impl::pot_quantile_impl [^pot_quantile_impl]].
  1492. Both `tag::pot_quantile<_left_or_right_>` and `tag::pot_quantile_prob<_left_or_right_>` satisfy the
  1493. `tag::quantile` feature and can be extracted using the `quantile()` extractor.
  1494. [variablelist
  1495. [[Result Type] [``
  1496. numeric::functional::fdiv<_sample_type_, std::size_t>::result_type
  1497. ``]]
  1498. [[Depends On] [`pot_quantile<_left_or_right_>` depends on `peaks_over_threshold<_left_or_right_>` \n
  1499. `pot_quantile_prob<_left_or_right_>` depends on `peaks_over_threshold_prob<_left_or_right_>` ]]
  1500. [[Variants] [`pot_quantile_prob<_left_or_right_>`]]
  1501. [[Initialization Parameters] [ `tag::peaks_over_threshold::threshold_value` \n
  1502. `tag::peaks_over_threshold_prob::threshold_probability` \n
  1503. `tag::tail<_left_or_right_>::cache_size` ]]
  1504. [[Accumulator Parameters] [['none]]]
  1505. [[Extractor Parameters] [`quantile_probability`]]
  1506. [[Accumulator Complexity] [TODO]]
  1507. [[Extractor Complexity] [TODO]]
  1508. ]
  1509. [*Header]
  1510. [def _POT_QUANTILE_HPP_ [headerref boost/accumulators/statistics/pot_quantile.hpp]]
  1511. #include <_POT_QUANTILE_HPP_>
  1512. [*Example]
  1513. // tolerance in %
  1514. double epsilon = 1.;
  1515. double alpha = 0.999;
  1516. double threshold_probability = 0.99;
  1517. double threshold = 3.;
  1518. // two random number generators
  1519. boost::lagged_fibonacci607 rng;
  1520. boost::normal_distribution<> mean_sigma(0,1);
  1521. boost::exponential_distribution<> lambda(1);
  1522. boost::variate_generator<boost::lagged_fibonacci607&, boost::normal_distribution<> > normal(rng, mean_sigma);
  1523. boost::variate_generator<boost::lagged_fibonacci607&, boost::exponential_distribution<> > exponential(rng, lambda);
  1524. accumulator_set<double, stats<tag::pot_quantile<right>(with_threshold_value)> > acc1(
  1525. tag::peaks_over_threshold::threshold_value = threshold
  1526. );
  1527. accumulator_set<double, stats<tag::pot_quantile<right>(with_threshold_probability)> > acc2(
  1528. tag::tail<right>::cache_size = 2000
  1529. , tag::peaks_over_threshold_prob::threshold_probability = threshold_probability
  1530. );
  1531. threshold_probability = 0.995;
  1532. threshold = 5.;
  1533. accumulator_set<double, stats<tag::pot_quantile<right>(with_threshold_value)> > acc3(
  1534. tag::peaks_over_threshold::threshold_value = threshold
  1535. );
  1536. accumulator_set<double, stats<tag::pot_quantile<right>(with_threshold_probability)> > acc4(
  1537. tag::tail<right>::cache_size = 2000
  1538. , tag::peaks_over_threshold_prob::threshold_probability = threshold_probability
  1539. );
  1540. for (std::size_t i = 0; i < 100000; ++i)
  1541. {
  1542. double sample = normal();
  1543. acc1(sample);
  1544. acc2(sample);
  1545. }
  1546. for (std::size_t i = 0; i < 100000; ++i)
  1547. {
  1548. double sample = exponential();
  1549. acc3(sample);
  1550. acc4(sample);
  1551. }
  1552. BOOST_CHECK_CLOSE( quantile(acc1, quantile_probability = alpha), 3.090232, epsilon );
  1553. BOOST_CHECK_CLOSE( quantile(acc2, quantile_probability = alpha), 3.090232, epsilon );
  1554. BOOST_CHECK_CLOSE( quantile(acc3, quantile_probability = alpha), 6.908, epsilon );
  1555. BOOST_CHECK_CLOSE( quantile(acc4, quantile_probability = alpha), 6.908, epsilon );
  1556. [*See also]
  1557. * [classref boost::accumulators::impl::pot_quantile_impl [^pot_quantile_impl]]
  1558. * [link accumulators.user_s_guide.the_statistical_accumulators_library.peaks_over_threshold [^peaks_over_threshold]]
  1559. [endsect]
  1560. [section:pot_tail_mean pot_tail_mean]
  1561. Estimation of the (coherent) tail mean based on the peaks over threshold method (for both left and right tails).
  1562. For implementation details, see [classref boost::accumulators::impl::pot_tail_mean_impl [^pot_tail_mean_impl]].
  1563. Both `tag::pot_tail_mean<_left_or_right_>` and `tag::pot_tail_mean_prob<_left_or_right_>` satisfy the
  1564. `tag::tail_mean` feature and can be extracted using the `tail_mean()` extractor.
  1565. [variablelist
  1566. [[Result Type] [``
  1567. numeric::functional::fdiv<_sample_type_, std::size_t>::result_type
  1568. ``]]
  1569. [[Depends On] [`pot_tail_mean<_left_or_right_>` depends on `peaks_over_threshold<_left_or_right_>`
  1570. and `pot_quantile<_left_or_right_>` \n
  1571. `pot_tail_mean_prob<_left_or_right_>` depends on `peaks_over_threshold_prob<_left_or_right_>`
  1572. and `pot_quantile_prob<_left_or_right_>` ]]
  1573. [[Variants] [`pot_tail_mean_prob<_left_or_right_>`]]
  1574. [[Initialization Parameters] [ `tag::peaks_over_threshold::threshold_value` \n
  1575. `tag::peaks_over_threshold_prob::threshold_probability` \n
  1576. `tag::tail<_left_or_right_>::cache_size` ]]
  1577. [[Accumulator Parameters] [['none]]]
  1578. [[Extractor Parameters] [`quantile_probability`]]
  1579. [[Accumulator Complexity] [TODO]]
  1580. [[Extractor Complexity] [TODO]]
  1581. ]
  1582. [*Header]
  1583. [def _POT_TAIL_MEAN_HPP_ [headerref boost/accumulators/statistics/pot_tail_mean.hpp]]
  1584. #include <_POT_TAIL_MEAN_HPP_>
  1585. [*Example]
  1586. // TODO
  1587. [*See also]
  1588. * [classref boost::accumulators::impl::pot_tail_mean_impl [^pot_tail_mean_impl]]
  1589. * [link accumulators.user_s_guide.the_statistical_accumulators_library.peaks_over_threshold [^peaks_over_threshold]]
  1590. * [link accumulators.user_s_guide.the_statistical_accumulators_library.pot_quantile [^pot_quantile]]
  1591. [endsect]
  1592. [section:rolling_count rolling_count]
  1593. The rolling count is the current number of elements in the rolling window.
  1594. [variablelist
  1595. [[Result Type] [``std::size_t``]]
  1596. [[Depends On] [`rolling_window_plus1`]]
  1597. [[Variants] [['none]]]
  1598. [[Initialization Parameters] [`tag::rolling_window::window_size`]]
  1599. [[Accumulator Parameters] [['none]]]
  1600. [[Extractor Parameters] [['none]]]
  1601. [[Accumulator Complexity] [O(1)]]
  1602. [[Extractor Complexity] [O(1)]]
  1603. ]
  1604. [*Header]
  1605. [def _ROLLING_COUNT_HPP_ [headerref boost/accumulators/statistics/rolling_count.hpp]]
  1606. #include <_ROLLING_COUNT_HPP_>
  1607. [*Example]
  1608. accumulator_set<int, stats<tag::rolling_count> > acc(tag::rolling_window::window_size = 3);
  1609. BOOST_CHECK_EQUAL(0u, rolling_count(acc));
  1610. acc(1);
  1611. BOOST_CHECK_EQUAL(1u, rolling_count(acc));
  1612. acc(1);
  1613. BOOST_CHECK_EQUAL(2u, rolling_count(acc));
  1614. acc(1);
  1615. BOOST_CHECK_EQUAL(3u, rolling_count(acc));
  1616. acc(1);
  1617. BOOST_CHECK_EQUAL(3u, rolling_count(acc));
  1618. acc(1);
  1619. BOOST_CHECK_EQUAL(3u, rolling_count(acc));
  1620. [*See also]
  1621. * [classref boost::accumulators::impl::rolling_count_impl [^rolling_count_impl]]
  1622. [endsect]
  1623. [section:rolling_sum rolling_sum]
  1624. The rolling sum is the sum of the last /N/ samples.
  1625. [variablelist
  1626. [[Result Type] [``_sample_type_``]]
  1627. [[Depends On] [`rolling_window_plus1`]]
  1628. [[Variants] [['none]]]
  1629. [[Initialization Parameters] [`tag::rolling_window::window_size`]]
  1630. [[Accumulator Parameters] [['none]]]
  1631. [[Extractor Parameters] [['none]]]
  1632. [[Accumulator Complexity] [O(1)]]
  1633. [[Extractor Complexity] [O(1)]]
  1634. ]
  1635. [*Header]
  1636. [def _ROLLING_SUM_HPP_ [headerref boost/accumulators/statistics/rolling_sum.hpp]]
  1637. #include <_ROLLING_SUM_HPP_>
  1638. [*Example]
  1639. accumulator_set<int, stats<tag::rolling_sum> > acc(tag::rolling_window::window_size = 3);
  1640. BOOST_CHECK_EQUAL(0, rolling_sum(acc));
  1641. acc(1);
  1642. BOOST_CHECK_EQUAL(1, rolling_sum(acc));
  1643. acc(2);
  1644. BOOST_CHECK_EQUAL(3, rolling_sum(acc));
  1645. acc(3);
  1646. BOOST_CHECK_EQUAL(6, rolling_sum(acc));
  1647. acc(4);
  1648. BOOST_CHECK_EQUAL(9, rolling_sum(acc));
  1649. acc(5);
  1650. BOOST_CHECK_EQUAL(12, rolling_sum(acc));
  1651. [*See also]
  1652. * [classref boost::accumulators::impl::rolling_sum_impl [^rolling_sum_impl]]
  1653. [endsect]
  1654. [section:rolling_mean rolling_mean]
  1655. The rolling mean is the mean over the last /N/ samples. It is computed by dividing
  1656. the rolling sum by the rolling count.
  1657. Lazy or iterative calculation of the mean over the last /N/ samples. The lazy calculation is associated with the `tag::lazy_rolling_mean`
  1658. feature, and the iterative calculation (which is the default) with the `tag::immediate_rolling_mean` feature. Both can be extracted
  1659. using the `tag::rolling_mean()` extractor. For more implementation details, see
  1660. [classref boost::accumulators::impl::lazy_rolling_mean_impl [^lazy_rolling_mean_impl]] and
  1661. [classref boost::accumulators::impl::immediate_rolling_mean_impl [^immediate_rolling_mean_impl]]
  1662. [variablelist
  1663. [[Result Type] [``
  1664. numeric::functional::fdiv<_sample_type_, std::size_t>::result_type
  1665. ``]]
  1666. [[Depends On] [`lazy_rolling_mean` depends on `rolling_sum` and `rolling_count` \n
  1667. `immediate_rolling_mean` depends on `rolling_count`]]
  1668. [[Variants] [`lazy_rolling_mean` (a.k.a. `rolling_mean(lazy))` \n
  1669. `immediate_rolling_mean` (a.k.a. `rolling_mean(immediate)`)]]
  1670. [[Initialization Parameters] [`tag::rolling_window::window_size`]]
  1671. [[Accumulator Parameters] [['none]]]
  1672. [[Extractor Parameters] [['none]]]
  1673. [[Accumulator Complexity] [O(1)]]
  1674. [[Extractor Complexity] [O(1)]]
  1675. ]
  1676. [*Header]
  1677. [def _ROLLING_MEAN_HPP_ [headerref boost/accumulators/statistics/rolling_mean.hpp]]
  1678. #include <_ROLLING_MEAN_HPP_>
  1679. [*Example]
  1680. accumulator_set<int, stats<tag::rolling_mean> > acc(tag::rolling_window::window_size = 5);
  1681. acc(1);
  1682. acc(2);
  1683. acc(3);
  1684. BOOST_CHECK_CLOSE( rolling_mean(acc), 2.0, 1e-6 );
  1685. acc(4);
  1686. acc(5);
  1687. acc(6);
  1688. acc(7);
  1689. BOOST_CHECK_CLOSE( rolling_mean(acc), 5.0, 1e-6 );
  1690. [*See also]
  1691. * [classref boost::accumulators::impl::lazy_rolling_mean_impl [^lazy_rolling_mean_impl]]
  1692. * [classref boost::accumulators::impl::immediate_rolling_mean_impl [^immediate_rolling_mean_impl]]
  1693. * [link accumulators.user_s_guide.the_statistical_accumulators_library.rolling_count [^rolling_count]]
  1694. * [link accumulators.user_s_guide.the_statistical_accumulators_library.rolling_sum [^rolling_sum]]
  1695. [endsect]
  1696. [section:rolling_moment rolling_moment]
  1697. rolling_moment<M> calculates the /M/-th moment of the samples, which is defined as the sum of the /M/-th power of the samples over the count of samples, over the last /N/ samples.
  1698. [variablelist
  1699. [[Result Type] [``
  1700. numeric::functional::fdiv<_sample_type_, std::size_t>::result_type
  1701. ``]]
  1702. [[Depends On] [['none]]]
  1703. [[Variants] [['none]]]
  1704. [[Initialization Parameters] [`tag::rolling_window::window_size`]]
  1705. [[Accumulator Parameters] [['none]]]
  1706. [[Extractor Parameters] [['none]]]
  1707. [[Accumulator Complexity] [O(1)]]
  1708. [[Extractor Complexity] [O(1)]]
  1709. ]
  1710. [*Header]
  1711. [def _ROLLING_MOMENT_HPP_ [headerref boost/accumulators/statistics/rolling_moment.hpp]]
  1712. #include <_ROLLING_MOMENT_HPP_>
  1713. [*Example]
  1714. accumulator_set<int, stats<tag::rolling_moment<2> > > acc(tag::rolling_window::window_size = 3);
  1715. acc(2);
  1716. acc(4);
  1717. BOOST_CHECK_CLOSE( rolling_moment<2>(acc), (4.0 + 16.0)/2, 1e-5 );
  1718. acc(5);
  1719. acc(6);
  1720. BOOST_CHECK_CLOSE( rolling_moment<2>(acc), (16.0 + 25.0 + 36.0)/3, 1e-5 );
  1721. [*See also]
  1722. * [classref boost::accumulators::impl::rolling_moment_impl [^rolling_moment_impl]]
  1723. [endsect]
  1724. [section:rolling_variance rolling_variance]
  1725. Lazy or iterative calculation of the variance over the last /N/ samples. The lazy calculation is associated with the `tag::lazy_rolling_variance`
  1726. feature, and the iterative calculation with the `tag::immediate_rolling_variance` feature. Both can be extracted using the `tag::rolling_variance()` extractor.
  1727. For more implementation details, see
  1728. [classref boost::accumulators::impl::lazy_rolling_variance_impl [^lazy_rolling_variance_impl]] and
  1729. [classref boost::accumulators::impl::immediate_rolling_variance_impl [^immediate_rolling_variance_impl]]
  1730. [variablelist
  1731. [[Result Type] [``
  1732. numeric::functional::fdiv<_sample_type_, std::size_t>::result_type
  1733. ``]]
  1734. [[Depends On] [`lazy_rolling_variance` depends on `rolling_moment<2>`, `rolling_count` and `rolling_mean` \n
  1735. `immediate_rolling_variance` depends on `rolling_count` and `immediate_rolling_mean`]]
  1736. [[Variants] [`lazy_rolling_variance` (a.k.a. `rolling_variance(lazy))` \n
  1737. `immediate_rolling_variance` (a.k.a. `rolling_variance(immediate)`)]]
  1738. [[Initialization Parameters] [`tag::rolling_window::window_size`]]
  1739. [[Accumulator Parameters] [['none]]]
  1740. [[Extractor Parameters] [['none]]]
  1741. [[Accumulator Complexity] [O(1)]]
  1742. [[Extractor Complexity] [O(1)]]
  1743. ]
  1744. [*Header]
  1745. [def _ROLLING_VARIANCE_HPP_ [headerref boost/accumulators/statistics/rolling_variance.hpp]]
  1746. #include <_ROLLING_VARIANCE_HPP_>
  1747. [*Example]
  1748. accumulator_set<double, stats<tag::rolling_variance> > acc(tag::rolling_window::window_size = 4);
  1749. acc(1.2);
  1750. BOOST_CHECK_CLOSE( rolling_variance(acc), 0.0, 1e-10 ); // variance is not defined for a single sample
  1751. acc(2.3);
  1752. acc(3.4);
  1753. BOOST_CHECK_CLOSE( rolling_variance(acc), 1.21, 1e-10 ); // variance over samples 1-3
  1754. acc(4.5);
  1755. acc(0.4);
  1756. acc(2.2);
  1757. acc(7.1);
  1758. BOOST_CHECK_CLOSE( rolling_variance(acc), 8.41666666666667, 1e-10 ); // variance over samples 4-7
  1759. [*See also]
  1760. * [classref boost::accumulators::impl::lazy_rolling_variance_impl [^lazy_rolling_variance_impl]]
  1761. * [classref boost::accumulators::impl::immediate_rolling_variance_impl [^immediate_rolling_variance_impl]]
  1762. * [link accumulators.user_s_guide.the_statistical_accumulators_library.rolling_count [^rolling_count]]
  1763. * [link accumulators.user_s_guide.the_statistical_accumulators_library.rolling_mean [^rolling_mean]]
  1764. * [link accumulators.user_s_guide.the_statistical_accumulators_library.immediate_rolling_mean [^immediate_rolling_mean]]
  1765. * [link accumulators.user_s_guide.the_statistical_accumulators_library.rolling_moment [^rolling_moment]]
  1766. [endsect]
  1767. [section:skewness skewness]
  1768. The skewness of a sample distribution is defined as the ratio of the 3rd central moment and the [^3/2]-th power
  1769. of the 2nd central moment (the variance) of the samples 3. For implementation details, see
  1770. [classref boost::accumulators::impl::skewness_impl [^skewness_impl]].
  1771. [variablelist
  1772. [[Result Type] [``
  1773. numeric::functional::fdiv<_sample_type_, _sample_type_>::result_type
  1774. ``]]
  1775. [[Depends On] [`mean` \n `moment<2>` \n `moment<3>`]]
  1776. [[Variants] [['none]]]
  1777. [[Initialization Parameters] [['none]]]
  1778. [[Accumulator Parameters] [['none]]]
  1779. [[Extractor Parameters] [['none]]]
  1780. [[Accumulator Complexity] [O(1)]]
  1781. [[Extractor Complexity] [O(1)]]
  1782. ]
  1783. [*Header]
  1784. [def _SKEWNESS_HPP_ [headerref boost/accumulators/statistics/skewness.hpp]]
  1785. #include <_SKEWNESS_HPP_>
  1786. [*Example]
  1787. accumulator_set<int, stats<tag::skewness > > acc2;
  1788. acc2(2);
  1789. acc2(7);
  1790. acc2(4);
  1791. acc2(9);
  1792. acc2(3);
  1793. BOOST_CHECK_EQUAL( mean(acc2), 5 );
  1794. BOOST_CHECK_EQUAL( accumulators::moment<2>(acc2), 159./5. );
  1795. BOOST_CHECK_EQUAL( accumulators::moment<3>(acc2), 1171./5. );
  1796. BOOST_CHECK_CLOSE( skewness(acc2), 0.406040288214, 1e-6 );
  1797. [*See also]
  1798. * [classref boost::accumulators::impl::skewness_impl [^skewness_impl]]
  1799. * [link accumulators.user_s_guide.the_statistical_accumulators_library.mean [^mean]]
  1800. * [link accumulators.user_s_guide.the_statistical_accumulators_library.moment [^moment]]
  1801. [endsect]
  1802. [section:sum sum ['and variants]]
  1803. For summing the samples, weights or variates. The default implementation uses the standard sum operation,
  1804. but variants using the Kahan summation algorithm are also provided.
  1805. [variablelist
  1806. [[Result Type] [`_sample_type_` for summing samples \n
  1807. `_weight_type_` for summing weights \n
  1808. `_variate_type_` for summing variates]]
  1809. [[Depends On] [['none]]]
  1810. [[Variants] [`tag::sum` \n
  1811. `tag::sum_of_weights` \n
  1812. `tag::sum_of_variates<_variate_type_, _variate_tag_>` \n
  1813. `tag::sum_kahan` (a.k.a. `tag::sum(kahan)`) \n
  1814. `tag::sum_of_weights_kahan` (a.k.a. `tag::sum_of_weights(kahan)`) \n
  1815. `tag::sum_of_variates_kahan<_variate_type_, _variate_tag_>` \n]]
  1816. [[Initialization Parameters] [['none]]]
  1817. [[Accumulator Parameters] [`weight` for summing weights \n
  1818. `_variate_tag_` for summing variates]]
  1819. [[Extractor Parameters] [['none]]]
  1820. [[Accumulator Complexity] [O(1). Note that the Kahan sum performs four floating-point sum
  1821. operations per accumulated value, whereas the naive sum
  1822. performs only one.]]
  1823. [[Extractor Complexity] [O(1)]]
  1824. ]
  1825. [*Header]
  1826. [def _SUM_HPP_ [headerref boost/accumulators/statistics/sum.hpp]]
  1827. [def _SUM_KAHAN_HPP_ [headerref boost/accumulators/statistics/sum_kahan.hpp]]
  1828. #include <_SUM_HPP_>
  1829. #include <_SUM_KAHAN_HPP_>
  1830. [*Example]
  1831. accumulator_set<
  1832. int
  1833. , stats<
  1834. tag::sum
  1835. , tag::sum_of_weights
  1836. , tag::sum_of_variates<int, tag::covariate1>
  1837. >
  1838. , int
  1839. > acc;
  1840. acc(1, weight = 2, covariate1 = 3);
  1841. BOOST_CHECK_EQUAL(2, sum(acc)); // weighted sample = 1 * 2
  1842. BOOST_CHECK_EQUAL(2, sum_of_weights(acc));
  1843. BOOST_CHECK_EQUAL(3, sum_of_variates(acc));
  1844. acc(2, weight = 4, covariate1 = 6);
  1845. BOOST_CHECK_EQUAL(10, sum(acc)); // weighted sample = 2 * 4
  1846. BOOST_CHECK_EQUAL(6, sum_of_weights(acc));
  1847. BOOST_CHECK_EQUAL(9, sum_of_variates(acc));
  1848. acc(3, weight = 6, covariate1 = 9);
  1849. BOOST_CHECK_EQUAL(28, sum(acc)); // weighted sample = 3 * 6
  1850. BOOST_CHECK_EQUAL(12, sum_of_weights(acc));
  1851. BOOST_CHECK_EQUAL(18, sum_of_variates(acc));
  1852. // demonstrate Kahan summation
  1853. accumulator_set<float, stats<tag::sum_kahan> > acc;
  1854. BOOST_CHECK_EQUAL(0.0f, sum_kahan(acc));
  1855. for (size_t i = 0; i < 1e6; ++i) {
  1856. acc(1e-6f);
  1857. }
  1858. BOOST_CHECK_EQUAL(1.0f, sum_kahan(acc));
  1859. [*See also]
  1860. * [classref boost::accumulators::impl::sum_impl [^sum_impl]]
  1861. * [classref boost::accumulators::impl::sum_kahan_impl [^sum_kahan_impl]]
  1862. [endsect]
  1863. [section:tail tail]
  1864. Tracks the largest or smallest [^N] values. `tag::tail<right>` tracks the largest [^N],
  1865. and `tag::tail<left>` tracks the smallest. The parameter [^N] is specified with the
  1866. `tag::tail<_left_or_right_>::cache_size` initialization parameter. For implementation details, see
  1867. [classref boost::accumulators::impl::tail_impl [^tail_impl]].
  1868. Both `tag::tail<left>` and `tag::tail<right>` satisfy the `tag::abstract_tail` feature and
  1869. can be extracted with the `tail()` extractor.
  1870. [variablelist
  1871. [[Result Type] [``
  1872. boost::iterator_range<
  1873. boost::reverse_iterator<
  1874. boost::permutation_iterator<
  1875. std::vector<_sample_type_>::const_iterator // samples
  1876. , std::vector<std::size_t>::iterator // indices
  1877. >
  1878. >
  1879. >
  1880. ``]]
  1881. [[Depends On] [['none]]]
  1882. [[Variants] [`abstract_tail`]]
  1883. [[Initialization Parameters] [`tag::tail<_left_or_right_>::cache_size`]]
  1884. [[Accumulator Parameters] [['none]]]
  1885. [[Extractor Parameters] [['none]]]
  1886. [[Accumulator Complexity] [O(log N), where N is the cache size]]
  1887. [[Extractor Complexity] [O(N log N), where N is the cache size]]
  1888. ]
  1889. [*Header]
  1890. [def _TAIL_HPP_ [headerref boost/accumulators/statistics/tail.hpp]]
  1891. #include <_TAIL_HPP_>
  1892. [*Example]
  1893. See the Example for [link accumulators.user_s_guide.the_statistical_accumulators_library.tail_variate [^tail_variate]].
  1894. [*See also]
  1895. * [classref boost::accumulators::impl::tail_impl [^tail_impl]]
  1896. * [link accumulators.user_s_guide.the_statistical_accumulators_library.tail_variate [^tail_variate]]
  1897. [endsect]
  1898. [section:coherent_tail_mean coherent_tail_mean]
  1899. Estimation of the coherent tail mean based on order statistics (for both left and right tails).
  1900. The left coherent tail mean feature is `tag::coherent_tail_mean<left>`, and the right coherent
  1901. tail mean feature is `tag::coherent_tail_mean<right>`. They both share the `tag::tail_mean` feature
  1902. and can be extracted with the `tail_mean()` extractor. For more implementation details, see
  1903. [classref boost::accumulators::impl::coherent_tail_mean_impl [^coherent_tail_mean_impl]]
  1904. [variablelist
  1905. [[Result Type] [``
  1906. numeric::functional::fdiv<_sample_type_, std::size_t>::result_type
  1907. ``]]
  1908. [[Depends On] [`count` \n `quantile` \n `non_coherent_tail_mean<_left_or_right_>`]]
  1909. [[Variants] [['none]]]
  1910. [[Initialization Parameters] [`tag::tail<_left_or_right_>::cache_size`]]
  1911. [[Accumulator Parameters] [['none]]]
  1912. [[Extractor Parameters] [`quantile_probability`]]
  1913. [[Accumulator Complexity] [O(log N), where N is the cache size]]
  1914. [[Extractor Complexity] [O(N log N), where N is the cache size]]
  1915. ]
  1916. [*Header]
  1917. [def _TAIL_MEAN_HPP_ [headerref boost/accumulators/statistics/tail_mean.hpp]]
  1918. #include <_TAIL_MEAN_HPP_>
  1919. [*Example]
  1920. See the example for
  1921. [link accumulators.user_s_guide.the_statistical_accumulators_library.non_coherent_tail_mean [^non_coherent_tail_mean]].
  1922. [*See also]
  1923. * [classref boost::accumulators::impl::coherent_tail_mean_impl [^coherent_tail_mean_impl]]
  1924. * [link accumulators.user_s_guide.the_statistical_accumulators_library.count [^count]]
  1925. * [link accumulators.user_s_guide.the_statistical_accumulators_library.extended_p_square_quantile [^extended_p_square_quantile]]
  1926. * [link accumulators.user_s_guide.the_statistical_accumulators_library.pot_quantile [^pot_quantile]]
  1927. * [link accumulators.user_s_guide.the_statistical_accumulators_library.tail_quantile [^tail_quantile]]
  1928. * [link accumulators.user_s_guide.the_statistical_accumulators_library.non_coherent_tail_mean [^non_coherent_tail_mean]]
  1929. [endsect]
  1930. [section:non_coherent_tail_mean non_coherent_tail_mean]
  1931. Estimation of the (non-coherent) tail mean based on order statistics (for both left and right tails).
  1932. The left non-coherent tail mean feature is `tag::non_coherent_tail_mean<left>`, and the right non-choherent
  1933. tail mean feature is `tag::non_coherent_tail_mean<right>`. They both share the `tag::abstract_non_coherent_tail_mean`
  1934. feature and can be extracted with the `non_coherent_tail_mean()` extractor. For more implementation details, see
  1935. [classref boost::accumulators::impl::non_coherent_tail_mean_impl [^non_coherent_tail_mean_impl]]
  1936. [variablelist
  1937. [[Result Type] [``
  1938. numeric::functional::fdiv<_sample_type_, std::size_t>::result_type
  1939. ``]]
  1940. [[Depends On] [`count` \n `tail<_left_or_right_>`]]
  1941. [[Variants] [`abstract_non_coherent_tail_mean`]]
  1942. [[Initialization Parameters] [`tag::tail<_left_or_right_>::cache_size`]]
  1943. [[Accumulator Parameters] [['none]]]
  1944. [[Extractor Parameters] [`quantile_probability`]]
  1945. [[Accumulator Complexity] [O(log N), where N is the cache size]]
  1946. [[Extractor Complexity] [O(N log N), where N is the cache size]]
  1947. ]
  1948. [*Header]
  1949. [def _TAIL_MEAN_HPP_ [headerref boost/accumulators/statistics/tail_mean.hpp]]
  1950. #include <_TAIL_MEAN_HPP_>
  1951. [*Example]
  1952. // tolerance in %
  1953. double epsilon = 1;
  1954. std::size_t n = 100000; // number of MC steps
  1955. std::size_t c = 10000; // cache size
  1956. typedef accumulator_set<double, stats<tag::non_coherent_tail_mean<right>, tag::tail_quantile<right> > > accumulator_t_right1;
  1957. typedef accumulator_set<double, stats<tag::non_coherent_tail_mean<left>, tag::tail_quantile<left> > > accumulator_t_left1;
  1958. typedef accumulator_set<double, stats<tag::coherent_tail_mean<right>, tag::tail_quantile<right> > > accumulator_t_right2;
  1959. typedef accumulator_set<double, stats<tag::coherent_tail_mean<left>, tag::tail_quantile<left> > > accumulator_t_left2;
  1960. accumulator_t_right1 acc0( right_tail_cache_size = c );
  1961. accumulator_t_left1 acc1( left_tail_cache_size = c );
  1962. accumulator_t_right2 acc2( right_tail_cache_size = c );
  1963. accumulator_t_left2 acc3( left_tail_cache_size = c );
  1964. // a random number generator
  1965. boost::lagged_fibonacci607 rng;
  1966. for (std::size_t i = 0; i < n; ++i)
  1967. {
  1968. double sample = rng();
  1969. acc0(sample);
  1970. acc1(sample);
  1971. acc2(sample);
  1972. acc3(sample);
  1973. }
  1974. // check uniform distribution
  1975. BOOST_CHECK_CLOSE( non_coherent_tail_mean(acc0, quantile_probability = 0.95), 0.975, epsilon );
  1976. BOOST_CHECK_CLOSE( non_coherent_tail_mean(acc0, quantile_probability = 0.975), 0.9875, epsilon );
  1977. BOOST_CHECK_CLOSE( non_coherent_tail_mean(acc0, quantile_probability = 0.99), 0.995, epsilon );
  1978. BOOST_CHECK_CLOSE( non_coherent_tail_mean(acc0, quantile_probability = 0.999), 0.9995, epsilon );
  1979. BOOST_CHECK_CLOSE( non_coherent_tail_mean(acc1, quantile_probability = 0.05), 0.025, epsilon );
  1980. BOOST_CHECK_CLOSE( non_coherent_tail_mean(acc1, quantile_probability = 0.025), 0.0125, epsilon );
  1981. BOOST_CHECK_CLOSE( non_coherent_tail_mean(acc1, quantile_probability = 0.01), 0.005, 5 );
  1982. BOOST_CHECK_CLOSE( non_coherent_tail_mean(acc1, quantile_probability = 0.001), 0.0005, 10 );
  1983. BOOST_CHECK_CLOSE( tail_mean(acc2, quantile_probability = 0.95), 0.975, epsilon );
  1984. BOOST_CHECK_CLOSE( tail_mean(acc2, quantile_probability = 0.975), 0.9875, epsilon );
  1985. BOOST_CHECK_CLOSE( tail_mean(acc2, quantile_probability = 0.99), 0.995, epsilon );
  1986. BOOST_CHECK_CLOSE( tail_mean(acc2, quantile_probability = 0.999), 0.9995, epsilon );
  1987. BOOST_CHECK_CLOSE( tail_mean(acc3, quantile_probability = 0.05), 0.025, epsilon );
  1988. BOOST_CHECK_CLOSE( tail_mean(acc3, quantile_probability = 0.025), 0.0125, epsilon );
  1989. BOOST_CHECK_CLOSE( tail_mean(acc3, quantile_probability = 0.01), 0.005, 5 );
  1990. BOOST_CHECK_CLOSE( tail_mean(acc3, quantile_probability = 0.001), 0.0005, 10 );
  1991. [*See also]
  1992. * [classref boost::accumulators::impl::non_coherent_tail_mean_impl [^non_coherent_tail_mean_impl]]
  1993. * [link accumulators.user_s_guide.the_statistical_accumulators_library.count [^count]]
  1994. * [link accumulators.user_s_guide.the_statistical_accumulators_library.tail [^tail]]
  1995. [endsect]
  1996. [section:tail_quantile tail_quantile]
  1997. Tail quantile estimation based on order statistics (for both left and right tails).
  1998. The left tail quantile feature is `tag::tail_quantile<left>`, and the right
  1999. tail quantile feature is `tag::tail_quantile<right>`. They both share the `tag::quantile`
  2000. feature and can be extracted with the `quantile()` extractor. For more implementation details, see
  2001. [classref boost::accumulators::impl::tail_quantile_impl [^tail_quantile_impl]]
  2002. [variablelist
  2003. [[Result Type] [``
  2004. _sample_type_
  2005. ``]]
  2006. [[Depends On] [`count` \n `tail<_left_or_right_>`]]
  2007. [[Variants] [['none]]]
  2008. [[Initialization Parameters] [`tag::tail<_left_or_right_>::cache_size`]]
  2009. [[Accumulator Parameters] [['none]]]
  2010. [[Extractor Parameters] [`quantile_probability`]]
  2011. [[Accumulator Complexity] [O(log N), where N is the cache size]]
  2012. [[Extractor Complexity] [O(N log N), where N is the cache size]]
  2013. ]
  2014. [*Header]
  2015. [def _TAIL_QUANTILE_HPP_ [headerref boost/accumulators/statistics/tail_quantile.hpp]]
  2016. #include <_TAIL_QUANTILE_HPP_>
  2017. [*Example]
  2018. // tolerance in %
  2019. double epsilon = 1;
  2020. std::size_t n = 100000; // number of MC steps
  2021. std::size_t c = 10000; // cache size
  2022. typedef accumulator_set<double, stats<tag::tail_quantile<right> > > accumulator_t_right;
  2023. typedef accumulator_set<double, stats<tag::tail_quantile<left> > > accumulator_t_left;
  2024. accumulator_t_right acc0( tag::tail<right>::cache_size = c );
  2025. accumulator_t_right acc1( tag::tail<right>::cache_size = c );
  2026. accumulator_t_left acc2( tag::tail<left>::cache_size = c );
  2027. accumulator_t_left acc3( tag::tail<left>::cache_size = c );
  2028. // two random number generators
  2029. boost::lagged_fibonacci607 rng;
  2030. boost::normal_distribution<> mean_sigma(0,1);
  2031. boost::variate_generator<boost::lagged_fibonacci607&, boost::normal_distribution<> > normal(rng, mean_sigma);
  2032. for (std::size_t i = 0; i < n; ++i)
  2033. {
  2034. double sample1 = rng();
  2035. double sample2 = normal();
  2036. acc0(sample1);
  2037. acc1(sample2);
  2038. acc2(sample1);
  2039. acc3(sample2);
  2040. }
  2041. // check uniform distribution
  2042. BOOST_CHECK_CLOSE( quantile(acc0, quantile_probability = 0.95 ), 0.95, epsilon );
  2043. BOOST_CHECK_CLOSE( quantile(acc0, quantile_probability = 0.975), 0.975, epsilon );
  2044. BOOST_CHECK_CLOSE( quantile(acc0, quantile_probability = 0.99 ), 0.99, epsilon );
  2045. BOOST_CHECK_CLOSE( quantile(acc0, quantile_probability = 0.999), 0.999, epsilon );
  2046. BOOST_CHECK_CLOSE( quantile(acc2, quantile_probability = 0.05 ), 0.05, 2 );
  2047. BOOST_CHECK_CLOSE( quantile(acc2, quantile_probability = 0.025), 0.025, 2 );
  2048. BOOST_CHECK_CLOSE( quantile(acc2, quantile_probability = 0.01 ), 0.01, 3 );
  2049. BOOST_CHECK_CLOSE( quantile(acc2, quantile_probability = 0.001), 0.001, 20 );
  2050. // check standard normal distribution
  2051. BOOST_CHECK_CLOSE( quantile(acc1, quantile_probability = 0.975), 1.959963, epsilon );
  2052. BOOST_CHECK_CLOSE( quantile(acc1, quantile_probability = 0.999), 3.090232, epsilon );
  2053. BOOST_CHECK_CLOSE( quantile(acc3, quantile_probability = 0.025), -1.959963, epsilon );
  2054. BOOST_CHECK_CLOSE( quantile(acc3, quantile_probability = 0.001), -3.090232, epsilon );
  2055. [*See also]
  2056. * [classref boost::accumulators::impl::tail_quantile_impl [^tail_quantile_impl]]
  2057. * [link accumulators.user_s_guide.the_statistical_accumulators_library.count [^count]]
  2058. * [link accumulators.user_s_guide.the_statistical_accumulators_library.tail [^tail]]
  2059. [endsect]
  2060. [section:tail_variate tail_variate]
  2061. Tracks the covariates of largest or smallest [^N] samples.
  2062. `tag::tail_variate<_variate_type_, _variate_tag_, right>` tracks the covariate associated with
  2063. _variate_tag_ for the largest [^N], and `tag::tail_variate<_variate_type_, _variate_tag_, left>`
  2064. for the smallest. The parameter [^N] is specified with the `tag::tail<_left_or_right_>::cache_size`
  2065. initialization parameter. For implementation details, see
  2066. [classref boost::accumulators::impl::tail_variate_impl [^tail_variate_impl]].
  2067. Both `tag::tail_variate<_variate_type_, _variate_tag_, right>` and
  2068. `tag::tail_variate<_variate_type_, _variate_tag_, left>` satisfy the `tag::abstract_tail_variate` feature
  2069. and can be extracted with the `tail_variate()` extractor.
  2070. [variablelist
  2071. [[Result Type] [``
  2072. boost::iterator_range<
  2073. boost::reverse_iterator<
  2074. boost::permutation_iterator<
  2075. std::vector<_variate_type_>::const_iterator // variates
  2076. , std::vector<std::size_t>::iterator // indices
  2077. >
  2078. >
  2079. >
  2080. ``]]
  2081. [[Depends On] [`tail<_left_or_right_>`]]
  2082. [[Variants] [`abstract_tail_variate`]]
  2083. [[Initialization Parameters] [`tag::tail<_left_or_right_>::cache_size`]]
  2084. [[Accumulator Parameters] [['none]]]
  2085. [[Extractor Parameters] [['none]]]
  2086. [[Accumulator Complexity] [O(log N), where N is the cache size]]
  2087. [[Extractor Complexity] [O(N log N), where N is the cache size]]
  2088. ]
  2089. [*Header]
  2090. [def _TAIL_VARIATE_HPP_ [headerref boost/accumulators/statistics/tail_variate.hpp]]
  2091. #include <_TAIL_VARIATE_HPP_>
  2092. [*Example]
  2093. accumulator_set<int, stats<tag::tail_variate<int, tag::covariate1, right> > > acc(
  2094. tag::tail<right>::cache_size = 4
  2095. );
  2096. acc(8, covariate1 = 3);
  2097. CHECK_RANGE_EQUAL(tail(acc), {8});
  2098. CHECK_RANGE_EQUAL(tail_variate(acc), {3});
  2099. acc(16, covariate1 = 1);
  2100. CHECK_RANGE_EQUAL(tail(acc), {16, 8});
  2101. CHECK_RANGE_EQUAL(tail_variate(acc), {1, 3});
  2102. acc(12, covariate1 = 4);
  2103. CHECK_RANGE_EQUAL(tail(acc), {16, 12, 8});
  2104. CHECK_RANGE_EQUAL(tail_variate(acc), {1, 4, 3});
  2105. acc(24, covariate1 = 5);
  2106. CHECK_RANGE_EQUAL(tail(acc), {24, 16, 12, 8});
  2107. CHECK_RANGE_EQUAL(tail_variate(acc), {5, 1, 4, 3});
  2108. acc(1, covariate1 = 9);
  2109. CHECK_RANGE_EQUAL(tail(acc), {24, 16, 12, 8});
  2110. CHECK_RANGE_EQUAL(tail_variate(acc), {5, 1, 4, 3});
  2111. acc(9, covariate1 = 7);
  2112. CHECK_RANGE_EQUAL(tail(acc), {24, 16, 12, 9});
  2113. CHECK_RANGE_EQUAL(tail_variate(acc), {5, 1, 4, 7});
  2114. [*See also]
  2115. * [classref boost::accumulators::impl::tail_variate_impl [^tail_variate_impl]]
  2116. * [link accumulators.user_s_guide.the_statistical_accumulators_library.tail [^tail]]
  2117. [endsect]
  2118. [section:tail_variate_means tail_variate_means ['and variants]]
  2119. Estimation of the absolute and relative tail variate means (for both left and right tails).
  2120. The absolute tail variate means has the feature
  2121. `tag::absolute_tail_variate_means<_left_or_right_, _variate_type_, _variate_tag_>`
  2122. and the relative tail variate mean has the feature
  2123. `tag::relative_tail_variate_means<_left_or_right_, _variate_type_, _variate_tag_>`. All
  2124. absolute tail variate mean features share the `tag::abstract_absolute_tail_variate_means`
  2125. feature and can be extracted with the `tail_variate_means()` extractor. All the
  2126. relative tail variate mean features share the `tag::abstract_relative_tail_variate_means`
  2127. feature and can be extracted with the `relative_tail_variate_means()` extractor.
  2128. For more implementation details, see
  2129. [classref boost::accumulators::impl::tail_variate_means_impl [^tail_variate_means_impl]]
  2130. [variablelist
  2131. [[Result Type] [``
  2132. boost::iterator_range<
  2133. std::vector<
  2134. numeric::functional::fdiv<_sample_type_, std::size_t>::result_type
  2135. >::iterator
  2136. >
  2137. ``]]
  2138. [[Depends On] [`non_coherent_tail_mean<_left_or_right_>` \n
  2139. `tail_variate<_variate_type_, _variate_tag_, _left_or_right_>`]]
  2140. [[Variants] [`tag::absolute_tail_variate_means<_left_or_right_, _variate_type_, _variate_tag_>` \n
  2141. `tag::relative_tail_variate_means<_left_or_right_, _variate_type_, _variate_tag_>`]]
  2142. [[Initialization Parameters] [`tag::tail<_left_or_right_>::cache_size`]]
  2143. [[Accumulator Parameters] [['none]]]
  2144. [[Extractor Parameters] [`quantile_probability`]]
  2145. [[Accumulator Complexity] [O(log N), where N is the cache size]]
  2146. [[Extractor Complexity] [O(N log N), where N is the cache size]]
  2147. ]
  2148. [*Header]
  2149. [def _TAIL_VARIATE_MEANS_HPP_ [headerref boost/accumulators/statistics/tail_variate_means.hpp]]
  2150. #include <_TAIL_VARIATE_MEANS_HPP_>
  2151. [*Example]
  2152. std::size_t c = 5; // cache size
  2153. typedef double variate_type;
  2154. typedef std::vector<variate_type> variate_set_type;
  2155. typedef accumulator_set<double, stats<
  2156. tag::tail_variate_means<right, variate_set_type, tag::covariate1>(relative)>, tag::tail<right> >
  2157. accumulator_t1;
  2158. typedef accumulator_set<double, stats<
  2159. tag::tail_variate_means<right, variate_set_type, tag::covariate1>(absolute)>, tag::tail<right> >
  2160. accumulator_t2;
  2161. typedef accumulator_set<double, stats<
  2162. tag::tail_variate_means<left, variate_set_type, tag::covariate1>(relative)>, tag::tail<left> >
  2163. accumulator_t3;
  2164. typedef accumulator_set<double, stats<
  2165. tag::tail_variate_means<left, variate_set_type, tag::covariate1>(absolute)>, tag::tail<left> >
  2166. accumulator_t4;
  2167. accumulator_t1 acc1( right_tail_cache_size = c );
  2168. accumulator_t2 acc2( right_tail_cache_size = c );
  2169. accumulator_t3 acc3( left_tail_cache_size = c );
  2170. accumulator_t4 acc4( left_tail_cache_size = c );
  2171. variate_set_type cov1, cov2, cov3, cov4, cov5;
  2172. double c1[] = { 10., 20., 30., 40. }; // 100
  2173. double c2[] = { 26., 4., 17., 3. }; // 50
  2174. double c3[] = { 46., 64., 40., 50. }; // 200
  2175. double c4[] = { 1., 3., 70., 6. }; // 80
  2176. double c5[] = { 2., 2., 2., 14. }; // 20
  2177. cov1.assign(c1, c1 + sizeof(c1)/sizeof(variate_type));
  2178. cov2.assign(c2, c2 + sizeof(c2)/sizeof(variate_type));
  2179. cov3.assign(c3, c3 + sizeof(c3)/sizeof(variate_type));
  2180. cov4.assign(c4, c4 + sizeof(c4)/sizeof(variate_type));
  2181. cov5.assign(c5, c5 + sizeof(c5)/sizeof(variate_type));
  2182. acc1(100., covariate1 = cov1);
  2183. acc1( 50., covariate1 = cov2);
  2184. acc1(200., covariate1 = cov3);
  2185. acc1( 80., covariate1 = cov4);
  2186. acc1( 20., covariate1 = cov5);
  2187. acc2(100., covariate1 = cov1);
  2188. acc2( 50., covariate1 = cov2);
  2189. acc2(200., covariate1 = cov3);
  2190. acc2( 80., covariate1 = cov4);
  2191. acc2( 20., covariate1 = cov5);
  2192. acc3(100., covariate1 = cov1);
  2193. acc3( 50., covariate1 = cov2);
  2194. acc3(200., covariate1 = cov3);
  2195. acc3( 80., covariate1 = cov4);
  2196. acc3( 20., covariate1 = cov5);
  2197. acc4(100., covariate1 = cov1);
  2198. acc4( 50., covariate1 = cov2);
  2199. acc4(200., covariate1 = cov3);
  2200. acc4( 80., covariate1 = cov4);
  2201. acc4( 20., covariate1 = cov5);
  2202. // check relative risk contributions
  2203. BOOST_CHECK_EQUAL( *(relative_tail_variate_means(acc1, quantile_probability = 0.7).begin() ), 14./75. ); // (10 + 46) / 300 = 14/75
  2204. BOOST_CHECK_EQUAL( *(relative_tail_variate_means(acc1, quantile_probability = 0.7).begin() + 1), 7./25. ); // (20 + 64) / 300 = 7/25
  2205. BOOST_CHECK_EQUAL( *(relative_tail_variate_means(acc1, quantile_probability = 0.7).begin() + 2), 7./30. ); // (30 + 40) / 300 = 7/30
  2206. BOOST_CHECK_EQUAL( *(relative_tail_variate_means(acc1, quantile_probability = 0.7).begin() + 3), 3./10. ); // (40 + 50) / 300 = 3/10
  2207. BOOST_CHECK_EQUAL( *(relative_tail_variate_means(acc3, quantile_probability = 0.3).begin() ), 14./35. ); // (26 + 2) / 70 = 14/35
  2208. BOOST_CHECK_EQUAL( *(relative_tail_variate_means(acc3, quantile_probability = 0.3).begin() + 1), 3./35. ); // ( 4 + 2) / 70 = 3/35
  2209. BOOST_CHECK_EQUAL( *(relative_tail_variate_means(acc3, quantile_probability = 0.3).begin() + 2), 19./70. ); // (17 + 2) / 70 = 19/70
  2210. BOOST_CHECK_EQUAL( *(relative_tail_variate_means(acc3, quantile_probability = 0.3).begin() + 3), 17./70. ); // ( 3 + 14) / 70 = 17/70
  2211. // check absolute risk contributions
  2212. BOOST_CHECK_EQUAL( *(tail_variate_means(acc2, quantile_probability = 0.7).begin() ), 28 ); // (10 + 46) / 2 = 28
  2213. BOOST_CHECK_EQUAL( *(tail_variate_means(acc2, quantile_probability = 0.7).begin() + 1), 42 ); // (20 + 64) / 2 = 42
  2214. BOOST_CHECK_EQUAL( *(tail_variate_means(acc2, quantile_probability = 0.7).begin() + 2), 35 ); // (30 + 40) / 2 = 35
  2215. BOOST_CHECK_EQUAL( *(tail_variate_means(acc2, quantile_probability = 0.7).begin() + 3), 45 ); // (40 + 50) / 2 = 45
  2216. BOOST_CHECK_EQUAL( *(tail_variate_means(acc4, quantile_probability = 0.3).begin() ), 14 ); // (26 + 2) / 2 = 14
  2217. BOOST_CHECK_EQUAL( *(tail_variate_means(acc4, quantile_probability = 0.3).begin() + 1), 3 ); // ( 4 + 2) / 2 = 3
  2218. BOOST_CHECK_EQUAL( *(tail_variate_means(acc4, quantile_probability = 0.3).begin() + 2),9.5 ); // (17 + 2) / 2 = 9.5
  2219. BOOST_CHECK_EQUAL( *(tail_variate_means(acc4, quantile_probability = 0.3).begin() + 3),8.5 ); // ( 3 + 14) / 2 = 8.5
  2220. // check relative risk contributions
  2221. BOOST_CHECK_EQUAL( *(relative_tail_variate_means(acc1, quantile_probability = 0.9).begin() ), 23./100. ); // 46/200 = 23/100
  2222. BOOST_CHECK_EQUAL( *(relative_tail_variate_means(acc1, quantile_probability = 0.9).begin() + 1), 8./25. ); // 64/200 = 8/25
  2223. BOOST_CHECK_EQUAL( *(relative_tail_variate_means(acc1, quantile_probability = 0.9).begin() + 2), 1./5. ); // 40/200 = 1/5
  2224. BOOST_CHECK_EQUAL( *(relative_tail_variate_means(acc1, quantile_probability = 0.9).begin() + 3), 1./4. ); // 50/200 = 1/4
  2225. BOOST_CHECK_EQUAL( *(relative_tail_variate_means(acc3, quantile_probability = 0.1).begin() ), 1./10. ); // 2/ 20 = 1/10
  2226. BOOST_CHECK_EQUAL( *(relative_tail_variate_means(acc3, quantile_probability = 0.1).begin() + 1), 1./10. ); // 2/ 20 = 1/10
  2227. BOOST_CHECK_EQUAL( *(relative_tail_variate_means(acc3, quantile_probability = 0.1).begin() + 2), 1./10. ); // 2/ 20 = 1/10
  2228. BOOST_CHECK_EQUAL( *(relative_tail_variate_means(acc3, quantile_probability = 0.1).begin() + 3), 7./10. ); // 14/ 20 = 7/10
  2229. // check absolute risk contributions
  2230. BOOST_CHECK_EQUAL( *(tail_variate_means(acc2, quantile_probability = 0.9).begin() ), 46 ); // 46
  2231. BOOST_CHECK_EQUAL( *(tail_variate_means(acc2, quantile_probability = 0.9).begin() + 1), 64 ); // 64
  2232. BOOST_CHECK_EQUAL( *(tail_variate_means(acc2, quantile_probability = 0.9).begin() + 2), 40 ); // 40
  2233. BOOST_CHECK_EQUAL( *(tail_variate_means(acc2, quantile_probability = 0.9).begin() + 3), 50 ); // 50
  2234. BOOST_CHECK_EQUAL( *(tail_variate_means(acc4, quantile_probability = 0.1).begin() ), 2 ); // 2
  2235. BOOST_CHECK_EQUAL( *(tail_variate_means(acc4, quantile_probability = 0.1).begin() + 1), 2 ); // 2
  2236. BOOST_CHECK_EQUAL( *(tail_variate_means(acc4, quantile_probability = 0.1).begin() + 2), 2 ); // 2
  2237. BOOST_CHECK_EQUAL( *(tail_variate_means(acc4, quantile_probability = 0.1).begin() + 3), 14 ); // 14
  2238. [*See also]
  2239. * [classref boost::accumulators::impl::tail_variate_means_impl [^tail_variate_means_impl]]
  2240. * [link accumulators.user_s_guide.the_statistical_accumulators_library.non_coherent_tail_mean [^non_coherent_tail_mean]]
  2241. * [link accumulators.user_s_guide.the_statistical_accumulators_library.tail_variate [^tail_variate]]
  2242. [endsect]
  2243. [section:variance variance ['and variants]]
  2244. Lazy or iterative calculation of the variance. The lazy calculation is associated with the `tag::lazy_variance`
  2245. feature, and the iterative calculation with the `tag::variance` feature. Both can be extracted
  2246. using the `tag::variance()` extractor. For more implementation details, see
  2247. [classref boost::accumulators::impl::lazy_variance_impl [^lazy_variance_impl]] and
  2248. [classref boost::accumulators::impl::variance_impl [^variance_impl]]
  2249. [variablelist
  2250. [[Result Type] [``
  2251. numeric::functional::fdiv<_sample_type_, std::size_t>::result_type
  2252. ``]]
  2253. [[Depends On] [`tag::lazy_variance` depends on `tag::moment<2>` and `tag::mean` \n
  2254. `tag::variance` depends on `tag::count` and `tag::immediate_mean`]]
  2255. [[Variants] [`tag::lazy_variance` (a.k.a. `tag::variance(lazy))` \n
  2256. `tag::variance` (a.k.a. `tag::variance(immediate)`)]]
  2257. [[Initialization Parameters] [['none]]]
  2258. [[Accumulator Parameters] [['none]]]
  2259. [[Extractor Parameters] [['none]]]
  2260. [[Accumulator Complexity] [O(1)]]
  2261. [[Extractor Complexity] [O(1)]]
  2262. ]
  2263. [*Header]
  2264. [def _VARIANCE_HPP_ [headerref boost/accumulators/statistics/variance.hpp]]
  2265. #include <_VARIANCE_HPP_>
  2266. [*Example]
  2267. // lazy variance
  2268. accumulator_set<int, stats<tag::variance(lazy)> > acc1;
  2269. acc1(1);
  2270. acc1(2);
  2271. acc1(3);
  2272. acc1(4);
  2273. acc1(5);
  2274. BOOST_CHECK_EQUAL(5u, count(acc1));
  2275. BOOST_CHECK_CLOSE(3., mean(acc1), 1e-5);
  2276. BOOST_CHECK_CLOSE(11., accumulators::moment<2>(acc1), 1e-5);
  2277. BOOST_CHECK_CLOSE(2., variance(acc1), 1e-5);
  2278. // immediate variance
  2279. accumulator_set<int, stats<tag::variance> > acc2;
  2280. acc2(1);
  2281. acc2(2);
  2282. acc2(3);
  2283. acc2(4);
  2284. acc2(5);
  2285. BOOST_CHECK_EQUAL(5u, count(acc2));
  2286. BOOST_CHECK_CLOSE(3., mean(acc2), 1e-5);
  2287. BOOST_CHECK_CLOSE(2., variance(acc2), 1e-5);
  2288. [*See also]
  2289. * [classref boost::accumulators::impl::lazy_variance_impl [^lazy_variance_impl]]
  2290. * [classref boost::accumulators::impl::variance_impl [^variance_impl]]
  2291. * [link accumulators.user_s_guide.the_statistical_accumulators_library.count [^count]]
  2292. * [link accumulators.user_s_guide.the_statistical_accumulators_library.mean [^mean]]
  2293. * [link accumulators.user_s_guide.the_statistical_accumulators_library.moment [^moment]]
  2294. [endsect]
  2295. [section:weighted_covariance weighted_covariance]
  2296. An iterative Monte Carlo estimator for the weighted covariance. The feature is specified as
  2297. `tag::weighted_covariance<_variate_type_, _variate_tag_>` and is extracted with the `weighted_variate()`
  2298. extractor. For more implementation details, see
  2299. [classref boost::accumulators::impl::weighted_covariance_impl [^weighted_covariance_impl]]
  2300. [variablelist
  2301. [[Result Type] [``
  2302. numeric::functional::outer_product<
  2303. numeric::functional::multiplies<
  2304. _weight_type_
  2305. , numeric::functional::fdiv<_sample_type_, std::size_t>::result_type
  2306. >::result_type
  2307. , numeric::functional::multiplies<
  2308. _weight_type_
  2309. , numeric::functional::fdiv<_variate_type_, std::size_t>::result_type
  2310. >::result_type
  2311. >
  2312. ``]]
  2313. [[Depends On] [`count` \n
  2314. `sum_of_weights` \n
  2315. `weighted_mean` \n
  2316. `weighted_mean_of_variates<_variate_type_, _variate_tag_>`]]
  2317. [[Variants] [`abstract_weighted_covariance`]]
  2318. [[Initialization Parameters] [['none]]]
  2319. [[Accumulator Parameters] [`weight` \n
  2320. `_variate_tag_`]]
  2321. [[Extractor Parameters] [['none]]]
  2322. [[Accumulator Complexity] [O(1)]]
  2323. [[Extractor Complexity] [O(1)]]
  2324. ]
  2325. [*Header]
  2326. [def _WEIGHTED_COVARIANCE_HPP_ [headerref boost/accumulators/statistics/weighted_covariance.hpp]]
  2327. #include <_WEIGHTED_COVARIANCE_HPP_>
  2328. [*Example]
  2329. accumulator_set<double, stats<tag::weighted_covariance<double, tag::covariate1> >, double > acc;
  2330. acc(1., weight = 1.1, covariate1 = 2.);
  2331. acc(1., weight = 2.2, covariate1 = 4.);
  2332. acc(2., weight = 3.3, covariate1 = 3.);
  2333. acc(6., weight = 4.4, covariate1 = 1.);
  2334. double epsilon = 1e-6;
  2335. BOOST_CHECK_CLOSE(weighted_covariance(acc), -2.39, epsilon);
  2336. [*See also]
  2337. * [classref boost::accumulators::impl::weighted_covariance_impl [^weighted_covariance_impl]]
  2338. * [link accumulators.user_s_guide.the_statistical_accumulators_library.count [^count]]
  2339. * [link accumulators.user_s_guide.the_statistical_accumulators_library.sum [^sum]]
  2340. * [link accumulators.user_s_guide.the_statistical_accumulators_library.weighted_mean [^weighted_mean]]
  2341. [endsect]
  2342. [section:weighted_density weighted_density]
  2343. The `tag::weighted_density` feature returns a histogram of the weighted sample distribution. For more
  2344. implementation details, see [classref boost::accumulators::impl::weighted_density_impl [^weighted_density_impl]].
  2345. [variablelist
  2346. [[Result Type] [``
  2347. iterator_range<
  2348. std::vector<
  2349. std::pair<
  2350. numeric::functional::fdiv<_weight_type_, std::size_t>::result_type
  2351. , numeric::functional::fdiv<_weight_type_, std::size_t>::result_type
  2352. >
  2353. >::iterator
  2354. >
  2355. ``]]
  2356. [[Depends On] [`count` \n `sum_of_weights` \n `min` \n `max`]]
  2357. [[Variants] [['none]]]
  2358. [[Initialization Parameters] [`tag::weighted_density::cache_size` \n `tag::weighted_density::num_bins`]]
  2359. [[Accumulator Parameters] [`weight`]]
  2360. [[Extractor Parameters] [['none]]]
  2361. [[Accumulator Complexity] [TODO]]
  2362. [[Extractor Complexity] [O(N), when N is `weighted_density::num_bins`]]
  2363. ]
  2364. [*Header]
  2365. [def _WEIGHTED_DENSITY_HPP_ [headerref boost/accumulators/statistics/weighted_density.hpp]]
  2366. #include <_WEIGHTED_DENSITY_HPP_>
  2367. [/ TODO add example ]
  2368. [*See also]
  2369. * [classref boost::accumulators::impl::weighted_density_impl [^weighted_density_impl]]
  2370. * [link accumulators.user_s_guide.the_statistical_accumulators_library.count [^count]]
  2371. * [link accumulators.user_s_guide.the_statistical_accumulators_library.sum [^sum]]
  2372. * [link accumulators.user_s_guide.the_statistical_accumulators_library.min [^min]]
  2373. * [link accumulators.user_s_guide.the_statistical_accumulators_library.max [^max]]
  2374. [endsect]
  2375. [section:weighted_extended_p_square weighted_extended_p_square]
  2376. Multiple quantile estimation with the extended [^P^2] algorithm for weighted samples. For further
  2377. details, see [classref boost::accumulators::impl::weighted_extended_p_square_impl [^weighted_extended_p_square_impl]].
  2378. [variablelist
  2379. [[Result Type] [``
  2380. boost::iterator_range<
  2381. _implementation_defined_
  2382. >
  2383. ``]]
  2384. [[Depends On] [`count` \n `sum_of_weights`]]
  2385. [[Variants] [['none]]]
  2386. [[Initialization Parameters] [`tag::weighted_extended_p_square::probabilities`]]
  2387. [[Accumulator Parameters] [`weight`]]
  2388. [[Extractor Parameters] [['none]]]
  2389. [[Accumulator Complexity] [TODO]]
  2390. [[Extractor Complexity] [O(1)]]
  2391. ]
  2392. [*Header]
  2393. [def _WEIGHTED_EXTENDED_P_SQUARE_HPP_ [headerref boost/accumulators/statistics/weighted_extended_p_square.hpp]]
  2394. #include <_WEIGHTED_EXTENDED_P_SQUARE_HPP_>
  2395. [*Example]
  2396. typedef accumulator_set<double, stats<tag::weighted_extended_p_square>, double> accumulator_t;
  2397. // tolerance in %
  2398. double epsilon = 1;
  2399. // some random number generators
  2400. double mu1 = -1.0;
  2401. double mu2 = 1.0;
  2402. boost::lagged_fibonacci607 rng;
  2403. boost::normal_distribution<> mean_sigma1(mu1, 1);
  2404. boost::normal_distribution<> mean_sigma2(mu2, 1);
  2405. boost::variate_generator<boost::lagged_fibonacci607&, boost::normal_distribution<> > normal1(rng, mean_sigma1);
  2406. boost::variate_generator<boost::lagged_fibonacci607&, boost::normal_distribution<> > normal2(rng, mean_sigma2);
  2407. std::vector<double> probs_uniform, probs_normal1, probs_normal2, probs_normal_exact1, probs_normal_exact2;
  2408. double p1[] = {/*0.001,*/ 0.01, 0.1, 0.5, 0.9, 0.99, 0.999};
  2409. probs_uniform.assign(p1, p1 + sizeof(p1) / sizeof(double));
  2410. double p2[] = {0.001, 0.025};
  2411. double p3[] = {0.975, 0.999};
  2412. probs_normal1.assign(p2, p2 + sizeof(p2) / sizeof(double));
  2413. probs_normal2.assign(p3, p3 + sizeof(p3) / sizeof(double));
  2414. double p4[] = {-3.090232, -1.959963};
  2415. double p5[] = {1.959963, 3.090232};
  2416. probs_normal_exact1.assign(p4, p4 + sizeof(p4) / sizeof(double));
  2417. probs_normal_exact2.assign(p5, p5 + sizeof(p5) / sizeof(double));
  2418. accumulator_t acc_uniform(tag::weighted_extended_p_square::probabilities = probs_uniform);
  2419. accumulator_t acc_normal1(tag::weighted_extended_p_square::probabilities = probs_normal1);
  2420. accumulator_t acc_normal2(tag::weighted_extended_p_square::probabilities = probs_normal2);
  2421. for (std::size_t i = 0; i < 100000; ++i)
  2422. {
  2423. acc_uniform(rng(), weight = 1.);
  2424. double sample1 = normal1();
  2425. double sample2 = normal2();
  2426. acc_normal1(sample1, weight = std::exp(-mu1 * (sample1 - 0.5 * mu1)));
  2427. acc_normal2(sample2, weight = std::exp(-mu2 * (sample2 - 0.5 * mu2)));
  2428. }
  2429. // check for uniform distribution
  2430. for (std::size_t i = 0; i < probs_uniform.size(); ++i)
  2431. {
  2432. BOOST_CHECK_CLOSE(weighted_extended_p_square(acc_uniform)[i], probs_uniform[i], epsilon);
  2433. }
  2434. // check for standard normal distribution
  2435. for (std::size_t i = 0; i < probs_normal1.size(); ++i)
  2436. {
  2437. BOOST_CHECK_CLOSE(weighted_extended_p_square(acc_normal1)[i], probs_normal_exact1[i], epsilon);
  2438. BOOST_CHECK_CLOSE(weighted_extended_p_square(acc_normal2)[i], probs_normal_exact2[i], epsilon);
  2439. }
  2440. [*See also]
  2441. * [classref boost::accumulators::impl::weighted_extended_p_square_impl [^weighted_extended_p_square_impl]]
  2442. * [link accumulators.user_s_guide.the_statistical_accumulators_library.count [^count]]
  2443. * [link accumulators.user_s_guide.the_statistical_accumulators_library.sum [^sum]]
  2444. [endsect]
  2445. [section:weighted_kurtosis weighted_kurtosis]
  2446. The kurtosis of a sample distribution is defined as the ratio of the 4th central moment and the
  2447. square of the 2nd central moment (the variance) of the samples, minus 3. The term [^-3] is added
  2448. in order to ensure that the normal distribution has zero kurtosis. For more implementation
  2449. details, see [classref boost::accumulators::impl::weighted_kurtosis_impl [^weighted_kurtosis_impl]]
  2450. [variablelist
  2451. [[Result Type] [``
  2452. numeric::functional::fdiv<
  2453. numeric::functional::multiplies<_sample_type_, _weight_type_>::result_type
  2454. , numeric::functional::multiplies<_sample_type_, _weight_type_>::result_type
  2455. >::result_type
  2456. ``]]
  2457. [[Depends On] [`weighted_mean` \n `weighted_moment<2>` \n `weighted_moment<3>` \n `weighted_moment<4>`]]
  2458. [[Variants] [['none]]]
  2459. [[Initialization Parameters] [['none]]]
  2460. [[Accumulator Parameters] [['none]]]
  2461. [[Extractor Parameters] [['none]]]
  2462. [[Accumulator Complexity] [O(1)]]
  2463. [[Extractor Complexity] [O(1)]]
  2464. ]
  2465. [*Header]
  2466. [def _WEIGHTED_KURTOSIS_HPP_ [headerref boost/accumulators/statistics/weighted_kurtosis.hpp]]
  2467. #include <_WEIGHTED_KURTOSIS_HPP_>
  2468. [*Example]
  2469. accumulator_set<int, stats<tag::weighted_kurtosis>, int > acc2;
  2470. acc2(2, weight = 4);
  2471. acc2(7, weight = 1);
  2472. acc2(4, weight = 3);
  2473. acc2(9, weight = 1);
  2474. acc2(3, weight = 2);
  2475. BOOST_CHECK_EQUAL( weighted_mean(acc2), 42./11. );
  2476. BOOST_CHECK_EQUAL( accumulators::weighted_moment<2>(acc2), 212./11. );
  2477. BOOST_CHECK_EQUAL( accumulators::weighted_moment<3>(acc2), 1350./11. );
  2478. BOOST_CHECK_EQUAL( accumulators::weighted_moment<4>(acc2), 9956./11. );
  2479. BOOST_CHECK_CLOSE( weighted_kurtosis(acc2), 0.58137026432, 1e-6 );
  2480. [*See also]
  2481. * [classref boost::accumulators::impl::weighted_kurtosis_impl [^weighted_kurtosis_impl]]
  2482. * [link accumulators.user_s_guide.the_statistical_accumulators_library.weighted_mean [^weighted_mean]]
  2483. * [link accumulators.user_s_guide.the_statistical_accumulators_library.weighted_moment [^weighted_moment]]
  2484. [endsect]
  2485. [section:weighted_mean weighted_mean ['and variants]]
  2486. Calculates the weighted mean of samples or variates. The calculation is either
  2487. lazy (in the result extractor), or immediate (in the accumulator). The lazy implementation
  2488. is the default. For more implementation details, see
  2489. [classref boost::accumulators::impl::weighted_mean_impl [^weighted_mean_impl]] or.
  2490. [classref boost::accumulators::impl::immediate_weighted_mean_impl [^immediate_weighted_mean_impl]]
  2491. [variablelist
  2492. [[Result Type] [For samples, `numeric::functional::fdiv<numeric::functional::multiplies<_sample_type_, _weight_type_>::result_type, _weight_type_>::result_type` \n
  2493. For variates, `numeric::functional::fdiv<numeric::functional::multiplies<_variate_type_, _weight_type_>::result_type, _weight_type_>::result_type`]]
  2494. [[Depends On] [`sum_of_weights` \n
  2495. The lazy mean of samples depends on `weighted_sum` \n
  2496. The lazy mean of variates depends on `weighted_sum_of_variates<>`]]
  2497. [[Variants] [`weighted_mean_of_variates<_variate_type_, _variate_tag_>` \n
  2498. `immediate_weighted_mean` \n
  2499. `immediate_weighted_mean_of_variates<_variate_type_, _variate_tag_>`]]
  2500. [[Initialization Parameters] [['none]]]
  2501. [[Accumulator Parameters] [['none]]]
  2502. [[Extractor Parameters] [['none]]]
  2503. [[Accumulator Complexity] [O(1)]]
  2504. [[Extractor Complexity] [O(1)]]
  2505. ]
  2506. [*Header]
  2507. [def _WEIGHTED_MEAN_HPP_ [headerref boost/accumulators/statistics/weighted_mean.hpp]]
  2508. #include <_WEIGHTED_MEAN_HPP_>
  2509. [*Example]
  2510. accumulator_set<
  2511. int
  2512. , stats<
  2513. tag::weighted_mean
  2514. , tag::weighted_mean_of_variates<int, tag::covariate1>
  2515. >
  2516. , int
  2517. > acc;
  2518. acc(10, weight = 2, covariate1 = 7); // 20
  2519. BOOST_CHECK_EQUAL(2, sum_of_weights(acc)); //
  2520. //
  2521. acc(6, weight = 3, covariate1 = 8); // 18
  2522. BOOST_CHECK_EQUAL(5, sum_of_weights(acc)); //
  2523. //
  2524. acc(4, weight = 4, covariate1 = 9); // 16
  2525. BOOST_CHECK_EQUAL(9, sum_of_weights(acc)); //
  2526. //
  2527. acc(6, weight = 5, covariate1 = 6); //+ 30
  2528. BOOST_CHECK_EQUAL(14, sum_of_weights(acc)); //
  2529. //= 84 / 14 = 6
  2530. BOOST_CHECK_EQUAL(6., weighted_mean(acc));
  2531. BOOST_CHECK_EQUAL(52./7., (accumulators::weighted_mean_of_variates<int, tag::covariate1>(acc)));
  2532. accumulator_set<
  2533. int
  2534. , stats<
  2535. tag::weighted_mean(immediate)
  2536. , tag::weighted_mean_of_variates<int, tag::covariate1>(immediate)
  2537. >
  2538. , int
  2539. > acc2;
  2540. acc2(10, weight = 2, covariate1 = 7); // 20
  2541. BOOST_CHECK_EQUAL(2, sum_of_weights(acc2)); //
  2542. //
  2543. acc2(6, weight = 3, covariate1 = 8); // 18
  2544. BOOST_CHECK_EQUAL(5, sum_of_weights(acc2)); //
  2545. //
  2546. acc2(4, weight = 4, covariate1 = 9); // 16
  2547. BOOST_CHECK_EQUAL(9, sum_of_weights(acc2)); //
  2548. //
  2549. acc2(6, weight = 5, covariate1 = 6); //+ 30
  2550. BOOST_CHECK_EQUAL(14, sum_of_weights(acc2)); //
  2551. //= 84 / 14 = 6
  2552. BOOST_CHECK_EQUAL(6., weighted_mean(acc2));
  2553. BOOST_CHECK_EQUAL(52./7., (accumulators::weighted_mean_of_variates<int, tag::covariate1>(acc2)));
  2554. [*See also]
  2555. * [classref boost::accumulators::impl::weighted_mean_impl [^weighted_mean_impl]]
  2556. * [classref boost::accumulators::impl::immediate_weighted_mean_impl [^immediate_weighted_mean_impl]]
  2557. * [link accumulators.user_s_guide.the_statistical_accumulators_library.weighted_sum [^weighted_sum]]
  2558. * [link accumulators.user_s_guide.the_statistical_accumulators_library.sum [^sum]]
  2559. [endsect]
  2560. [section:weighted_median weighted_median ['and variants]]
  2561. Median estimation for weighted samples based on the [^P^2] quantile estimator, the density estimator, or
  2562. the [^P^2] cumulative distribution estimator. For more implementation details, see
  2563. [classref boost::accumulators::impl::weighted_median_impl [^weighted_median_impl]],
  2564. [classref boost::accumulators::impl::with_weighted_density_median_impl [^with_weighted_density_median_impl]],
  2565. and [classref boost::accumulators::impl::with_weighted_p_square_cumulative_distribution_median_impl [^with_weighted_p_square_cumulative_distribution_median_impl]].
  2566. The three median accumulators all satisfy the `tag::weighted_median` feature, and can all be
  2567. extracted with the `weighted_median()` extractor.
  2568. [variablelist
  2569. [[Result Type] [``
  2570. numeric::functional::fdiv<_sample_type_, std::size_t>::result_type
  2571. ``]]
  2572. [[Depends On] [`weighted_median` depends on `weighted_p_square_quantile_for_median` \n
  2573. `with_weighted_density_median` depends on `count` and `weighted_density` \n
  2574. `with_weighted_p_square_cumulative_distribution_median` depends on `weighted_p_square_cumulative_distribution`]]
  2575. [[Variants] [`with_weighted_density_median` (a.k.a. `weighted_median(with_weighted_density)`) \n
  2576. `with_weighted_p_square_cumulative_distribution_median` (a.k.a. `weighted_median(with_weighted_p_square_cumulative_distribution)`)]]
  2577. [[Initialization Parameters] [`with_weighted_density_median` requires `tag::weighted_density::cache_size` and `tag::weighted_density::num_bins` \n
  2578. `with_weighted_p_square_cumulative_distribution_median` requires `tag::weighted_p_square_cumulative_distribution::num_cells`]]
  2579. [[Accumulator Parameters] [`weight`]]
  2580. [[Extractor Parameters] [['none]]]
  2581. [[Accumulator Complexity] [TODO]]
  2582. [[Extractor Complexity] [TODO]]
  2583. ]
  2584. [*Header]
  2585. [def _WEIGHTED_MEDIAN_HPP_ [headerref boost/accumulators/statistics/weighted_median.hpp]]
  2586. #include <_WEIGHTED_MEDIAN_HPP_>
  2587. [*Example]
  2588. // Median estimation of normal distribution N(1,1) using samples from a narrow normal distribution N(1,0.01)
  2589. // The weights equal to the likelihood ratio of the corresponding samples
  2590. // two random number generators
  2591. double mu = 1.;
  2592. double sigma_narrow = 0.01;
  2593. double sigma = 1.;
  2594. boost::lagged_fibonacci607 rng;
  2595. boost::normal_distribution<> mean_sigma_narrow(mu,sigma_narrow);
  2596. boost::variate_generator<boost::lagged_fibonacci607&, boost::normal_distribution<> > normal_narrow(rng, mean_sigma_narrow);
  2597. accumulator_set<double, stats<tag::weighted_median(with_weighted_p_square_quantile) >, double > acc;
  2598. accumulator_set<double, stats<tag::weighted_median(with_weighted_density) >, double >
  2599. acc_dens( tag::weighted_density::cache_size = 10000, tag::weighted_density::num_bins = 1000 );
  2600. accumulator_set<double, stats<tag::weighted_median(with_weighted_p_square_cumulative_distribution) >, double >
  2601. acc_cdist( tag::weighted_p_square_cumulative_distribution::num_cells = 100 );
  2602. for (std::size_t i=0; i<100000; ++i)
  2603. {
  2604. double sample = normal_narrow();
  2605. acc(sample, weight = std::exp(0.5 * (sample - mu) * (sample - mu) * ( 1./sigma_narrow/sigma_narrow - 1./sigma/sigma )));
  2606. acc_dens(sample, weight = std::exp(0.5 * (sample - mu) * (sample - mu) * ( 1./sigma_narrow/sigma_narrow - 1./sigma/sigma )));
  2607. acc_cdist(sample, weight = std::exp(0.5 * (sample - mu) * (sample - mu) * ( 1./sigma_narrow/sigma_narrow - 1./sigma/sigma )));
  2608. }
  2609. BOOST_CHECK_CLOSE(1., weighted_median(acc), 1e-1);
  2610. BOOST_CHECK_CLOSE(1., weighted_median(acc_dens), 1e-1);
  2611. BOOST_CHECK_CLOSE(1., weighted_median(acc_cdist), 1e-1);
  2612. [*See also]
  2613. * [classref boost::accumulators::impl::weighted_median_impl [^weighted_median_impl]]
  2614. * [classref boost::accumulators::impl::with_weighted_density_median_impl [^with_weighted_density_median_impl]]
  2615. * [classref boost::accumulators::impl::with_weighted_p_square_cumulative_distribution_median_impl [^with_weighted_p_square_cumulative_distribution_median_impl]]
  2616. * [link accumulators.user_s_guide.the_statistical_accumulators_library.count [^count]]
  2617. * [link accumulators.user_s_guide.the_statistical_accumulators_library.weighted_p_square_quantile [^weighted_p_square_quantile]]
  2618. * [link accumulators.user_s_guide.the_statistical_accumulators_library.weighted_p_square_cumulative_distribution [^weighted_p_square_cumulative_distribution]]
  2619. [endsect]
  2620. [section:weighted_moment weighted_moment]
  2621. Calculates the N-th moment of the weighted samples, which is defined as the sum of the weighted N-th
  2622. power of the samples over the sum of the weights.
  2623. [variablelist
  2624. [[Result Type] [``
  2625. numeric::functional::fdiv<
  2626. numeric::functional::multiplies<_sample_type_, _weight_type_>::result_type
  2627. , weight_type
  2628. >::result_type
  2629. ``]]
  2630. [[Depends On] [`count` \n `sum_of_weights`]]
  2631. [[Variants] [['none]]]
  2632. [[Initialization Parameters] [['none]]]
  2633. [[Accumulator Parameters] [`weight`]]
  2634. [[Extractor Parameters] [['none]]]
  2635. [[Accumulator Complexity] [O(1)]]
  2636. [[Extractor Complexity] [O(1)]]
  2637. ]
  2638. [*Header]
  2639. [def _WEIGHTED_MOMENT_HPP_ [headerref boost/accumulators/statistics/weighted_moment.hpp]]
  2640. #include <_WEIGHTED_MOMENT_HPP_>
  2641. [*Example]
  2642. accumulator_set<double, stats<tag::weighted_moment<2> >, double> acc2;
  2643. accumulator_set<double, stats<tag::weighted_moment<7> >, double> acc7;
  2644. acc2(2.1, weight = 0.7);
  2645. acc2(2.7, weight = 1.4);
  2646. acc2(1.8, weight = 0.9);
  2647. acc7(2.1, weight = 0.7);
  2648. acc7(2.7, weight = 1.4);
  2649. acc7(1.8, weight = 0.9);
  2650. BOOST_CHECK_CLOSE(5.403, accumulators::weighted_moment<2>(acc2), 1e-5);
  2651. BOOST_CHECK_CLOSE(548.54182, accumulators::weighted_moment<7>(acc7), 1e-5);
  2652. [*See also]
  2653. * [classref boost::accumulators::impl::weighted_moment_impl [^weighted_moment_impl]]
  2654. * [link accumulators.user_s_guide.the_statistical_accumulators_library.count [^count]]
  2655. * [link accumulators.user_s_guide.the_statistical_accumulators_library.sum [^sum]]
  2656. [endsect]
  2657. [section:weighted_p_square_cumulative_distribution weighted_p_square_cumulative_distribution]
  2658. Histogram calculation of the cumulative distribution with the [^P^2] algorithm for weighted samples.
  2659. For more implementation details, see
  2660. [classref boost::accumulators::impl::weighted_p_square_cumulative_distribution_impl [^weighted_p_square_cumulative_distribution_impl]]
  2661. [variablelist
  2662. [[Result Type] [``
  2663. iterator_range<
  2664. std::vector<
  2665. std::pair<
  2666. numeric::functional::fdiv<weighted_sample, std::size_t>::result_type
  2667. , numeric::functional::fdiv<weighted_sample, std::size_t>::result_type
  2668. >
  2669. >::iterator
  2670. >
  2671. ``
  2672. where `weighted_sample` is `numeric::functional::multiplies<_sample_type_, _weight_type_>::result_type`]]
  2673. [[Depends On] [`count` \n `sum_or_weights`]]
  2674. [[Variants] [['none]]]
  2675. [[Initialization Parameters] [`tag::weighted_p_square_cumulative_distribution::num_cells`]]
  2676. [[Accumulator Parameters] [`weight`]]
  2677. [[Extractor Parameters] [['none]]]
  2678. [[Accumulator Complexity] [TODO]]
  2679. [[Extractor Complexity] [O(N) where N is `num_cells`]]
  2680. ]
  2681. [*Header]
  2682. [def _WEIGHTED_P_SQUARE_CUMULATIVE_DISTRIBUTION_HPP_ [headerref boost/accumulators/statistics/weighted_p_square_cumul_dist.hpp]]
  2683. #include <_WEIGHTED_P_SQUARE_CUMULATIVE_DISTRIBUTION_HPP_>
  2684. [*Example]
  2685. // tolerance in %
  2686. double epsilon = 4;
  2687. typedef accumulator_set<double, stats<tag::weighted_p_square_cumulative_distribution>, double > accumulator_t;
  2688. accumulator_t acc_upper(tag::weighted_p_square_cumulative_distribution::num_cells = 100);
  2689. accumulator_t acc_lower(tag::weighted_p_square_cumulative_distribution::num_cells = 100);
  2690. // two random number generators
  2691. double mu_upper = 1.0;
  2692. double mu_lower = -1.0;
  2693. boost::lagged_fibonacci607 rng;
  2694. boost::normal_distribution<> mean_sigma_upper(mu_upper,1);
  2695. boost::normal_distribution<> mean_sigma_lower(mu_lower,1);
  2696. boost::variate_generator<boost::lagged_fibonacci607&, boost::normal_distribution<> > normal_upper(rng, mean_sigma_upper);
  2697. boost::variate_generator<boost::lagged_fibonacci607&, boost::normal_distribution<> > normal_lower(rng, mean_sigma_lower);
  2698. for (std::size_t i=0; i<100000; ++i)
  2699. {
  2700. double sample = normal_upper();
  2701. acc_upper(sample, weight = std::exp(-mu_upper * (sample - 0.5 * mu_upper)));
  2702. }
  2703. for (std::size_t i=0; i<100000; ++i)
  2704. {
  2705. double sample = normal_lower();
  2706. acc_lower(sample, weight = std::exp(-mu_lower * (sample - 0.5 * mu_lower)));
  2707. }
  2708. typedef iterator_range<std::vector<std::pair<double, double> >::iterator > histogram_type;
  2709. histogram_type histogram_upper = weighted_p_square_cumulative_distribution(acc_upper);
  2710. histogram_type histogram_lower = weighted_p_square_cumulative_distribution(acc_lower);
  2711. // Note that applying importance sampling results in a region of the distribution
  2712. // to be estimated more accurately and another region to be estimated less accurately
  2713. // than without importance sampling, i.e., with unweighted samples
  2714. for (std::size_t i = 0; i < histogram_upper.size(); ++i)
  2715. {
  2716. // problem with small results: epsilon is relative (in percent), not absolute!
  2717. // check upper region of distribution
  2718. if ( histogram_upper[i].second > 0.1 )
  2719. BOOST_CHECK_CLOSE( 0.5 * (1.0 + erf( histogram_upper[i].first / sqrt(2.0) )), histogram_upper[i].second, epsilon );
  2720. // check lower region of distribution
  2721. if ( histogram_lower[i].second < -0.1 )
  2722. BOOST_CHECK_CLOSE( 0.5 * (1.0 + erf( histogram_lower[i].first / sqrt(2.0) )), histogram_lower[i].second, epsilon );
  2723. }
  2724. [*See also]
  2725. * [classref boost::accumulators::impl::weighted_p_square_cumulative_distribution_impl [^weighted_p_square_cumulative_distribution_impl]]
  2726. * [link accumulators.user_s_guide.the_statistical_accumulators_library.count [^count]]
  2727. * [link accumulators.user_s_guide.the_statistical_accumulators_library.sum [^sum]]
  2728. [endsect]
  2729. [section:weighted_p_square_quantile weighted_p_square_quantile ['and variants]]
  2730. Single quantile estimation with the [^P^2] algorithm. For more implementation details, see
  2731. [classref boost::accumulators::impl::weighted_p_square_quantile_impl [^weighted_p_square_quantile_impl]]
  2732. [variablelist
  2733. [[Result Type] [``
  2734. numeric::functional::fdiv<
  2735. numeric::functional::multiplies<_sample_type_, _weight_type_>::result_type
  2736. , std::size_t
  2737. >::result_type
  2738. ``]]
  2739. [[Depends On] [`count` \n `sum_of_weights`]]
  2740. [[Variants] [`weighted_p_square_quantile_for_median`]]
  2741. [[Initialization Parameters] [`quantile_probability`, which defaults to `0.5`.
  2742. (Note: for `weighted_p_square_quantile_for_median`, the `quantile_probability`
  2743. parameter is ignored and is always `0.5`.)]]
  2744. [[Accumulator Parameters] [`weight`]]
  2745. [[Extractor Parameters] [['none]]]
  2746. [[Accumulator Complexity] [TODO]]
  2747. [[Extractor Complexity] [O(1)]]
  2748. ]
  2749. [*Header]
  2750. [def _WEIGHTED_P_SQUARE_QUANTILE_HPP_ [headerref boost/accumulators/statistics/weighted_p_square_quantile.hpp]]
  2751. #include <_WEIGHTED_P_SQUARE_QUANTILE_HPP_>
  2752. [*Example]
  2753. typedef accumulator_set<double, stats<tag::weighted_p_square_quantile>, double> accumulator_t;
  2754. // tolerance in %
  2755. double epsilon = 1;
  2756. // some random number generators
  2757. double mu4 = -1.0;
  2758. double mu5 = -1.0;
  2759. double mu6 = 1.0;
  2760. double mu7 = 1.0;
  2761. boost::lagged_fibonacci607 rng;
  2762. boost::normal_distribution<> mean_sigma4(mu4, 1);
  2763. boost::normal_distribution<> mean_sigma5(mu5, 1);
  2764. boost::normal_distribution<> mean_sigma6(mu6, 1);
  2765. boost::normal_distribution<> mean_sigma7(mu7, 1);
  2766. boost::variate_generator<boost::lagged_fibonacci607&, boost::normal_distribution<> > normal4(rng, mean_sigma4);
  2767. boost::variate_generator<boost::lagged_fibonacci607&, boost::normal_distribution<> > normal5(rng, mean_sigma5);
  2768. boost::variate_generator<boost::lagged_fibonacci607&, boost::normal_distribution<> > normal6(rng, mean_sigma6);
  2769. boost::variate_generator<boost::lagged_fibonacci607&, boost::normal_distribution<> > normal7(rng, mean_sigma7);
  2770. accumulator_t acc0(quantile_probability = 0.001);
  2771. accumulator_t acc1(quantile_probability = 0.025);
  2772. accumulator_t acc2(quantile_probability = 0.975);
  2773. accumulator_t acc3(quantile_probability = 0.999);
  2774. accumulator_t acc4(quantile_probability = 0.001);
  2775. accumulator_t acc5(quantile_probability = 0.025);
  2776. accumulator_t acc6(quantile_probability = 0.975);
  2777. accumulator_t acc7(quantile_probability = 0.999);
  2778. for (std::size_t i=0; i<100000; ++i)
  2779. {
  2780. double sample = rng();
  2781. acc0(sample, weight = 1.);
  2782. acc1(sample, weight = 1.);
  2783. acc2(sample, weight = 1.);
  2784. acc3(sample, weight = 1.);
  2785. double sample4 = normal4();
  2786. double sample5 = normal5();
  2787. double sample6 = normal6();
  2788. double sample7 = normal7();
  2789. acc4(sample4, weight = std::exp(-mu4 * (sample4 - 0.5 * mu4)));
  2790. acc5(sample5, weight = std::exp(-mu5 * (sample5 - 0.5 * mu5)));
  2791. acc6(sample6, weight = std::exp(-mu6 * (sample6 - 0.5 * mu6)));
  2792. acc7(sample7, weight = std::exp(-mu7 * (sample7 - 0.5 * mu7)));
  2793. }
  2794. // check for uniform distribution with weight = 1
  2795. BOOST_CHECK_CLOSE( weighted_p_square_quantile(acc0), 0.001, 15 );
  2796. BOOST_CHECK_CLOSE( weighted_p_square_quantile(acc1), 0.025, 5 );
  2797. BOOST_CHECK_CLOSE( weighted_p_square_quantile(acc2), 0.975, epsilon );
  2798. BOOST_CHECK_CLOSE( weighted_p_square_quantile(acc3), 0.999, epsilon );
  2799. // check for shifted standard normal distribution ("importance sampling")
  2800. BOOST_CHECK_CLOSE( weighted_p_square_quantile(acc4), -3.090232, epsilon );
  2801. BOOST_CHECK_CLOSE( weighted_p_square_quantile(acc5), -1.959963, epsilon );
  2802. BOOST_CHECK_CLOSE( weighted_p_square_quantile(acc6), 1.959963, epsilon );
  2803. BOOST_CHECK_CLOSE( weighted_p_square_quantile(acc7), 3.090232, epsilon );
  2804. [*See also]
  2805. * [classref boost::accumulators::impl::weighted_p_square_quantile_impl [^weighted_p_square_quantile_impl]]
  2806. * [link accumulators.user_s_guide.the_statistical_accumulators_library.count [^count]]
  2807. * [link accumulators.user_s_guide.the_statistical_accumulators_library.sum [^sum]]
  2808. [endsect]
  2809. [section:weighted_peaks_over_threshold weighted_peaks_over_threshold ['and variants]]
  2810. Weighted peaks over threshold method for weighted quantile and weighted tail mean estimation.
  2811. For more implementation details,
  2812. see [classref boost::accumulators::impl::weighted_peaks_over_threshold_impl [^weighted_peaks_over_threshold_impl]]
  2813. and [classref boost::accumulators::impl::weighted_peaks_over_threshold_prob_impl [^weighted_peaks_over_threshold_prob_impl]].
  2814. Both `tag::weighted_peaks_over_threshold<_left_or_right_>` and
  2815. `tag::weighted_peaks_over_threshold_prob<_left_or_right_>` satisfy the
  2816. `tag::weighted_peaks_over_threshold<_left_or_right_>` feature and can be extracted using the
  2817. `weighted_peaks_over_threshold()` extractor.
  2818. [variablelist
  2819. [[Result Type] [`tuple<float_type, float_type, float_type>` where `float_type` is
  2820. ``
  2821. numeric::functional::fdiv<
  2822. numeric::functional::multiplies<_sample_type_, _weight_type_>::result_type
  2823. , std::size_t
  2824. >::result_type
  2825. ``]]
  2826. [[Depends On] [`weighted_peaks_over_threshold<_left_or_right_>` depends on `sum_of_weights` \n
  2827. `weighted_peaks_over_threshold_prob<_left_or_right_>` depends on `sum_of_weights` and `tail_weights<_left_or_right_>`]]
  2828. [[Variants] [`weighted_peaks_over_threshold_prob`]]
  2829. [[Initialization Parameters] [ `tag::peaks_over_threshold::threshold_value` \n
  2830. `tag::peaks_over_threshold_prob::threshold_probability` \n
  2831. `tag::tail<_left_or_right_>::cache_size` ]]
  2832. [[Accumulator Parameters] [`weight`]]
  2833. [[Extractor Parameters] [['none]]]
  2834. [[Accumulator Complexity] [TODO]]
  2835. [[Extractor Complexity] [O(1)]]
  2836. ]
  2837. [*Header]
  2838. [def _WEIGHTED_PEAKS_OVER_THRESHOLD_HPP_ [headerref boost/accumulators/statistics/weighted_peaks_over_threshold.hpp]]
  2839. #include <_WEIGHTED_PEAKS_OVER_THRESHOLD_HPP_>
  2840. [/ TODO Add example]
  2841. [*See also]
  2842. * [classref boost::accumulators::impl::weighted_peaks_over_threshold_impl [^weighted_peaks_over_threshold_impl]]
  2843. * [classref boost::accumulators::impl::weighted_peaks_over_threshold_prob_impl [^weighted_peaks_over_threshold_prob_impl]]
  2844. * [link accumulators.user_s_guide.the_statistical_accumulators_library.sum [^sum]]
  2845. * [link accumulators.user_s_guide.the_statistical_accumulators_library.tail [^tail]]
  2846. [endsect]
  2847. [section:weighted_skewness weighted_skewness]
  2848. The skewness of a sample distribution is defined as the ratio of the 3rd central moment and the [^3/2]-th power
  2849. of the 2nd central moment (the variance) of the samples 3. The skewness estimator for weighted samples
  2850. is formally identical to the estimator for unweighted samples, except that the weighted counterparts of
  2851. all measures it depends on are to be taken.
  2852. For implementation details, see
  2853. [classref boost::accumulators::impl::weighted_skewness_impl [^weighted_skewness_impl]].
  2854. [variablelist
  2855. [[Result Type] [``
  2856. numeric::functional::fdiv<
  2857. numeric::functional::multiplies<_sample_type_, _weight_type_>::result_type
  2858. , numeric::functional::multiplies<_sample_type_, _weight_type_>::result_type
  2859. >::result_type
  2860. ``]]
  2861. [[Depends On] [`weighted_mean` \n `weighted_moment<2>` \n `weighted_moment<3>`]]
  2862. [[Variants] [['none]]]
  2863. [[Initialization Parameters] [['none]]]
  2864. [[Accumulator Parameters] [`weight`]]
  2865. [[Extractor Parameters] [['none]]]
  2866. [[Accumulator Complexity] [O(1)]]
  2867. [[Extractor Complexity] [O(1)]]
  2868. ]
  2869. [*Header]
  2870. [def _WEIGHTED_SKEWNESS_HPP_ [headerref boost/accumulators/statistics/weighted_skewness.hpp]]
  2871. #include <_WEIGHTED_SKEWNESS_HPP_>
  2872. [*Example]
  2873. accumulator_set<int, stats<tag::weighted_skewness>, int > acc2;
  2874. acc2(2, weight = 4);
  2875. acc2(7, weight = 1);
  2876. acc2(4, weight = 3);
  2877. acc2(9, weight = 1);
  2878. acc2(3, weight = 2);
  2879. BOOST_CHECK_EQUAL( weighted_mean(acc2), 42./11. );
  2880. BOOST_CHECK_EQUAL( accumulators::weighted_moment<2>(acc2), 212./11. );
  2881. BOOST_CHECK_EQUAL( accumulators::weighted_moment<3>(acc2), 1350./11. );
  2882. BOOST_CHECK_CLOSE( weighted_skewness(acc2), 1.30708406282, 1e-6 );
  2883. [*See also]
  2884. * [classref boost::accumulators::impl::weighted_skewness_impl [^weighted_skewness_impl]]
  2885. * [link accumulators.user_s_guide.the_statistical_accumulators_library.weighted_mean [^weighted_mean]]
  2886. * [link accumulators.user_s_guide.the_statistical_accumulators_library.weighted_moment [^weighted_moment]]
  2887. [endsect]
  2888. [section:weighted_sum weighted_sum ['and variants]]
  2889. For summing the weighted samples or variates. All of the `tag::weighted_sum_of_variates<>` features
  2890. can be extracted with the `weighted_sum_of_variates()` extractor. Variants that implement the Kahan
  2891. summation algorithm are also provided.
  2892. [variablelist
  2893. [[Result Type] [`numeric::functional::multiplies<_sample_type_, _weight_type_>::result_type` for summing weighted samples \n
  2894. `numeric::functional::multiplies<_variate_type_, _weight_type_>::result_type` for summing weighted variates]]
  2895. [[Depends On] [['none]]]
  2896. [[Variants] [`tag::weighted_sum` \n
  2897. `tag::weighted_sum_of_variates<_variate_type_, _variate_tag_>` \n
  2898. `tag::weighted_sum_kahan` (a.k.a. tag::weighted_sum(kahan)) \n
  2899. `tag::weighted_sum_of_variates_kahan<_variate_type_, _variate_tag_>` \n]]
  2900. [[Initialization Parameters] [['none]]]
  2901. [[Accumulator Parameters] [`weight` \n
  2902. `_variate_tag_` for summing variates]]
  2903. [[Extractor Parameters] [['none]]]
  2904. [[Accumulator Complexity] [O(1). Note that the Kahan sum performs four floating-point sum
  2905. operations per accumulated value, whereas the naive sum
  2906. performs only one.]]
  2907. [[Extractor Complexity] [O(1)]]
  2908. ]
  2909. [*Header]
  2910. [def _WEIGHTED_SUM_HPP_ [headerref boost/accumulators/statistics/weighted_sum.hpp]]
  2911. [def _WEIGHTED_SUM_KAHAN_HPP_ [headerref boost/accumulators/statistics/weighted_sum_kahan.hpp]]
  2912. #include <_WEIGHTED_SUM_HPP_>
  2913. #include <_WEIGHTED_SUM_KAHAN_HPP_>
  2914. [*Example]
  2915. accumulator_set<int, stats<tag::weighted_sum, tag::weighted_sum_of_variates<int, tag::covariate1> >, int> acc;
  2916. acc(1, weight = 2, covariate1 = 3);
  2917. BOOST_CHECK_EQUAL(2, weighted_sum(acc));
  2918. BOOST_CHECK_EQUAL(6, weighted_sum_of_variates(acc));
  2919. acc(2, weight = 3, covariate1 = 6);
  2920. BOOST_CHECK_EQUAL(8, weighted_sum(acc));
  2921. BOOST_CHECK_EQUAL(24, weighted_sum_of_variates(acc));
  2922. acc(4, weight = 6, covariate1 = 9);
  2923. BOOST_CHECK_EQUAL(32, weighted_sum(acc));
  2924. BOOST_CHECK_EQUAL(78, weighted_sum_of_variates(acc));
  2925. // demonstrate weighted Kahan summation
  2926. accumulator_set<float, stats<tag::weighted_sum_kahan>, float > acc;
  2927. BOOST_CHECK_EQUAL(0.0f, weighted_sum_kahan(acc));
  2928. for (size_t i = 0; i < 1e6; ++i) {
  2929. acc(1.0f, weight = 1e-6f);
  2930. }
  2931. BOOST_CHECK_EQUAL(1.0f, weighted_sum_kahan(acc));
  2932. [*See also]
  2933. * [classref boost::accumulators::impl::weighted_sum_impl [^weighted_sum_impl]]
  2934. * [classref boost::accumulators::impl::weighted_sum_impl [^weighted_sum_kahan_impl]]
  2935. [endsect]
  2936. [section:non_coherent_weighted_tail_mean non_coherent_weighted_tail_mean]
  2937. Estimation of the (non-coherent) weighted tail mean based on order statistics (for both left and right tails).
  2938. The left non-coherent weighted tail mean feature is `tag::non_coherent_weighted_tail_mean<left>`, and the right
  2939. non-choherent weighted tail mean feature is `tag::non_coherent_weighted_tail_mean<right>`. They both share the
  2940. `tag::abstract_non_coherent_tail_mean` feature with the unweighted non-coherent tail mean accumulators and can
  2941. be extracted with either the `non_coherent_tail_mean()` or the `non_coherent_weighted_tail_mean()` extractors.
  2942. For more implementation details, see
  2943. [classref boost::accumulators::impl::non_coherent_weighted_tail_mean_impl [^non_coherent_weighted_tail_mean_impl]].
  2944. [variablelist
  2945. [[Result Type] [``
  2946. numeric::functional::fdiv<
  2947. numeric::functional::multiplies<_sample_type_, _weight_type_>::result_type
  2948. , std::size_t
  2949. >::result_type
  2950. ``]]
  2951. [[Depends On] [`sum_of_weights` \n `tail_weights<_left_or_right_>`]]
  2952. [[Variants] [`abstract_non_coherent_tail_mean`]]
  2953. [[Initialization Parameters] [`tag::tail<_left_or_right_>::cache_size`]]
  2954. [[Accumulator Parameters] [['none]]]
  2955. [[Extractor Parameters] [`quantile_probability`]]
  2956. [[Accumulator Complexity] [O(log N), where N is the cache size]]
  2957. [[Extractor Complexity] [O(N log N), where N is the cache size]]
  2958. ]
  2959. [*Header]
  2960. [def _WEIGHTED_TAIL_MEAN_HPP_ [headerref boost/accumulators/statistics/weighted_tail_mean.hpp]]
  2961. #include <_WEIGHTED_TAIL_MEAN_HPP_>
  2962. [*Example]
  2963. // tolerance in %
  2964. double epsilon = 1;
  2965. std::size_t n = 100000; // number of MC steps
  2966. std::size_t c = 25000; // cache size
  2967. accumulator_set<double, stats<tag::non_coherent_weighted_tail_mean<right> >, double >
  2968. acc0( right_tail_cache_size = c );
  2969. accumulator_set<double, stats<tag::non_coherent_weighted_tail_mean<left> >, double >
  2970. acc1( left_tail_cache_size = c );
  2971. // random number generators
  2972. boost::lagged_fibonacci607 rng;
  2973. for (std::size_t i = 0; i < n; ++i)
  2974. {
  2975. double smpl = std::sqrt(rng());
  2976. acc0(smpl, weight = 1./smpl);
  2977. }
  2978. for (std::size_t i = 0; i < n; ++i)
  2979. {
  2980. double smpl = rng();
  2981. acc1(smpl*smpl, weight = smpl);
  2982. }
  2983. // check uniform distribution
  2984. BOOST_CHECK_CLOSE( non_coherent_weighted_tail_mean(acc0, quantile_probability = 0.95), 0.975, epsilon );
  2985. BOOST_CHECK_CLOSE( non_coherent_weighted_tail_mean(acc0, quantile_probability = 0.975), 0.9875, epsilon );
  2986. BOOST_CHECK_CLOSE( non_coherent_weighted_tail_mean(acc0, quantile_probability = 0.99), 0.995, epsilon );
  2987. BOOST_CHECK_CLOSE( non_coherent_weighted_tail_mean(acc0, quantile_probability = 0.999), 0.9995, epsilon );
  2988. BOOST_CHECK_CLOSE( non_coherent_weighted_tail_mean(acc1, quantile_probability = 0.05), 0.025, epsilon );
  2989. BOOST_CHECK_CLOSE( non_coherent_weighted_tail_mean(acc1, quantile_probability = 0.025), 0.0125, epsilon );
  2990. BOOST_CHECK_CLOSE( non_coherent_weighted_tail_mean(acc1, quantile_probability = 0.01), 0.005, epsilon );
  2991. BOOST_CHECK_CLOSE( non_coherent_weighted_tail_mean(acc1, quantile_probability = 0.001), 0.0005, 5*epsilon );
  2992. [*See also]
  2993. * [classref boost::accumulators::impl::non_coherent_weighted_tail_mean_impl [^non_coherent_weighted_tail_mean_impl]]
  2994. * [link accumulators.user_s_guide.the_statistical_accumulators_library.sum [^sum]]
  2995. * [link accumulators.user_s_guide.the_statistical_accumulators_library.tail [^tail]]
  2996. [endsect]
  2997. [section:weighted_tail_quantile weighted_tail_quantile]
  2998. Tail quantile estimation based on order statistics of weighted samples (for both left
  2999. and right tails). The left weighted tail quantile feature is `tag::weighted_tail_quantile<left>`,
  3000. and the right weighted tail quantile feature is `tag::weighted_tail_quantile<right>`. They both
  3001. share the `tag::quantile` feature with the unweighted tail quantile accumulators and can be
  3002. extracted with either the `quantile()` or the `weighted_tail_quantile()` extractors. For more
  3003. implementation details, see
  3004. [classref boost::accumulators::impl::weighted_tail_quantile_impl [^weighted_tail_quantile_impl]]
  3005. [variablelist
  3006. [[Result Type] [``
  3007. _sample_type_
  3008. ``]]
  3009. [[Depends On] [`sum_of_weights` \n `tail_weights<_left_or_right_>`]]
  3010. [[Variants] [['none]]]
  3011. [[Initialization Parameters] [`tag::tail<_left_or_right_>::cache_size`]]
  3012. [[Accumulator Parameters] [['none]]]
  3013. [[Extractor Parameters] [`quantile_probability`]]
  3014. [[Accumulator Complexity] [O(log N), where N is the cache size]]
  3015. [[Extractor Complexity] [O(N log N), where N is the cache size]]
  3016. ]
  3017. [*Header]
  3018. [def _WEIGHTED_TAIL_QUANTILE_HPP_ [headerref boost/accumulators/statistics/weighted_tail_quantile.hpp]]
  3019. #include <_WEIGHTED_TAIL_QUANTILE_HPP_>
  3020. [*Example]
  3021. // tolerance in %
  3022. double epsilon = 1;
  3023. std::size_t n = 100000; // number of MC steps
  3024. std::size_t c = 20000; // cache size
  3025. double mu1 = 1.0;
  3026. double mu2 = -1.0;
  3027. boost::lagged_fibonacci607 rng;
  3028. boost::normal_distribution<> mean_sigma1(mu1,1);
  3029. boost::normal_distribution<> mean_sigma2(mu2,1);
  3030. boost::variate_generator<boost::lagged_fibonacci607&, boost::normal_distribution<> > normal1(rng, mean_sigma1);
  3031. boost::variate_generator<boost::lagged_fibonacci607&, boost::normal_distribution<> > normal2(rng, mean_sigma2);
  3032. accumulator_set<double, stats<tag::weighted_tail_quantile<right> >, double>
  3033. acc1(right_tail_cache_size = c);
  3034. accumulator_set<double, stats<tag::weighted_tail_quantile<left> >, double>
  3035. acc2(left_tail_cache_size = c);
  3036. for (std::size_t i = 0; i < n; ++i)
  3037. {
  3038. double sample1 = normal1();
  3039. double sample2 = normal2();
  3040. acc1(sample1, weight = std::exp(-mu1 * (sample1 - 0.5 * mu1)));
  3041. acc2(sample2, weight = std::exp(-mu2 * (sample2 - 0.5 * mu2)));
  3042. }
  3043. // check standard normal distribution
  3044. BOOST_CHECK_CLOSE( quantile(acc1, quantile_probability = 0.975), 1.959963, epsilon );
  3045. BOOST_CHECK_CLOSE( quantile(acc1, quantile_probability = 0.999), 3.090232, epsilon );
  3046. BOOST_CHECK_CLOSE( quantile(acc2, quantile_probability = 0.025), -1.959963, epsilon );
  3047. BOOST_CHECK_CLOSE( quantile(acc2, quantile_probability = 0.001), -3.090232, epsilon );
  3048. [*See also]
  3049. * [classref boost::accumulators::impl::weighted_tail_quantile_impl [^weighted_tail_quantile_impl]]
  3050. * [link accumulators.user_s_guide.the_statistical_accumulators_library.sum [^sum]]
  3051. * [link accumulators.user_s_guide.the_statistical_accumulators_library.tail [^tail]]
  3052. [endsect]
  3053. [section:weighted_tail_variate_means weighted_tail_variate_means ['and variants]]
  3054. Estimation of the absolute and relative weighted tail variate means (for both left and right tails)
  3055. The absolute weighted tail variate means has the feature
  3056. `tag::absolute_weighted_tail_variate_means<_left_or_right_, _variate_type_, _variate_tag_>`
  3057. and the relative weighted tail variate mean has the feature
  3058. `tag::relative_weighted_tail_variate_means<_left_or_right_, _variate_type_, _variate_tag_>`. All
  3059. absolute weighted tail variate mean features share the `tag::abstract_absolute_tail_variate_means`
  3060. feature with their unweighted variants and can be extracted with the `tail_variate_means()` and
  3061. `weighted_tail_variate_means()` extractors. All the relative weighted tail variate mean features
  3062. share the `tag::abstract_relative_tail_variate_means` feature with their unweighted variants
  3063. and can be extracted with either the `relative_tail_variate_means()` or
  3064. `relative_weighted_tail_variate_means()` extractors.
  3065. For more implementation details, see
  3066. [classref boost::accumulators::impl::weighted_tail_variate_means_impl [^weighted_tail_variate_means_impl]]
  3067. [variablelist
  3068. [[Result Type] [``
  3069. boost::iterator_range<
  3070. numeric::functional::fdiv<
  3071. numeric::functional::multiplies<_variate_type_, _weight_type_>::result_type
  3072. , _weight_type_
  3073. >::result_type::iterator
  3074. >
  3075. ``]]
  3076. [[Depends On] [`non_coherent_weighted_tail_mean<_left_or_right_>` \n
  3077. `tail_variate<_variate_type_, _variate_tag_, _left_or_right_>` \n
  3078. `tail_weights<_left_or_right_>`]]
  3079. [[Variants] [`tag::absolute_weighted_tail_variate_means<_left_or_right_, _variate_type_, _variate_tag_>` \n
  3080. `tag::relative_weighted_tail_variate_means<_left_or_right_, _variate_type_, _variate_tag_>`]]
  3081. [[Initialization Parameters] [`tag::tail<_left_or_right_>::cache_size`]]
  3082. [[Accumulator Parameters] [['none]]]
  3083. [[Extractor Parameters] [`quantile_probability`]]
  3084. [[Accumulator Complexity] [O(log N), where N is the cache size]]
  3085. [[Extractor Complexity] [O(N log N), where N is the cache size]]
  3086. ]
  3087. [*Header]
  3088. [def _WEIGHTED_TAIL_VARIATE_MEANS_HPP_ [headerref boost/accumulators/statistics/weighted_tail_variate_means.hpp]]
  3089. #include <_WEIGHTED_TAIL_VARIATE_MEANS_HPP_>
  3090. [*Example]
  3091. std::size_t c = 5; // cache size
  3092. typedef double variate_type;
  3093. typedef std::vector<variate_type> variate_set_type;
  3094. accumulator_set<double, stats<tag::weighted_tail_variate_means<right, variate_set_type, tag::covariate1>(relative)>, double >
  3095. acc1( right_tail_cache_size = c );
  3096. accumulator_set<double, stats<tag::weighted_tail_variate_means<right, variate_set_type, tag::covariate1>(absolute)>, double >
  3097. acc2( right_tail_cache_size = c );
  3098. accumulator_set<double, stats<tag::weighted_tail_variate_means<left, variate_set_type, tag::covariate1>(relative)>, double >
  3099. acc3( left_tail_cache_size = c );
  3100. accumulator_set<double, stats<tag::weighted_tail_variate_means<left, variate_set_type, tag::covariate1>(absolute)>, double >
  3101. acc4( left_tail_cache_size = c );
  3102. variate_set_type cov1, cov2, cov3, cov4, cov5;
  3103. double c1[] = { 10., 20., 30., 40. }; // 100
  3104. double c2[] = { 26., 4., 17., 3. }; // 50
  3105. double c3[] = { 46., 64., 40., 50. }; // 200
  3106. double c4[] = { 1., 3., 70., 6. }; // 80
  3107. double c5[] = { 2., 2., 2., 14. }; // 20
  3108. cov1.assign(c1, c1 + sizeof(c1)/sizeof(variate_type));
  3109. cov2.assign(c2, c2 + sizeof(c2)/sizeof(variate_type));
  3110. cov3.assign(c3, c3 + sizeof(c3)/sizeof(variate_type));
  3111. cov4.assign(c4, c4 + sizeof(c4)/sizeof(variate_type));
  3112. cov5.assign(c5, c5 + sizeof(c5)/sizeof(variate_type));
  3113. acc1(100., weight = 0.8, covariate1 = cov1);
  3114. acc1( 50., weight = 0.9, covariate1 = cov2);
  3115. acc1(200., weight = 1.0, covariate1 = cov3);
  3116. acc1( 80., weight = 1.1, covariate1 = cov4);
  3117. acc1( 20., weight = 1.2, covariate1 = cov5);
  3118. acc2(100., weight = 0.8, covariate1 = cov1);
  3119. acc2( 50., weight = 0.9, covariate1 = cov2);
  3120. acc2(200., weight = 1.0, covariate1 = cov3);
  3121. acc2( 80., weight = 1.1, covariate1 = cov4);
  3122. acc2( 20., weight = 1.2, covariate1 = cov5);
  3123. acc3(100., weight = 0.8, covariate1 = cov1);
  3124. acc3( 50., weight = 0.9, covariate1 = cov2);
  3125. acc3(200., weight = 1.0, covariate1 = cov3);
  3126. acc3( 80., weight = 1.1, covariate1 = cov4);
  3127. acc3( 20., weight = 1.2, covariate1 = cov5);
  3128. acc4(100., weight = 0.8, covariate1 = cov1);
  3129. acc4( 50., weight = 0.9, covariate1 = cov2);
  3130. acc4(200., weight = 1.0, covariate1 = cov3);
  3131. acc4( 80., weight = 1.1, covariate1 = cov4);
  3132. acc4( 20., weight = 1.2, covariate1 = cov5);
  3133. // check relative risk contributions
  3134. BOOST_CHECK_EQUAL( *(relative_weighted_tail_variate_means(acc1, quantile_probability = 0.7).begin() ), (0.8*10 + 1.0*46)/(0.8*100 + 1.0*200) );
  3135. BOOST_CHECK_EQUAL( *(relative_weighted_tail_variate_means(acc1, quantile_probability = 0.7).begin() + 1), (0.8*20 + 1.0*64)/(0.8*100 + 1.0*200) );
  3136. BOOST_CHECK_EQUAL( *(relative_weighted_tail_variate_means(acc1, quantile_probability = 0.7).begin() + 2), (0.8*30 + 1.0*40)/(0.8*100 + 1.0*200) );
  3137. BOOST_CHECK_EQUAL( *(relative_weighted_tail_variate_means(acc1, quantile_probability = 0.7).begin() + 3), (0.8*40 + 1.0*50)/(0.8*100 + 1.0*200) );
  3138. BOOST_CHECK_EQUAL( *(relative_weighted_tail_variate_means(acc3, quantile_probability = 0.3).begin() ), (0.9*26 + 1.2*2)/(0.9*50 + 1.2*20) );
  3139. BOOST_CHECK_EQUAL( *(relative_weighted_tail_variate_means(acc3, quantile_probability = 0.3).begin() + 1), (0.9*4 + 1.2*2)/(0.9*50 + 1.2*20) );
  3140. BOOST_CHECK_EQUAL( *(relative_weighted_tail_variate_means(acc3, quantile_probability = 0.3).begin() + 2), (0.9*17 + 1.2*2)/(0.9*50 + 1.2*20) );
  3141. BOOST_CHECK_EQUAL( *(relative_weighted_tail_variate_means(acc3, quantile_probability = 0.3).begin() + 3), (0.9*3 + 1.2*14)/(0.9*50 + 1.2*20) );
  3142. // check absolute risk contributions
  3143. BOOST_CHECK_EQUAL( *(weighted_tail_variate_means(acc2, quantile_probability = 0.7).begin() ), (0.8*10 + 1.0*46)/1.8 );
  3144. BOOST_CHECK_EQUAL( *(weighted_tail_variate_means(acc2, quantile_probability = 0.7).begin() + 1), (0.8*20 + 1.0*64)/1.8 );
  3145. BOOST_CHECK_EQUAL( *(weighted_tail_variate_means(acc2, quantile_probability = 0.7).begin() + 2), (0.8*30 + 1.0*40)/1.8 );
  3146. BOOST_CHECK_EQUAL( *(weighted_tail_variate_means(acc2, quantile_probability = 0.7).begin() + 3), (0.8*40 + 1.0*50)/1.8 );
  3147. BOOST_CHECK_EQUAL( *(weighted_tail_variate_means(acc4, quantile_probability = 0.3).begin() ), (0.9*26 + 1.2*2)/2.1 );
  3148. BOOST_CHECK_EQUAL( *(weighted_tail_variate_means(acc4, quantile_probability = 0.3).begin() + 1), (0.9*4 + 1.2*2)/2.1 );
  3149. BOOST_CHECK_EQUAL( *(weighted_tail_variate_means(acc4, quantile_probability = 0.3).begin() + 2), (0.9*17 + 1.2*2)/2.1 );
  3150. BOOST_CHECK_EQUAL( *(weighted_tail_variate_means(acc4, quantile_probability = 0.3).begin() + 3), (0.9*3 + 1.2*14)/2.1 );
  3151. // check relative risk contributions
  3152. BOOST_CHECK_EQUAL( *(relative_weighted_tail_variate_means(acc1, quantile_probability = 0.9).begin() ), 1.0*46/(1.0*200) );
  3153. BOOST_CHECK_EQUAL( *(relative_weighted_tail_variate_means(acc1, quantile_probability = 0.9).begin() + 1), 1.0*64/(1.0*200) );
  3154. BOOST_CHECK_EQUAL( *(relative_weighted_tail_variate_means(acc1, quantile_probability = 0.9).begin() + 2), 1.0*40/(1.0*200) );
  3155. BOOST_CHECK_EQUAL( *(relative_weighted_tail_variate_means(acc1, quantile_probability = 0.9).begin() + 3), 1.0*50/(1.0*200) );
  3156. BOOST_CHECK_EQUAL( *(relative_weighted_tail_variate_means(acc3, quantile_probability = 0.1).begin() ), 1.2*2/(1.2*20) );
  3157. BOOST_CHECK_EQUAL( *(relative_weighted_tail_variate_means(acc3, quantile_probability = 0.1).begin() + 1), 1.2*2/(1.2*20) );
  3158. BOOST_CHECK_EQUAL( *(relative_weighted_tail_variate_means(acc3, quantile_probability = 0.1).begin() + 2), 1.2*2/(1.2*20) );
  3159. BOOST_CHECK_EQUAL( *(relative_weighted_tail_variate_means(acc3, quantile_probability = 0.1).begin() + 3), 1.2*14/(1.2*20) );
  3160. // check absolute risk contributions
  3161. BOOST_CHECK_EQUAL( *(weighted_tail_variate_means(acc2, quantile_probability = 0.9).begin() ), 1.0*46/1.0 );
  3162. BOOST_CHECK_EQUAL( *(weighted_tail_variate_means(acc2, quantile_probability = 0.9).begin() + 1), 1.0*64/1.0 );
  3163. BOOST_CHECK_EQUAL( *(weighted_tail_variate_means(acc2, quantile_probability = 0.9).begin() + 2), 1.0*40/1.0 );
  3164. BOOST_CHECK_EQUAL( *(weighted_tail_variate_means(acc2, quantile_probability = 0.9).begin() + 3), 1.0*50/1.0 );
  3165. BOOST_CHECK_EQUAL( *(weighted_tail_variate_means(acc4, quantile_probability = 0.1).begin() ), 1.2*2/1.2 );
  3166. BOOST_CHECK_EQUAL( *(weighted_tail_variate_means(acc4, quantile_probability = 0.1).begin() + 1), 1.2*2/1.2 );
  3167. BOOST_CHECK_EQUAL( *(weighted_tail_variate_means(acc4, quantile_probability = 0.1).begin() + 2), 1.2*2/1.2 );
  3168. BOOST_CHECK_EQUAL( *(weighted_tail_variate_means(acc4, quantile_probability = 0.1).begin() + 3), 1.2*14/1.2 );
  3169. [*See also]
  3170. * [classref boost::accumulators::impl::weighted_tail_variate_means_impl [^weighted_tail_variate_means_impl]]
  3171. * [link accumulators.user_s_guide.the_statistical_accumulators_library.non_coherent_weighted_tail_mean [^non_coherent_weighted_tail_mean]]
  3172. * [link accumulators.user_s_guide.the_statistical_accumulators_library.tail_variate [^tail_variate]]
  3173. * [link accumulators.user_s_guide.the_statistical_accumulators_library.tail [^tail]]
  3174. [endsect]
  3175. [section:weighted_variance weighted_variance ['and variants]]
  3176. Lazy or iterative calculation of the weighted variance. The lazy calculation is associated with the `tag::lazy_weighted_variance`
  3177. feature, and the iterative calculation with the `tag::weighted_variance` feature. Both can be extracted
  3178. using the `tag::weighted_variance()` extractor. For more implementation details, see
  3179. [classref boost::accumulators::impl::lazy_weighted_variance_impl [^lazy_weighted_variance_impl]] and
  3180. [classref boost::accumulators::impl::weighted_variance_impl [^weighted_variance_impl]]
  3181. [variablelist
  3182. [[Result Type] [``
  3183. numeric::functional::fdiv<
  3184. numeric::functional::multiplies<_sample_type_, _weight_type_>::result_type
  3185. , std::size_t
  3186. >::result_type
  3187. ``]]
  3188. [[Depends On] [`tag::lazy_weighted_variance` depends on `tag::weighted_moment<2>` and `tag::weighted_mean` \n
  3189. `tag::weighted_variance` depends on `tag::count` and `tag::immediate_weighted_mean`]]
  3190. [[Variants] [`tag::lazy_weighted_variance` (a.k.a. `tag::weighted_variance(lazy))` \n
  3191. `tag::weighted_variance` (a.k.a. `tag::weighted_variance(immediate)`)]]
  3192. [[Initialization Parameters] [['none]]]
  3193. [[Accumulator Parameters] [`weight`]]
  3194. [[Extractor Parameters] [['none]]]
  3195. [[Accumulator Complexity] [O(1)]]
  3196. [[Extractor Complexity] [O(1)]]
  3197. ]
  3198. [*Header]
  3199. [def _WEIGHTED_VARIANCE_HPP_ [headerref boost/accumulators/statistics/weighted_variance.hpp]]
  3200. #include <_WEIGHTED_VARIANCE_HPP_>
  3201. [*Example]
  3202. // lazy weighted_variance
  3203. accumulator_set<int, stats<tag::weighted_variance(lazy)>, int> acc1;
  3204. acc1(1, weight = 2); // 2
  3205. acc1(2, weight = 3); // 6
  3206. acc1(3, weight = 1); // 3
  3207. acc1(4, weight = 4); // 16
  3208. acc1(5, weight = 1); // 5
  3209. // weighted_mean = (2+6+3+16+5) / (2+3+1+4+1) = 32 / 11 = 2.9090909090909090909090909090909
  3210. BOOST_CHECK_EQUAL(5u, count(acc1));
  3211. BOOST_CHECK_CLOSE(2.9090909, weighted_mean(acc1), 1e-5);
  3212. BOOST_CHECK_CLOSE(10.1818182, accumulators::weighted_moment<2>(acc1), 1e-5);
  3213. BOOST_CHECK_CLOSE(1.7190083, weighted_variance(acc1), 1e-5);
  3214. // immediate weighted_variance
  3215. accumulator_set<int, stats<tag::weighted_variance>, int> acc2;
  3216. acc2(1, weight = 2);
  3217. acc2(2, weight = 3);
  3218. acc2(3, weight = 1);
  3219. acc2(4, weight = 4);
  3220. acc2(5, weight = 1);
  3221. BOOST_CHECK_EQUAL(5u, count(acc2));
  3222. BOOST_CHECK_CLOSE(2.9090909, weighted_mean(acc2), 1e-5);
  3223. BOOST_CHECK_CLOSE(1.7190083, weighted_variance(acc2), 1e-5);
  3224. // check lazy and immediate variance with random numbers
  3225. // two random number generators
  3226. boost::lagged_fibonacci607 rng;
  3227. boost::normal_distribution<> mean_sigma(0,1);
  3228. boost::variate_generator<boost::lagged_fibonacci607&, boost::normal_distribution<> > normal(rng, mean_sigma);
  3229. accumulator_set<double, stats<tag::weighted_variance>, double > acc_lazy;
  3230. accumulator_set<double, stats<tag::weighted_variance(immediate)>, double > acc_immediate;
  3231. for (std::size_t i=0; i<10000; ++i)
  3232. {
  3233. double value = normal();
  3234. acc_lazy(value, weight = rng());
  3235. acc_immediate(value, weight = rng());
  3236. }
  3237. BOOST_CHECK_CLOSE(1., weighted_variance(acc_lazy), 1.);
  3238. BOOST_CHECK_CLOSE(1., weighted_variance(acc_immediate), 1.);
  3239. [*See also]
  3240. * [classref boost::accumulators::impl::lazy_weighted_variance_impl [^lazy_weighted_variance_impl]]
  3241. * [classref boost::accumulators::impl::weighted_variance_impl [^weighted_variance_impl]]
  3242. * [link accumulators.user_s_guide.the_statistical_accumulators_library.count [^count]]
  3243. * [link accumulators.user_s_guide.the_statistical_accumulators_library.weighted_mean [^weighted_mean]]
  3244. * [link accumulators.user_s_guide.the_statistical_accumulators_library.weighted_moment [^weighted_moment]]
  3245. [endsect]
  3246. [endsect]
  3247. [endsect]
  3248. [section Acknowledgements]
  3249. Boost.Accumulators represents the efforts of many individuals. I would like to thank
  3250. Daniel Egloff of _ZKB_ for helping to conceive the library and realize its
  3251. implementation. I would also like to thank David Abrahams and Matthias Troyer for
  3252. their key contributions to the design of the library. Many thanks are due to Michael
  3253. Gauckler and Olivier Gygi, who, along with Daniel Egloff, implemented many of the
  3254. statistical accumulators.
  3255. I would also like to thank Simon West for all his assistance maintaining
  3256. Boost.Accumulators.
  3257. Finally, I would like to thank _ZKB_ for sponsoring the work on Boost.Accumulators
  3258. and graciously donating it to the community.
  3259. [endsect]
  3260. [section Reference]
  3261. [xinclude accdoc.xml]
  3262. [xinclude statsdoc.xml]
  3263. [xinclude opdoc.xml]
  3264. [endsect]