updates + tests
This commit is contained in:
parent
1144b80a46
commit
1555902fc4
13 changed files with 207 additions and 2 deletions
|
|
@ -7,6 +7,13 @@ import (
|
|||
util "github.com/wcharczuk/go-chart/util"
|
||||
)
|
||||
|
||||
// Interface Assertions.
|
||||
var (
|
||||
_ Series = (*LinearRegressionSeries)(nil)
|
||||
_ FirstValuesProvider = (*LinearRegressionSeries)(nil)
|
||||
_ LastValuesProvider = (*LinearRegressionSeries)(nil)
|
||||
)
|
||||
|
||||
// LinearRegressionSeries is a series that plots the n-nearest neighbors
|
||||
// linear regression for the values.
|
||||
type LinearRegressionSeries struct {
|
||||
|
|
@ -82,6 +89,19 @@ func (lrs *LinearRegressionSeries) GetValues(index int) (x, y float64) {
|
|||
return
|
||||
}
|
||||
|
||||
// GetFirstValues computes the first linear regression value.
|
||||
func (lrs *LinearRegressionSeries) GetFirstValues() (x, y float64) {
|
||||
if lrs.InnerSeries == nil || lrs.InnerSeries.Len() == 0 {
|
||||
return
|
||||
}
|
||||
if lrs.m == 0 && lrs.b == 0 {
|
||||
lrs.computeCoefficients()
|
||||
}
|
||||
x, y = lrs.InnerSeries.GetValues(0)
|
||||
y = (lrs.m * lrs.normalize(x)) + lrs.b
|
||||
return
|
||||
}
|
||||
|
||||
// GetLastValues computes the last linear regression value.
|
||||
func (lrs *LinearRegressionSeries) GetLastValues() (x, y float64) {
|
||||
if lrs.InnerSeries == nil || lrs.InnerSeries.Len() == 0 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue