11 #include <gsl/gsl_cdf.h>
14 using std::lower_bound;
15 using std::max_element;
17 using std::min_element;
22 : fNeedsSort(true), fPeriod(1.0), fTolerance(1.0)
42 rate =
fValues.size() / maximum;
52 ? (
unsigned int) (maximum /
fPeriod)
56 while( 1.0 -
pow(gsl_cdf_binomial_P(k, p, n), 1.0 +
fAdjustments.size())
76 vector<double>::const_iterator position
81 if (position ==
fValues.begin()) {
82 distance =
fValues.front() - value;
85 else if (position ==
fValues.end()) {
86 distance = value -
fValues.back();
90 double distanceBelow = value - *(position - 1);
91 double distanceAbove = *position - value;
92 distance =
min(distanceBelow, distanceAbove);
93 if (distanceBelow < distanceAbove) {
94 closestValue = *(position - 1);
97 closestValue = *position;
105 const double stepSize)
107 const double oldPeriod =
fPeriod;
108 double bestPeriod = oldPeriod;
113 while ( fabs(steps * stepSize) < uncertainty ) {
115 fPeriod = oldPeriod + steps * stepSize;
118 if (totalGoodness > bestTotalGoodness) {
119 bestTotalGoodness = totalGoodness;
134 unsigned int bestGoodness = 0;
136 for (vector<double>::const_iterator valueIter =
fValues.begin();
142 if (goodness > bestGoodness) {
143 bestGoodness = goodness;
155 for (vector<double>::const_iterator adjustmentIter =
fAdjustments.begin();
159 double adjustedValue = value + *adjustmentIter;
160 unsigned int goodnessWithAdjustment
163 if (goodnessWithAdjustment > goodness) {
164 goodness = goodnessWithAdjustment;
175 unsigned int goodness = 0;
179 double maximum = *( max_element(
fValues.begin(),
fValues.end()) );
180 double minimum = *( min_element(
fValues.begin(),
fValues.end()) );
182 double closestVal = 0;
184 for (
double val = value;
194 for (
double val = value -
fPeriod;
210 unsigned int totalGoodness = 0;
212 for (vector<double>::const_iterator valueIter =
fValues.begin();
220 return totalGoodness;
Diana::QComplex pow(const Diana::QComplex &z, double a)
Raise a complex number to a real power.
double min(const Diana::QVector &v)
Diana::QVector exp(const Diana::QVector &v)
std::vector< double > fValues
Time values.
double fPeriod
Period for repetition of values.
double DistanceToClosestElement(const double value, double &closestValue)
Computes distance from 'value' to closest element in fValues.
unsigned int GetGoodness(const double value)
Get goodness for a given time, using adjustments.
unsigned int fGoodnessThreshold
Goodness threshold at a certain false positive rate.
double fTolerance
Size of window in which to look for event.
QTimingAnalyzer()
Constructor.
unsigned int GetBestGoodness()
Get best goodness parameter for the values in fValues.
void ComputeGoodnessThreshold(const double falseRate)
Compute goodness threshold at given false positive rate.
unsigned int GetTotalGoodness()
Get total goodness for the values in fValues.
virtual ~QTimingAnalyzer()
Destructor.
void FindPeriod(const double uncertainty, const double stepSize=0.008)
Find period by searching within 'uncertainty' of fPeriod.
bool fNeedsSort
Whether or not vector could be out of order.
std::vector< double > fAdjustments
Adjustments.
unsigned int GetGoodnessParameter(const double value)
Get goodness for a given time value, no adjustments.