techniques.BN
Class Variable

java.lang.Object
  |
  +--techniques.BN.Variable
All Implemented Interfaces:
Cloneable

public class Variable
extends Object
implements Cloneable

Represents a variable in a bayes net, and beyond the variable name stores the possible values and the conditional probability table for the variable. By default variables have 2 given values (1) Boolean.FALSE, and (2) Boolean.TRUE . These values are mapped to numbers (from 0 to getNumValues) and programs need to explicitly retrieve the given values for the non numeric values.


Constructor Summary
Variable(String varName)
           
Variable(String varName, Object[] varGivenValues)
           
 
Method Summary
 Object clone()
           
 Object getGivenValue(int ndx)
          Maps number to given value
 Object[] getGivenValues()
          Returns all given values (in an array with indices representing the mapping from number to given value)
 String getName()
          Returns variable name
 int getNumValues()
          Returns number of values used by variable
 Variable[] getParents()
           
 double getProb(HashMap evidence)
          Used to get the probability values for the given variable evidence.
 double getProb(int value, HashMap evidence)
          Used to get the probability values for the given variable vaue index/number and evidence
 ProbTable getProbTable()
          Returns cond.
 int getValNdx(Object givenValue)
          Maps given value to number
 int[] getValues()
          Just returns all numbers from 0 to getNumValues()
 void setParent(Variable var)
          set parents for the conditional prob.
 void setParents(Variable[] vars)
          set parents for the conditional prob.
 void setProb(int i, double[] valueCPT)
          Used to set the condition probability table values for the given variable vaue index/number
 void setTrueProb(double[] trueCPT)
          Used to set the condition probability table values by only providing values for variable given value being Boolean.TRUE (the method calculate values for Boolean.FALSE).
 String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Variable

public Variable(String varName)
Parameters:
varName - - name of variable

Variable

public Variable(String varName,
                Object[] varGivenValues)
Parameters:
varName - - name of variable
varGivenValues - - given values of the variables (note all variables have values which are integers, and given values, for example Boolean.TRUE and Boolean.FALSE
Method Detail

getName

public String getName()
Returns variable name

getProbTable

public ProbTable getProbTable()
Returns cond. prob. table

toString

public String toString()
Overrides:
toString in class Object

getGivenValues

public Object[] getGivenValues()
Returns all given values (in an array with indices representing the mapping from number to given value)

getValues

public int[] getValues()
Just returns all numbers from 0 to getNumValues()

getValNdx

public int getValNdx(Object givenValue)
Maps given value to number

getGivenValue

public Object getGivenValue(int ndx)
Maps number to given value

getNumValues

public int getNumValues()
Returns number of values used by variable

setParent

public void setParent(Variable var)
set parents for the conditional prob. table

setParents

public void setParents(Variable[] vars)
set parents for the conditional prob. table

getParents

public Variable[] getParents()

setTrueProb

public void setTrueProb(double[] trueCPT)
Used to set the condition probability table values by only providing values for variable given value being Boolean.TRUE (the method calculate values for Boolean.FALSE).

setProb

public void setProb(int i,
                    double[] valueCPT)
Used to set the condition probability table values for the given variable vaue index/number

getProb

public double getProb(int value,
                      HashMap evidence)
Used to get the probability values for the given variable vaue index/number and evidence
Parameters:
value - - variable value index/number
evidence - - a map of variables to their value indices

getProb

public double getProb(HashMap evidence)
Used to get the probability values for the given variable evidence. All values (as given by indices) in the table (for the variable and parents), need to be specified in the evidence (otherwise a not enough evidence exception will be thrown).

clone

public Object clone()
             throws CloneNotSupportedException