RBNLearning
Class GradientGraph

java.lang.Object
  extended by RBNLearning.GradientGraph

public class GradientGraph
extends java.lang.Object

Main class for RBN parameter learning. The Gradient Graph is a representation of the likelihood function given data consisting of pairs of relational input domains (objects of type RelStruc), and observed values of the probabilistic relations (given as objects of type Instantiation). Each pair may contain a different input domain, or there may be multiple observations of the probabilistic relations for one input domain. Nodes in the gradient graph correspond to ground probability formulas obtained from recursively evaluating the probability formulas corresponding to the ground atoms in the Instantiations. Identical ground (sub-) formulas obtained from the evaluation of different instantiated ground atoms are included only once in the GradientGraph. For this purpose a hashtable allNodes for the nodes is maintained. The keys for the nodes are constructed as strings consisting of a concatentation of the index of the data case with the string representation of the ground probability formula. Example: the probabilistic relation r(x,y) is defined by F(x,y) = (s(x,y):t(y),0.6). In both the first and the second data pair the ground atom r(4,7) is observed to be true. Then two nodes will be constructed, one with key 1.(s(4,7):t(7),0.6), and one with key 2.(s(4,7):t(7),0.6). Since the sub-formulas s(4,7) and t(7) may evaluate differently in the two data pairs, these formulas have to be distinguished. If, for example, s(4,7) is observed to be true in the first data pair, and false in the second, then a further nodes with key 1.t(7) will be constructed, but no node 2.t(7).


Constructor Summary
GradientGraph(Primula mypr, RelData data, LearnModule mylm)
           
 
Method Summary
protected  void addToIndicators(GradientGraphIndicatorNode ggin)
           
protected  double computeCombFunc(int cf, double[] args)
           
 double[] computeLikelihood(LearnThread mythread)
          Computes the likelihood value given the current parameter setting by Gibbs sampling.
 double[] currentLikelihood()
           
 double[] currentParameters()
           
 void evaluateBounds()
           
 void evaluateLikelihoodAndPartDerivs(boolean likelihoodonly)
          Computes the empirical likelihood and empirical partial derivatives of the current sample.
 double[] getParameters()
           
 void gibbsSample(int windowindex, LearnThread mythread)
          Performs one round of Gibbs sampling.
 boolean initIndicators(LearnThread mythread)
           
 double[] learnParameters(LearnThread mythread)
           
 int numberOfEdges()
          Returns the number of links in the graph
 int numberOfIndicators()
          Returns the number of indicator nodes in the graph
 int numberOfNodes()
          Returns the number of nodes in the graph
 int numberOfParameters()
           
 java.lang.String parameterAt(int i)
           
 java.lang.String[] parameters()
           
 void resetBounds()
          Resets to [-1,-1] the bounds in all nodes
 void resetValues(boolean valueonly)
           
 void setParameters(double[] thetas)
          Sets the parameter values to thetas.
 void setParametersRandom()
           
 void setParametersUniform()
           
 void setTruthVals(int sno)
          Sets the truthval fields in the ProbFormNodes corresponding to unobserved atoms to the truthvalues in the sno's sample If sno<0 do nothing!
 void showAllLikelihoods(double incr)
          Prints a list of likelihood values for all possible parameter settings obtained by varying each parameter from 0.0 to 1.0 using a stepsize of incr
 void showAllNodes(int verbose, RelStruc A)
           
 java.lang.String showGraphInfo(int verbose, RelStruc A)
           
 void showLikelihoodNode(RelStruc A)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GradientGraph

public GradientGraph(Primula mypr,
                     RelData data,
                     LearnModule mylm)
              throws RBNCompatibilityException
Throws:
RBNCompatibilityException
Method Detail

addToIndicators

protected void addToIndicators(GradientGraphIndicatorNode ggin)

computeCombFunc

protected double computeCombFunc(int cf,
                                 double[] args)

currentLikelihood

public double[] currentLikelihood()

currentParameters

public double[] currentParameters()

numberOfParameters

public int numberOfParameters()

parameters

public java.lang.String[] parameters()

parameterAt

public java.lang.String parameterAt(int i)

evaluateLikelihoodAndPartDerivs

public void evaluateLikelihoodAndPartDerivs(boolean likelihoodonly)
Computes the empirical likelihood and empirical partial derivatives of the current sample. The value and gradient fields contain the values for the last sample. When numchains=0, then value = likelihoodsum and gradient = gradientsum are the correct values.


evaluateBounds

public void evaluateBounds()

resetValues

public void resetValues(boolean valueonly)

resetBounds

public void resetBounds()
Resets to [-1,-1] the bounds in all nodes


initIndicators

public boolean initIndicators(LearnThread mythread)

gibbsSample

public void gibbsSample(int windowindex,
                        LearnThread mythread)
Performs one round of Gibbs sampling. Each variable is resampled once. windowindex is the index of the oldest among the this.windowsize samples that are being stored. In the GradientGraphIndicatorNode.sampledVals arrays the values windowindex+0,...,windowindex+numchains-1 are overwritten


setTruthVals

public void setTruthVals(int sno)
Sets the truthval fields in the ProbFormNodes corresponding to unobserved atoms to the truthvalues in the sno's sample If sno<0 do nothing!


showLikelihoodNode

public void showLikelihoodNode(RelStruc A)

showAllNodes

public void showAllNodes(int verbose,
                         RelStruc A)

learnParameters

public double[] learnParameters(LearnThread mythread)

setParameters

public void setParameters(double[] thetas)
Sets the parameter values to thetas. thetas[i] will be the value of the parameter in the i'th position in this.paramNodes


getParameters

public double[] getParameters()

setParametersRandom

public void setParametersRandom()

setParametersUniform

public void setParametersUniform()

showGraphInfo

public java.lang.String showGraphInfo(int verbose,
                                      RelStruc A)

showAllLikelihoods

public void showAllLikelihoods(double incr)
Prints a list of likelihood values for all possible parameter settings obtained by varying each parameter from 0.0 to 1.0 using a stepsize of incr


numberOfNodes

public int numberOfNodes()
Returns the number of nodes in the graph


numberOfIndicators

public int numberOfIndicators()
Returns the number of indicator nodes in the graph


numberOfEdges

public int numberOfEdges()
Returns the number of links in the graph


computeLikelihood

public double[] computeLikelihood(LearnThread mythread)
Computes the likelihood value given the current parameter setting by Gibbs sampling. It is assumed that initIndicators() has been successfully executed. Returns double array with result[0]=per node likelihood, result[1]=data log-likelihood

Returns: