|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.Bayesia.api.APIInference
public class APIInference
The class APIInference is used to perform exact or approximate inference on a bayesian network. The bayesian network is loaded from an xbl file. This format is generated by BayesiaLab from Bayesia.
The exact inference is performed with a junction tree algorithm. The approximate inference is performed with a likelihood weighting algorithm.
The class APIInference allows to use networks containing discrete, interval, constraint and utility nodes. It allows also the use of temporal networks.
All the methods of this class can throw an instance of IllegalOperationException which is a subclass of RuntimeException so you can avoid to catch them.
| Field Summary | |
|---|---|
static int |
APPROXIMATE_INFERENCE
|
static int |
EXACT_INFERENCE
|
| Constructor Summary | |
|---|---|
APIInference(BayesianNetworkTransferHandler networkHandler,
java.lang.String licenceKey,
int inferenceType)
Creates a new APIExactInference with the network stored in the specified BayesianNetworkTransferHandler. |
|
APIInference(BayesianNetworkTransferHandler networkHandler,
java.lang.String licenceServerHost,
int licenseServerPort,
java.lang.String userGroup,
int inferenceType)
Creates a new APIExactInference with the network stored in the specified BayesianNetworkTransferHandler. |
|
APIInference(java.lang.String fileName,
java.lang.String licenceKey,
int inferenceType)
Creates a new APIExactInference with the network stored in the specified file. |
|
APIInference(java.lang.String fileName,
java.lang.String licenceServerHost,
int licenseServerPort,
java.lang.String userGroup,
int inferenceType)
Creates a new APIExactInference with the network stored in the specified file. |
|
| Method Summary | |
|---|---|
void |
close()
Method used to close the current instance of APIInference. |
java.lang.String |
getArcComment(java.lang.String nodeName1,
java.lang.String nodeName2)
Returns the comment associated to the arc between the nodes named nodeName1 and nodeName2. |
java.lang.String |
getComment()
Returns the comment associated to the network. |
int |
getCurrentTime()
Returns the current time of the network. |
java.lang.String |
getFormula(java.lang.String nodeName)
Returns the formula associated to the node as String. |
int |
getInferenceType()
Returns APPROXIMATE_INFERENCE if the inference type is approximate or EXACT_INFERENCE if the inference type is exact. |
float[][] |
getIntervals(java.lang.String nodeName)
Returns an array containing the minimum and the maximum of each interval of the node as floats. |
int[] |
getIntValues(java.lang.String nodeName)
Returns an array containing the values of the node as integers if the node is an integer node. |
double |
getLikelihood(java.lang.String nodeName,
java.lang.String value)
Returns the likelihood associated to a value of a node. |
double[] |
getLikelihoods(java.lang.String nodeName)
Retrieves an array containing the likelihoods associated to the values of a node. |
double |
getMean(java.lang.String nodeName)
Returns the mean of an interval or an integer node. |
java.lang.String |
getName()
Returns the name of the loaded network. |
java.lang.String |
getNodeComment(java.lang.String nodeName)
Returns the comment associated to the specified node |
java.lang.String[] |
getNodeNames()
Returns an array containing the name of the nodes in the network |
int |
getNodeNumber()
Returns the number of nodes in the network |
java.lang.String |
getObservedValue(java.lang.String nodeName)
Returns the observed value of the specified node if the node is observed. |
double[] |
getProbabilities(java.lang.String nodeName)
Return the posterior probabilities associated to the values of the specified node. |
double |
getProbability(java.lang.String nodeName,
java.lang.String value)
Returns the probability associated to a specific value of a node. |
double[] |
getQualities(java.lang.String nodeName)
Returns an array containing the qualities of a decision node. it can be used only on a decision node. |
int |
getSampleSize()
Returnss the sample size used to perform the approximate inference. |
double |
getStandardDeviation(java.lang.String nodeName)
Returns the standard deviation of an interval or an integer node. |
java.lang.String[] |
getStringValues(java.lang.String nodeName)
Returns an array containing the values of the node as String. |
double[] |
getUtility(java.lang.String nodeName)
Returns an array containing the minimum utility, the current utility and the maximum utility of a utility node. it can be used only on a utility node. |
int |
getValueNumber(java.lang.String nodeName)
Returns the number of values of the specified node. |
void |
increaseTime()
Performs a step of temporal simulation : from getCurrentTime() to getCurrentTime()+1. |
boolean |
isBoolean(java.lang.String nodeName)
Tests if the specified node is boolean, i.e. its values are equivalent to true and false. |
boolean |
isConstraint(java.lang.String nodeName)
Tests if the node is a constraint node. |
boolean |
isDecision(java.lang.String nodeName)
Tests if the node is a decision node. |
boolean |
isInteger(java.lang.String nodeName)
Tests if all the values of the specified node are integers. |
boolean |
isInterval(java.lang.String nodeName)
Tests if the node is described by a list of consecutives intervals. |
boolean |
isObservationValidityEnabled()
Returns the state of the observation validity checking. |
boolean |
isObserved(java.lang.String nodeName)
Tests if the specified node is observed. |
boolean |
isTemporal()
Tests if the network is temporal. |
boolean |
isUtility(java.lang.String nodeName)
Tests if the node is a utility node. |
boolean |
observe(java.lang.String nodeName,
float value)
Observes a float value for an interval node only. |
boolean |
observe(java.lang.String nodeName,
short valueIndex)
Observes a value through its index for a node. |
boolean |
observe(java.lang.String nodeName,
java.lang.String value)
Observes a value for a node. |
void |
resetTime()
Resets the time to 0. |
void |
setInferenceType(int type)
Sets the type of inference to use. |
boolean |
setLikelihood(java.lang.String nodeName,
short valueIndex,
double likelihood)
Sets the likelihood for a value of a node (soft evidence). |
boolean |
setLikelihood(java.lang.String nodeName,
java.lang.String value,
double likelihood)
Sets the likelihood for a value of a node (soft evidence). |
void |
setObservationValidityEnabled(boolean b)
Sets the observation validity enabled or not. |
void |
setSampleSize(int sampleSize)
Sets the sample size used by approximate inference. |
void |
setTime(int time)
Performs a temporal simulation from the current time to the specified time. |
void |
unobserve(java.lang.String nodeName)
Unobserves the specified node. |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int EXACT_INFERENCE
public static final int APPROXIMATE_INFERENCE
| Constructor Detail |
|---|
public APIInference(java.lang.String fileName,
java.lang.String licenceKey,
int inferenceType)
APIExactInference with the network stored in the specified file. You must provide a valid licence key for inference.
fileName - the name of the xbl file containing the networklicenceKey - the key of the licence.inferenceType - one of EXACT_INFERENCE and APPROXIMATE_INFERENCE.
public APIInference(java.lang.String fileName,
java.lang.String licenceServerHost,
int licenseServerPort,
java.lang.String userGroup,
int inferenceType)
APIExactInference with the network stored in the specified file. You must provide the host and the port of the license server. The user group is optional, depending on the configuration of the license ont the license server. Use this constructor if you use a license server.
fileName - the name of the xbl file containing the networklicenceServerHost - the host of the license server.licenseServerPort - the port of the license server.userGroup - the user group corresponding to the license, maybe null if no user group is specified on the license server.inferenceType - one of EXACT_INFERENCE and APPROXIMATE_INFERENCE.
public APIInference(BayesianNetworkTransferHandler networkHandler,
java.lang.String licenceKey,
int inferenceType)
APIExactInference with the network stored in the specified BayesianNetworkTransferHandler. You must provide a valid licence key for inference.
networkHandler - the transfer handler containing the networklicenceKey - the key of the licence.inferenceType - one of EXACT_INFERENCE and APPROXIMATE_INFERENCE.
public APIInference(BayesianNetworkTransferHandler networkHandler,
java.lang.String licenceServerHost,
int licenseServerPort,
java.lang.String userGroup,
int inferenceType)
APIExactInference with the network stored in the specified BayesianNetworkTransferHandler. You must provide the host and the port of the license server. The user group is optional, depending on the configuration of the license ont the license server. Use this constructor if you use a license server.
networkHandler - the transfer handler containing the network.licenceServerHost - the host of the license server.licenseServerPort - the port of the license server.userGroup - the user group corresponding to the license, maybe null if no user group is specified on the license server.inferenceType - one of EXACT_INFERENCE and APPROXIMATE_INFERENCE.| Method Detail |
|---|
public final boolean isObservationValidityEnabled()
public final void setObservationValidityEnabled(boolean b)
With this option enabled : observe("aNode", "aValue");
is equal to, with this option disabled : if (getProbability("aNode", "aValue")>0) {
observe("aNode", "aValue");
}
b - the new state of the observation validity checkingobserve(String, String),
observe(String, float)public final java.lang.String getName()
public java.lang.String[] getNodeNames()
public final int getNodeNumber()
public final java.lang.String getComment()
public final java.lang.String getNodeComment(java.lang.String nodeName)
nodeName - the name of the node we want the comment
public final java.lang.String getArcComment(java.lang.String nodeName1,
java.lang.String nodeName2)
nodeName1 and nodeName2.
nodeName1 - the name of the first extremity nodenodeName2 - the name of the second extremity node
public final boolean isInteger(java.lang.String nodeName)
nodeName - the name of the tested node
public final boolean isBoolean(java.lang.String nodeName)
nodeName - the name of the tested node
public final boolean isInterval(java.lang.String nodeName)
nodeName - the name of the tested node
public final boolean isDecision(java.lang.String nodeName)
nodeName - the name of the tested node
public final boolean isUtility(java.lang.String nodeName)
nodeName - the name of the tested node
public final boolean isConstraint(java.lang.String nodeName)
nodeName - the name of the tested node
public final int getValueNumber(java.lang.String nodeName)
public final java.lang.String[] getStringValues(java.lang.String nodeName)
String. It can't be used on constraint and utility nodes.
nodeName - the name of the node
public final int[] getIntValues(java.lang.String nodeName)
nodeName - the name of the node
public final float[][] getIntervals(java.lang.String nodeName)
nodeName - the name of the node
public final java.lang.String getFormula(java.lang.String nodeName)
String. If the node doesn't have a formula it return an empty String.
nodeName - the name of the node
String representing the formula of the nodepublic final boolean isObserved(java.lang.String nodeName)
nodeName - the name of the node
public final java.lang.String getObservedValue(java.lang.String nodeName)
nodeName - the name of the node
public final boolean observe(java.lang.String nodeName,
java.lang.String value)
isObservationValidityEnabled() returns true, it can return false if the observation is not possible, i.e. the posterior probability of the observed value is 0. It can't be used on constraint and utility nodes.
nodeName - the name of the node we want to observevalue - the value to observe
isObservationValidityEnabled(),
setObservationValidityEnabled(boolean)
public final boolean observe(java.lang.String nodeName,
short valueIndex)
isObservationValidityEnabled() returns true, it can return false if the observation is not possible, i.e. the posterior probability of the observed value is 0. It can't be used on constraint and utility nodes.
nodeName - the name of the node we want to observevalueIndex - the index of the value to observe
isObservationValidityEnabled(),
setObservationValidityEnabled(boolean)
public final boolean observe(java.lang.String nodeName,
float value)
isObservationValidityEnabled() returns true, it can return false if the observation is not possible, i.e. the posterior probability of the observed value is 0. It can be used only on interval nodes.
nodeName - the name of the interval node we want to observevalue - the value to observe
isObservationValidityEnabled(),
setObservationValidityEnabled(boolean)
public final boolean setLikelihood(java.lang.String nodeName,
java.lang.String value,
double likelihood)
nodeName - the name of the nodevalue - the value of the nodelikelihood - the likelihood associated to the given value
public final boolean setLikelihood(java.lang.String nodeName,
short valueIndex,
double likelihood)
nodeName - the name of the nodevalueIndex - the index of the value of the nodelikelihood - the likelihood associated to the given index value
public final double[] getLikelihoods(java.lang.String nodeName)
nodeName - the name of the node
public final double getLikelihood(java.lang.String nodeName,
java.lang.String value)
nodeName - the name of the nodevalue - the value of the node
public final void unobserve(java.lang.String nodeName)
nodeName - the name of the node to unobservepublic final boolean isTemporal()
getCurrentTime(),
resetTime(),
increaseTime(),
setTime(int)public final int getCurrentTime()
Warning: It must be used only if the network is temporal. Please see isTemporal().
isTemporal()public final void resetTime()
setTime(0).
Warning: It must be used only if the network is temporal. Please see isTemporal().
isTemporal(),
getCurrentTime(),
setTime(int)public final void increaseTime()
getCurrentTime() to getCurrentTime()+1. This method is equivalent to setTime(getCurrentTime()+1).
Warning: It must be used only if the network is temporal. Please see isTemporal().
isTemporal(),
getCurrentTime(),
setTime(int)public final void setTime(int time)
time. If the given time is less than the current time, it will restart the simulation from 0. The parameter time must be superior or equal to 0. If time is 0, the method is equivalent to resetTime(). If time equals getCurrentTime()+1, the method is equivalent to increaseTime().
Warning: It must be used only if the network is temporal. Please see isTemporal().
time - the time to reach.isTemporal(),
getCurrentTime(),
resetTime(),
increaseTime()public final void setInferenceType(int type)
EXACT_INFERENCE a junction tree algorithm will be used otherwise, if the parameter is APPROXIMATE_INFERENCE a likelihood weighting algorithm is used.
type - the type of inference to be used.getInferenceType()public final int getInferenceType()
APPROXIMATE_INFERENCE if the inference type is approximate or EXACT_INFERENCE if the inference type is exact.
setInferenceType(int)public final void setSampleSize(int sampleSize)
sampleSize - the size of samples used by approximate inference.getSampleSize()public final int getSampleSize()
setSampleSize(int)public final double[] getProbabilities(java.lang.String nodeName)
Warning:If isObservationValidityEnabled() returns false and an observation on a node was illegal, the method will return an array with 0 as the probability of each modality.
nodeName - the name of the node
public final double getProbability(java.lang.String nodeName,
java.lang.String value)
Warning:If isObservationValidityEnabled() returns false and an observation on a node was illegal, the method will return 0 as the probability of the modality.
nodeName - the name of the nodevalue - the value of the node
public final double[] getUtility(java.lang.String nodeName)
Warning:If isObservationValidityEnabled() returns false and an observation on a node was illegal, the method will return the minimum utility as the utility of the node.
nodeName - the name of the utility node
public final double[] getQualities(java.lang.String nodeName)
Warning:If isObservationValidityEnabled() returns false and an observation on a node was illegal, the method will return 0 as the qualities of the node.
nodeName - the name of the decision node
public final double getMean(java.lang.String nodeName)
nodeName - the name of the numeric node
public final double getStandardDeviation(java.lang.String nodeName)
nodeName - the name of the numeric node
public final void close()
APIInference.
WARNING: If you use a license server, this method must be called once you don't need the instance anymore. It allows to release the license on the license server.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||