All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.clust4j.kernel.ANOVAKernel Maven / Gradle / Ivy

Go to download

A suite of classification clustering algorithm implementations for Java. A number of partitional, hierarchical and density-based algorithms including DBSCAN, k-Means, k-Medoids, MeanShift, Affinity Propagation, HDBSCAN and more.

The newest version!
/*******************************************************************************
 *    Copyright 2015, 2016 Taylor G Smith
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 *******************************************************************************/
package com.clust4j.kernel;

import org.apache.commons.math3.util.FastMath;

import com.clust4j.utils.VecUtils;

/**
 * The ANOVA kernel is also a {@link RadialBasisKernel}, just as the {@link GaussianKernel} 
 * and {@link LaplacianKernel}. It is said to perform well in multidimensional 
 * regression problems (Hofmann, 2008).
 * 
 * @see Souza, Cesar R. -- Kernel Functions for Machine Learning Applications.
 * @author Taylor G Smith
 */
public class ANOVAKernel extends RadialBasisKernel {
	/**
	 * 
	 */
	private static final long serialVersionUID = -2352083487381024145L;
	final public static double DEFAULT_DEGREE = 1;
	private final double degree;

	public ANOVAKernel() {
		this(DEFAULT_DEGREE);
	}
	
	public ANOVAKernel(final double degree) {
		this(DEFAULT_SIGMA, degree);
	}
	
	public ANOVAKernel(final double sigma, final double degree) {
		super(sigma);
		
		this.degree = degree;
	}
	
	public double getDegree() {
		return degree;
	}
	
	@Override
	public String getName() {
		return "ANOVAKernel";
	}
	
	@Override
	public double getPartialSimilarity(final double[] a, final double[] b) {
		VecUtils.checkDims(a, b);
		
		double s = 0, diff;
		for(int i = 0; i < a.length; i++) {
			diff = a[i] - b[i];
			s += FastMath.pow(FastMath.exp((diff * diff) * -getSigma()), getDegree());
		}
		
		return s;
	}
	
	@Override
	public double partialSimilarityToSimilarity(double partial) {
		return partial;
	}
	
	@Override
	public double similarityToPartialSimilarity(double full) {
		return full;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy