diff --git a/metrics/pairwise/chebyshev.go b/metrics/pairwise/chebyshev.go index 0068433..86f5663 100644 --- a/metrics/pairwise/chebyshev.go +++ b/metrics/pairwise/chebyshev.go @@ -12,7 +12,7 @@ func NewChebyshev() *Chebyshev { return &Chebyshev{} } -func (self *Chebyshev) Distance(vectorX *mat64.Dense, vectorY *mat64.Dense) float64 { +func (c *Chebyshev) Distance(vectorX *mat64.Dense, vectorY *mat64.Dense) float64 { r1, c1 := vectorX.Dims() r2, c2 := vectorY.Dims() if r1 != r2 || c1 != c2 { diff --git a/metrics/pairwise/cranberra.go b/metrics/pairwise/cranberra.go index 5f673bb..09551de 100644 --- a/metrics/pairwise/cranberra.go +++ b/metrics/pairwise/cranberra.go @@ -19,7 +19,7 @@ func cranberraDistanceStep(num float64, denom float64) float64 { return num / denom } -func (self *Cranberra) Distance(vectorX *mat64.Dense, vectorY *mat64.Dense) float64 { +func (c *Cranberra) Distance(vectorX *mat64.Dense, vectorY *mat64.Dense) float64 { r1, c1 := vectorX.Dims() r2, c2 := vectorY.Dims() if r1 != r2 || c1 != c2 { diff --git a/metrics/pairwise/euclidean.go b/metrics/pairwise/euclidean.go index 17302e0..8be0931 100644 --- a/metrics/pairwise/euclidean.go +++ b/metrics/pairwise/euclidean.go @@ -13,18 +13,18 @@ func NewEuclidean() *Euclidean { } // InnerProduct computes a Eucledian inner product. -func (self *Euclidean) InnerProduct(vectorX *mat64.Dense, vectorY *mat64.Dense) float64 { +func (e *Euclidean) InnerProduct(vectorX *mat64.Dense, vectorY *mat64.Dense) float64 { result := vectorX.Dot(vectorY) return result } // Distance computes Euclidean distance (also known as L2 distance). -func (self *Euclidean) Distance(vectorX *mat64.Dense, vectorY *mat64.Dense) float64 { +func (e *Euclidean) Distance(vectorX *mat64.Dense, vectorY *mat64.Dense) float64 { subVector := mat64.NewDense(0, 0, nil) subVector.Sub(vectorX, vectorY) - result := self.InnerProduct(subVector, subVector) + result := e.InnerProduct(subVector, subVector) return math.Sqrt(result) } diff --git a/metrics/pairwise/manhattan.go b/metrics/pairwise/manhattan.go index 14f0597..5664a9d 100644 --- a/metrics/pairwise/manhattan.go +++ b/metrics/pairwise/manhattan.go @@ -14,7 +14,7 @@ func NewManhattan() *Manhattan { // Distance computes the Manhattan distance, also known as L1 distance. // == the sum of the absolute values of elements. -func (self *Manhattan) Distance(vectorX *mat64.Dense, vectorY *mat64.Dense) float64 { +func (m *Manhattan) Distance(vectorX *mat64.Dense, vectorY *mat64.Dense) float64 { r1, c1 := vectorX.Dims() r2, c2 := vectorY.Dims() if r1 != r2 || c1 != c2 { diff --git a/metrics/pairwise/poly_kernel.go b/metrics/pairwise/poly_kernel.go index b5628fc..a4844bb 100644 --- a/metrics/pairwise/poly_kernel.go +++ b/metrics/pairwise/poly_kernel.go @@ -17,18 +17,18 @@ func NewPolyKernel(degree int) *PolyKernel { // InnerProduct computes the inner product through a kernel trick // K(x, y) = (x^T y + 1)^d -func (self *PolyKernel) InnerProduct(vectorX *mat64.Dense, vectorY *mat64.Dense) float64 { +func (p *PolyKernel) InnerProduct(vectorX *mat64.Dense, vectorY *mat64.Dense) float64 { result := vectorX.Dot(vectorY) - result = math.Pow(result+1, float64(self.degree)) + result = math.Pow(result+1, float64(p.degree)) return result } // Distance computes distance under the polynomial kernel (maybe not needed?) -func (self *PolyKernel) Distance(vectorX *mat64.Dense, vectorY *mat64.Dense) float64 { +func (p *PolyKernel) Distance(vectorX *mat64.Dense, vectorY *mat64.Dense) float64 { subVector := mat64.NewDense(0, 0, nil) subVector.Sub(vectorX, vectorY) - result := self.InnerProduct(subVector, subVector) + result := p.InnerProduct(subVector, subVector) return math.Sqrt(result) } diff --git a/metrics/pairwise/rbf_kernel.go b/metrics/pairwise/rbf_kernel.go index 1c46710..1f3fc14 100644 --- a/metrics/pairwise/rbf_kernel.go +++ b/metrics/pairwise/rbf_kernel.go @@ -17,11 +17,11 @@ func NewRBFKernel(gamma float64) *RBFKernel { // InnerProduct computes the inner product through a kernel trick // K(x, y) = exp(-gamma * ||x - y||^2) -func (self *RBFKernel) InnerProduct(vectorX *mat64.Dense, vectorY *mat64.Dense) float64 { +func (r *RBFKernel) InnerProduct(vectorX *mat64.Dense, vectorY *mat64.Dense) float64 { euclidean := NewEuclidean() distance := euclidean.Distance(vectorX, vectorY) - result := math.Exp(-self.gamma * math.Pow(distance, 2)) + result := math.Exp(-r.gamma * math.Pow(distance, 2)) return result }