Adds a new sample to the moving average and returns the updated value.

@param newSample the new value to be added
@return Double indicating the updated moving average value after adding a new sample.
770567
public double addNewSample(double newSample) {
        final double sample = calculateLog(newSample);
        return Double.longBitsToDouble(valueEncodedAsLong.updateAndGet(value -> {
            return Double.doubleToRawLongBits(sample * newSampleWeight + (1.0 - newSampleWeight) * Double.longBitsToDouble(value));
        }));
    }
1097396
func NewSample(jobCount int, msgSize int, start, end time.Time, nc *nats.Conn) *Sample {
	s := Sample{JobMsgCnt: jobCount, Start: start, End: end}
	s.MsgBytes = uint64(msgSize * jobCount)
	s.MsgCnt = nc.OutMsgs + nc.InMsgs
	s.IOBytes = nc.OutBytes + nc.InBytes
	return &s
}
657419
public float[] calculate(float pSample[])
	{
		final int wAps = pSample.length / ss;
		int n2 = ss2;
//		int nu1 = nu - 1;
		int a = 0;

		for (int b=0; a<pSample.length; b++)
		{
			xre[b] = (long)(pSample[a]*FRAC_FAC);
			xim[b] = 0;
			a += wAps;
		}

		int x = 0;
		for (int l=1; l<=nu; l++)
		{
			for (int k=0; k<ss; k+=n2)
			{
				for (int i=1; i<=n2; i++)
				{
					final long c = fftCos[x];
					final long s = fftSin[x];
					final int kn2 = k + n2;
					final long tr = (xre[kn2]*c + xim[kn2]*s)>>FRAC_BITS;
					final long ti = (xim[kn2]*c - xre[kn2]*s)>>FRAC_BITS;
					xre[kn2] = xre[k] - tr;
					xim[kn2] = xim[k] - ti;
					xre[k] += tr;
					xim[k] += ti;
					k++;
					x++;
				}

			}

//			nu1--;
			n2 >>= 1;
		}

		for (int k=0; k<ss; k++)
		{
			final int r = fftBr[k];
			if (r > k)
			{
				final long tr = xre[k];
				final long ti = xim[k];
				xre[k] = xre[r];
				xim[k] = xim[r];
				xre[r] = tr;
				xim[r] = ti;
			}
		}

		mag[0] = ((float)((longSqrt(xre[0]*xre[0] + xim[0]*xim[0]))>>FRAC_BITS)) / ((float)ss);
		for (int i=1; i<ss2; i++)
			mag[i] = ((float)((longSqrt(xre[i]*xre[i] + xim[i]*xim[i])<<1)>>FRAC_BITS)) / ((float)ss);

		return mag;
	}
150985
public synchronized void update(double sample) {
        long now = System.currentTimeMillis();

        removeOutOfTimeWindowEntries();
        cslm.put(now, sample);
    }
642257
public static Sample ofTimeDouble(long time, double numericValue) {
        return new Sample(time, null, null, null)
                .setNumericValueFromDouble(numericValue);
    }
88754
void addSample(StopwatchSample sample) {
		total += sample.getTotal();
		counter += sample.getCounter();

		if (min > sample.getMin()) {
			min = sample.getMin();
			minTimestamp = sample.getMinTimestamp();
		}

		if (max < sample.getMax()) {
			max = sample.getMax();
			maxTimestamp = sample.getMaxTimestamp();
		}

		active += sample.getActive();

		if (maxActive < sample.getMaxActive()) {
			maxActive = sample.getMaxActive();
			maxActiveTimestamp = sample.getMaxActiveTimestamp();
		}
	}
1018093
private <S> void printSamples(final S referenceSample,
      final S predictedSample) {
    final String details = "Expected: {\n" + referenceSample
        + "}\nPredicted: {\n" + predictedSample + "}";
    this.printStream.println(details);
  }
1023434
public boolean sendSample(SampleMessage sampleMessage) {
    if (!this.canSendSamples) {
      log.warn("Cannot send samples.");
      return false;
    }

    if (this.session.getScheduledWriteMessages() > this.maxOutstandingSamples) {
      log.warn("Buffer full, cannot send sample.");
      return false;
    }
    this.session.write(sampleMessage);
    return true;
  }
94749
@Override
    public void generateSample(double value, String label) {
        PerfMonSampleResult res = new PerfMonSampleResult();
        res.setSampleLabel(label);
        res.setValue(value);
        res.setSuccessful(true);
        SampleEvent e = new SampleEvent(res, PERFMON);
        super.sampleOccurred(e);
    }
786542
def average(old_avg, current_value, count):
    
    if old_avg is None:
        return current_value
    return (float(old_avg) * count + current_value) / (count + 1)
862370
public static SamplingResult getSamplingResult(final Relation<?> rel) {
    Collection<SamplingResult> selections = ResultUtil.filterResults(rel.getHierarchy(), rel, SamplingResult.class);
    if(selections.isEmpty()) {
      final SamplingResult newsam = new SamplingResult(rel);
      ResultUtil.addChildResult(rel, newsam);
      return newsam;
    }
    return selections.iterator().next();
  }
688850
public Timecode addPrecise(SampleCount samples) throws ResamplingException
	{
		final SampleCount mySamples = getSampleCount();
		final SampleCount totalSamples = mySamples.addPrecise(samples);

		return TimecodeBuilder.fromSamples(totalSamples, dropFrame).build();
	}
711838
public void add(double x)
    {
        if (Double.isNaN(mean))//fist case
        {
            mean = x;
            variance = 0;
        }
        else//general case
        {
            //first update stnd deviation 
            variance = (1-smoothing)*(variance + smoothing*Math.pow(x-mean, 2));
            mean = (1-smoothing)*mean + smoothing*x;
        }
                    
    }
1118266
public UpdatableSketchBuilder<U, S> setSamplingProbability(final float samplingProbability) {
    if ((samplingProbability < 0) || (samplingProbability > 1f)) {
      throw new SketchesArgumentException("sampling probability must be between 0 and 1");
    }
    samplingProbability_ = samplingProbability;
    return this;
  }
1268263
public static double covariance(TransposeDataList transposeDataList, boolean isSample) {
        if(transposeDataList.size()!=2) {
            throw new IllegalArgumentException("The collection must contain observations from 2 groups.");
        }
        
        double covariance = 0.0;
        
        Object[] keys = transposeDataList.keySet().toArray();
        Object keyX = keys[0];
        Object keyY = keys[1];
        
        FlatDataCollection flatDataCollectionX = transposeDataList.get(keyX).toFlatDataCollection();
        FlatDataCollection flatDataCollectionY = transposeDataList.get(keyY).toFlatDataCollection();
        
        int n = flatDataCollectionX.size();
        if(n<=1 || n!=flatDataCollectionY.size()) {
            throw new IllegalArgumentException("The number of observations in each group must be equal and larger than 1.");
        }
        
        double meanX = mean(flatDataCollectionX);
        double meanY = mean(flatDataCollectionY);
        
        Iterator<Double> iteratorX = flatDataCollectionX.iteratorDouble();
        Iterator<Double> iteratorY = flatDataCollectionY.iteratorDouble();
        while (iteratorX.hasNext() && iteratorY.hasNext()) {
            covariance+=(iteratorX.next()-meanX)*
                        (iteratorY.next()-meanY);
        }
        
        if(isSample) {
            covariance/=(n-1.0);
        }
        else {
            covariance/=n;
        }
        
        return covariance;
    }
1271477
public static double variance(FlatDataCollection flatDataCollection, boolean isSample) {
        /* Uses the formal Variance = E(X^2) - mean^2 */
        int n = 0;
        double mean = 0.0;
        double squaredMean = 0.0;
        Iterator<Double> it = flatDataCollection.iteratorDouble();
        while(it.hasNext()) {
            Double v = it.next();
            if(v != null) {
                ++n;
                mean+=v;
                squaredMean+=v*v;
            }
        }

        if(n<=1) {
            throw new IllegalArgumentException("The provided collection must have more than 1 elements.");
        }
        
        mean/=n;
        squaredMean/=n;
        
        double variance = squaredMean - mean*mean;
        
        /* Unbiased for sample */
        if(isSample) {
            variance*=n/(n-1.0);
        }
        
        return variance;
    }
1107342
public final void sample()
  {
    synchronized (_lock) {
      long count = _totalCount.get();
      long lastCount = _lastAvgTotalCount;
      _lastAvgTotalCount = count;

      long sum = _sum.get();
      double lastSum = _lastAvgSum;
      _lastAvgSum = sum;

      if (count == lastCount) {
        _avg =  0;
      }
      else {
        _avg = _scale * (sum - lastSum) / (double) (count - lastCount);
      }
    }
  }