Pandora
Pandora source code navigator
Loading...
Searching...
No Matches
LArDiscreteProbabilityHelper.h
Go to the documentation of this file.
1
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
16namespace lar_content
17{
18
23{
24public:
35 template <typename T>
37 const T &t1, const T &t2, std::mt19937 &randomNumberGenerator, const unsigned int nPermutations);
38
49 template <typename T>
51 const T &t1, const T &t2, const unsigned int nIntegrationSteps, const float upperLimit);
52
61 template <typename T>
62 static float CalculateCorrelationCoefficient(const T &t1, const T &t2);
63
71 template <typename T>
72 static float CalculateMean(const T &t);
73
74private:
83 template <typename T>
84 static T MakeRandomisedSample(const T &t, std::mt19937 &randomNumberGenerator);
85
94 template <typename T>
95 static std::vector<T> MakeRandomisedSample(const std::vector<T> &t, std::mt19937 &randomNumberGenerator);
96
104 template <typename T>
105 static unsigned int GetSize(const T &t);
106
114 template <typename T>
115 static unsigned int GetSize(const std::vector<T> &t);
116
125 template <typename T>
126 static float GetElement(const T &t, const unsigned int index);
127
136 template <typename T>
137 static float GetElement(const std::vector<T> &t, const unsigned int index);
138};
139
140//------------------------------------------------------------------------------------------------------------------------------------------
141
142template <typename T>
143inline 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
151template <>
153{
154 return DiscreteProbabilityVector(t, randomNumberGenerator);
155}
156
157//------------------------------------------------------------------------------------------------------------------------------------------
158
159template <typename T>
160inline unsigned int LArDiscreteProbabilityHelper::GetSize(const std::vector<T> &t)
161{
162 return t.size();
163}
164
165template <>
167{
168 return t.GetSize();
169}
170
171//------------------------------------------------------------------------------------------------------------------------------------------
172
173template <typename T>
174inline float LArDiscreteProbabilityHelper::GetElement(const std::vector<T> &t, const unsigned int index)
175{
176 return static_cast<float>(t.at(index));
177}
178
179template <>
180inline float LArDiscreteProbabilityHelper::GetElement(const DiscreteProbabilityVector &t, const unsigned int index)
181{
182 return static_cast<float>(t.GetProbability(index));
183}
184
185} // namespace lar_content
186
187#endif // #ifndef LAR_DISCRETE_PROBABILITY_HELPER_H
Header file for the lar discrete probability vector class.
float GetProbability(const unsigned int index) const
Get the probability value of the element in the vector.
unsigned int GetSize() const
Get the size of the probability vector.
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 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 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 GetElement(const T &t, const unsigned int index)
Get an element in a dataset.
static float CalculateCorrelationCoefficient(const T &t1, const T &t2)
Calculate the correlation coefficient between two datasets.
static float CalculateMean(const T &t)
Calculate the mean of a dataset.