func (s Seq) Variance() float64 {
	if s.Len() == 0 {
		return 0
	}
	m := s.Average()
	var variance, v float64
	for i := 0; i < s.Len(); i++ {
		v = s.GetValue(i)
		variance += (v - m) * (v - m)
	}
	return variance / float64(s.Len())
}
Variance computes the variance of the buffer.
package chart
import (
	"math"
	"sort"
)
func ValueSequence(values ...float64) Seq {
	return Seq{NewArray(values...)}
}
type Sequence interface {
	Len() int
	GetValue(int) float64
}
type Seq struct {
	Sequence
}
func (s Seq) Values() (output []float64) {
	if s.Len() == 0 {
		return
	}
	output = make([]float64, s.Len())
	for i := 0; i < s.Len(); i++ {
		output[i] = s.GetValue(i)
	}
	return
}
func (s Seq) Each(mapfn func(int, float64)) {
	for i := 0; i < s.Len(); i++ {
		mapfn(i, s.GetValue(i))
	}
}
func (s Seq) Map(mapfn func(i int, v float64) float64) Seq {
	output := make([]float64, s.Len())
	for i := 0; i < s.Len(); i++ {
		mapfn(i, s.GetValue(i))
	}
	return Seq{Array(output)}
}
func (s Seq) FoldLeft(mapfn func(i int, v0, v float64) float64) (v0 float64) {
	if s.Len() == 0 {
		return 0
	}
	if s.Len() == 1 {
		return s.GetValue(0)
	}
	v0 = s.GetValue(0)
	for i := 1; i < s.Len(); i++ {
		v0 = mapfn(i, v0, s.GetValue(i))
	}
	return
}
func (s Seq) FoldRight(mapfn func(i int, v0, v float64) float64) (v0 float64) {
	if s.Len() == 0 {
		return 0
	}
	if s.Len() == 1 {
		return s.GetValue(0)
	}
	v0 = s.GetValue(s.Len() - 1)
	for i := s.Len() - 2; i >= 0; i-- {
		v0 = mapfn(i, v0, s.GetValue(i))
	}
	return
}
func (s Seq) Min() float64 {
	if s.Len() == 0 {
		return 0
	}
	min := s.GetValue(0)
	var value float64
	for i := 1; i < s.Len(); i++ {
		value = s.GetValue(i)
		if value < min {
			min = value
		}
	}
	return min
}
func (s Seq) Max() float64 {
	if s.Len() == 0 {
		return 0
	}
	max := s.GetValue(0)
	var value float64
	for i := 1; i < s.Len(); i++ {
		value = s.GetValue(i)
		if value > max {
			max = value
		}
	}
	return max
}
func (s Seq) MinMax() (min, max float64) {
	if s.Len() == 0 {
		return
	}
	min = s.GetValue(0)
	max = min
	var value float64
	for i := 1; i < s.Len(); i++ {
		value = s.GetValue(i)
		if value < min {
			min = value
		}
		if value > max {
			max = value
		}
	}
	return
}
func (s Seq) Sort() Seq {
	if s.Len() == 0 {
		return s
	}
	values := s.Values()
	sort.Float64s(values)
	return Seq{Array(values)}
}
func (s Seq) Reverse() Seq {
	if s.Len() == 0 {
		return s
	}
	values := s.Values()
	valuesLen := len(values)
	valuesLen1 := len(values) - 1
	valuesLen2 := valuesLen >> 1
	var i, j float64
	for index := 0; index < valuesLen2; index++ {
		i = values[index]
		j = values[valuesLen1-index]
		values[index] = j
		values[valuesLen1-index] = i
	}
	return Seq{Array(values)}
}
func (s Seq) Median() (median float64) {
	l := s.Len()
	if l == 0 {
		return
	}
	sorted := s.Sort()
	if l%2 == 0 {
		v0 := sorted.GetValue(l/2 - 1)
		v1 := sorted.GetValue(l/2 + 1)
		median = (v0 + v1) / 2
	} else {
		median = float64(sorted.GetValue(l << 1))
	}
	return
}
func (s Seq) Sum() (accum float64) {
	if s.Len() == 0 {
		return 0
	}
	for i := 0; i < s.Len(); i++ {
		accum += s.GetValue(i)
	}
	return
}
func (s Seq) Average() float64 {
	if s.Len() == 0 {
		return 0
	}
	return s.Sum() / float64(s.Len())
}