Documentation ¶
Index ¶
- Variables
- type Dataset
- type Hypothesis
- type LinearRegression
- func (b LinearRegression) Fct(x Vector) float64
- func (b *LinearRegression) GradientDescent(dataset Dataset, alpha float64, plotData bool) <-chan string
- func (b LinearRegression) PartialDerivative(dataset Dataset, j int) float64
- func (b LinearRegression) SquaredError(dataset Dataset) float64
- func (b LinearRegression) String() string
- type MRow
- type Matrix
- func (ma Matrix) Add(ma2 Matrix) Matrix
- func (ma Matrix) Copy() Matrix
- func (ma Matrix) Dim() (int, int)
- func (ma Matrix) DimMatch(ma2 Matrix) bool
- func (ma Matrix) Equal(ma2 Matrix) bool
- func (ma Matrix) Extend(m1, n1 int) Matrix
- func (ma Matrix) Identity() Matrix
- func (ma Matrix) Inverse() Matrix
- func (ma Matrix) Mul(ma2 Matrix) Matrix
- func (ma Matrix) MulV(v Vector) Vector
- func (ma Matrix) Scale(n float64) Matrix
- func (ma Matrix) SetSubMatrix(ma2 Matrix, m, n int) Matrix
- func (ma Matrix) String() string
- func (ma Matrix) Sub(ma2 Matrix) Matrix
- func (ma Matrix) SubMatrix(m, n, m1, n1 int) Matrix
- func (ma Matrix) ToVector() Vector
- func (ma Matrix) Transpose() Matrix
- func (ma Matrix) Validate() error
- type Vector
Constants ¶
This section is empty.
Variables ¶
var ( ErrBadDim = errors.New("bad dimenstion for matrix") ErrInconsistentData = errors.New("matrix has different y dimension per x") ErrUninitialized = errors.New("matrix not initialized") ErrIdentityInvalidSize = errors.New("current dimension of matrix does not have an identity") ErrNegativeIndex = errors.New("negative index are not supported") ErrOutOfBound = errors.New("index out of bound") ErrNotAVector = errors.New("the current vector has invalid dimension for a vector") ErrSingularMatrix = errors.New("the matrix is singuler") )
Common erros.
Functions ¶
This section is empty.
Types ¶
type Hypothesis ¶
type Hypothesis interface { Fct(Vector) float64 // h.Fct(x) = y. SquaredError(dataset Dataset) float64 // Cost function. }
Hypothesis .
type LinearRegression ¶
type LinearRegression struct {
Θ Vector
}
LinearRegression is the linar regression algorithm.
- Hypothesis: h(x) = Θ[0][0] + Θ[1][0]*x
func (LinearRegression) Fct ¶
func (b LinearRegression) Fct(x Vector) float64
Fct implements the hypothesis function.
func (*LinearRegression) GradientDescent ¶
func (b *LinearRegression) GradientDescent(dataset Dataset, alpha float64, plotData bool) <-chan string
GradientDescent .
func (LinearRegression) PartialDerivative ¶
func (b LinearRegression) PartialDerivative(dataset Dataset, j int) float64
PartialDerivative .
func (LinearRegression) SquaredError ¶
func (b LinearRegression) SquaredError(dataset Dataset) float64
SquaredError process the squared error of the given hypothesis on the given dataset. The squared error equation is: $$\frac{1}{2m}\sum_{i=1}^{m} (h(x^{(i)})-y^{(i)})^2 $$ - 1/(2m) * Sum from i=1 to m of square h(x(i))-y(i). TODO: rename CostFunction() ?
func (LinearRegression) String ¶
func (b LinearRegression) String() string
type MRow ¶
type MRow []float64
MRow is the row type for matrix.
func (MRow) Add ¶
Add adds the given matrix to the current one and return the result. NOTE: Does not change current matrix state.
type Matrix ¶
type Matrix []MRow
Matrix .
func (Matrix) Add ¶
Add adds the given matrix to the current one and return the result. NOTE: Does not change current matrix state.
func (Matrix) DimMatch ¶
DimMatch checks if the given matrice has the same dimension as the current one.
func (Matrix) Extend ¶
Extend returns a copy of the current matrix with m more rows and n more cols. The extended rows/cols are set to 0. Extend(0, 0) creates an identical copy of the matrix. NOTE: Does not change state of current matrix.
func (Matrix) Identity ¶
Identity returns the identify matrix for the current one. NOTE: Does not change current matrix state.
func (Matrix) Inverse ¶
Inverse returns the inverted copy of the current matrix. NOTE: Does not change current matrix state.
func (Matrix) Mul ¶
Mul returns the result of the current matrix multiplied by the given one. NOTE: Does not change current matrix state.
func (Matrix) MulV ¶
MulV multiplies the current matrix with the given vector. Returns a Vector. NOTE: Does not change current matrix state.
func (Matrix) Scale ¶
Scale returns the result of the scalar multiplication of the given scalar and the current matrix. NOTE: Does not change current matrix state.
func (Matrix) SetSubMatrix ¶
SetSubMatrix updates the current matrix with the given submatrix starting at m,n index. NOTE: Changes the state of the current matrix. NOTE: Overflowing submatrix produce an error.
func (Matrix) Sub ¶
Sub substracts the given matrix to the current one and return the result. NOTE: Does not change current matrix state.
func (Matrix) SubMatrix ¶
SubMatrix return a sub matrix part of the current matrix. Starts at (m,n) index (0 indexed) and of dimension (m1,n1) NOTE: Changes to the sub matrix will change the parent one.
type Vector ¶
type Vector Matrix
Vector is a matrix with 1 column.
func ToVector ¶
ToVector converts the matrix type to vector and validates the resulting vector. panic if the given matrix is not of (1,n) dimension.
func (Vector) SubV ¶
SubV returns the result of v - v2 as a copy. NOTE: Does not change cureent vector state.