mirror of
https://github.com/sjwhitworth/golearn.git
synced 2025-04-26 13:49:14 +08:00
29 lines
496 B
Go
29 lines
496 B
Go
package pairwise
|
|
|
|
import (
|
|
"math"
|
|
|
|
"github.com/gonum/matrix/mat64"
|
|
)
|
|
|
|
type RBFKernel struct {
|
|
gamma float64
|
|
}
|
|
|
|
func NewRBFKernel(gamma float64) *RBFKernel {
|
|
return &RBFKernel{gamma: gamma}
|
|
}
|
|
|
|
func (self *RBFKernel) InnerProduct(vectorX *mat64.Dense, vectorY *mat64.Dense) (float64, error) {
|
|
euclidean := NewEuclidean()
|
|
distance, err := euclidean.Distance(vectorX, vectorY)
|
|
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
|
|
result := math.Exp(self.gamma * math.Pow(distance, 2))
|
|
|
|
return result, nil
|
|
}
|