LArDiscreteProbabilityHelper.h
Go to the documentation of this file.
1 /**
2  * @file larpandoracontent/LArHelpers/LArDiscreteProbabilityHelper.h
3  *
4  * @brief Header file for the discrete probability helper class.
5  *
6  * $Log: $
7  */
8 #ifndef LAR_DISCRETE_PROBABILITY_HELPER_HELPER_H
9 #define LAR_DISCRETE_PROBABILITY_HELPER_HELPER_H 1
10 
12 
13 #include <algorithm>
14 #include <random>
15 
16 namespace lar_content
17 {
18 
19 /**
20  * @brief LArDiscreteProbabilityHelper class
21  */
23 {
24 public:
25  /**
26  * @brief Calculate P value for measured correlation coefficient between two datasets via a permutation test
27  *
28  * @param t1 the first input dataset
29  * @param t2 the second input dataset
30  * @param randomNumberGenerator the random number generator to shuffle the datasets
31  * @param nPermutations the number of permutations to run
32  *
33  * @return the p-value
34  */
35  template <typename T>
37  const T &t1, const T &t2, std::mt19937 &randomNumberGenerator, const unsigned int nPermutations);
38 
39  /**
40  * @brief Calculate P value for measured correlation coefficient between two datasets via a integrating the student T dist.
41  *
42  * @param t1 the first input dataset
43  * @param t2 the second input dataset
44  * @param nIntegrationSteps how many steps to use in the trapezium integration
45  * @param upperLimit the upper limit of the integration
46  *
47  * @return the p-value
48  */
49  template <typename T>
51  const T &t1, const T &t2, const unsigned int nIntegrationSteps, const float upperLimit);
52 
53  /**
54  * @brief Calculate the correlation coefficient between two datasets
55  *
56  * @param t1 the first input dataset
57  * @param t2 the second input dataset
58  *
59  * @return the correlation coefficient
60  */
61  template <typename T>
62  static float CalculateCorrelationCoefficient(const T &t1, const T &t2);
63 
64  /**
65  * @brief Calculate the mean of a dataset
66  *
67  * @param t the dataset
68  *
69  * @return the mean
70  */
71  template <typename T>
72  static float CalculateMean(const T &t);
73 
74 private:
75  /**
76  * @brief Make a randomised copy of a dataset
77  *
78  * @param t the dataset to be shuffled
79  * @param randomNumberGenerator the random number generator
80  *
81  * @return the reshuffled dataset
82  */
83  template <typename T>
84  static T MakeRandomisedSample(const T &t, std::mt19937 &randomNumberGenerator);
85 
86  /**
87  * @brief Make a randomised copy of dataset (dataset is an std::vector)
88  *
89  * @param t the std::vector-based dataset to be shuffled
90  * @param randomNumberGenerator the random number generator
91  *
92  * @return the reshuffled std::vector
93  */
94  template <typename T>
95  static std::vector<T> MakeRandomisedSample(const std::vector<T> &t, std::mt19937 &randomNumberGenerator);
96 
97  /**
98  * @brief Get the size the size of a dataset
99  *
100  * @param t the dataset
101  *
102  * @return the dataset size
103  */
104  template <typename T>
105  static unsigned int GetSize(const T &t);
106 
107  /**
108  * @brief Get the size of a dataset (dataset is an std::vector)
109  *
110  * @param t the std::vector dataset
111  *
112  * @return the std::vector-based dataset size
113  */
114  template <typename T>
115  static unsigned int GetSize(const std::vector<T> &t);
116 
117  /**
118  * @brief Get an element in a dataset
119  *
120  * @param t the dataset
121  * @param index the index of the element
122  *
123  * @return the dataset element
124  */
125  template <typename T>
126  static float GetElement(const T &t, const unsigned int index);
127 
128  /**
129  * @brief Get an element in a dataset (dataset is an std::vector)
130  *
131  * @param t the std::vector dataset
132  * @param index the index of the element
133  *
134  * @return the std::vector-based dataset element
135  */
136  template <typename T>
137  static float GetElement(const std::vector<T> &t, const unsigned int index);
138 };
139 
140 //------------------------------------------------------------------------------------------------------------------------------------------
141 
142 template <typename T>
143 inline std::vector<T> LArDiscreteProbabilityHelper::MakeRandomisedSample(const std::vector<T> &t, std::mt19937 &randomNumberGenerator)
144 {
145  std::vector<T> randomisedVector(t);
146  std::shuffle(randomisedVector.begin(), randomisedVector.end(), randomNumberGenerator);
147 
148  return randomisedVector;
149 }
150 
151 template <>
153 {
154  return DiscreteProbabilityVector(t, randomNumberGenerator);
155 }
156 
157 //------------------------------------------------------------------------------------------------------------------------------------------
158 
159 template <typename T>
160 inline unsigned int LArDiscreteProbabilityHelper::GetSize(const std::vector<T> &t)
161 {
162  return t.size();
163 }
164 
165 template <>
167 {
168  return t.GetSize();
169 }
170 
171 //------------------------------------------------------------------------------------------------------------------------------------------
172 
173 template <typename T>
174 inline float LArDiscreteProbabilityHelper::GetElement(const std::vector<T> &t, const unsigned int index)
175 {
176  return static_cast<float>(t.at(index));
177 }
178 
179 template <>
181 {
182  return static_cast<float>(t.GetProbability(index));
183 }
184 
185 } // namespace lar_content
186 
187 #endif // #ifndef LAR_DISCRETE_PROBABILITY_HELPER_H
static float CalculateCorrelationCoefficientPValueFromPermutationTest(const T &t1, const T &t2, std::mt19937 &randomNumberGenerator, const unsigned int nPermutations)
Calculate P value for measured correlation coefficient between two datasets via a permutation test...
static float CalculateCorrelationCoefficientPValueFromStudentTDistribution(const T &t1, const T &t2, const unsigned int nIntegrationSteps, const float upperLimit)
Calculate P value for measured correlation coefficient between two datasets via a integrating the stu...
static float CalculateCorrelationCoefficient(const T &t1, const T &t2)
Calculate the correlation coefficient between two datasets.
float GetProbability(const unsigned int index) const
Get the probability value of the element in the vector.
Header file for the lar discrete probability vector class.
static T MakeRandomisedSample(const T &t, std::mt19937 &randomNumberGenerator)
Make a randomised copy of a dataset.
static unsigned int GetSize(const T &t)
Get the size the size of a dataset.
static float CalculateMean(const T &t)
Calculate the mean of a dataset.
static float GetElement(const T &t, const unsigned int index)
Get an element in a dataset.
unsigned int GetSize() const
Get the size of the probability vector.