Skip to content

Commit

Permalink
Merge pull request sjwhitworth#147 from Sentimentron/issue-146
Browse files Browse the repository at this point in the history
metrics: update dot-product to match new mat64 version
  • Loading branch information
Sentimentron committed Sep 28, 2016
2 parents 473ffe8 + fab0758 commit 9345938
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion metrics/pairwise/euclidean.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 3 additions & 1 deletion metrics/pairwise/poly_kernel.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +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)
subVectorX := vectorX.ColView(0)
subVectorY := vectorY.ColView(0)
result := mat64.Dot(subVectorX, subVectorY)
result = math.Pow(result+1, float64(p.degree))

return result
Expand Down

0 comments on commit 9345938

Please sign in to comment.