com.cra.bnet.engine
Class Discretizer

java.lang.Object
  |
  +--com.cra.bnet.engine.Discretizer

public class Discretizer
extends Object

Discretizes a value of a continuous variable to a state of a discrete variable. This class uses a set of boundaries to define the discretized regions of the continuous variable. For example, suppose an instance was created as follows:

 double[] boundaries = new double[] {0, 10, 20};
 Discretizer discretizer = new Discretizer(boundaries);
 
The discretizer would then discretize values v as follows:

Note: When creating boundaries, make sure that the node has the correct number of states to support the boundaries you create.

The discretizer can then be used to convert a continuous value into hard evidence for a discrete node:

 double[] evidence = discretizer.getEvidence(2.5);
 DiscreteNode node = ...;
 node.setEvidence(evidence);
 
The evidence array above represents hard evidence for state 1 of the discrete node, since the value of 2.5 corresponds to the second discrete region. The array would consist of [0 1 0 0].

For more information and instruction on converting evidence from a continuous variable into hard evidence, please see the BNet.EngineKit Developer's Guide.


Constructor Summary
Discretizer(double[] boundaries)
          Creates a new Discretizer using the specified boundaries.
 
Method Summary
 double[] getBoundaries()
          Returns the boundaries that this discretizer uses.
 double[] getEvidence(double value)
          Discretizes the specified value and creates evidence that can be posted to a discrete node.
 int getIndex(double value)
          Returns the index of the discrete state that the specified value is discretized to.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Discretizer

public Discretizer(double[] boundaries)
Creates a new Discretizer using the specified boundaries.

Parameters:
boundaries - boundaries used to discretize numbers.
Throws:
NullPointerException - if boundaries is null.
IllegalArgumentException - if the length of the boundaries array is zero.
Method Detail

getBoundaries

public double[] getBoundaries()
Returns the boundaries that this discretizer uses.

Returns:
the boundaries that this discretizer uses.

getIndex

public int getIndex(double value)
Returns the index of the discrete state that the specified value is discretized to.

Parameters:
value - continuous value.
Returns:
the index of the discrete state that the specified value is discretized to.

getEvidence

public double[] getEvidence(double value)
Discretizes the specified value and creates evidence that can be posted to a discrete node. Clients can provide the returned array to the DiscreteNode.setEvidence method.

Parameters:
value - continuous value.
Returns:
evidence that can be posted to a discrete node.