regression

package
v0.0.0-...-000f34f Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2018 License: MPL-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package regression provides linear transformation functions.

Package regression provides linear transformation functions.

Package regression provides linear transformation functions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewPlot

func NewPlot(ps PlotSettings) (*plot.Plot, error)

NewPlot -

func PlotRegression

func PlotRegression(x []float64, ys [][]float64, f func(float64) float64, r2, sDev float64, ps PlotSettings) error

PlotRegression -

func PlotTimeData

func PlotTimeData(x []float64, ys [][]float64, ps PlotSettings) error

PlotTimeData -

func PolynomialRegression

func PolynomialRegression(m int, x, y []float64) (*mat.Dense, error)

PolynomialRegression - Least Squares Polynomial Regression Returns A and B matrix based on the given polynomial degree. m: polynomial degree n: number of points When m = 2:

                             A = B
   (n)a₀ +  (∑xᵢ)a₁ + (∑xᵢ²)a₂ = ∑yᵢ
 (∑xᵢ)a₀ + (∑xᵢ²)a₁ + (∑xᵢ³)a₂ = ∑xᵢyᵢ
(∑xᵢ²)a₀ + (∑xᵢ³)a₁ + (∑xᵢ⁴)a₂ = ∑xᵢ²yᵢ

Types

type BOverX

type BOverX struct{}

BOverX - Provides the transformation functions that satisfy:

y = a + b / (1 + x)

to:

y = a + b * 1 / (1 + x)

func (*BOverX) FRestoreA

func (*BOverX) FRestoreA(at float64) (a float64)

FRestoreA - function to restore A

func (*BOverX) FRestoreB

func (*BOverX) FRestoreB(bt float64) (b float64)

FRestoreB - function to restore B

func (*BOverX) FTransformX

func (*BOverX) FTransformX(x float64) (xt float64)

FTransformX - function to transform X

func (*BOverX) FTransformY

func (*BOverX) FTransformY(y float64) (yt float64)

FTransformY - function to transform Y

func (*BOverX) FX

func (*BOverX) FX(a, b, x float64) (y float64)

FX - Function to calculate normal y values

y = 1 / (a + bx)

func (*BOverX) FY

func (*BOverX) FY(a, b, y float64) (x float64)

FY - Solve the equation for y, used for interpolation

x = (1/((y -a ) / b)) - 1

func (*BOverX) Name

func (*BOverX) Name() string

Name - Name

func (*BOverX) TLabel

func (*BOverX) TLabel() string

TLabel - Top label

func (*BOverX) TextEquation

func (*BOverX) TextEquation() string

TextEquation - ASCII equation

func (*BOverX) TextTransformedEquation

func (*BOverX) TextTransformedEquation() string

TextTransformedEquation - Text equation

func (*BOverX) XLabel

func (*BOverX) XLabel() string

XLabel - X label

func (*BOverX) YLabel

func (*BOverX) YLabel() string

YLabel - Y label

type Exponential

type Exponential struct{}

Exponential - Provides the transformation functions that satisfy:

y = ae^(bx) = aB^x

to:

ln y = ln a + bx = ln a + ln B * x

func (*Exponential) FRestoreA

func (*Exponential) FRestoreA(at float64) (a float64)

FRestoreA - function to restore A

func (*Exponential) FRestoreB

func (*Exponential) FRestoreB(bt float64) (b float64)

FRestoreB - function to restore B

func (*Exponential) FTransformX

func (*Exponential) FTransformX(x float64) (xt float64)

FTransformX - function to transform X

func (*Exponential) FTransformY

func (*Exponential) FTransformY(y float64) (yt float64)

FTransformY - function to transform Y

func (*Exponential) FX

func (*Exponential) FX(a, b, x float64) (y float64)

FX - Function to calculate normal y values

y = aB^x

func (*Exponential) FY

func (*Exponential) FY(a, b, y float64) (x float64)

FY - Solve the equation for y, used for interpolation

x = ln(y/a)/ln(b)

func (*Exponential) Name

func (*Exponential) Name() string

Name - Name

func (*Exponential) TLabel

func (*Exponential) TLabel() string

TLabel - Top label

func (*Exponential) TextEquation

func (*Exponential) TextEquation() string

TextEquation - ASCII equation

func (*Exponential) TextTransformedEquation

func (*Exponential) TextTransformedEquation() string

TextTransformedEquation - Text equation

func (*Exponential) XLabel

func (*Exponential) XLabel() string

XLabel - X label

func (*Exponential) YLabel

func (*Exponential) YLabel() string

YLabel - Y label

type Interpolation

type Interpolation interface {
	FY(a, b, y float64) float64 // fy(y) solve the equation for y, used for interpolation.
	FX(a, b, x float64) float64 // fx(x)
}

Interpolation - Allows to get an X or Y point based on y or x.

type LinearTransformation

type LinearTransformation interface {
	Name() string
	FX(a, b, x float64) float64    // fx(x)
	FTransformX(x float64) float64 // function to transform X
	FTransformY(y float64) float64 // function to transform Y
	FRestoreA(at float64) float64  // function to restore A
	FRestoreB(bt float64) float64  // function to restore B
}

LinearTransformation -

type LnPower

type LnPower struct{}

LnPower - Provides the transformation functions that satisfy:

y = ln(ax^b)

to:

y = ln a + b * ln x

func (*LnPower) FRestoreA

func (*LnPower) FRestoreA(at float64) (a float64)

FRestoreA - function to restore A

func (*LnPower) FRestoreB

func (*LnPower) FRestoreB(bt float64) (b float64)

FRestoreB - function to restore B

func (*LnPower) FTransformX

func (*LnPower) FTransformX(x float64) (xt float64)

FTransformX - function to transform X

func (*LnPower) FTransformY

func (*LnPower) FTransformY(y float64) (yt float64)

FTransformY - function to transform Y

func (*LnPower) FX

func (*LnPower) FX(a, b, x float64) (y float64)

FX - Function to calculate normal y values

y = ln a + b ln x

func (*LnPower) FY

func (*LnPower) FY(a, b, y float64) (x float64)

FY - Solve the equation for y, used for interpolation

x = ((y - b)/ln a)^e

func (*LnPower) Name

func (*LnPower) Name() string

Name - Name

func (*LnPower) TLabel

func (*LnPower) TLabel() string

TLabel - Top label

func (*LnPower) TextEquation

func (*LnPower) TextEquation() string

TextEquation - ASCII equation

func (*LnPower) TextTransformedEquation

func (*LnPower) TextTransformedEquation() string

TextTransformedEquation - Text equation

func (*LnPower) XLabel

func (*LnPower) XLabel() string

XLabel - X label

func (*LnPower) YLabel

func (*LnPower) YLabel() string

YLabel - Y label

type None

type None struct{}

None - No transformation

func (*None) FRestoreA

func (*None) FRestoreA(at float64) (a float64)

FRestoreA - function to restore A

func (*None) FRestoreB

func (*None) FRestoreB(bt float64) (b float64)

FRestoreB - function to restore B

func (*None) FTransformX

func (*None) FTransformX(x float64) (xt float64)

FTransformX - function to transform X

func (*None) FTransformY

func (*None) FTransformY(y float64) (yt float64)

FTransformY - function to transform Y

func (*None) FX

func (*None) FX(a, b, x float64) (y float64)

FX - Function to calculate normal y values

y = a + bx

func (*None) FY

func (*None) FY(a, b, y float64) (x float64)

FY - Solve the equation for y, used for interpolation

x = (y - a)/b

func (*None) Name

func (*None) Name() string

Name - Name

func (*None) TLabel

func (*None) TLabel() string

TLabel - Top label

func (*None) TextEquation

func (*None) TextEquation() string

TextEquation - ASCII equation

func (*None) TextTransformedEquation

func (*None) TextTransformedEquation() string

TextTransformedEquation - Text equation

func (*None) XLabel

func (*None) XLabel() string

XLabel - X label

func (*None) YLabel

func (*None) YLabel() string

YLabel - Y label

type OneOverX

type OneOverX struct{}

OneOverX - Provides the transformation functions that satisfy:

y = 1 / (a + bx)

to:

1/y = a + bx

func (*OneOverX) FRestoreA

func (*OneOverX) FRestoreA(at float64) (a float64)

FRestoreA - function to restore A

func (*OneOverX) FRestoreB

func (*OneOverX) FRestoreB(bt float64) (b float64)

FRestoreB - function to restore B

func (*OneOverX) FTransformX

func (*OneOverX) FTransformX(x float64) (xt float64)

FTransformX - function to transform X

func (*OneOverX) FTransformY

func (*OneOverX) FTransformY(y float64) (yt float64)

FTransformY - function to transform Y

func (*OneOverX) FX

func (*OneOverX) FX(a, b, x float64) (y float64)

FX - Function to calculate normal y values

y = 1 / (a + bx)

func (*OneOverX) FY

func (*OneOverX) FY(a, b, y float64) (x float64)

FY - Solve the equation for y, used for interpolation

x = (1/y - a) / b

func (*OneOverX) Name

func (*OneOverX) Name() string

Name - Name

func (*OneOverX) TLabel

func (*OneOverX) TLabel() string

TLabel - Top label

func (*OneOverX) TextEquation

func (*OneOverX) TextEquation() string

TextEquation - ASCII equation

func (*OneOverX) TextTransformedEquation

func (*OneOverX) TextTransformedEquation() string

TextTransformedEquation - Text equation

func (*OneOverX) XLabel

func (*OneOverX) XLabel() string

XLabel - X label

func (*OneOverX) YLabel

func (*OneOverX) YLabel() string

YLabel - Y label

type OneOverX2

type OneOverX2 struct{}

OneOverX2 - Provides the transformation functions that satisfy:

y = 1 / (a + bx)^2

to:

1/sqrt(y) = a + bx

func (*OneOverX2) FRestoreA

func (*OneOverX2) FRestoreA(at float64) (a float64)

FRestoreA - function to restore A

func (*OneOverX2) FRestoreB

func (*OneOverX2) FRestoreB(bt float64) (b float64)

FRestoreB - function to restore B

func (*OneOverX2) FTransformX

func (*OneOverX2) FTransformX(x float64) (xt float64)

FTransformX - function to transform X

func (*OneOverX2) FTransformY

func (*OneOverX2) FTransformY(y float64) (yt float64)

FTransformY - function to transform Y

func (*OneOverX2) FX

func (*OneOverX2) FX(a, b, x float64) (y float64)

FX - Function to calculate normal y values

y = 1 / (a + bx)^2

func (*OneOverX2) FY

func (*OneOverX2) FY(a, b, y float64) (x float64)

FY - Solve the equation for y, used for interpolation

x = (1/sqrt(y) - a)/b

func (*OneOverX2) Name

func (*OneOverX2) Name() string

Name - Name

func (*OneOverX2) TLabel

func (*OneOverX2) TLabel() string

TLabel - Top label

func (*OneOverX2) TextEquation

func (*OneOverX2) TextEquation() string

TextEquation - ASCII equation

func (*OneOverX2) TextTransformedEquation

func (*OneOverX2) TextTransformedEquation() string

TextTransformedEquation - Text equation

func (*OneOverX2) XLabel

func (*OneOverX2) XLabel() string

XLabel - X label

func (*OneOverX2) YLabel

func (*OneOverX2) YLabel() string

YLabel - Y label

type PlotSettings

type PlotSettings struct {
	Title     string
	XLabel    string
	YLabel    string
	DataLabel string
	Bold      bool
}

PlotSettings -

type Plotter

type Plotter interface {
	Name() string
	TextEquation() string
	TextTransformedEquation() string
	TLabel() string             // Top label
	XLabel() string             // X label
	YLabel() string             // Y label
	FX(a, b, x float64) float64 // fx(x)
}

Plotter -

type PolynomialSolution

type PolynomialSolution struct {
	X, Y   []float64 // Original data slices.
	Degree int
	A      *mat.Dense // Solution
	R2     float64
	SDev   float64
}

PolynomialSolution - Polynomial solution.

func SolvePolynomial

func SolvePolynomial(xo, yo []float64, degree int) (PolynomialSolution, error)

SolvePolynomial - Given a pointer to X and Y []float64 data and a linear transformation function, it will return the solution.

func SolvePolynomialReverseMatrix

func SolvePolynomialReverseMatrix(xo, yo []float64, degree int) (PolynomialSolution, error)

SolvePolynomialReverseMatrix - Given a pointer to X and Y []float64 data and a linear transformation function, it will return the solution using the Reverse Matrix.

func (PolynomialSolution) Plot

func (s PolynomialSolution) Plot() error

Plot -

func (PolynomialSolution) PolynomialFunction

func (s PolynomialSolution) PolynomialFunction() func(x float64) float64

PolynomialFunction - Returns a linear function based on the provided A matrix.

type Power

type Power struct{}

Power - Provides the transformation functions that satisfy:

y = ax^b

to:

log y = log a + b * log x

func (*Power) FRestoreA

func (*Power) FRestoreA(at float64) (a float64)

FRestoreA - function to restore A

func (*Power) FRestoreB

func (*Power) FRestoreB(bt float64) (b float64)

FRestoreB - function to restore B

func (*Power) FTransformX

func (*Power) FTransformX(x float64) (xt float64)

FTransformX - function to transform X

func (*Power) FTransformY

func (*Power) FTransformY(y float64) (yt float64)

FTransformY - function to transform Y

func (*Power) FX

func (*Power) FX(a, b, x float64) (y float64)

FX - Function to calculate normal y values

y = ax^b

func (*Power) FY

func (*Power) FY(a, b, y float64) (x float64)

FY - Solve the equation for y, used for interpolation

x = sqrt(y/a,b)

func (*Power) Name

func (*Power) Name() string

Name - Name

func (*Power) TLabel

func (*Power) TLabel() string

TLabel - Top label

func (*Power) TextEquation

func (*Power) TextEquation() string

TextEquation - Text equation

func (*Power) TextTransformedEquation

func (*Power) TextTransformedEquation() string

TextTransformedEquation - Text equation

func (*Power) XLabel

func (*Power) XLabel() string

XLabel - X label

func (*Power) YLabel

func (*Power) YLabel() string

YLabel - Y label

type Solution

type Solution struct {
	X, Y   []float64 // original data slices.
	Xt, Yt []float64 // transformed data slices
	At, Bt float64   // solution to the transformed linear equation
	A, B   float64   // solution to the linear equation
	LT     LinearTransformation
	R2t    float64
	R2     float64
	SDevt  float64
	SDev   float64
}

Solution - Linear Transformation Solution.

func SolveTransformation

func SolveTransformation(xo, yo []float64, lt LinearTransformation) (Solution, error)

SolveTransformation - Given a pointer to X and Y []float64 data and a linear transformation function, it will return the solution.

func (Solution) LinearFunction

func (s Solution) LinearFunction() func(x float64) float64

LinearFunction - Returns a linear function based on the transformed At and Bt values.

func (Solution) Plot

func (s Solution) Plot(p Plotter) error

Plot -

func (Solution) PlotLinearTransformation

func (s Solution) PlotLinearTransformation(p Plotter) error

PlotLinearTransformation -

func (Solution) RegressionFunction

func (s Solution) RegressionFunction() func(x float64) float64

RegressionFunction -

type Sqrt

type Sqrt struct{}

Sqrt - Provides the transformation functions that satisfy:

y = a + b * sqrt(x)

to:

y = a + b * sqrt(x)

func (*Sqrt) FRestoreA

func (*Sqrt) FRestoreA(at float64) (a float64)

FRestoreA - function to restore A

func (*Sqrt) FRestoreB

func (*Sqrt) FRestoreB(bt float64) (b float64)

FRestoreB - function to restore B

func (*Sqrt) FTransformX

func (*Sqrt) FTransformX(x float64) (xt float64)

FTransformX - function to transform X

func (*Sqrt) FTransformY

func (*Sqrt) FTransformY(y float64) (yt float64)

FTransformY - function to transform Y

func (*Sqrt) FX

func (*Sqrt) FX(a, b, x float64) (y float64)

FX - Function to calculate normal y values

y = a + b * sqrt(x)

func (*Sqrt) FY

func (*Sqrt) FY(a, b, y float64) (x float64)

FY - Solve the equation for y, used for interpolation

x = ((y - a)/b)^2

func (*Sqrt) Name

func (*Sqrt) Name() string

Name - Name

func (*Sqrt) TLabel

func (*Sqrt) TLabel() string

TLabel - Top label

func (*Sqrt) TextEquation

func (*Sqrt) TextEquation() string

TextEquation - ASCII equation

func (*Sqrt) TextTransformedEquation

func (*Sqrt) TextTransformedEquation() string

TextTransformedEquation - Text equation

func (*Sqrt) XLabel

func (*Sqrt) XLabel() string

XLabel - X label

func (*Sqrt) YLabel

func (*Sqrt) YLabel() string

YLabel - Y label

type YDataLabel

type YDataLabel struct {
	Data  plotter.XYs
	Label string
}

YDataLabel -

Jump to

Keyboard shortcuts

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