Exemple #1
0
 /// <summary>
 /// Tests if two objects are equal within given relative epsilon.
 /// </summary>
 /// <param name="epsilon">maximum allowed relative error (e.g. 0.01 for 1% accurancy)</param>
 /// <returns>True if two objects are equal; false otherwise.</returns>
 public bool NearlyEquals(StatisticsTSLock other, double epsilon = EDouble.RELATIVE_EPSILON)
 {
     if (other == null)
     {
         return(false);
     }
     lock (this._lock)
         lock (other._lock)
             return(this._count == other._count &&
                    this._mean.NearlyEquals(other._mean, epsilon) &&
                    this.q.NearlyEquals(other.q, epsilon) &&
                    this._min == other._min &&
                    this._max == other._max);
 }
Exemple #2
0
 public StatisticsTSLock(StatisticsTSLock initialValue)
 {
     if (initialValue == null)
     {
         throw new ArgumentNullException("initialValue");
     }
     lock (initialValue._lock)
     {
         this._count = initialValue._count;
         this._mean  = initialValue._mean;
         this.q      = initialValue.q;
         this._min   = initialValue._min;
         this._max   = initialValue._max;
     }
 }
Exemple #3
0
 public void Add(StatisticsTSLock value)
 {
     if (value == null)
     {
         throw new ArgumentNullException("value");
     }
     lock (this._lock)
     {
         if (value == this)
         {
             value = value.Clone();
         }
         var prevCount = this._count;
         var prevMean  = this._mean;
         this._count += value._count;
         this._mean  += (value._mean - this._mean) * value._count / this._count;
         // first add standard deviation given by difference between
         // means of two object (it will be zero if the objects
         // has the same mean)
         this.q += value._count * (value._mean - prevMean) * (value._mean - this._mean);
         // then simply add the standard deviation of other object
         // (this won't change the resulting standard deviation if the
         // two objects previously had the same standard deviation)
         this.q += value.q;
         this._standardDeviation       = null;
         this._sampleStandardDeviation = null;
         if (value._min < this._min)
         {
             this._min = value._min;
         }
         if (this._max < value._max)
         {
             this._max = value._max;
         }
     }
 }