From: Miroslav Lichvar Date: Wed, 21 Jun 2017 15:48:26 +0000 (+0200) Subject: sourcestats: include precision in weight calculation X-Git-Tag: 3.2-pre1~47 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7fb7f95979de6ab90557478e89fa74e9fc15fce3;p=thirdparty%2Fchrony.git sourcestats: include precision in weight calculation In order to stabilize the weights of refclock samples which have only slightly different distances, don't allow the stddev value used in the weight calculation to be smaller than the precision and also assign weight of 1 to all samples which have distance < minimum + precision. --- diff --git a/sourcestats.c b/sourcestats.c index d8d42462..a18b8b25 100644 --- a/sourcestats.c +++ b/sourcestats.c @@ -51,9 +51,6 @@ #define MIN_SKEW 1.0e-12 #define MAX_SKEW 1.0e+02 -/* The minimum assumed std dev for weighting */ -#define MIN_WEIGHT_SD 1.0e-9 - /* The asymmetry of network jitter when all jitter is in one direction */ #define MAX_ASYMMETRY 0.5 @@ -489,6 +486,7 @@ SST_DoNewRegression(SST_Stats inst) double min_distance, mean_distance; double sd_weight, sd; double old_skew, old_freq, stress; + double precision; convert_to_intervals(inst, times_back + inst->runs_samples); @@ -510,11 +508,15 @@ SST_DoNewRegression(SST_Stats inst) /* And now, work out the weight vector */ - sd = mean_distance - min_distance; - sd = CLAMP(MIN_WEIGHT_SD, sd, min_distance); + precision = LCL_GetSysPrecisionAsQuantum(); + sd = (mean_distance - min_distance) / SD_TO_DIST_RATIO; + sd = CLAMP(precision, sd, min_distance); + min_distance += precision; for (i=0; in_samples; i++) { - sd_weight = 1.0 + SD_TO_DIST_RATIO * (peer_distances[i] - min_distance) / sd; + sd_weight = 1.0; + if (peer_distances[i] > min_distance) + sd_weight += (peer_distances[i] - min_distance) / sd; weights[i] = sd_weight * sd_weight; } }