/// <summary> /// Adopts the data from source instance. /// </summary> /// <param name="source">The source instance.</param> public void Adopt(WeightedAvg source) { SumOfSamples = source.SumOfSamples; SumOfWeights = source.SumOfWeights; Result = source.Result; NumOfSamples = source.NumOfSamples; return; }
/// <summary> /// Adopts the source instance. /// </summary> /// <param name="source">Source instance</param> public void Adopt(WeightedAvg source) { _sumOfWeightedValues = source._sumOfWeightedValues; _sumOfWeights = source._sumOfWeights; _avg = source._avg; _numOfSamples = source._numOfSamples; return; }
/// <summary> /// Adopts the source instance. /// </summary> /// <param name="source">Source instance</param> public void Adopt(WeightedAvg source) { SumOfValues = source.SumOfValues; SumOfWeights = source.SumOfWeights; Avg = source.Avg; NumOfSamples = source.NumOfSamples; return; }
/// <summary> /// Returns weighted average /// </summary> /// <param name="weights">Weights to be used</param> /// <param name="latestFirst">Specifies logical order (latest..oldest or oldest..latest)</param> /// <param name="reqNumOfSamples">Number of requiered samples</param> public WeightedAvg GetWeightedAvg(double[] weights = null, bool latestFirst = false, int reqNumOfSamples = -1) { CheckReadyness(reqNumOfSamples); int numOfSamplesToBeProcessed = weights == null ? reqNumOfSamples == -1 ? _dataWindow.Count : reqNumOfSamples : Math.Min(weights.Length, reqNumOfSamples == -1 ? _dataWindow.Count : reqNumOfSamples); WeightedAvg wAvg = new WeightedAvg(); for (int i = 0; i < numOfSamplesToBeProcessed; i++) { wAvg.AddSampleValue(_dataWindow.GetElementAt(i, latestFirst), weights == null ? 1d : weights[i]); } return(wAvg); }
/// <summary> /// Computes the weighted average of the data currently stored in the window. /// </summary> /// <param name="weights">The weights.</param> public WeightedAvg GetDataWeightedAvg(double[] weights) { CheckReadyness(weights.Length); int numOfSamplesToBeProcessed = weights.Length; WeightedAvg wAvg = new WeightedAvg(); for (int i = numOfSamplesToBeProcessed - 1, j = 0; i >= 0; i--, j++) { wAvg.AddSample(_dataQueue.GetElementAt(i, true), weights[j]); } return(wAvg); }
/// <summary> /// Computes the linearly weighted average of the differences of the data in the window. /// </summary> /// <param name="reqNumOfSamples">The requiered mumber of samples (-1 means all).</param> public WeightedAvg GetDataDiffLinWeightedAvg(int reqNumOfSamples = -1) { int numOfSamplesToBeProcessed = reqNumOfSamples == -1 ? _dataQueue.Count : reqNumOfSamples; CheckReadyness(numOfSamplesToBeProcessed); WeightedAvg wAvg = new WeightedAvg(); for (int i = numOfSamplesToBeProcessed - 2, w = 1; i >= 0; i--, w++) { wAvg.AddSample(_dataQueue.GetElementAt(i, true) - _dataQueue.GetElementAt(i + 1, true)); } return(wAvg); }
/// <summary> /// The copy constructor. /// </summary> /// <param name="source">The source instance.</param> public WeightedAvg(WeightedAvg source) { Adopt(source); return; }