示例#1
0
func (m *MADer) Float64() float64 {
	if len(m.el) == 0 {
		return 0.0
	}
	med := m.Medianer.Float64()
	abs := make([]bisect.Elem, 0, len(m.el))
	for _, e := range m.el {
		abs = bisect.Insort(abs, mEl(math.Abs(float64(e.(mEl))-med)))
	}
	var mad float64
	if len(abs)%2 == 0 {
		mad = (float64(abs[len(abs)/2].(mEl)) + float64(abs[len(abs)/2-1].(mEl))) / 2.0
	} else {
		mad = float64(abs[len(abs)/2].(mEl))
	}
	return mad
}
示例#2
0
func (m *Medianer) Aggregate(value []byte) {
	var f, _ = strconv.ParseFloat(string(value), 64)
	m.el = bisect.Insort(m.el, mEl(f))
}