Documentation
¶
Index ¶
- Constants
- func GSS(min, max float64, iters int, f func(float64) float64) float64
- type KMeans
- 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 Vec3
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 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.