JaRMoS  1.1
Java Reduced Model Simulations
 All Classes Namespaces Files Functions Variables Enumerator Groups Pages
GaussKernel.java
Go to the documentation of this file.
1 package kermor.kernel;
2 
3 import org.apache.commons.math.linear.Array2DRowRealMatrix;
4 import org.apache.commons.math.linear.RealMatrix;
5 import org.apache.commons.math.util.FastMath;
6 
15 public class GaussKernel implements IKernel {
16 
17  public double gamma;
18 
19  public GaussKernel(double gamma) {
20  this.gamma = gamma;
21  }
22 
27  @Override
28  public RealMatrix evaluate(RealMatrix x, RealMatrix y) {
29  RealMatrix res = new Array2DRowRealMatrix(x.getColumnDimension(), y.getColumnDimension());
30  for (int i = 0; i < x.getColumnDimension(); i++) {
31  res.setColumn(i, evaluate(x.getColumn(i), y));
32  }
33  return res;
34  }
35 
39  @Override
40  public double[] evaluate(double[] x, RealMatrix y) {
41  double[] res = new double[y.getColumnDimension()];
42  for (int i = 0; i < y.getColumnDimension(); i++) {
43  res[i] = FastMath.exp(-(distance_sq(x, y.getColumn(i))) / (gamma * gamma));
44  }
45  return res;
46  }
47 
51  @Override
52  public double[] evaluate(double t, double[] ti) {
53  double[] res = new double[ti.length];
54  for (int i = 0; i < ti.length; i++) {
55  res[i] = FastMath.exp(-(t - ti[i]) * (t - ti[i]) / (gamma * gamma));
56  }
57  return res;
58  }
59 
60  private double distance_sq(double[] p1, double[] p2) {
61  double sum = 0;
62  for (int i = 0; i < p1.length; i++) {
63  sum += (p1[i] - p2[i]) * (p1[i] - p2[i]);
64  }
65  return sum;
66  }
67 }
Interface for kernel implementations in JKerMor.
Definition: IKernel.java:14
Implementation of the Gaussian kernel .
double[] evaluate(double t, double[] ti)
double[] evaluate(double[] x, RealMatrix y)
RealMatrix evaluate(RealMatrix x, RealMatrix y)