pt.tumba.ngram.bayes
Class DiscreteFunction

java.lang.Object
  extended by pt.tumba.ngram.bayes.DiscreteFunction
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
ProbabilityFunction

public class DiscreteFunction
extends java.lang.Object
implements java.io.Serializable

See Also:
Serialized Form

Field Summary
protected  double[] values
           
protected  DiscreteVariable[] variables
           
 
Constructor Summary
DiscreteFunction()
          Default constructor for a 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.
 int get_index(int ind)
          Get a DiscreteVariable object with a particular index.
 int[] get_indexes()
          Get an array with all the indexes of the DiscreteVariable objects in the current DiscreteFunction.
 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.
 double get_value(int index)
          Get a value of the current DiscreteFunction given the position of the value in the array of values.
 double[] get_values()
          Get all values of the current DiscreteFunction.
 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 function (in-place) assuming that it is a conditional distribution for the first variable
 void normalize()
          Normalize a 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.
 void print()
          Print method for DiscreteFunction.
 void print(java.io.PrintStream out)
          Print method for DiscreteFunction into a PrintStream.
(package private)  boolean same_variables(DiscreteFunction df)
           
 void set_value(int index, double v)
          Set a value in the current DiscreteFunction given its position in the array of values.
 void set_values(double[] vs)
          Set the values in the DiscreteFunction.
 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.
 
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
Constructor Detail

DiscreteFunction

public DiscreteFunction()
Default constructor for a 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.


same_variables

boolean same_variables(DiscreteFunction df)

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.


normalize

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


normalize_first

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


print

public void print()
Print method for DiscreteFunction.


print

public void print(java.io.PrintStream out)
Print method for DiscreteFunction into a PrintStream.


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_indexes

public int[] get_indexes()
Get an array with all the indexes of the DiscreteVariable objects in the current DiscreteFunction.


get_index

public int get_index(int ind)
Get a DiscreteVariable object with a particular index.

Parameters:
ind - Index of the desired DiscreteVariable.

get_values

public double[] get_values()
Get all values of the current DiscreteFunction.


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_values

public void set_values(double[] vs)
Set the values in the DiscreteFunction.


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.