// Catalano Statistics Library
// The Catalano Framework
//
// Copyright © Diego Catalano, 2012-2016
// diego.catalano at live.com
//
// Copyright © César Souza, 2009-2013
// cesarsouza at gmail.com
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
//
package Catalano.Statistics.Kernels;
/**
*
* @author Diego
*/
public class Dirichlet implements IMercerKernel{
private int dimension;
/**
* Gets the dimension for the kernel.
* @return Dimension.
*/
public int getDimension() {
return dimension;
}
/**
* Sets the dimension for the kernel.
* @param dimension Dimension.
*/
public void setDimension(int dimension) {
this.dimension = dimension;
}
/**
* Constructs a new Dirichlet Kernel
* @param dimension Dimension of the kernel.
*/
public Dirichlet(int dimension) {
this.dimension = dimension;
}
@Override
public double Function(double[] x, double[] y) {
// Optimization in case x and y are
// exactly the same object reference.
double prod = 1;
for (int i = 0; i < x.length; i++)
{
double delta = x[i] - y[i];
double num = Math.sin((dimension + 0.5) * (delta));
double den = 2.0 * Math.sin(delta / 2.0);
prod *= num / den;
}
return prod;
}
}
Ads help maintain this website.