blog
Interface Query

All Known Implementing Classes:
AbstractQuery, ArgSpecQuery, FormulaQuery

public interface Query

Interface for queries that can be answered by an inference engine. A Query object records both results from a single run of an inference algorithm, and statistics about the results of several runs (if the inference algorithm is randomized, each run may yield different results).

The getVariables method returns a set of random variables such that the result of this query depends only on the posterior joint distribution of these variables. There are two ways in which this posterior distribution can be provided to the Query object. One is to call updateStats repeatedly, passing in partial worlds with weights; these worlds must be complete enough to define values for all the query's variables. The other way is to pass in a factor over these variables using setPosterior.


Method Summary
 boolean checkTypesAndScope(Model model)
          Returns true if this query satisfies type and scope constraints.
 int compile()
          Does compilation steps that can only be done correctly once the model is complete.
 java.lang.Object getLocation()
          Returns an object whose toString method yields a description of the location where this query occurred in an input file.
 java.util.Collection<? extends BayesNetVar> getVariables()
          Returns a collection of (basic or derived) random variables such that the result of this query depends only on the posterior joint distribution for these variables.
 void logResults(int numSamples)
          If a log file has been specified, prints the results so far to that file.
 void printResults(java.io.PrintStream s)
          Prints the results of this query to the given stream.
 void printVarianceResults(java.io.PrintStream s)
          Prints across-run statistics.
 void setPosterior(ve.Factor posterior)
          Sets the posterior distribution for the variables returned by getVariables.
 void updateStats(PartialWorld world, double weight)
          Updates the within-run statistics for this query to reflect the given world sampled with the given weight.
 void zeroOut()
          Ends the current run, records across-run statistics for it, and clears the within-run statistics.
 

Method Detail

printResults

void printResults(java.io.PrintStream s)
Prints the results of this query to the given stream.


logResults

void logResults(int numSamples)
If a log file has been specified, prints the results so far to that file.

Parameters:
numSamples - the number of samples taken by the inference engine so far (can be set to zero for non-sampling inference engines)

getVariables

java.util.Collection<? extends BayesNetVar> getVariables()
Returns a collection of (basic or derived) random variables such that the result of this query depends only on the posterior joint distribution for these variables.

Throws:
java.lang.IllegalStateException - if compile has not yet been called

checkTypesAndScope

boolean checkTypesAndScope(Model model)
Returns true if this query satisfies type and scope constraints. If there is a type or scope error, prints a message to standard error and returns false.


compile

int compile()
Does compilation steps that can only be done correctly once the model is complete. Prints messages to standard error if any errors are encountered. Returns the number of errors encountered.


updateStats

void updateStats(PartialWorld world,
                 double weight)
Updates the within-run statistics for this query to reflect the given world sampled with the given weight. The world must be complete enough to define values for all the variables returned by getVariables.

The effects of calling both updateStats and setPosterior in the same run are not defined.


setPosterior

void setPosterior(ve.Factor posterior)
Sets the posterior distribution for the variables returned by getVariables. This overwrites any results specified previously for the current run using this method or updateStats.

The effects of calling both updateStats and setPosterior in the same run are not defined.

Parameters:
posterior - factor whose set of variables is the same as the collection returned by getVariables, and whose entries sum to 1

zeroOut

void zeroOut()
Ends the current run, records across-run statistics for it, and clears the within-run statistics.


printVarianceResults

void printVarianceResults(java.io.PrintStream s)
Prints across-run statistics.


getLocation

java.lang.Object getLocation()
Returns an object whose toString method yields a description of the location where this query occurred in an input file.