wcharczuk/go-chart · linear_regression_series.go
go logo
func (lrs *LinearRegressionSeries) GetFirstValues() (x, y float64) {
	if lrs.InnerSeries == nil || lrs.InnerSeries.Len() == 0 {
		return
	}
	if lrs.IsZero() {
		lrs.computeCoefficients()
	}
	x, y = lrs.InnerSeries.GetValues(0)
	y = (lrs.m * lrs.normalize(x)) + lrs.b
	return
}
Similar code snippets
1.
wcharczuk/go-chart · linear_regression_series.go
Match rating: 82.08% · See similar code snippets
go logo
func (lrs *LinearRegressionSeries) GetValues(index int) (x, y float64) {
	if lrs.InnerSeries == nil || lrs.InnerSeries.Len() == 0 {
		return
	}
	if lrs.IsZero() {
		lrs.computeCoefficients()
	}
	offset := lrs.GetOffset()
	effectiveIndex := util.Math.MinInt(index+offset, lrs.InnerSeries.Len())
	x, y = lrs.InnerSeries.GetValues(effectiveIndex)
	y = (lrs.m * lrs.normalize(x)) + lrs.b
	return
}
2.
wcharczuk/go-chart · linear_regression_series.go
Match rating: 81.99% · See similar code snippets
go logo
func (lrs *LinearRegressionSeries) GetLastValues() (x, y float64) {
	if lrs.InnerSeries == nil || lrs.InnerSeries.Len() == 0 {
		return
	}
	if lrs.IsZero() {
		lrs.computeCoefficients()
	}
	endIndex := lrs.GetEndIndex()
	x, y = lrs.InnerSeries.GetValues(endIndex)
	y = (lrs.m * lrs.normalize(x)) + lrs.b
	return
}
3.
wcharczuk/go-chart · linear_regression_series.go
Match rating: 68.4% · See similar code snippets
go logo
func (lrs LinearRegressionSeries) Len() int {
	return util.Math.MinInt(lrs.GetLimit(), lrs.InnerSeries.Len()-lrs.GetOffset())
}
4.
wcharczuk/go-chart · linear_regression_series.go
Match rating: 66.88% · See similar code snippets
go logo
func (lrs LinearRegressionSeries) GetLimit() int {
	if lrs.Limit == 0 {
		return lrs.InnerSeries.Len()
	}
	return lrs.Limit
}
5.
wcharczuk/go-chart · linear_regression_series.go
Match rating: 66.21% · See similar code snippets
go logo
func (lrs LinearRegressionSeries) GetEndIndex() int {
	windowEnd := lrs.GetOffset() + lrs.GetLimit()
	innerSeriesLastIndex := lrs.InnerSeries.Len() - 1
	return util.Math.MinInt(windowEnd, innerSeriesLastIndex)
}
6.
wcharczuk/go-chart · linear_regression_series.go
Match rating: 64.0% · See similar code snippets
go logo
func (lrs *LinearRegressionSeries) Validate() error {
	if lrs.InnerSeries == nil {
		return fmt.Errorf("linear regression series requires InnerSeries to be set")
	}
	return nil
}
7.
wcharczuk/go-chart · polynomial_regression_series.go
Match rating: 59.51% · See similar code snippets
go logo
func (prs *PolynomialRegressionSeries) GetFirstValues() (x, y float64) {
	if prs.InnerSeries == nil || prs.InnerSeries.Len() == 0 {
		return
	}
	if prs.coeffs == nil {
		coeffs, err := prs.computeCoefficients()
		if err != nil {
			panic(err)
		}
		prs.coeffs = coeffs
	}
	x, y = prs.InnerSeries.GetValues(0)
	y = prs.apply(x)
	return
}
8.
wcharczuk/go-chart · linear_regression_series.go
Match rating: 58.82% · See similar code snippets
go logo
func (lrs *LinearRegressionSeries) computeCoefficients() {
	startIndex := lrs.GetOffset()
	endIndex := lrs.GetEndIndex()

	p := float64(endIndex - startIndex)

	xvalues := seq.NewBufferWithCapacity(lrs.Len())
	for index := startIndex; index < endIndex; index++ {
		x, _ := lrs.InnerSeries.GetValues(index)
		xvalues.Enqueue(x)
	}

	lrs.avgx = seq.Seq{Provider: xvalues}.Average()
	lrs.stddevx = seq.Seq{Provider: xvalues}.StdDev()

	var sumx, sumy, sumxx, sumxy float64
	for index := startIndex; index < endIndex; index++ {
		x, y := lrs.InnerSeries.GetValues(index)

		x = lrs.normalize(x)

		sumx += x
		sumy += y
		sumxx += x * x
		sumxy += x * y
	}

	lrs.m = (p*sumxy - sumx*sumy) / (p*sumxx - sumx*sumx)
	lrs.b = (sumy / p) - (lrs.m * sumx / p)
}
9.
wcharczuk/go-chart · linear_series.go
Match rating: 53.44% · See similar code snippets
go logo
func (ls LinearSeries) Validate() error {
	if ls.InnerSeries == nil {
		return fmt.Errorf("linear regression series requires InnerSeries to be set")
	}
	return nil
}
10.
wcharczuk/go-chart · macd_series.go
Match rating: 50.48% · See similar code snippets
go logo
func (macd MACDSeries) Len() int {
	if macd.InnerSeries == nil {
		return 0
	}

	return macd.InnerSeries.Len()
}