LArDiscreteProbabilityHelper class.
More...
#include <LArDiscreteProbabilityHelper.h>
|
template<typename T > |
static T | MakeRandomisedSample (const T &t, std::mt19937 &randomNumberGenerator) |
| Make a randomised copy of a dataset. More...
|
|
template<typename T > |
static std::vector< T > | MakeRandomisedSample (const std::vector< T > &t, std::mt19937 &randomNumberGenerator) |
| Make a randomised copy of dataset (dataset is an std::vector) More...
|
|
template<typename T > |
static unsigned int | GetSize (const T &t) |
| Get the size the size of a dataset. More...
|
|
template<typename T > |
static unsigned int | GetSize (const std::vector< T > &t) |
| Get the size of a dataset (dataset is an std::vector) More...
|
|
template<typename T > |
static float | GetElement (const T &t, const unsigned int index) |
| Get an element in a dataset. More...
|
|
template<typename T > |
static float | GetElement (const std::vector< T > &t, const unsigned int index) |
| Get an element in a dataset (dataset is an std::vector) More...
|
|
template<typename T >
template float lar_content::LArDiscreteProbabilityHelper::CalculateCorrelationCoefficient |
( |
const T & |
t1, |
|
|
const T & |
t2 |
|
) |
| |
|
static |
Calculate the correlation coefficient between two datasets.
- Parameters
-
t1 | the first input dataset |
t2 | the second input dataset |
- Returns
- the correlation coefficient
Definition at line 74 of file LArDiscreteProbabilityHelper.cc.
79 throw pandora::StatusCodeException(pandora::STATUS_CODE_INVALID_PARAMETER);
82 throw pandora::StatusCodeException(pandora::STATUS_CODE_INVALID_PARAMETER);
87 float variance1(0.
f), variance2(0.
f), covariance(0.
f);
89 for (
unsigned int iElement = 0; iElement < size1; ++iElement)
94 variance1 += diff1 * diff1;
95 variance2 += diff2 * diff2;
96 covariance += diff1 * diff2;
99 if (variance1 < std::numeric_limits<float>::epsilon() || variance2 < std::numeric_limits<float>::epsilon())
100 throw pandora::StatusCodeException(pandora::STATUS_CODE_FAILURE);
102 const float sqrtVars(std::sqrt(variance1 * variance2));
103 if (sqrtVars < std::numeric_limits<float>::epsilon())
104 throw pandora::StatusCodeException(pandora::STATUS_CODE_FAILURE);
106 return covariance / sqrtVars;
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.
template<typename T >
template float lar_content::LArDiscreteProbabilityHelper::CalculateCorrelationCoefficientPValueFromPermutationTest |
( |
const T & |
t1, |
|
|
const T & |
t2, |
|
|
std::mt19937 & |
randomNumberGenerator, |
|
|
const unsigned int |
nPermutations |
|
) |
| |
|
static |
Calculate P value for measured correlation coefficient between two datasets via a permutation test.
- Parameters
-
t1 | the first input dataset |
t2 | the second input dataset |
randomNumberGenerator | the random number generator to shuffle the datasets |
nPermutations | the number of permutations to run |
- Returns
- the p-value
Definition at line 16 of file LArDiscreteProbabilityHelper.cc.
19 if (1 > nPermutations)
20 throw pandora::StatusCodeException(pandora::STATUS_CODE_INVALID_PARAMETER);
24 unsigned int nExtreme(0);
25 for (
unsigned int iPermutation = 0; iPermutation < nPermutations; ++iPermutation)
31 if ((rRandomised - rNominal) > std::numeric_limits<float>::epsilon())
35 return static_cast<float>(nExtreme) / static_cast<float>(nPermutations);
static float CalculateCorrelationCoefficient(const T &t1, const T &t2)
Calculate the correlation coefficient between two datasets.
static T MakeRandomisedSample(const T &t, std::mt19937 &randomNumberGenerator)
Make a randomised copy of a dataset.
template<typename T >
template float lar_content::LArDiscreteProbabilityHelper::CalculateCorrelationCoefficientPValueFromStudentTDistribution |
( |
const T & |
t1, |
|
|
const T & |
t2, |
|
|
const unsigned int |
nIntegrationSteps, |
|
|
const float |
upperLimit |
|
) |
| |
|
static |
Calculate P value for measured correlation coefficient between two datasets via a integrating the student T dist.
- Parameters
-
t1 | the first input dataset |
t2 | the second input dataset |
nIntegrationSteps | how many steps to use in the trapezium integration |
upperLimit | the upper limit of the integration |
- Returns
- the p-value
Definition at line 41 of file LArDiscreteProbabilityHelper.cc.
48 throw pandora::StatusCodeException(pandora::STATUS_CODE_INVALID_PARAMETER);
50 const float tTestStatisticDenominator(1.
f - correlation - correlation);
52 if (tTestStatisticDenominator < std::numeric_limits<float>::epsilon())
53 throw pandora::StatusCodeException(pandora::STATUS_CODE_FAILURE);
55 const float tTestStatistic(correlation * std::sqrt(dof) / (std::sqrt(tTestStatisticDenominator)));
56 const float tDistCoeff(std::tgamma(0.5
f * (dof + 1.
f)) / std::tgamma(0.5
f * dof) / (std::sqrt(dof *
M_PI)));
58 const float dx((upperLimit - tTestStatistic) / static_cast<float>(nIntegrationSteps));
59 float integral(tDistCoeff *
std::pow(1.
f + tTestStatistic * tTestStatistic / dof, -0.5
f * (dof + 1.
f)) +
60 tDistCoeff *
std::pow(1.
f + upperLimit * upperLimit / dof, -0.5
f * (dof + 1.
f)));
61 for (
unsigned int iStep = 1; iStep < nIntegrationSteps; ++iStep)
64 std::pow(1.
f + (tTestStatistic + static_cast<float>(iStep) * dx) * (tTestStatistic + static_cast<float>(iStep) * dx) / dof,
static float CalculateCorrelationCoefficient(const T &t1, const T &t2)
Calculate the correlation coefficient between two datasets.
static unsigned int GetSize(const T &t)
Get the size the size of a dataset.
template<typename T >
template float lar_content::LArDiscreteProbabilityHelper::CalculateMean |
( |
const T & |
t | ) |
|
|
static |
Calculate the mean of a dataset.
- Parameters
-
- Returns
- the mean
Definition at line 112 of file LArDiscreteProbabilityHelper.cc.
116 throw pandora::StatusCodeException(pandora::STATUS_CODE_NOT_INITIALIZED);
119 for (
unsigned int iElement = 0; iElement <
size; ++iElement)
122 return mean /
static_cast<float>(
size);
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
static unsigned int GetSize(const T &t)
Get the size the size of a dataset.
static float GetElement(const T &t, const unsigned int index)
Get an element in a dataset.
double mean(sqlite3 *db, std::string const &table_name, std::string const &column_name)
template<typename T >
static float lar_content::LArDiscreteProbabilityHelper::GetElement |
( |
const T & |
t, |
|
|
const unsigned int |
index |
|
) |
| |
|
staticprivate |
Get an element in a dataset.
- Parameters
-
t | the dataset |
index | the index of the element |
- Returns
- the dataset element
template<typename T >
float lar_content::LArDiscreteProbabilityHelper::GetElement |
( |
const std::vector< T > & |
t, |
|
|
const unsigned int |
index |
|
) |
| |
|
inlinestaticprivate |
Get an element in a dataset (dataset is an std::vector)
- Parameters
-
t | the std::vector dataset |
index | the index of the element |
- Returns
- the std::vector-based dataset element
Definition at line 174 of file LArDiscreteProbabilityHelper.h.
176 return static_cast<float>(t.at(
index));
template<>
float lar_content::LArDiscreteProbabilityHelper::GetElement |
( |
const DiscreteProbabilityVector & |
t, |
|
|
const unsigned int |
index |
|
) |
| |
|
inline |
template<typename T >
static unsigned int lar_content::LArDiscreteProbabilityHelper::GetSize |
( |
const T & |
t | ) |
|
|
staticprivate |
Get the size the size of a dataset.
- Parameters
-
- Returns
- the dataset size
template<typename T >
unsigned int lar_content::LArDiscreteProbabilityHelper::GetSize |
( |
const std::vector< T > & |
t | ) |
|
|
inlinestaticprivate |
Get the size of a dataset (dataset is an std::vector)
- Parameters
-
- Returns
- the std::vector-based dataset size
Definition at line 160 of file LArDiscreteProbabilityHelper.h.
template<typename T >
static T lar_content::LArDiscreteProbabilityHelper::MakeRandomisedSample |
( |
const T & |
t, |
|
|
std::mt19937 & |
randomNumberGenerator |
|
) |
| |
|
staticprivate |
Make a randomised copy of a dataset.
- Parameters
-
t | the dataset to be shuffled |
randomNumberGenerator | the random number generator |
- Returns
- the reshuffled dataset
template<typename T >
std::vector< T > lar_content::LArDiscreteProbabilityHelper::MakeRandomisedSample |
( |
const std::vector< T > & |
t, |
|
|
std::mt19937 & |
randomNumberGenerator |
|
) |
| |
|
inlinestaticprivate |
Make a randomised copy of dataset (dataset is an std::vector)
- Parameters
-
t | the std::vector-based dataset to be shuffled |
randomNumberGenerator | the random number generator |
- Returns
- the reshuffled std::vector
Definition at line 143 of file LArDiscreteProbabilityHelper.h.
145 std::vector<T> randomisedVector(t);
146 std::shuffle(randomisedVector.begin(), randomisedVector.end(), randomNumberGenerator);
148 return randomisedVector;
The documentation for this class was generated from the following files: