Documentation
¶
Index ¶
- Constants
- func GSS(min, max float64, iters int, f func(float64) float64) float64
- type KMeans
- type Matrix2
- func (m *Matrix2) Add(m1 *Matrix2) *Matrix2
- func (m *Matrix2) Det() float64
- func (m *Matrix2) Eigenvalues() [2]complex128
- func (m *Matrix2) Inverse() *Matrix2
- func (m *Matrix2) InvertInPlace()
- func (m *Matrix2) InvertInPlaceDet(det float64)
- func (m *Matrix2) Mul(m1 *Matrix2) *Matrix2
- func (m *Matrix2) MulColumn(c Vec2) Vec2
- func (m *Matrix2) MulColumnInv(c Vec2, det float64) Vec2
- func (m *Matrix2) SVD(u, s, v *Matrix2)
- func (m *Matrix2) Scale(s float64)
- func (m *Matrix2) Transpose() *Matrix2
- type Matrix3
- func (m *Matrix3) Add(m1 *Matrix3) *Matrix3
- func (m *Matrix3) Cols() [3]Vec3
- func (m *Matrix3) Det() float64
- func (m *Matrix3) Eigenvalues() [3]complex128
- func (m *Matrix3) Inverse() *Matrix3
- func (m *Matrix3) InvertInPlace()
- func (m *Matrix3) InvertInPlaceDet(det float64)
- func (m *Matrix3) Mul(m1 *Matrix3) *Matrix3
- func (m *Matrix3) MulColumn(c Vec3) Vec3
- func (m *Matrix3) MulColumnInv(c Vec3, det float64) Vec3
- func (m *Matrix3) Rows() [3]Vec3
- func (m *Matrix3) SVD(u, s, v *Matrix3)
- func (m *Matrix3) Scale(s float64)
- func (m *Matrix3) Transpose() *Matrix3
- type Matrix4
- func (m *Matrix4) Add(m1 *Matrix4) *Matrix4
- func (m *Matrix4) CharPoly() Polynomial
- func (m *Matrix4) Cols() [4]Vec4
- func (m *Matrix4) Det() float64
- func (m *Matrix4) Mul(m1 *Matrix4) *Matrix4
- func (m *Matrix4) MulColumn(v Vec4) Vec4
- func (m *Matrix4) Rows() [4]Vec4
- func (m *Matrix4) SVD(u, s, v *Matrix4)
- func (m *Matrix4) Scale(s float64) *Matrix4
- func (m *Matrix4) Sub(m1 *Matrix4) *Matrix4
- func (m *Matrix4) Transpose() *Matrix4
- type Polynomial
- func (p Polynomial) Add(p1 Polynomial) Polynomial
- func (p Polynomial) Derivative() Polynomial
- func (p Polynomial) Eval(x float64) float64
- func (p Polynomial) IterRealRoots(f func(x float64) bool)
- func (p Polynomial) Mul(p1 Polynomial) Polynomial
- func (p Polynomial) RealRoots() []float64
- func (p Polynomial) Scale(c float64) Polynomial
- func (p Polynomial) String() string
- type SparseCholesky
- type SparseMatrix
- type Vec
- func (v Vec) Add(v1 Vec) Vec
- func (v Vec) Dist(v1 Vec) float64
- func (v Vec) DistSquared(v1 Vec) float64
- func (v Vec) Dot(v1 Vec) float64
- func (v Vec) Norm() float64
- func (v Vec) NormSquared() float64
- func (v Vec) Normalize() Vec
- func (v Vec) ProjectOut(v1 Vec) Vec
- func (v Vec) Scale(s float64) Vec
- func (v Vec) Sub(v1 Vec) Vec
- type Vec2
- type Vec3
- func (v Vec3) Add(v1 Vec3) Vec3
- func (v Vec3) Cross(v1 Vec3) Vec3
- func (v Vec3) Dist(v1 Vec3) float64
- func (v Vec3) Dot(v1 Vec3) float64
- func (v Vec3) Norm() float64
- func (v Vec3) Normalize() Vec3
- func (v Vec3) OrthoBasis() (Vec3, Vec3)
- func (v Vec3) ProjectOut(v1 Vec3) Vec3
- func (v Vec3) Scale(f float64) Vec3
- func (v Vec3) Sub(v1 Vec3) Vec3
- func (v Vec3) Sum() float64
- type Vec4
- func (v Vec4) Add(v1 Vec4) Vec4
- func (v Vec4) Dist(v1 Vec4) float64
- func (v Vec4) Dot(v1 Vec4) float64
- func (v Vec4) Norm() float64
- func (v Vec4) Normalize() Vec4
- func (v Vec4) OrthoBasis() (Vec4, Vec4, Vec4)
- func (v Vec4) ProjectOut(v1 Vec4) Vec4
- func (v Vec4) Scale(f float64) Vec4
- func (v Vec4) Sub(v1 Vec4) Vec4
- func (v Vec4) Sum() float64
Constants ¶
const DefaultGSSIters = 64
Variables ¶
This section is empty.
Functions ¶
Types ¶
type KMeans ¶ added in v0.3.3
type KMeans struct { // Centers is the K-means cluster centers. Centers []Vec // Data stores all of the data points. Data []Vec }
KMeans stores the (intermediate) results of K-means clustering.
This type can be created using NewKMeans() to create an initial clustering using K-means++. Then, Iterate() can be called repeatedly to refine the clustering as desired.
type Matrix2 ¶ added in v0.3.4
type Matrix2 [4]float64
Matrix2 is a 2x2 matrix, stored in row-major order.
func NewMatrix2Columns ¶ added in v0.3.4
NewMatrix2Columns creates a Matrix2 with the given coordinates as column entries.
func NewMatrix2Rotation ¶ added in v0.3.4
NewMatrix2Rotation creates a rotation matrix that rotates column vectors by theta.
func (*Matrix2) Eigenvalues ¶ added in v0.3.4
func (m *Matrix2) Eigenvalues() [2]complex128
Eigenvalues computes the eigenvalues of the matrix.
There may be a repeated eigenvalue, but for numerical reasons two are always returned.
func (*Matrix2) InvertInPlace ¶ added in v0.3.4
func (m *Matrix2) InvertInPlace()
InvertInPlace moves the inverse of m into m without causing any new allocations.
func (*Matrix2) InvertInPlaceDet ¶ added in v0.3.4
InvertInPlaceDet is an optimization for InvertInPlace when the determinant has been pre-computed.
func (*Matrix2) MulColumn ¶ added in v0.3.4
MulColumn multiplies the matrix m by a column vector represented by c.
func (*Matrix2) MulColumnInv ¶ added in v0.3.4
MulColumnInv multiplies the inverse of m by the column c, given the determinant of m.
func (*Matrix2) SVD ¶ added in v0.3.4
SVD computes the singular value decomposition of the matrix.
It populates matrices u, s, and v, such that
m = u*s*v.Transpose()
The singular values in s are sorted largest to smallest.
type Matrix3 ¶ added in v0.3.4
type Matrix3 [9]float64
Matrix3 is a 3x3 matrix, stored in row-major order.
func NewMatrix3Columns ¶ added in v0.3.4
NewMatrix3Columns creates a Matrix3 with the given coordinates as column entries.
func NewMatrix3Rotation ¶ added in v0.3.4
NewMatrix3Rotation creates a 3D rotation matrix. Points are rotated around the given vector in a right-handed direction.
The axis is assumed to be normalized. The angle is measured in radians.
func (*Matrix3) Eigenvalues ¶ added in v0.3.4
func (m *Matrix3) Eigenvalues() [3]complex128
Eigenvalues computes the eigenvalues of the matrix.
There may be repeated eigenvalues, but for numerical reasons three are always returned.
func (*Matrix3) InvertInPlace ¶ added in v0.3.4
func (m *Matrix3) InvertInPlace()
InvertInPlace moves the inverse of m into m without causing any new allocations.
func (*Matrix3) InvertInPlaceDet ¶ added in v0.3.4
InvertInPlaceDet is an optimization for InvertInPlace when the determinant has been pre-computed.
func (*Matrix3) MulColumn ¶ added in v0.3.4
MulColumn multiplies the matrix m by a column vector represented by c.
func (*Matrix3) MulColumnInv ¶ added in v0.3.4
MulColumnInv multiplies the inverse of m by the column c, given the determinant of m.
func (*Matrix3) SVD ¶ added in v0.3.4
SVD computes the singular value decomposition of the matrix.
It populates matrices u, s, and v, such that
m = u*s*v.Transpose()
The singular values in s are sorted largest to smallest.
type Matrix4 ¶ added in v0.3.4
type Matrix4 [16]float64
func NewMatrix4Columns ¶ added in v0.3.4
NewMatrix4Columns creates a Matrix4 from the columns.
func NewMatrix4Identity ¶ added in v0.3.4
func NewMatrix4Identity() *Matrix4
NewMatrix4Identity creates an identity matrix.
func (*Matrix4) CharPoly ¶ added in v0.3.4
func (m *Matrix4) CharPoly() Polynomial
CharPoly computes the characteristic polynomial of the matrix.
func (*Matrix4) SVD ¶ added in v0.3.4
SVD computes the singular value decomposition of the matrix.
It populates matrices u, s, and v, such that
m = u*s*v.Transpose()
The singular values in s are sorted largest to smallest.
type Polynomial ¶
type Polynomial []float64
A Polynomial is an equation of the form
a0 + a1*x + a2*x^2 + a3*x^3 + ...
Here, the polynomial is represented as an array of [a0, a1, ...].
func (Polynomial) Add ¶
func (p Polynomial) Add(p1 Polynomial) Polynomial
Add returns the sum of p and p1.
func (Polynomial) Derivative ¶
func (p Polynomial) Derivative() Polynomial
Derivative computes the derivative of the polynomial.
func (Polynomial) Eval ¶
func (p Polynomial) Eval(x float64) float64
Eval evaluates the polynomial at the given x value.
func (Polynomial) IterRealRoots ¶
func (p Polynomial) IterRealRoots(f func(x float64) bool)
IterRealRoots iterates over the real roots of p. This is similar to RealRoots(), but allows the caller to stop iteration early be returning false.
func (Polynomial) Mul ¶
func (p Polynomial) Mul(p1 Polynomial) Polynomial
Mul computes the product of two polynomials.
func (Polynomial) RealRoots ¶
func (p Polynomial) RealRoots() []float64
RealRoots computes the real roots of p, i.e. values of X such that p(x) = 0. The result may have duplicates since roots can be repeated.
If the polynomial has an infinite number of roots, one NaN root is returned.
func (Polynomial) Scale ¶ added in v0.3.0
func (p Polynomial) Scale(c float64) Polynomial
Scale returns a new polynomial with the coefficients of p multiplied by c.
func (Polynomial) String ¶
func (p Polynomial) String() string
String returns a string representation of p.
type SparseCholesky ¶
type SparseCholesky struct {
// contains filtered or unexported fields
}
SparseCholesky is a sparse LU decomposition of a symmetric matrix.
Once instantiated, this object can be used to quickly apply the inverse of a matrix to vectors.
func NewSparseCholesky ¶
func NewSparseCholesky(mat *SparseMatrix) *SparseCholesky
func (*SparseCholesky) ApplyInverseVec3 ¶
func (a *SparseCholesky) ApplyInverseVec3(x []Vec3) []Vec3
ApplyInverseVec3 computes (A^-1*x, A^-1*y, A^-1*z).
func (*SparseCholesky) ApplyVec3 ¶
func (a *SparseCholesky) ApplyVec3(x []Vec3) []Vec3
ApplyVec3 computes (A*x, A*y, A*z).
type SparseMatrix ¶
type SparseMatrix struct {
// contains filtered or unexported fields
}
A SparseMatrix is a square matrix where entries can be set to non-zero values in any order, and not all entries must be set.
func NewSparseMatrix ¶
func NewSparseMatrix(size int) *SparseMatrix
func (*SparseMatrix) ApplyVec3 ¶
func (a *SparseMatrix) ApplyVec3(x []Vec3) []Vec3
ApplyVec3 computes (A*x, A*y, A*z).
func (*SparseMatrix) Iterate ¶
func (a *SparseMatrix) Iterate(row int, f func(col int, x float64))
Iterate loops through the non-zero entries in a row.
func (*SparseMatrix) Permute ¶
func (a *SparseMatrix) Permute(perm []int) *SparseMatrix
Permute permutes the rows and columns by perm, where perm is the result of applying the permutation to the list [0...n-1].
func (*SparseMatrix) RCM ¶
func (a *SparseMatrix) RCM() []int
RCM computes the reverse Cuthill-McKee permutation for the matrix.
func (*SparseMatrix) Set ¶
func (a *SparseMatrix) Set(row, col int, x float64)
Set adds an entry to the matrix.
The entry should not already be set.
type Vec ¶
type Vec []float64
Vec is a vector of arbitrary dimension.
func (Vec) DistSquared ¶ added in v0.3.3
DistSquared computes ||v-v1||^2.
func (Vec) ProjectOut ¶
ProjectOut projects the direction v1 out of v.
type Vec2 ¶ added in v0.3.4
type Vec2 [2]float64
A Vec2 is a 2-dimensional tuple of floats.
func NewVec2RandomNormal ¶ added in v0.3.4
func NewVec2RandomNormal() Vec2
NewVec2RandomNormal creates a random normal vector.
func NewVec2RandomUnit ¶ added in v0.3.4
func NewVec2RandomUnit() Vec2
NewVec2RandomUnit creates a unit-length Vec2 in a random direction.
func (Vec2) ProjectOut ¶ added in v0.3.4
ProjectOut projects the v1 direction out of v.
type Vec3 ¶
type Vec3 [3]float64
A Vec3 is a 3-dimensional tuple of floats.
func LeastSquares3 ¶ added in v0.3.4
LeastSquares3 computes the least squares solution to the equation Ax = b, where A is a matrix with rows vs, and b is a column matrix.
The epsilon argument is a lower bound for singular values in the psuedoinverse.
func LeastSquaresReg3 ¶ added in v0.3.4
LeastSquaresReg3 is like LeastSquares3, but uses ridge regression with a penalty equal to lambda.
func NewVec3RandomNormal ¶
func NewVec3RandomNormal() Vec3
NewVec3RandomNormal creates a random normal vector.
func NewVec3RandomUnit ¶ added in v0.3.4
func NewVec3RandomUnit() Vec3
NewVec3RandomUnit creates a unit-length Vec3 in a random direction.
func (Vec3) OrthoBasis ¶ added in v0.3.4
OrthoBasis creates two unit vectors which are orthogonal to v and to each other.
If v is axis-aligned, the other vectors will be as well.
func (Vec3) ProjectOut ¶ added in v0.3.4
ProjectOut projects the v1 direction out of v.
type Vec4 ¶ added in v0.3.4
type Vec4 [4]float64
A Vec4 is a 4-dimensional tuple of floats.
func NewVec4RandomNormal ¶ added in v0.3.4
func NewVec4RandomNormal() Vec4
NewVec4RandomNormal creates a random normal vector.
func NewVec4RandomUnit ¶ added in v0.3.4
func NewVec4RandomUnit() Vec4
NewVec4RandomUnit creates a unit-length Vec3 in a random direction.
func (Vec4) OrthoBasis ¶ added in v0.3.4
OrthoBasis creates three unit vectors which are orthogonal to v and to each other.
If v is axis-aligned, the other vectors will be as well.
The behavior of this method is undefined if v is zero.
func (Vec4) ProjectOut ¶ added in v0.3.4
ProjectOut projects the v1 direction out of v.