polyfit

package
v0.0.0-...-2bcc11b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 8, 2024 License: GPL-3.0 Imports: 3 Imported by: 0

README

This copy is exported from https://github.com/openacid/slim/releases/tag/v0.5.9

After v0.5.9 polyfit module is removed from github.com/openacid/slim

Documentation

Overview

Package polyfit models a polynomial y from sample points xs and ys, to minimizes the squared residuals.

See https://en.wikipedia.org/wiki/Least_squares#Linear_least_squares

Since 0.5.4

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Fitting

type Fitting struct {
	N      int
	Degree int
	// contains filtered or unexported fields
}

Fitting models a polynomial y from sample points xs and ys, to minimizes the squared residuals. It returns coefficients of the polynomial y:

y = β₁ + β₂x + β₃x² + ...

It use linear regression, which assumes y is in form of:

    m
y = ∑ βⱼ Φⱼ(x)
    j=1

In our case:

Φⱼ(x) = x^(j-1)

Then

(Xᵀ × X) βⱼ = Xᵀ × Y
Xᵢⱼ = [ Φⱼ(xᵢ) ]

See https://en.wikipedia.org/wiki/Least_squares#Linear_least_squares

Since 0.5.4

func NewFitting

func NewFitting(xs, ys []float64, degree int) *Fitting

NewFitting creates a new polynomial fitting context.

Since 0.5.4

func (*Fitting) Add

func (f *Fitting) Add(x, y float64)

Add a point(x, y) into this fitting.

Since 0.5.4

func (*Fitting) Merge

func (f *Fitting) Merge(b *Fitting)

Merge Combines two sets of sample data.

This can be done because:

|X₁|ᵀ × |X₁| = X₁ᵀ × X₁ + X₂ᵀ × X₂
|X₂|    |X₂|

Since 0.5.4

func (*Fitting) Solve

func (f *Fitting) Solve(minimizeDegree bool) []float64

Solve the equation and returns coefficients of result polynomial. The number of coefficients is f.Degree + 1.

Since 0.5.4

func (*Fitting) String

func (f *Fitting) String() string

String prints human readable info of a fitting. It includes: n: the number of points. degree: expected degree of polynomial. and two matrix.

Since 0.5.4

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL