public class OnlineEngineSop
extends java.lang.Object
After we have evaluated, we can also compute answers to many additional queries by performing a second top-down pass, called differentiation, in time that is linear in the size of the circuit. These queries include, for each value of each network variable, and for each position of each potential, a partial derivative, a marginal, and a posterior marginal.
The implementation for this class is trivial. Each method invokes a method in the superclass. The purpose of this class is to define which operations are available for the particular compile kind by selectively making operations in the superclass public.
Constructor and Description |
---|
OnlineEngineSop(java.io.BufferedReader lmReader,
java.io.BufferedReader acReader,
boolean enableDifferentiation)
Reads a literal map from the first given reader, reads an AC from the
second given reader, and constructs an online engine linked to the read
literal map and read AC.
|
OnlineEngineSop(java.lang.String lmFilename,
java.lang.String acFilename,
boolean enableDifferentiation)
Reads a literal map from the file having the first given name, reads an AC
from the file having the second given name, and constructs an online engine
linked to the read literal map and read AC.
|
Modifier and Type | Method and Description |
---|---|
void |
differentiate()
Differentiates the circuit.
|
boolean |
differentiationResultsAvailable()
Returns whether differentiation results are available.
|
void |
evaluate(Evidence e)
Evaluates the circuit under the given evidence.
|
boolean |
evaluateResultsAvailable()
Returns whether evaluation results are available.
|
double |
evaluationResults()
Returns value computed during the most recent evaluation.
|
java.lang.String |
nameForPot(int p)
Returns the name of the given potential.
|
java.lang.String |
nameForVar(int v)
Returns the name of the given variable.
|
int |
numPotentials()
Returns the number of potentials.
|
int |
numVariables()
Returns the number of variables.
|
int |
potForName(java.lang.String n)
Returns the potential having the given name.
|
double[] |
potMarginals(int pot)
For each position p of the given network potential, returns p's marginal or
Double.NaN if p is not a query position.
|
double[] |
potPartials(int pot)
For each position p of the given network potential, returns the partial
derivative of the AC with respect to the p's parameter or Double.NaN if the
position is not a query position.
|
double[] |
potPosteriors(int pot)
For each position p of the given network potential, returns p's posterior
or Double.NaN if p is not a query position.
|
int |
varForName(java.lang.String n)
Returns the variable having the given name.
|
double[] |
varMarginals(int v)
For each value x of the given network variable, returns x's marginal P(x,e)
or Double.NaN if the value is not a query value.
|
double[] |
varPartials(int v)
For each value x of the given network variable, returns the partial
derivative of the AC with respect to the x's indicator or Double.NaN if
the value is not a query value.
|
double[] |
varPosteriors(int v)
For each value x of the given network variable, returns x's posterior
P(x|e) or Double.NaN if the value is not a query value.
|
public OnlineEngineSop(java.lang.String lmFilename, java.lang.String acFilename, boolean enableDifferentiation) throws java.lang.Exception
lmFilename
- the first given name.acFilename
- the second given name.enableDifferentiation
- if true, then differentiation can be performed
on the engine but the engine will require more memory.java.lang.Exception
- if fails.public OnlineEngineSop(java.io.BufferedReader lmReader, java.io.BufferedReader acReader, boolean enableDifferentiation) throws java.lang.Exception
lmReader
- the first given name.acReader
- the second given name.enableDifferentiation
- if true, then differentiation can be performed
on the engine but the engine will require more memory.java.lang.Exception
- if fails.public void differentiate() throws java.lang.Exception
java.lang.Exception
- if fails.public boolean differentiationResultsAvailable()
public double[] varPartials(int v) throws java.lang.Exception
v
- the given network variable.java.lang.Exception
- if fails.public double[] varMarginals(int v) throws java.lang.Exception
v
- the given network variable.java.lang.Exception
- if fails.public double[] varPosteriors(int v) throws java.lang.Exception
v
- the given network variable.java.lang.Exception
- if fails.public double[] potPartials(int pot) throws java.lang.Exception
pot
- the given network potential.java.lang.Exception
- if fails.public double[] potMarginals(int pot) throws java.lang.Exception
pot
- the given network potential.java.lang.Exception
- if fails.public double[] potPosteriors(int pot) throws java.lang.Exception
pot
- the given network potential.java.lang.Exception
- if fails.public int numVariables()
public int numPotentials()
public int varForName(java.lang.String n)
n
- the given name.public int potForName(java.lang.String n)
n
- the given name.public java.lang.String nameForVar(int v)
v
- the given variable.public java.lang.String nameForPot(int p)
p
- the given potential.public void evaluate(Evidence e) throws java.lang.Exception
e
- the given evidence.java.lang.Exception
- if the evaluation fails.public boolean evaluateResultsAvailable()
public double evaluationResults() throws java.lang.Exception
java.lang.Exception
- if the evaluation fails.