1
0
mirror of https://github.com/sjwhitworth/golearn.git synced 2025-04-26 13:49:14 +08:00

metrics: update dot-product to match new mat64 version

See issue #146
This commit is contained in:
Vineeth Pillai 2016-09-22 09:24:04 +01:00 committed by Richard Townsend
parent 473ffe8e83
commit 2d462da5b3
2 changed files with 6 additions and 3 deletions

View File

@ -14,7 +14,9 @@ func NewEuclidean() *Euclidean {
// InnerProduct computes a Eucledian inner product.
func (e *Euclidean) InnerProduct(vectorX *mat64.Dense, vectorY *mat64.Dense) float64 {
result := mat64.Dot(vectorX, vectorY)
subVector := mat64.NewDense(0, 0, nil)
subVector.MulElem(vectorX, vectorY)
result := mat64.Sum(subVector)
return result
}

View File

@ -18,8 +18,9 @@ func NewPolyKernel(degree int) *PolyKernel {
// InnerProduct computes the inner product through a kernel trick
// K(x, y) = (x^T y + 1)^d
func (p *PolyKernel) InnerProduct(vectorX *mat64.Dense, vectorY *mat64.Dense) float64 {
result := mat64.Dot(vectorX, vectorY)
result = math.Pow(result+1, float64(p.degree))
subVector := mat64.NewDense(0, 0, nil)
subVector.MulElem(vectorX, vectorY)
result := mat64.Sum(subVector)
return result
}