2014-05-02 21:10:55 +08:00
|
|
|
package pairwise
|
|
|
|
|
|
|
|
import (
|
|
|
|
"math"
|
|
|
|
|
2014-05-03 00:55:38 +08:00
|
|
|
"github.com/gonum/matrix/mat64"
|
2014-05-02 21:10:55 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
type RBFKernel struct {
|
|
|
|
gamma float64
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewRBFKernel(gamma float64) *RBFKernel {
|
|
|
|
return &RBFKernel{gamma: gamma}
|
|
|
|
}
|
|
|
|
|
2014-05-03 00:55:38 +08:00
|
|
|
func (self *RBFKernel) InnerProduct(vectorX *mat64.Dense, vectorY *mat64.Dense) (float64, error) {
|
2014-05-02 21:10:55 +08:00
|
|
|
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
|
|
|
|
}
|