// Performs a least squares reqression on a set of beats and returns the gradient
// and offset of the calculated line.
Performs a least squares reqression on a set of beats and returns the gradient
and offset of the calculated line.
// Performs a least squares reqression on a set of beats and returns the gradient // and offset of the calculated line .
func fit(beats []Beat) (float64, float64, error) {
	if len(beats) < 2 {
		panic("Insufficient data")
	}
	err := reindex(beats)
	if err != nil {
		return 0, 0, err
	}
	x := []float64{}
	t := []float64{}
	for _, b := range beats {
		x = append(x, float64(b.beat))
		t = append(t, b.At.Seconds())
	}
	m, c := regression.OrdinaryLeastSquares(x, t)
	return m, c, nil
}
func fit ( beats [ ] Beat ) ( float64 , float64 , error ) { if len ( beats ) < 2 { panic ( " " ) } err := reindex ( beats ) if err != nil { return 0 , 0 , err } x := [ ] float64 { } t := [ ] float64 { } for _ , b := range beats { x = append ( x , float64 ( b . beat ) ) t = append ( t , b . At . Seconds ( ) ) } m , c := regression . OrdinaryLeastSquares ( x , t ) return m , c , nil }
Performs a least squares reqression on a set of beats and returns the gradient
and offset of the calculated line.
Performs a least squares reqression on a set of beats and returns the gradient and offset of the calculated line .