BayesianNetworks
Class DiscreteFunction

java.lang.Object
  |
  +--BayesianNetworks.DiscreteFunction

public class DiscreteFunction
extends java.lang.Object


Field Summary
protected  BayesNet bn
           
protected  double[] values
           
protected  DiscreteVariable[] variables
           
 
Constructor Summary
DiscreteFunction(BayesNet b_n, int n_vb, int n_vl)
          Constructor for DiscreteFunction.
DiscreteFunction(DiscreteFunction df, BayesNet b_n)
          Constructor for DiscreteFunction.
DiscreteFunction(DiscreteVariable[] for_variables, DiscreteVariable[] given_variables, double[] table)
          Basic constructor for DiscreteFunction.
DiscreteFunction(DiscreteVariable[] pvs, double[] v)
          Simple constructor for DiscreteFunction.
DiscreteFunction(int n_vb, int n_vl)
          Simple constructor for DiscreteFunction.
 
Method Summary
 double evaluate(DiscreteVariable[] pvs, int[] value_indexes)
          Evaluate a function given a (possibly partial) instantiation of variables through the indexes.
 double evaluate(int[] value_indexes)
          Evaluate a function given a (possibly partial) instantiation of variables through the markers.
 double evaluate(java.lang.String[][] variable_value_pairs)
          Evaluate a function given a list of pairs (Variable Value) which specifies a value of the function.
 double expected_value(DiscreteFunction df)
          Obtain expected value of a DiscreteFunction The current implementation is very limited; it assumes that both the DiscreteFunction object and the DiscreteFunctions object has a single variable, and the variable must be the same for both functions.
 int get_index(int ind)
          Get a DiscreteVariable object with a particular index.
 int get_position_from_indexes(DiscreteVariable[] pvs, int[] variable_indexes)
          Get position in a function from a (possibly partial) instantiation of variables through the indexes.
 int get_position_from_indexes(int[] variable_indexes)
          Get position in a function from a (possibly partial) instantiation of variables through the indexes.
 double get_value(int index)
          Get a value of the current DiscreteFunction given the position of the value in the array of values.
 DiscreteVariable get_variable(int index)
          Get a variable in the current DiscreteFunction.
 DiscreteVariable[] get_variables()
          Get the variables in the current DiscreteFunction.
 boolean memberOf(int index)
          Check whether an index is present in the function.
 DiscreteFunction multiply(DiscreteVariable[] dvs, DiscreteFunction mult)
          Multiply two DiscreteFunction objects.
 void normalize_first()
          Normalize a probability function (in-place) assuming that it is a conditional distribution for the first variable
 void normalize()
          Normalize a probability function (in-place).
 int number_values()
          Return the number of values in the current DiscreteFunction.
 int number_variables()
          Return the number of DiscreteVariable objects in the current DiscreteFunction.
 double posterior_expected_value(DiscreteFunction df)
          Obtain posterior expected value of a DiscreteFunction This assumes that the probability values are unnormalized, equal to p(x, e) where e is the evidence.
 void set_value(int index, double v)
          Set a value in the current DiscreteFunction given its position in the array of values.
 void set_value(java.lang.String[][] variable_value_pairs, double val)
          Set a single value of the probability function.
 void set_variable(int index, DiscreteVariable dv)
          Set a DiscreteVariable in the current DiscreteFunction given its position in the array of values.
 DiscreteFunction sum_out(DiscreteVariable[] dvs, boolean[] markers)
          Sum out some variables in the function.
 double variance(DiscreteFunction df)
          Calculate the variance of a DiscreteFunction.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

variables

protected DiscreteVariable[] variables

values

protected double[] values

bn

protected BayesNet bn
Constructor Detail

DiscreteFunction

public DiscreteFunction(DiscreteVariable[] for_variables,
                        DiscreteVariable[] given_variables,
                        double[] table)
Basic constructor for DiscreteFunction.

DiscreteFunction

public DiscreteFunction(BayesNet b_n,
                        int n_vb,
                        int n_vl)
Constructor for DiscreteFunction.

DiscreteFunction

public DiscreteFunction(DiscreteFunction df,
                        BayesNet b_n)
Constructor for DiscreteFunction.

DiscreteFunction

public DiscreteFunction(int n_vb,
                        int n_vl)
Simple constructor for DiscreteFunction.
Parameters:
n_vb - Number of variables in the function.
n_vl - Number of values in the function.

DiscreteFunction

public DiscreteFunction(DiscreteVariable[] pvs,
                        double[] v)
Simple constructor for DiscreteFunction.
Parameters:
pvs - An array of ProbabilityVariable objects.
v - An array of values for the function.
Method Detail

memberOf

public boolean memberOf(int index)
Check whether an index is present in the function.

evaluate

public double evaluate(DiscreteVariable[] pvs,
                       int[] value_indexes)
Evaluate a function given a (possibly partial) instantiation of variables through the indexes. Indexes indicate which variables are present in the function to be evaluated, assuming an array of DiscreteVariable objects is present.
Parameters:
pvs - The array of DiscreteVariable objects that is used to compute the position indicated by the markers.
value_indexes - The markers.

get_position_from_indexes

public int get_position_from_indexes(DiscreteVariable[] pvs,
                                     int[] variable_indexes)
Get position in a function from a (possibly partial) instantiation of variables through the indexes.

sum_out

public DiscreteFunction sum_out(DiscreteVariable[] dvs,
                                boolean[] markers)
Sum out some variables in the function.
Parameters:
markers - A boolean vector indicating which variables are to be summed out. If markers[i] is true, then the ith variable is to be summed out; if markers[i] is false, the ith variable is not to be summed out.

multiply

public DiscreteFunction multiply(DiscreteVariable[] dvs,
                                 DiscreteFunction mult)
Multiply two DiscreteFunction objects.

set_value

public void set_value(java.lang.String[][] variable_value_pairs,
                      double val)
Set a single value of the probability function.

evaluate

public double evaluate(java.lang.String[][] variable_value_pairs)
Evaluate a function given a list of pairs (Variable Value) which specifies a value of the function.

evaluate

public double evaluate(int[] value_indexes)
Evaluate a function given a (possibly partial) instantiation of variables through the markers. The markers indicate which variables are present in the function to be evaluated.

get_position_from_indexes

public int get_position_from_indexes(int[] variable_indexes)
Get position in a function from a (possibly partial) instantiation of variables through the indexes.

normalize

public void normalize()
Normalize a probability function (in-place).

normalize_first

public void normalize_first()
Normalize a probability function (in-place) assuming that it is a conditional distribution for the first variable

expected_value

public double expected_value(DiscreteFunction df)
Obtain expected value of a DiscreteFunction The current implementation is very limited; it assumes that both the DiscreteFunction object and the DiscreteFunctions object has a single variable, and the variable must be the same for both functions.

posterior_expected_value

public double posterior_expected_value(DiscreteFunction df)
Obtain posterior expected value of a DiscreteFunction This assumes that the probability values are unnormalized, equal to p(x, e) where e is the evidence. The current implementation is very limited; it assumes that both the DiscreteFunction object and the DiscreteFunctions object has a single variable, and the variable must be the same for both functions.

variance

public double variance(DiscreteFunction df)
Calculate the variance of a DiscreteFunction. The current implementation is very limited; it assumes that both the DiscreteFunction object and the DiscreteFunctions object has a single variable, and the variable must be the same for both functions.

number_variables

public int number_variables()
Return the number of DiscreteVariable objects in the current DiscreteFunction.

number_values

public int number_values()
Return the number of values in the current DiscreteFunction.

get_variables

public DiscreteVariable[] get_variables()
Get the variables in the current DiscreteFunction.

get_variable

public DiscreteVariable get_variable(int index)
Get a variable in the current DiscreteFunction.
Parameters:
index - Position of the variable to be returned in the array of DiscreteVariable objects.

get_index

public int get_index(int ind)
Get a DiscreteVariable object with a particular index.
Parameters:
ind - Index of the desired DiscreteVariable.

get_value

public double get_value(int index)
Get a value of the current DiscreteFunction given the position of the value in the array of values.

set_value

public void set_value(int index,
                      double v)
Set a value in the current DiscreteFunction given its position in the array of values.
Parameters:
index - The position of the value.
v - The new value.

set_variable

public void set_variable(int index,
                         DiscreteVariable dv)
Set a DiscreteVariable in the current DiscreteFunction given its position in the array of values.
Parameters:
index - The position of the value.
pv - The new DiscreteVariable.