18 template <
typename TX,
typename TY>
20 m_xUpperBound(static_cast<
float>(xUpperBound)),
21 m_useWidths(useWidths),
22 m_discreteProbabilityData(this->InitialiseDiscreteProbabilityData(inputData))
67 if (std::fabs(xHigh - xLow) < std::numeric_limits<float>::epsilon())
68 throw pandora::StatusCodeException(pandora::STATUS_CODE_INVALID_PARAMETER);
70 const float m((yHigh - yLow) / (xHigh - xLow));
71 const float c(yLow - m * xLow);
76 throw pandora::StatusCodeException(pandora::STATUS_CODE_INVALID_PARAMETER);
81 template <
typename TX,
typename TY>
84 if (2 > inputData.size())
85 throw pandora::StatusCodeException(pandora::STATUS_CODE_INVALID_PARAMETER);
87 std::sort(inputData.begin(), inputData.end(), DiscreteProbabilityVector::SortInputDataByX<TX, TY>);
89 if (inputData.back().first -
m_xUpperBound > std::numeric_limits<float>::epsilon())
90 throw pandora::StatusCodeException(pandora::STATUS_CODE_INVALID_PARAMETER);
94 if (normalisation < std::numeric_limits<float>::epsilon())
95 throw pandora::StatusCodeException(pandora::STATUS_CODE_FAILURE);
97 float accumulationDatum(0.
f);
100 for (
unsigned int iDatum = 0; iDatum < inputData.size() - 1; ++iDatum)
102 const float x(static_cast<float>(inputData.at(iDatum).first));
103 const float deltaX(static_cast<float>(inputData.at(iDatum + 1).first) - x);
104 const float densityDatum(static_cast<float>(inputData.at(iDatum).second) / normalisation);
105 accumulationDatum += densityDatum * (
m_useWidths ? deltaX : 1.f);
108 const float x(static_cast<float>(inputData.back().first));
110 const float densityDatum(static_cast<float>(inputData.back().second) / normalisation);
111 accumulationDatum += densityDatum * (
m_useWidths ? deltaX : 1.f);
122 if (2 > resamplingPoints.size())
123 throw pandora::StatusCodeException(pandora::STATUS_CODE_INVALID_PARAMETER);
127 float prevCumulativeData(0.
f);
128 for (
unsigned int iSample = 0; iSample < resamplingPoints.size() - 1; ++iSample)
130 const float xResampled(resamplingPoints.at(iSample));
131 const float deltaX(resamplingPoints.at(iSample + 1) - xResampled);
133 if (deltaX < std::numeric_limits<float>::epsilon())
134 throw pandora::StatusCodeException(pandora::STATUS_CODE_INVALID_PARAMETER);
137 const float densityDatumResampled((cumulativeDatumResampled - prevCumulativeData) / (
m_useWidths ? deltaX : 1.
f));
138 resampledProbabilityData.emplace_back(
140 prevCumulativeData = cumulativeDatumResampled;
143 const float xResampled(resamplingPoints.back());
146 if (deltaX < std::numeric_limits<float>::epsilon())
147 throw pandora::StatusCodeException(pandora::STATUS_CODE_INVALID_PARAMETER);
150 const float densityDatumResampled((cumulativeDatumResampled - prevCumulativeData) / (
m_useWidths ? deltaX : 1.
f));
151 resampledProbabilityData.emplace_back(
154 return resampledProbabilityData;
164 std::vector<unsigned int> randomisedElements(discreteProbabilityVector.
GetSize());
166 std::shuffle(
std::begin(randomisedElements),
std::end(randomisedElements), randomNumberGenerator);
168 float xPos(discreteProbabilityVector.
GetX(0));
169 float cumulativeProbability(0.
f);
170 for (
unsigned int iElement = 0; iElement < discreteProbabilityVector.
GetSize(); ++iElement)
172 const unsigned int randomElementIndex(randomisedElements.at(iElement));
173 const float deltaX(discreteProbabilityVector.
GetWidth(randomElementIndex));
175 cumulativeProbability += probabilityDensity * (
m_useWidths ? deltaX : 1.f);
176 randomisedProbabilityData.emplace_back(
181 return randomisedProbabilityData;
186 template <
typename TX,
typename TY>
189 const float deltaX(static_cast<float>(rhs.first) - static_cast<float>(lhs.first));
190 if (std::fabs(deltaX) < std::numeric_limits<float>::epsilon())
191 return (lhs.second < rhs.second);
193 return (lhs.first < rhs.first);
198 template <
typename TX,
typename TY>
201 if (2 > inputData.size())
202 throw pandora::StatusCodeException(pandora::STATUS_CODE_INVALID_PARAMETER);
204 float normalisation(0.
f);
206 for (
unsigned int iDatum = 0; iDatum < inputData.size() - 1; ++iDatum)
208 const float y(static_cast<float>(inputData.at(iDatum).second));
210 y * (
m_useWidths ?
static_cast<float>(inputData.at(iDatum + 1).first) - static_cast<float>(inputData.at(iDatum).first) : 1.
f);
212 const float y(static_cast<float>(inputData.back().second));
215 return normalisation;
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
std::vector< InputDatum< TX, TY >> InputData
float GetProbabilityDensity(const unsigned int index) const
Get the probability density value of the element in the vector.
void VerifyCompleteData() const
Verify the integrity of the complete probability vector.
float GetX(const unsigned int index) const
Get the x value of the element in the vector.
float EvaluateCumulativeProbability(const float x) const
Evaluate the cumulative probability at arbitrary x.
DiscreteProbabilityVector class.
DiscreteProbabilityData ResampleDiscreteProbabilityData(const DiscreteProbabilityVector &discreteProbabilityVector, const ResamplingPoints &resamplingPoints) const
Get a resampled probability data vector by resampling another probability data vector.
std::vector< DiscreteProbabilityDatum > DiscreteProbabilityData
float CalculateNormalisation(const InputData< TX, TY > &inputData) const
Calculate the probability normalisation.
DiscreteProbabilityData InitialiseDiscreteProbabilityData(InputData< TX, TY > inputData) const
Get a initialised probability data vector from the input data.
float GetWidth(const unsigned int index) const
Get the width of the element in the vectorr.
DiscreteProbabilityData RandomiseDiscreteProbabilityData(const DiscreteProbabilityVector &discreteProbabilityVector, std::mt19937 &randomNumberGenerator) const
Get a randomised probability data vector in which the x values are unchanged, the probability density...
static bool SortInputDataByX(const InputDatum< TX, TY > &lhs, const InputDatum< TX, TY > &rhs)
Sort the input data according to their x value.
InputData< float, float > AllFloatInputData
Header file for the lar discrete probability vector class.
DiscreteProbabilityVector(const InputData< TX, TY > &inputData, const TX xUpperBound, const bool useWidths)
Constructor.
DiscreteProbabilityData m_discreteProbabilityData
the probability data
float m_xUpperBound
the upper bound of the probability vector
bool m_useWidths
controls whether bin widths are used in calculations
DiscreteProbabilityData class.
unsigned int GetSize() const
Get the size of the probability vector.
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
std::pair< TX, TY > InputDatum
pandora::FloatVector ResamplingPoints