Documentation
¶
Overview ¶
Example (ExternalWeights) ¶
a := []float64{ 5, 6.0, 2.0, 4.5, 5, 5, 6.5, 3.5, 4.0, 5, 5, 5.5, 3.5, 5.0, 5, 5, 6.5, 2.5, 4.5, 5, } w := []float64{ 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, } width := 5 state := NewWithExternal(width, a, w) retVal := make([]float64, len(a)) if smoothed, err := UnsafeSmooth(state, width, 1, Linear, retVal); err == nil { fmt.Printf("Smoothed %1.2f\n", smoothed) } else { fmt.Printf("ERR %v", err) }
Output: Smoothed [5.00 3.50 2.00 3.50 5.00 5.00 4.25 3.50 4.25 5.00 5.00 4.25 3.50 4.25 5.00 5.00 3.75 2.50 3.75 5.00]
Example (Smooth) ¶
a := []float64{ 5, 6.0, 2.0, 4.5, 5, 5, 6.5, 3.5, 4.0, 5, 5, 5.5, 3.5, 5.0, 5, 5, 6.5, 2.5, 4.5, 5, } // Smooth on a seasonality width of 1, and period of 5 (i.e. look ahead 5 and regress on it) if smoothed, err := Smooth(a, 1, 5, Linear); err == nil { fmt.Printf("Smoothed %1.2f\n", smoothed) } // Smoothed on a periodic window of of 5 if smoothed, err := Smooth(a, 5, 1, Linear); err == nil { fmt.Printf("Smoothed %1.2f\n", smoothed) } // if smoothed, err := Smooth(a, 5, 1, Quadratic); err == nil { // fmt.Printf("Smoothed %1.1v\n", smoothed) // } // Smoothed [1e+01 1e+01 1e+01 9 7 5 5 5 5 5 5 3 1 -0.7 -3 -5 0.1 5 9 1e+01]
Output: Smoothed [5.00 5.00 5.00 5.00 5.00 5.00 5.00 5.00 5.00 5.00 5.00 5.00 5.00 5.00 5.00 5.00 5.00 5.00 5.00 5.00] Smoothed [5.50 4.60 3.86 3.93 4.86 5.43 5.21 4.50 4.14 4.71 5.14 4.78 4.50 4.57 5.00 5.43 4.93 4.22 4.35 4.78]
Index ¶
- func Linear(s *State, x, left, right float64) error
- func Quadratic(s *State, x, left, right float64) error
- func Regress(s *State, fn WeightUpdate, x, left, right float64) (retVal float64, err error)
- func Smooth(x []float64, width, jump int, fn WeightUpdate) ([]float64, error)
- func UnsafeSmooth(regression *State, width, jump int, fn WeightUpdate, retVal []float64) ([]float64, error)
- type State
- type WeightUpdate
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Linear ¶
Linear performs linear regression, but constrained to left and right values. The implementation is slightly different from the typical Y = (X'X)^-1(X'Y)
func Regress ¶
func Regress(s *State, fn WeightUpdate, x, left, right float64) (retVal float64, err error)
Regress performs local regression of x between left and right
func Smooth ¶
func Smooth(x []float64, width, jump int, fn WeightUpdate) ([]float64, error)
Smooth smooths a slice of float64, with the provided width, jumps and update functions
func UnsafeSmooth ¶
func UnsafeSmooth(regression *State, width, jump int, fn WeightUpdate, retVal []float64) ([]float64, error)
UnsafeSmooth is like Smooth, except the state is passed in, as well as a optional return value to be mutated.
Types ¶
type State ¶
type State struct {
// contains filtered or unexported fields
}
State represents a state for regression. Every field will be mutated by the Regress and Smooth functions
func NewWithExternal ¶
NewWithExternal creates a new LOESS state with externally provided weights
type WeightUpdate ¶
WeightUpdate is a function that modifies the State.
Click to show internal directories.
Click to hide internal directories.