package model.supervised.svm.kernels;

import utils.array.ArrayUtil;

/**
 * Created by hanxuan on 11/25/15 for machine_learning.
 */
public class GaussianK implements Kernel {

    public static double sigma = 1;

    @Override
    public double similarity(double[] x1, double[] x2) {
        double dis = ArrayUtil.euclidean(x1, x2);
        return Math.exp(- dis / sigma / 2);
    }
}

@@ -32,16 +32,63 @@
 rnels;%0A%0A
+import org.apache.commons.math3.util.FastMath;%0A
 import u
@@ -109,16 +109,16 @@
 ayUtil;%0A
-
 %0A/**%0A * 
@@ -243,21 +243,21 @@
  double 
-sigma
+GAMMA
  = 1;%0A%0A 
@@ -391,16 +391,20 @@
  return 
+Fast
 Math.exp
@@ -408,25 +408,228 @@
 exp(
+ 
 - 
-dis / sigma / 2
+GAMMA * dis);%0A    %7D%0A%0A    public double similarity(double x1x1, double x2x2, double%5B%5D x1, double%5B%5D x2) %7B%0A        double dis = x1x1 - 2 * ArrayUtil.innerProduct(x1, x2) + x2x2;%0A        return FastMath.exp( - GAMMA * dis
 );%0A 

add new similarity calculation method, if inner product of x1 * x1 and x2 * x2 are given