updates + tests
This commit is contained in:
parent
1144b80a46
commit
1555902fc4
13 changed files with 207 additions and 2 deletions
|
|
@ -8,6 +8,13 @@ import (
|
|||
util "github.com/wcharczuk/go-chart/util"
|
||||
)
|
||||
|
||||
// Interface Assertions.
|
||||
var (
|
||||
_ Series = (*PolynomialRegressionSeries)(nil)
|
||||
_ FirstValuesProvider = (*PolynomialRegressionSeries)(nil)
|
||||
_ LastValuesProvider = (*PolynomialRegressionSeries)(nil)
|
||||
)
|
||||
|
||||
// PolynomialRegressionSeries implements a polynomial regression over a given
|
||||
// inner series.
|
||||
type PolynomialRegressionSeries struct {
|
||||
|
|
@ -101,6 +108,23 @@ func (prs *PolynomialRegressionSeries) GetValues(index int) (x, y float64) {
|
|||
return
|
||||
}
|
||||
|
||||
// GetFirstValues computes the first poly regression value.
|
||||
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
|
||||
}
|
||||
|
||||
// GetLastValues computes the last poly regression value.
|
||||
func (prs *PolynomialRegressionSeries) GetLastValues() (x, y float64) {
|
||||
if prs.InnerSeries == nil || prs.InnerSeries.Len() == 0 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue