// WAbsdevMean calculates the weighted absolute deviation of a dataset
196789
func WAbsdevMean(w, data Interface, wmean float64) (wabsdev float64) {

	var W float64
	Len := data.Len()

	// calculate the sum of the absolute deviations
	for i := 0; i < Len; i++ {
		wi := w.Get(i)

		if wi > 0 {
			delta := math.Abs(data.Get(i) - wmean)
			W += wi
			wabsdev += (delta - wabsdev) * (wi / W)
		}
	}

	return
}
616853
func MedianAbsoluteDeviationPopulation(input Float64Data) (mad float64, err error) {
	if input.Len() == 0 {
		return math.NaN(), EmptyInputErr
	}

	i := copyslice(input)
	m, _ := Median(i)

	for key, value := range i {
		i[key] = math.Abs(value - m)
	}

	return Median(i)
}
1347906
func (sg *SampleGroup) StdDev() float64 {
	avg := float64(sg.AvgRate())
	sum := float64(0)
	for _, c := range sg.Samples {
		sum += math.Pow(float64(c.Rate())-avg, 2)
	}
	variance := sum / float64(len(sg.Samples))
	return math.Sqrt(variance)
}
490842
func (t *Template) GetAllAWSDocDBDBClusterResources() map[string]*resources.AWSDocDBDBCluster {
	results := map[string]*resources.AWSDocDBDBCluster{}
	for name, untyped := range t.Resources {
		switch resource := untyped.(type) {
		case *resources.AWSDocDBDBCluster:
			results[name] = resource
		}
	}
	return results
}
1059969
func (d *DefaultMetricCollector) FallbackFailures() *rolling.Number {
	d.mutex.RLock()
	defer d.mutex.RUnlock()
	return d.fallbackFailures
}
1141365
func AppendMeasure(b []byte, t time.Time, m stats.Measure) []byte {
	b = append(b, m.Name...)

	for _, tag := range m.Tags {
		b = append(b, ',')
		b = append(b, tag.Name...)
		b = append(b, '=')
		b = append(b, tag.Value...)
	}

	for i, field := range m.Fields {
		if len(field.Name) == 0 {
			field.Name = "value"
		}

		if i == 0 {
			b = append(b, ' ')
		} else {
			b = append(b, ',')
		}

		b = append(b, field.Name...)
		b = append(b, '=')

		switch v := field.Value; v.Type() {
		case stats.Null:
		case stats.Bool:
			if v.Bool() {
				b = append(b, "true"...)
			} else {
				b = append(b, "false"...)
			}
		case stats.Int:
			b = strconv.AppendInt(b, v.Int(), 10)
		case stats.Uint:
			b = strconv.AppendUint(b, v.Uint(), 10)
		case stats.Float:
			b = strconv.AppendFloat(b, v.Float(), 'g', -1, 64)
		case stats.Duration:
			b = strconv.AppendFloat(b, v.Duration().Seconds(), 'g', -1, 64)
		}
	}

	b = append(b, ' ')
	b = strconv.AppendInt(b, t.UnixNano(), 10)

	return append(b, '\n')
}
260511
func (t *Template) GetAllAWSDAXSubnetGroupResources() map[string]*resources.AWSDAXSubnetGroup {
	results := map[string]*resources.AWSDAXSubnetGroup{}
	for name, untyped := range t.Resources {
		switch resource := untyped.(type) {
		case *resources.AWSDAXSubnetGroup:
			results[name] = resource
		}
	}
	return results
}
987936
func StandardDeviationPopulation(input Float64Data) (sdev float64, err error) {

	if input.Len() == 0 {
		return math.NaN(), EmptyInputErr
	}

	// Get the population variance
	vp, _ := PopulationVariance(input)

	// Return the population standard deviation
	return math.Pow(vp, 0.5), nil
}
309118
func (e FAbsolute) Stats() []string {
	ret := make([]string, 0, len(e.Values))
	for _, v := range e.Values {
		ret = append(ret, fmt.Sprintf("%s:%g|a", e.Name, v))
	}
	return ret
}
458654
func AppendMeasure(b []byte, m stats.Measure) []byte {
	return AppendMeasureFiltered(b, m, nil)
}
142793
func GeoMean(xs []float64) float64 {
	if len(xs) == 0 {
		return math.NaN()
	}
	m := 0.0
	for i, x := range xs {
		if x <= 0 {
			return math.NaN()
		}
		lx := math.Log(x)
		m += (lx - m) / float64(i+1)
	}
	return math.Exp(m)
}
960132
func (m *JSONMetricRecorder) IsDeclaredMetric(key string) bool {
	_, ok := m.validMetrics[key]
	return ok
}
1078597
func (m *StandardMeter) RateMean() float64 {
	m.lock.RLock()
	rateMean := m.snapshot.rateMean
	m.lock.RUnlock()
	return rateMean
}
1106448
func WeakDistribute(input SimpleOutChannel, outputs ...SimpleInChannel) {
	if len(outputs) == 0 {
		panic("channels: WeakDistribute requires at least one output")
	}
	go distribute(input, outputs, false)
}
811653
func TssMean(data Interface, mean float64) (res float64) {

	// find the sum of the squares
	n := data.Len()
	for i := 0; i < n; i++ {
		delta := data.Get(i) - mean
		res += delta * delta
	}

	return
}
1105664
func (s Sample) Mean() float64 {
	if len(s.Xs) == 0 || s.Weights == nil {
		return Mean(s.Xs)
	}

	m, wsum := 0.0, 0.0
	for i, x := range s.Xs {
		// Use weighted incremental mean:
		//   m_i = (1 - w_i/wsum_i) * m_(i-1) + (w_i/wsum_i) * x_i
		//       = m_(i-1) + (x_i - m_(i-1)) * (w_i/wsum_i)
		w := s.Weights[i]
		wsum += w
		m += (x - m) * w / wsum
	}
	return m
}
550400
func (b *BoltBackend) CompareAndSwapVal(bucket []string, key string, newData []byte, prevData []byte, ttl time.Duration) error {
	if len(prevData) == 0 {
		return trace.BadParameter("missing prevData parameter, to atomically create item, use CreateVal method")
	}
	v := &kv{
		Created: b.clock.Now().UTC(),
		Value:   newData,
		TTL:     ttl,
	}
	newEncodedData, err := json.Marshal(v)
	if err != nil {
		return trace.Wrap(err)
	}
	err = b.db.Update(func(tx *bolt.Tx) error {
		bkt, err := GetBucket(tx, bucket)
		if err != nil {
			if trace.IsNotFound(err) {
				return trace.CompareFailed("key %q is not found", key)
			}
			return trace.Wrap(err)
		}
		currentData := bkt.Get([]byte(key))
		if currentData == nil {
			_, err := GetBucket(tx, append(bucket, key))
			if err == nil {
				return trace.BadParameter("key %q is a bucket", key)
			}
			return trace.CompareFailed("%v %v is not found", bucket, key)
		}
		var currentVal kv
		if err := json.Unmarshal(currentData, &currentVal); err != nil {
			return trace.Wrap(err)
		}
		if bytes.Compare(prevData, currentVal.Value) != 0 {
			return trace.CompareFailed("%q is not matching expected value", key)
		}
		return boltErr(bkt.Put([]byte(key), newEncodedData))
	})
	return trace.Wrap(err)
}