weka.gui.boundaryvisualizer
Class KDDataGenerator

java.lang.Object
  extended byweka.gui.boundaryvisualizer.KDDataGenerator
All Implemented Interfaces:
DataGenerator, java.io.Serializable

public class KDDataGenerator
extends java.lang.Object
implements DataGenerator, java.io.Serializable

KDDataGenerator. Class that uses kernels to generate new random instances based on a supplied set of instances.

Since:
1.0
Version:
$Revision: 1.4 $
Author:
Mark Hall
See Also:
DataGenerator, Serializable, Serialized Form

Field Summary
private  double[] m_globalMeansOrModes
           
private  Instances m_instances
           
private  int m_kernelBandwidth
           
private  double[][] m_kernelParams
           
private  double m_laplaceConst
           
protected  double[] m_Max
          The maximum values for numeric attributes.
protected  double[] m_Min
          The minimum values for numeric attributes.
private  double m_minStdDev
           
private static double m_normConst
           
private  java.util.Random m_random
           
private  int m_seed
           
private  double[] m_standardDeviations
           
private  boolean[] m_weightingDimensions
           
private  double[] m_weightingValues
           
 
Constructor Summary
KDDataGenerator()
           
 
Method Summary
 void buildGenerator(Instances inputInstances)
          Initialize the generator using the supplied instances
private  double[] computeCumulativeDistribution(double[] dist)
          Return a cumulative distribution from a discrete distribution
private  void computeParams()
           
private  double distance(Instance first, Instance second)
          Calculates the distance between two instances
 double[][] generateInstances(int[] indices)
          Generates a new instance using one kernel estimator.
 int getKernelBandwidth()
          Get the kernel bandwidth
 int getNumGeneratingModels()
          Return the number of kernels (there is one per training instance)
 double[] getWeights()
          Get weights
private  double norm(double x, int i)
          Normalizes a given value of a numeric attribute.
private  double normalDens(double x, double mean, double stdDev)
          Density function of normal distribution.
 void setKernelBandwidth(int kb)
          Set the kernel bandwidth (number of nearest neighbours to cover)
 void setSeed(int seed)
          Initializes a new random number generator using the supplied seed.
 void setWeightingDimensions(boolean[] dims)
          Set which dimensions to use when computing a weight for the next instance to generate
 void setWeightingValues(double[] vals)
          Set the values for the weighting dimensions to be used when computing the weight for the next instance to be generated
private  void updateMinMax(Instance instance)
          Updates the minimum and maximum values for all the attributes based on a new instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_instances

private Instances m_instances

m_standardDeviations

private double[] m_standardDeviations

m_globalMeansOrModes

private double[] m_globalMeansOrModes

m_minStdDev

private double m_minStdDev

m_laplaceConst

private double m_laplaceConst

m_seed

private int m_seed

m_random

private java.util.Random m_random

m_weightingDimensions

private boolean[] m_weightingDimensions

m_weightingValues

private double[] m_weightingValues

m_normConst

private static double m_normConst

m_kernelBandwidth

private int m_kernelBandwidth

m_kernelParams

private double[][] m_kernelParams

m_Min

protected double[] m_Min
The minimum values for numeric attributes.


m_Max

protected double[] m_Max
The maximum values for numeric attributes.

Constructor Detail

KDDataGenerator

public KDDataGenerator()
Method Detail

buildGenerator

public void buildGenerator(Instances inputInstances)
                    throws java.lang.Exception
Initialize the generator using the supplied instances

Specified by:
buildGenerator in interface DataGenerator
Parameters:
inputInstances - the instances to use as the basis of the kernels
Throws:
java.lang.Exception - if an error occurs

getWeights

public double[] getWeights()
Description copied from interface: DataGenerator
Get weights

Specified by:
getWeights in interface DataGenerator

computeCumulativeDistribution

private double[] computeCumulativeDistribution(double[] dist)
Return a cumulative distribution from a discrete distribution

Parameters:
dist - the distribution to use
Returns:
the cumulative distribution

generateInstances

public double[][] generateInstances(int[] indices)
                             throws java.lang.Exception
Generates a new instance using one kernel estimator. Each successive call to this method incremets the index of the kernel to use.

Specified by:
generateInstances in interface DataGenerator
Returns:
the new random instance
Throws:
java.lang.Exception - if an error occurs

normalDens

private double normalDens(double x,
                          double mean,
                          double stdDev)
Density function of normal distribution.

Parameters:
x - input value
mean - mean of distribution
stdDev - standard deviation of distribution

setWeightingDimensions

public void setWeightingDimensions(boolean[] dims)
Set which dimensions to use when computing a weight for the next instance to generate

Specified by:
setWeightingDimensions in interface DataGenerator
Parameters:
dims - an array of booleans indicating which dimensions to use

setWeightingValues

public void setWeightingValues(double[] vals)
Set the values for the weighting dimensions to be used when computing the weight for the next instance to be generated

Specified by:
setWeightingValues in interface DataGenerator
Parameters:
vals - an array of doubles containing the values of the weighting dimensions (corresponding to the entries that are set to true throw setWeightingDimensions)

getNumGeneratingModels

public int getNumGeneratingModels()
Return the number of kernels (there is one per training instance)

Specified by:
getNumGeneratingModels in interface DataGenerator
Returns:
the number of kernels

setKernelBandwidth

public void setKernelBandwidth(int kb)
Set the kernel bandwidth (number of nearest neighbours to cover)

Parameters:
kb - an int value

getKernelBandwidth

public int getKernelBandwidth()
Get the kernel bandwidth

Returns:
an int value

setSeed

public void setSeed(int seed)
Initializes a new random number generator using the supplied seed.

Specified by:
setSeed in interface DataGenerator
Parameters:
seed - an int value

distance

private double distance(Instance first,
                        Instance second)
Calculates the distance between two instances

Returns:
the distance between the two given instances, between 0 and 1

norm

private double norm(double x,
                    int i)
Normalizes a given value of a numeric attribute.

Parameters:
x - the value to be normalized
i - the attribute's index

updateMinMax

private void updateMinMax(Instance instance)
Updates the minimum and maximum values for all the attributes based on a new instance.

Parameters:
instance - the new instance

computeParams

private void computeParams()
                    throws java.lang.Exception
Throws:
java.lang.Exception