public class OnlineEngineMop
extends java.lang.Object
After we have evaluated, we can also differentiate in time that is linear in the size of the circuit. Afterward, we can additionally retrieve, for each value of each network variable, and for each position of each potential, a partial derivative, a marginal, and a posterior marginal.
After we have evaluated, we can also enumerate in time that is linear in the
size of the circuit. Afterward, we can additionally retrieve the number of
MOP instantiations, and we can compute the ith instantiation. When computing
multiple instantiations, work performed by the previous invocation will not
be redone, so it is most efficient to compute instantiations in order. For
example:
mopInstantiation.evaluate();
mopInstantiation.enumerate();
for (int i = 0; i < mopEngine.count(); ++i) {
HashMap<Variable, Integer\> m = mopEngine.instantiation(i);
}
}
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 |
---|
OnlineEngineMop(java.io.BufferedReader lmReader,
java.io.BufferedReader acReader,
boolean enableDifferentiation,
boolean enableEnumeration)
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.
|
OnlineEngineMop(java.lang.String lmFilename,
java.lang.String acFilename,
boolean enableDifferentiation,
boolean enableEnumeration)
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 |
---|---|
long |
count()
Returns the MOP count computed during the most recent enumerate operation
or Long.MAX_VALUE if this count exceeds the range of a long.
|
void |
differentiate()
Differentiates the circuit.
|
boolean |
differentiateResultsAvailable()
Returns whether differentiation results are available.
|
void |
enumerate()
Computes the number of mop instantiations and sets up the bookkeeping
necessary to iterate through mop instantiations.
|
boolean |
enumerateResultsAvailable()
Returns whether enumerate 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.util.Map<java.lang.Integer,java.lang.Integer> |
instantiation(long index)
Returns an unmodifiable map to the index'th mop instantiation, computed
during the most recent enumeration.
|
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 the position is not a query position.
|
double[] |
potPartials(int pot)
For each position p of the given network potential, returns the partial
derivative of the restricted AC with respect to x'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 or
Double.NaN if x is not a query value.
|
double[] |
varPartials(int v)
For each value x of the given network variable, returns the partial
derivative of the restricted 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 or
Double.NaN if x is not a query value.
|
public OnlineEngineMop(java.lang.String lmFilename, java.lang.String acFilename, boolean enableDifferentiation, boolean enableEnumeration) throws java.lang.Exception
acFilename
- the first given name.lmFilename
- the second given name.enableDifferentiation
- if true, then differentiation can be performed
on the engine but the engine will require more memory.enableEnumeration
- if true, then counting and enumeration can be
performed on the engine but the engine will require more memory.java.lang.Exception
- if fails.public OnlineEngineMop(java.io.BufferedReader lmReader, java.io.BufferedReader acReader, boolean enableDifferentiation, boolean enableEnumeration) 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.enableEnumeration
- if true, then counting and enumeration 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 differentiateResultsAvailable()
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 void enumerate() throws java.lang.Exception
java.lang.Exception
- if fails.public boolean enumerateResultsAvailable()
public long count() throws java.lang.Exception
java.lang.Exception
public java.util.Map<java.lang.Integer,java.lang.Integer> instantiation(long index) throws java.lang.Exception
index
- identifies which mop instantiation to obtain; should be in
[0, countingResults()).java.lang.Exception
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.