mirror of
https://github.com/sjwhitworth/golearn.git
synced 2025-04-28 13:48:56 +08:00
metrics: Fix TestPolyKernel
This commit is contained in:
parent
2d462da5b3
commit
fab0758198
@ -18,9 +18,10 @@ func NewPolyKernel(degree int) *PolyKernel {
|
|||||||
// InnerProduct computes the inner product through a kernel trick
|
// InnerProduct computes the inner product through a kernel trick
|
||||||
// K(x, y) = (x^T y + 1)^d
|
// K(x, y) = (x^T y + 1)^d
|
||||||
func (p *PolyKernel) InnerProduct(vectorX *mat64.Dense, vectorY *mat64.Dense) float64 {
|
func (p *PolyKernel) InnerProduct(vectorX *mat64.Dense, vectorY *mat64.Dense) float64 {
|
||||||
subVector := mat64.NewDense(0, 0, nil)
|
subVectorX := vectorX.ColView(0)
|
||||||
subVector.MulElem(vectorX, vectorY)
|
subVectorY := vectorY.ColView(0)
|
||||||
result := mat64.Sum(subVector)
|
result := mat64.Dot(subVectorX, subVectorY)
|
||||||
|
result = math.Pow(result+1, float64(p.degree))
|
||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user