Documentation ¶
Index ¶
- func Expect(t *testing.T, expect string, actual interface{})
- func ExpectNear(t *testing.T, expect float64, actual float64, acc float64)
- func MatrixDotProduct(one, two *Matrix) float64
- func Mod(a, b int) int
- func VecDotProduct(Vector1, Vector2 *Vector) float64
- type CircularBuffer
- type Matrix
- func (m *Matrix) Clear()
- func (m *Matrix) DeepCopy(that *Matrix)
- func (m *Matrix) Get(label, index int) float64
- func (m *Matrix) GetValues(label int) *Vector
- func (m *Matrix) Increment(that *Matrix, alpha float64)
- func (m *Matrix) IsSparse() bool
- func (m *Matrix) MarshalJSON() ([]byte, error)
- func (m *Matrix) Norm() float64
- func (m *Matrix) NumLabels() int
- func (m *Matrix) NumValues() int
- func (m *Matrix) Opposite() *Matrix
- func (m *Matrix) Populate() *Matrix
- func (m *Matrix) Scale(s float64)
- func (m *Matrix) Set(label, index int, value float64)
- func (m *Matrix) UnmarshalJSON(b []byte) error
- func (m *Matrix) WeightedSum(m1, m2 *Matrix, a, b float64)
- type MatrixJSON
- type Vector
- func (v *Vector) Clear()
- func (v *Vector) DeepCopy(that *Vector)
- func (v *Vector) Get(index int) float64
- func (v *Vector) Increment(that *Vector, alpha float64)
- func (v *Vector) IsHomogeneous(that *Vector) bool
- func (v *Vector) IsSparse() bool
- func (v *Vector) Keys() []int
- func (v *Vector) MarshalJSON() ([]byte, error)
- func (v *Vector) Multiply(a, b float64, that *Vector)
- func (v *Vector) Norm() float64
- func (v *Vector) Opposite() *Vector
- func (v *Vector) Populate() *Vector
- func (v *Vector) Scale(s float64)
- func (v *Vector) Set(index int, value float64)
- func (v *Vector) SetAll(value float64)
- func (v *Vector) SetValues(values []float64)
- func (v *Vector) UnmarshalJSON(b []byte) error
- func (v *Vector) WeightedSum(Vector1, Vector2 *Vector, a, b float64)
- type VectorJSON
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MatrixDotProduct ¶
Types ¶
type CircularBuffer ¶
type CircularBuffer struct {
// contains filtered or unexported fields
}
环形缓存 数据从0位置开始添加,当溢出时指针重置为0,新数据从0位置开始覆盖
type Matrix ¶
type Matrix struct {
// contains filtered or unexported fields
}
矩阵,用以存储多个标注对应的权重值
矩阵根据存储不同分为稀疏矩阵和稠密矩阵,区别见vector.go文件中对Vector结构体的注释
请不要直接创建Matrix,而是通过NewMatrix函数(稠密矩阵)和NewSparseMatrix(稀疏矩阵) 函数进行创建。
func NewSparseMatrix ¶
创建一个稀疏矩阵,该矩阵有numLabels个标注,每个标注有numValues个值
func (*Matrix) WeightedSum ¶
m = a * m1 + b * m2 注意m(指针)不能等于m1或者m2
type MatrixJSON ¶
Matrix结构体JSON串行化/反串行化临时存储结构体
type Vector ¶
type Vector struct {
// contains filtered or unexported fields
}
向量分两种类型:
- 稠密向量,元素的key从0开始到N结束,实际值保存在切片中 使用NewVector(length)开辟新的稠密向量 稠密向量的长度在新建向量时已经指定好,无法更改
- 稀疏向量,元素的key可以是不连续的值,保存在map中 使用NewSparseVector()开辟新的稀疏向量 稀疏向量主要用于处理特征稀疏的超大规模机器学习问题
需要注意的是
1. 请不要混合使用稀疏和稠密向量 2. 和其他类型一样,向量是协程不安全的
请使用如下方法遍历向量中元素的值
for _, key := range(vector.Keys()) { vector.Get(key) }
func (*Vector) IsHomogeneous ¶
返回两个向量是否同质,同质的两个向量稀疏类型相同,如果都是稠密矩阵则长度也需要相同
func (*Vector) WeightedSum ¶
计算两个向量的线性求和 v = a * Vector1 + b * Vector2
Click to show internal directories.
Click to hide internal directories.