fdadf

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2019 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExploreLearning

func ExploreLearning(af FDAdaptiveFilter, 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 (Fblms)
rand.Seed(1)
//creation of data
//number of samples
n := 512
L := 32
m := n / L
mu := 0.0000001

//input value
var x = make([][]float64, m)
for i := range x {
	x[i] = make([]float64, L)
}
//desired value
var d = make([][]float64, m)
for i := range d {
	d[i] = make([]float64, L)
}
var xRow = make([]float64, L)
for i := 0; i < m; i++ {
	for j := 0; j < L; j++ {
		xRow = misc.Unset(xRow, 0)
		xRow = append(xRow, rand.NormFloat64())
	}
	copy(x[i], xRow)
	copy(d[i], x[i])
}

af, err := NewFiltFBLMS(L, mu, "zeros")
check(err)
es, mus, err := ExploreLearning(af, d, x, 0.00001, 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.010

func PreTrainedRun

func PreTrainedRun(af FDAdaptiveFilter, 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. rows are `x` is input matrix. rows are samples and columns are features. `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 FDAdaptiveFilter

type FDAdaptiveFilter 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) ([][]float64, [][]float64, [][]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() (int, float64, []float64)

	//GetParams returns the name of FDADF.
	GetKindName() (kind string)
	// contains filtered or unexported methods
}

FDAdaptiveFilter is the basic Frequency Domain Adaptive Filter interface type.

func Must

Must checks whether err is nil or not. If err in not nil, this func causes panic.

func NewFiltFBLMS

func NewFiltFBLMS(n int, mu float64, w interface{}) (FDAdaptiveFilter, error)

NewFiltFBLMS is constructor of FBLMS filter. This func initialize filter length `n`, update step size `mu` and filter weight `w`.

type FiltFBLMS

type FiltFBLMS struct {
	// contains filtered or unexported fields
}

FiltFBLMS is base struct for FBLMS filter (Fast Block Least Mean Square filter). Use NewFiltFBLMS to make instance.

func (*FiltFBLMS) Adapt

func (af *FiltFBLMS) Adapt(d []float64, x []float64)

Adapt calculates the error `e` between desired value `d` and estimated value `y`, and update filter weights according to error `e`.

func (*FiltFBLMS) GetKindName

func (af *FiltFBLMS) GetKindName() (kind string)

GetParams returns the kind name of ADF.

func (*FiltFBLMS) GetParams

func (af *FiltFBLMS) GetParams() (n int, mu float64, w []float64)

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 (*FiltFBLMS) Predict

func (af *FiltFBLMS) Predict(x []float64) (y []float64)

Predict calculates the new output value `y` from input array `x`.

func (*FiltFBLMS) Run

func (af *FiltFBLMS) Run(d [][]float64, x [][]float64) ([][]float64, [][]float64, [][]float64, 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`. The arg `x`: rows are samples sets, columns are input values.

Jump to

Keyboard shortcuts

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