Quetzal-CoaTL
The Coalescence Template Library
Loading...
Searching...
No Matches
accumulator.hpp
1// Copyright 2022 Arnaud Becheler <arnaud.becheler@gmail.com>
2
3/*********************************************************************** * This program is free software; you can
4 *redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free
5 *Software Foundation; either version 2 of the License, or * (at your option) any later version. *
6 * *
7 ***************************************************************************/
8
9#ifndef __QUETZAL_ACCUMULATOR_H_INCLUDED__
10#define __QUETZAL_ACCUMULATOR_H_INCLUDED__
11
12#include <boost/accumulators/framework/accumulator_base.hpp>
13#include <boost/accumulators/framework/parameters/sample.hpp>
14
24{
25
26template <typename Sample> class tajima_accumulator : accumulator_base
27{
28 public:
32 typedef Sample result_type;
33
39 template <typename Args> tajima_accumulator(Args const &args) : sum(args[sample | Sample()])
40 {
41 }
42
46 template <typename Args> void operator()(Args const &args)
47 {
48 this->tajima += args[sample];
49 }
50
54 template <typename Args> result_type result(Args const &args) const
55 {
56 using tajimasD = quetzal::polymophism::statistics::tajimasD;
57 return tajimasD(mean_pairwise_differences(args[accumulator]), nb_segregating_site(args[accumulator]),
58 count(args[accumulator]));
59 }
60
61 private:
62 Sample sum;
63};
64
65template <typename Sample> struct mean_accumulator : accumulator_base
66{
67 typedef Sample result_type;
68 mean_accumulator(dont_care)
69 {
70 }
71
72 template <typename Args> result_type result(Args const &args) const
73 {
74 return sum(args[accumulator]) / count(args[accumulator]);
75 }
76};
77
78} // namespace boost::accumulators::impl
79
80namespace boost::accumulators::tag
81{
82struct segregating_sites;
83struct pairwise_differences;
84
88struct tajima : depends_on<count, pairwise_differences, segregating_sites>
89{
90 // Define a nested typedef called 'impl' that specifies which accumulator implements this feature.
92};
93} // namespace boost::accumulators::tag
94
95namespace boost::accumulators
96{
97namespace extract
98{
102extractor<tag::tajima> const tajima = {};
103} // namespace extract
104
108using extract::tajima;
109
110} // namespace boost::accumulators
111
112#endif
Sample result_type
The type returned by result() below.
Definition accumulator.hpp:32
result_type result(Args const &args) const
The result function will also be passed an argument pack, but we don't use it here.
Definition accumulator.hpp:54
tajima_accumulator(Args const &args)
Constructor with a Boost.Parameter argument pack.
Definition accumulator.hpp:39
void operator()(Args const &args)
The accumulate function is the function call operator, accepting an argument pack.
Definition accumulator.hpp:46
Putting the accumulator implementations in this namespace is recommended.
Definition accumulator.hpp:24
Definition accumulator.hpp:66
Tajima's statistics accumulator tag.
Definition accumulator.hpp:89