mirror of
https://github.com/sjwhitworth/golearn.git
synced 2025-04-28 13:48:56 +08:00
Merge pull request #147 from Sentimentron/issue-146
metrics: update dot-product to match new mat64 version
This commit is contained in:
commit
9345938082
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user