Documentation ¶
Index ¶
- func ExploreLearning(af AdaptiveFilter, d []float64, x [][]float64, muStart, muEnd float64, ...) ([]float64, []float64, error)
- func PreTrainedRun(af AdaptiveFilter, d []float64, x [][]float64, nTrain float64, epochs int) (y, e []float64, w [][]float64, err error)
- type AdaptiveFilter
- func Must(af AdaptiveFilter, err error) AdaptiveFilter
- func NewFiltAP(n int, mu float64, order int, eps float64, w []float64) (AdaptiveFilter, error)
- func NewFiltLMS(n int, mu float64, w []float64) (AdaptiveFilter, error)
- func NewFiltNLMS(n int, mu float64, eps float64, w []float64) (AdaptiveFilter, error)
- func NewFiltRLS(n int, mu float64, eps float64, w []float64) (AdaptiveFilter, error)
- type FiltAP
- func (af *FiltAP) Adapt(d float64, x []float64)
- func (af *FiltAP) GetKindName() string
- func (af *FiltAP) GetParams() (int, float64, []float64)
- func (af *FiltAP) Predict(x []float64) (y float64)
- func (af *FiltAP) Run(d []float64, x [][]float64) (y []float64, e []float64, wHist [][]float64, err error)
- func (af *FiltAP) SetStepSize(mu float64) error
- type FiltLMS
- func (af *FiltLMS) Adapt(d float64, x []float64)
- func (af *FiltLMS) GetKindName() string
- func (af *FiltLMS) GetParams() (int, float64, []float64)
- func (af *FiltLMS) Predict(x []float64) (y float64)
- func (af *FiltLMS) Run(d []float64, x [][]float64) (y []float64, e []float64, wHist [][]float64, err error)
- func (af *FiltLMS) SetStepSize(mu float64) error
- type FiltNLMS
- func (af *FiltNLMS) Adapt(d float64, x []float64)
- func (af *FiltNLMS) GetKindName() string
- func (af *FiltNLMS) GetParams() (int, float64, []float64)
- func (af *FiltNLMS) Predict(x []float64) (y float64)
- func (af *FiltNLMS) Run(d []float64, x [][]float64) (y []float64, e []float64, wHist [][]float64, err error)
- func (af *FiltNLMS) SetStepSize(mu float64) error
- type FiltRLS
- func (af *FiltRLS) Adapt(d float64, x []float64)
- func (af *FiltRLS) GetKindName() string
- func (af *FiltRLS) GetParams() (int, float64, []float64)
- func (af *FiltRLS) Predict(x []float64) (y float64)
- func (af *FiltRLS) Run(d []float64, x [][]float64) (y []float64, e []float64, wHist [][]float64, err error)
- func (af *FiltRLS) SetStepSize(mu float64) error
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExploreLearning ¶
func ExploreLearning(af AdaptiveFilter, d []float64, x [][]float64, muStart, muEnd float64, steps int, nTrain float64, epochs int, criteria string, targetW []float64) ([]float64, []float64, error)
ExploreLearning searches the `mu` with the smallest error value from the input matrix `x` and desired values `d`.
The arg `d` is desired value.
`x` is input matrix.
`muStart` is starting learning rate.
`muEnd` is final learning rate.
`steps` : how many learning rates should be tested between `muStart` and `muEnd`.
`nTrain` is train to test ratio, typical value is 0.5. (that means 50% of data is used for training)
`epochs` is number of training epochs, typical value is 1. This number describes how many times the training will be repeated.
`criteria` is how should be measured the mean error. Available values are "MSE", "MAE" and "RMSE".
`target_w` is target weights. If the slice is nil, the mean error is estimated from prediction error.
If an slice is provided, the error between weights and `target_w` is used.
Example (Ap) ¶
rand.Seed(1) //creation of data //number of samples n := 64 L := 8 order := 4 mu := 1.0 eps := 0.001 //input value var x = make([][]float64, n) //noise var v = make([]float64, n) //desired value var d = make([]float64, n) var xRow = make([]float64, L) for i := 0; i < n; i++ { xRow = misc.Unset(xRow, 0) xRow = append(xRow, rand.NormFloat64()) x[i] = append([]float64{}, xRow...) v[i] = rand.NormFloat64() * 0.1 d[i] = x[i][L-1] } af, err := NewFiltAP(L, mu, order, eps, nil) check(err) es, mus, err := ExploreLearning(af, d, x, 0.001, 5.0, 100, 0.5, 100, "MSE", nil) check(err) res := make(map[float64]float64, len(es)) for i := 0; i < len(es); i++ { res[es[i]] = mus[i] } //for i := 0; i < len(es); i++ { // fmt.Println(es[i], mus[i]) //} eMin := floats.Min(es) fmt.Printf("the step size mu with the smallest error is %.3f\n", res[eMin])
Output: the step size mu with the smallest error is 2.071
Example (Lms) ¶
rand.Seed(1) //creation of data //number of samples n := 64 L := 4 mu := 0.1 //input value var x = make([][]float64, n) //noise var v = make([]float64, n) //desired value var d = make([]float64, n) var xRow = make([]float64, L) for i := 0; i < n; i++ { xRow = misc.Unset(xRow, 0) xRow = append(xRow, rand.NormFloat64()) x[i] = append([]float64{}, xRow...) v[i] = rand.NormFloat64() * 0.1 d[i] = x[i][0] } af, err := NewFiltLMS(L, mu, nil) check(err) es, mus, err := ExploreLearning(af, d, x, 0.00001, 2.0, 100, 0.5, 100, "MSE", nil) check(err) res := make(map[float64]float64, len(es)) for i := 0; i < len(es); i++ { res[es[i]] = mus[i] } eMin := floats.Min(es) fmt.Printf("the step size mu with the smallest error is %.3f\n", res[eMin])
Output: the step size mu with the smallest error is 0.525
Example (Nlms) ¶
rand.Seed(1) //creation of data //number of samples //n := 64 n := 512 L := 8 mu := 1.0 eps := 0.001 //input value var x = make([][]float64, n) //noise var v = make([]float64, n) //desired value var d = make([]float64, n) var xRow = make([]float64, L) for i := 0; i < n; i++ { xRow = misc.Unset(xRow, 0) xRow = append(xRow, rand.NormFloat64()) x[i] = append([]float64{}, xRow...) v[i] = rand.NormFloat64() * 0.1 d[i] = x[i][L-1] } af, err := NewFiltNLMS(L, mu, eps, nil) check(err) es, mus, err := ExploreLearning(af, d, x, 0.00001, 2.0, 100, 0.5, 100, "MSE", nil) check(err) res := make(map[float64]float64, len(es)) for i := 0; i < len(es); i++ { res[es[i]] = mus[i] } eMin := floats.Min(es) fmt.Printf("the step size mu with the smallest error is %.3f\n", res[eMin])
Output: the step size mu with the smallest error is 1.535
Example (Rls) ¶
rand.Seed(1) //creation of data //number of samples n := 64 L := 4 mu := 1.0 eps := 0.001 //input value var x = make([][]float64, n) //noise var v = make([]float64, n) //desired value var d = make([]float64, n) var xRow = make([]float64, L) for i := 0; i < n; i++ { xRow = misc.Unset(xRow, 0) xRow = append(xRow, rand.NormFloat64()) x[i] = append([]float64{}, xRow...) v[i] = rand.NormFloat64() * 0.1 d[i] = x[i][L-1] } af, err := NewFiltRLS(L, mu, eps, nil) check(err) es, mus, err := ExploreLearning(af, d, x, 0.001, 1.0, 100, 0.5, 100, "MSE", nil) check(err) res := make(map[float64]float64, len(es)) for i := 0; i < len(es); i++ { res[es[i]] = mus[i] } //for i := 0; i < len(es); i++ { // fmt.Println(es[i], mus[i]) //} eMin := floats.Min(es) fmt.Printf("the step size mu with the smallest error is %.3f\n", res[eMin])
Output: the step size mu with the smallest error is 0.798
func PreTrainedRun ¶
func PreTrainedRun(af AdaptiveFilter, d []float64, x [][]float64, nTrain float64, epochs int) (y, e []float64, w [][]float64, err error)
PreTrainedRun use part of the data for few epochs of learning. The arg `d` is desired values. `x` is input matrix. columns are bunch of samples and rows are set of samples. `nTrain` is train to test ratio, typical value is 0.5. (that means 50% of data is used for training). `epochs` is number of training epochs, typical value is 1. This number describes how many times the training will be repeated.
Types ¶
type AdaptiveFilter ¶
type AdaptiveFilter interface { //Predict calculates the new estimated value `y` from input slice `x`. Predict(x []float64) (y float64) //Adapt calculates the error `e` between desired value `d` and estimated value `y`, //and update filter weights according to error `e`. Adapt(d float64, x []float64) //Run calculates the errors `e` between desired values `d` and estimated values `y` in a row, //while updating filter weights according to error `e`. Run(d []float64, x [][]float64) (y []float64, e []float64, wHist [][]float64, err error) //SetStepSize sets the step size of adaptive filter. SetStepSize(mu float64) error //GetParams returns the parameters at the time this func is called. //parameters contains `n`: filter length, `mu`: filter update step size and `w`: filter weights. GetParams() (n int, mu float64, w []float64) //GetParams returns the name of ADF. GetKindName() (kind string) // contains filtered or unexported methods }
AdaptiveFilter is the basic Adaptive Filter interface type.
func Must ¶
func Must(af AdaptiveFilter, err error) AdaptiveFilter
Must checks whether err is nil or not. If err in not nil, this func causes panic.
func NewFiltAP ¶
NewFiltAP is constructor of AP filter. This func initialize filter length `n`, update step size `mu`, projection order `order` and filter weight `w`.
func NewFiltLMS ¶
func NewFiltLMS(n int, mu float64, w []float64) (AdaptiveFilter, error)
NewFiltLMS is constructor of LMS filter. This func initialize filter length `n`, update step size `mu` and filter weight `w`.
func NewFiltNLMS ¶
NewFiltLMS is constructor of LMS filter. This func initialize filter length `n`, update step size `mu` and filter weight `w`.
func NewFiltRLS ¶
NewFiltRLS is constructor of RLS filter. This func initialize filter length `n`, update step size `mu`, small enough value `eps`, and filter weight `w`.
type FiltAP ¶
type FiltAP struct {
// contains filtered or unexported fields
}
FiltAP is base struct for AP filter. Use NewFiltAP to make instance.
func (*FiltAP) Adapt ¶
Adapt calculates the error `e` between desired value `d` and estimated value `y`, and update filter weights according to error `e`.
func (*FiltAP) GetKindName ¶
func (af *FiltAP) GetKindName() string
GetParams returns the name of ADF.
func (*FiltAP) GetParams ¶
GetParams returns the parameters at the time this func is called. parameters contains `n`: filter length, `mu`: filter update step size and `w`: filter weights.
func (*FiltAP) Run ¶
func (af *FiltAP) Run(d []float64, x [][]float64) (y []float64, e []float64, wHist [][]float64, err error)
Run calculates the errors `e` between desired values `d` and estimated values `y` in a row, while updating filter weights according to error `e`.
func (*FiltAP) SetStepSize ¶
SetStepSize set a update step size mu.
type FiltLMS ¶
type FiltLMS struct {
// contains filtered or unexported fields
}
FiltLMS is base struct for LMS filter. Use NewFiltLMS to make instance.
func (*FiltLMS) Adapt ¶
Adapt calculates the error `e` between desired value `d` and estimated value `y`, and update filter weights according to error `e`.
func (*FiltLMS) GetKindName ¶
func (af *FiltLMS) GetKindName() string
GetParams returns the name of ADF.
func (*FiltLMS) GetParams ¶
GetParams returns the parameters at the time this func is called. parameters contains `n`: filter length, `mu`: filter update step size and `w`: filter weights.
func (*FiltLMS) Run ¶
func (af *FiltLMS) Run(d []float64, x [][]float64) (y []float64, e []float64, wHist [][]float64, err error)
Run calculates the errors `e` between desired values `d` and estimated values `y` in a row, while updating filter weights according to error `e`.
func (*FiltLMS) SetStepSize ¶
SetStepSize set a update step size mu.
type FiltNLMS ¶
type FiltNLMS struct {
// contains filtered or unexported fields
}
FiltNLMS is base struct for NLMS filter. Use NewFiltNLMS to make instance.
func (*FiltNLMS) Adapt ¶
Adapt calculates the error `e` between desired value `d` and estimated value `y`, and update filter weights according to error `e`.
func (*FiltNLMS) GetKindName ¶
func (af *FiltNLMS) GetKindName() string
GetParams returns the name of ADF.
func (*FiltNLMS) GetParams ¶
GetParams returns the parameters at the time this func is called. parameters contains `n`: filter length, `mu`: filter update step size and `w`: filter weights.
func (*FiltNLMS) Run ¶
func (af *FiltNLMS) Run(d []float64, x [][]float64) (y []float64, e []float64, wHist [][]float64, err error)
Run calculates the errors `e` between desired values `d` and estimated values `y` in a row, while updating filter weights according to error `e`.
func (*FiltNLMS) SetStepSize ¶
SetStepSize set a update step size mu.
type FiltRLS ¶
type FiltRLS struct {
// contains filtered or unexported fields
}
FiltRLS is base struct for RLS filter. Use NewFiltRLS to make instance.
func (*FiltRLS) Adapt ¶
Adapt calculates the error `e` between desired value `d` and estimated value `y`, and update filter weights according to error `e`.
func (*FiltRLS) GetKindName ¶
func (af *FiltRLS) GetKindName() string
GetParams returns the name of ADF.
func (*FiltRLS) GetParams ¶
GetParams returns the parameters at the time this func is called. parameters contains `n`: filter length, `mu`: filter update step size and `w`: filter weights.
func (*FiltRLS) Run ¶
func (af *FiltRLS) Run(d []float64, x [][]float64) (y []float64, e []float64, wHist [][]float64, err error)
Run calculates the errors `e` between desired values `d` and estimated values `y` in a row, while updating filter weights according to error `e`.
func (*FiltRLS) SetStepSize ¶
SetStepSize set a update step size mu.