com.github.TKnudsen.ComplexDataObject.model.weighting.Integer.GaussianIntegerWeightingFunction Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of complex-data-object Show documentation
Show all versions of complex-data-object Show documentation
A library that models real-world objects in Java, referred to as ComplexDataObjects. Other features: IO and preprocessing of ComplexDataObjects.
package com.github.TKnudsen.ComplexDataObject.model.weighting.Integer;
/**
*
* Title: GaussianWeightingFunction
*
*
*
* Description: Provides a weighting for a given interval, the center of the
* values is defined by a reference (default: 0.0). The variance defines the
* diversity of the kernel.
*
*
*
* Copyright: Copyright (c) 2016
*
*
* @author Juergen Bernard
* @version 1.0
*/
public class GaussianIntegerWeightingFunction implements IIntegerWeightingKernel {
private Integer interval = Integer.MAX_VALUE;
private Integer reference = 0;
private Double variance;
public GaussianIntegerWeightingFunction(Double variance) {
this.variance = variance;
}
@Override
public double getWeight(Integer t) {
if (Math.abs(reference - t) > interval)
return 0.0;
if (interval == 0)
return 1.0;
return gaussian(t);
}
/**
*
* @param a
* @param b
* @param x
* @return
*/
public double gaussian(double x) {
double a = 1 / (variance * Math.sqrt(2 * Math.PI));
return a * Math.exp(-Math.pow((x - reference), 2) / (2 * Math.pow(variance, 2)));
}
@Override
public Integer getReference() {
return reference;
}
@Override
public void setReference(Integer t) {
this.reference = t;
}
public Double getVariance() {
return variance;
}
public void setVariance(Double variance) {
this.variance = variance;
}
@Override
public Integer getInterval() {
return this.interval;
}
@Override
public void setInterval(Integer interval) {
this.interval = interval;
}
}