public class APIInference
extends java.lang.Object
implements java.io.Closeable
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 using networks containing discrete, interval, constraint and utility nodes. It allows also the use of temporal or dynamic 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.
Modifier and Type | Field and Description |
---|---|
static int |
APPROXIMATE_INFERENCE |
static int |
EXACT_INFERENCE |
static int |
NONE_VALUE |
Constructor and Description |
---|
APIInference(BayesianNetworkTransferHandler networkHandler,
java.lang.String licenseKey,
int inferenceType)
Creates a new
APIInference with the network stored in the specified BayesianNetworkTransferHandler . |
APIInference(BayesianNetworkTransferHandler networkHandler,
java.lang.String licenseServerHost,
int licenseServerPort,
java.lang.String userName,
java.lang.String password,
java.lang.String account,
int inferenceType)
Creates a new
APIInference with the network stored in the specified BayesianNetworkTransferHandler . |
APIInference(java.io.InputStream stream,
java.lang.String licenseKey,
int inferenceType)
Creates a new
APIInference with the network read from the specified InputStream. |
APIInference(java.io.InputStream stream,
java.lang.String licenseServerHost,
int licenseServerPort,
java.lang.String userName,
java.lang.String password,
java.lang.String account,
int inferenceType)
Creates a new
APIInference with the network read from the specified InputStream. |
APIInference(java.lang.String fileName,
java.lang.String licenseKey,
int inferenceType)
Creates a new
APIInference with the network stored in the specified file. |
APIInference(java.lang.String fileName,
java.lang.String licenseServerHost,
int licenseServerPort,
java.lang.String userName,
java.lang.String password,
java.lang.String account,
int inferenceType)
Creates a new
APIInference with the network stored in the specified file. |
Modifier and Type | Method and Description |
---|---|
void |
close()
Method used to close the current instance of
APIInference . |
boolean |
containsClass(java.lang.String className)
Tests if a class with the given name exists in the network
|
boolean |
containsNode(java.lang.String nodeName)
Tests if a node with the given name exists in the network
|
BayesianNetworkTransferHandler |
exportNetwork(java.lang.String networkName)
Exports the network and its associated junction tree (if the inference type is
EXACT_INFERENCE ) with the specified name into a BayesianNetworkTransferHandler in order to used it with the APIInference , APIModeling or APILearning for example. |
java.lang.String |
getArcComment(java.lang.String nodeName1,
java.lang.String nodeName2)
Returns the html comment associated to the arc between the nodes named
nodeName1 and nodeName2 . |
java.lang.String |
getArcCommentAsString(java.lang.String nodeName1,
java.lang.String nodeName2)
Returns the comment string associated to the arc between the nodes named
nodeName1 and nodeName2 . |
int |
getArcOrientationBetween(java.lang.String nodeName1,
java.lang.String nodeName2)
Returns the orientation of the arc between
nodeName1 and nodeName2 . |
ResizableIcon |
getBackgroundImage()
Gets the image associated to the network.
|
java.lang.String[] |
getChildren(java.lang.String nodeName)
Returns the name of the children of the specified node
|
java.lang.String[] |
getClasses()
Returns an array containing the name of the classes declared in the network.
|
java.lang.String[] |
getClassNodes(java.lang.String className)
Returns an array containing the list of the node belonging to the given class.
|
java.lang.String |
getComment()
Returns the html comment associated to the network.
|
java.lang.Double[] |
getCompletedStateValues(java.lang.String nodeName)
Returns an array of
Double with a value or null for each state of the node. |
java.lang.String[] |
getConstraintNodeNames()
Returns the list of the names of constraint nodes.
|
java.lang.String[] |
getContinuousNodeNames()
Returns the list of the names of simple continuous nodes (neither discrete nor constraint nor decision nor utility nor function).
|
int |
getCurrentTime()
Returns the current time of the network.
|
java.lang.String[] |
getDecisionNodeNames()
Returns the list of the names of decision nodes.
|
java.lang.String[] |
getDiscreteNodeNames()
Returns the list of the names of simple discrete nodes (neither interval nor constraint nor decision nor utility nor function).
|
short |
getFilteredIndex(java.lang.String nodeName)
Returns the index of the filtered state of the specified node or -1 if the node does not have a filtered state.
|
java.lang.String |
getFilteredState(java.lang.String nodeName)
Returns the name of the filtered state of the specified node or null if the node does not have a filtered state.
|
java.lang.String |
getFormula(java.lang.String nodeName)
Returns the formula associated to the node as
String . |
java.lang.String[] |
getFunctionNodeNames()
Returns the list of the names of function nodes.
|
FunctionValue |
getFunctionValue(java.lang.String nodeName)
Returns the value of a function node as an instance of
FunctionValue . |
double[] |
getGlobalUtility()
Returns an array containing the sum of the minimum utilities, the sum of the current utilities and the sum of the maximum utilities of all utility nodes.
|
int |
getInferenceType()
Returns
APPROXIMATE_INFERENCE if the inference type is approximate or EXACT_INFERENCE if the inference type is exact. |
short |
getIntervalForValue(java.lang.String nodeName,
double value)
Retrieves the index of the interval corresponding to the specified double value for an continuous node only.
|
double[][] |
getIntervals(java.lang.String nodeName)
Returns an array containing the minimum and the maximum of each interval of the node as doubles.
|
int[] |
getIntValues(java.lang.String nodeName)
Returns an array containing the states of the node as integers if the node is an integer node.
|
double |
getJointProbability()
Return the joint probability of the network according to the evidence set.
|
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.
|
static double |
getMean(java.lang.Double[] values,
double[] probabilities)
Computes the mean given the values and the probability distribution.
|
double |
getMean(java.lang.String nodeName)
Returns the mean of a node.
|
double[] |
getMinXEntProbabilities(java.lang.String nodeName,
double[] initialProbabilities,
double targetMean)
Try to find the best probability distribution to obtain the target mean starting from the given initial probabilities, minimizing cross-entropy.
|
java.lang.String |
getName()
Returns the name of the loaded network.
|
java.lang.String[] |
getNodeClasses(java.lang.String nodeName)
Returns the classes of which the given node is associated.
|
java.awt.Color |
getNodeColor(java.lang.String nodeName)
Returns the
Color associated to the node or null if there is no associated color. |
java.lang.String |
getNodeComment(java.lang.String nodeName)
Returns the html comment associated to the specified node
|
java.lang.String |
getNodeCommentAsString(java.lang.String nodeName)
Returns the comment string associated to the specified node
|
java.lang.Double |
getNodeCost(java.lang.String nodeName)
Returns the cost associated to the node or null if there is no cost.
|
short |
getNodeFilteredState(java.lang.String nodeName)
Returns the index of the node's filtered state.
|
ResizableIcon |
getNodeImage(java.lang.String nodeName)
Gets the image as an instance of
ResizableIcon associated to the node or null if there is no associated image. |
java.lang.String |
getNodeLongName(java.lang.String nodeName)
Return the long name associated to the specified node or null if there is no long name
|
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.awt.geom.Point2D |
getNodePosition(java.lang.String nodeName)
Returns the position of the center of the node as a point with double precision.
|
short |
getNodeReferenceState(java.lang.String nodeName)
Returns the index of the node's reference state.
|
short |
getObservedIndex(java.lang.String nodeName)
Returns the index of the observed state of the specified node if the node is hard observed.
|
java.lang.Double |
getObservedMean(java.lang.String nodeName)
Returns the target mean of the specified node if the node is mean observed.
|
double[] |
getObservedProbabilities(java.lang.String nodeName)
Returns the target probabilities of the specified node if the node is probability observed.
|
java.lang.String |
getObservedValue(java.lang.String nodeName)
Returns the observed value of the specified node if the node is hard observed.
|
java.lang.String[] |
getParents(java.lang.String nodeName)
Returns the name of the parents of the specified node
|
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.
|
double[] |
getRealValues(java.lang.String nodeName)
Returns an array containing the states of the node as doubles if all the node's values are real numberss.
|
int |
getSampleSize()
Returnss the sample size used to perform the approximate inference.
|
java.lang.String[] |
getSortedNodeNames(APIUtils.NODE_SORTING_METHOD sortingMethod,
boolean increase)
Return an array containing the name of the nodes in the network sorted according to the
APIUtils.NODE_SORTING_METHOD |
static double |
getStandardDeviation(double mean,
java.lang.Double[] values,
double[] probabilities)
Computes the standard deviation given a mean, the values and the probability distribution.
|
double |
getStandardDeviation(java.lang.String nodeName)
Returns the standard deviation of a node.
|
java.lang.String[] |
getStandardNodeNames()
Returns the list of the names of standard chance nodes (neither constraint nor decision nor utility nor function).
|
int |
getStateCount(java.lang.String nodeName)
Returns the number of states of the specified node.
|
java.lang.String |
getStateLongNameAt(java.lang.String nodeName,
int state)
Returns the long names of a given state for a given node.
|
java.lang.String[] |
getStateLongNames(java.lang.String nodeName)
Returns an array of
String containing the long name for each state of the specified node. |
java.lang.Double |
getStateValueAt(java.lang.String nodeName,
int state)
Returns the value associated to the given state of the given node.
|
java.lang.Double[] |
getStateValues(java.lang.String nodeName)
Returns an array of
Double containing the values associated to each state of the given node. |
java.lang.String |
getStringComment()
Returns the comment as string associated to the network.
|
java.lang.String[] |
getStringValues(java.lang.String nodeName)
Returns an array containing the states of the node as
String . |
java.lang.String |
getTargetNodeName()
Returns the name of the target node of the network.
|
short |
getTargetState()
Returns the target state of the target node
|
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.
|
java.lang.String[] |
getUtilityNodeNames()
Returns the list of the names of utility nodes.
|
java.lang.Double[] |
getValues(java.lang.String nodeName)
Returns the values associated to the states of the specified node.
|
boolean |
hasArcBetween(java.lang.String nodeName1,
java.lang.String nodeName2)
Tests if there is an arc between the specified nodes
|
boolean |
hasConstraintNodes()
Tests if the networks contains constraint nodes.
|
boolean |
hasContinuousNodes()
Tests if the networks contains continuous nodes (neither discrete nor constraint nor decision nor utility nor function).
|
boolean |
hasDecisionNodes()
Tests if the networks contains decision nodes.
|
boolean |
hasDiscreteNodes()
Tests if the networks contains simple discrete nodes (neither interval nor constraint nor decision nor utility nor function).
|
boolean |
hasFilteredState(java.lang.String nodeName)
Tests if the specified node has a filtered state.
|
boolean |
hasFunctionNodes()
Tests if the networks contains function nodes.
|
boolean |
hasStandardNodes()
Tests if the networks contains standard chance nodes (neither constraint nor decision nor utility nor function).
|
boolean |
hasTargetNode()
Tests if the network has a target node defined
|
boolean |
hasTemporalArcBetween(java.lang.String nodeName1,
java.lang.String nodeName2)
Tests if there is a temporal arc between the specified chance nodes
|
boolean |
hasUtilityNodes()
Tests if the networks contains utility nodes.
|
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 |
isChildOf(java.lang.String nodeName1,
java.lang.String nodeName2)
Tests if there is an arc from
nodeName2 to nodeName1 |
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 |
isFunction(java.lang.String nodeName)
Tests if the node is a function node.
|
boolean |
isHardObserved(java.lang.String nodeName)
Returns true if the node has hard evidence set, i.e. a state if observed.
|
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 |
isLikelihoodObserved(java.lang.String nodeName)
Returns true if the node is observed with likelihoods.
|
boolean |
isMeanObserved(java.lang.String nodeName)
Returns true if the node is observed with target mean.
|
boolean |
isObservationValidityEnabled()
Returns the state of the observation validity checking.
|
boolean |
isObserved(java.lang.String nodeName)
Tests if the specified node is observed.
|
boolean |
isObservedMeanBinary(java.lang.String nodeName)
Returns true if the distribution used to compute the mean is binary, false if the distribution is generated by MinXEnt.
|
boolean |
isParentOf(java.lang.String nodeName1,
java.lang.String nodeName2)
Tests if there is an arc from
nodeName1 to nodeName2 |
boolean |
isProbabilityObserved(java.lang.String nodeName)
Returns true if the node is observed with target probabilities.
|
boolean |
isReal(java.lang.String nodeName)
Tests if all the values of the specified node are reals.
|
boolean |
isStandard(java.lang.String nodeName)
Tests if the node is a standard chance node (neither constraint nor decision nor utility nor function).
|
boolean |
isTemporal()
Tests if the network is temporal.
|
boolean |
isUtility(java.lang.String nodeName)
Tests if the node is a utility node.
|
boolean |
nodeContainsClass(java.lang.String nodeName,
java.lang.String className)
Tests if a class with the given name exists in the given node
|
boolean |
observe(java.lang.String nodeName,
double value)
Observes a double 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 |
save(java.io.OutputStream stream)
Saves the created network and its associated junction tree (if the inference type is
EXACT_INFERENCE ) into the specified OutputStream . |
void |
save(java.lang.String path)
Saves the created network and its associated junction tree (if the inference type is
EXACT_INFERENCE ) into the file specified by the given path. |
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).
|
boolean |
setLikelihoodFromMean(java.lang.String nodeName,
double mean,
boolean binaryDistribution)
Computes the likelihood for all the values of a node in order to have its mean equal to the specified one.
|
boolean |
setLikelihoodFromProbabilities(java.lang.String nodeName,
double[] probabilities)
Computes the likelihood for all the values of a node in order to have its probabilities equal to the specified ones.
|
boolean |
setLikelihoods(java.lang.String nodeName,
double[] likelihoods)
Sets the likelihoods for all the values of a node.
|
void |
setObservationValidityEnabled(boolean b)
Sets the observation validity enabled or not.
|
boolean |
setObservedMean(java.lang.String nodeName,
double mean,
boolean binaryDistribution)
Computes the likelihood for all the values of a node in order to have its mean equal to the specified one.
|
boolean |
setObservedProbabilities(java.lang.String nodeName,
double[] probabilities)
Computes the likelihood for all the values of a node in order to have its probabilities equal to the specified ones.
|
void |
setSampleSize(int sampleSize)
Sets the sample size used by approximate inference.
|
void |
setTargetNode(java.lang.String nodeName,
short state)
Set the given node as target node with the given target state.
|
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.
|
void |
unobserveAll()
Unobserves all the nodes.
|
public static final int EXACT_INFERENCE
public static final int APPROXIMATE_INFERENCE
public static final int NONE_VALUE
public APIInference(java.io.InputStream stream, java.lang.String licenseKey, int inferenceType)
APIInference
with the network read from the specified InputStream. You must provide a valid licence key for inference.stream
- the stream of the xbl file containing the networklicenseKey
- the key of the licence.inferenceType
- one of EXACT_INFERENCE
and APPROXIMATE_INFERENCE
.public APIInference(java.lang.String fileName, java.lang.String licenseKey, int inferenceType)
APIInference
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 networklicenseKey
- the key of the licence.inferenceType
- one of EXACT_INFERENCE
and APPROXIMATE_INFERENCE
.public APIInference(java.io.InputStream stream, java.lang.String licenseServerHost, int licenseServerPort, java.lang.String userName, java.lang.String password, java.lang.String account, int inferenceType)
APIInference
with the network read from the specified InputStream. You must provide the host and the port of the license server. You must provide also the user name and the password of an access added to the license. This access must be associated to this license on the LicenseServer by using the Management Console of BayesiaLicenseServer. Use this constructor if you use a license server.stream
- the stream of the xbl file containing the networklicenseServerHost
- the host of the license server.licenseServerPort
- the port of the license server.userName
- the user name corresponding to an existing access added to the license on the license server. Cannot be null.password
- the passord corresponding to the access added to the license on the license server. Cannot be null.account
- the account corresponding to the license. Cannot be null, but can be set as empty String on dedicated BLS.inferenceType
- one of EXACT_INFERENCE
and APPROXIMATE_INFERENCE
.public APIInference(java.lang.String fileName, java.lang.String licenseServerHost, int licenseServerPort, java.lang.String userName, java.lang.String password, java.lang.String account, int inferenceType)
APIInference
with the network stored in the specified file. You must provide the host and the port of the license server. You must provide also the user name and the password of an access added to the license. This access must be associated to this license on the LicenseServer by using the Management Console of BayesiaLicenseServer. Use this constructor if you use a license server.fileName
- the name of the xbl file containing the networklicenseServerHost
- the host of the license server.licenseServerPort
- the port of the license server.userName
- the user name corresponding to an existing access added to the license on the license server. Cannot be null.password
- the password corresponding to the access added to the license on the license server. Cannot be null.account
- the account corresponding to the license. Cannot be null, but can be set as empty String on dedicated BLS.inferenceType
- one of EXACT_INFERENCE
and APPROXIMATE_INFERENCE
.public APIInference(BayesianNetworkTransferHandler networkHandler, java.lang.String licenseKey, int inferenceType)
APIInference
with the network stored in the specified BayesianNetworkTransferHandler
. You must provide a valid license key for inference.networkHandler
- the transfer handler containing the networklicenseKey
- the key of the license.inferenceType
- one of EXACT_INFERENCE
and APPROXIMATE_INFERENCE
.public APIInference(BayesianNetworkTransferHandler networkHandler, java.lang.String licenseServerHost, int licenseServerPort, java.lang.String userName, java.lang.String password, java.lang.String account, int inferenceType)
APIInference
with the network stored in the specified BayesianNetworkTransferHandler
. You must provide the host and the port of the license server. You must provide also the user name and the password of an access added to the license. This access must be associated to this license on the LicenseServer by using the Management Console of BayesiaLicenseServer. Use this constructor if you use a license server.networkHandler
- the transfer handler containing the network.licenseServerHost
- the host of the license server.licenseServerPort
- the port of the license server.userName
- the user name corresponding to an existing access added to the license on the license server. Cannot be null.password
- the passord corresponding to the access added to the license on the license server. Cannot be null.account
- the account corresponding to the license. Cannot be null, but can be set as empty String on dedicated BLS.inferenceType
- one of EXACT_INFERENCE
and APPROXIMATE_INFERENCE
.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");
}
When fixed probabilities or fixed mean are involved, only with exact inference, a convergence algorithm is used to reach the target probabilities or target mean. Each time a new observation is done (hard evidence, or other fixed probabilities or fixed mean), the convergence algorithm tries to reach the target probabilities or target mean for each concerned nodes. If it fails, then the current observation method will return false.
b
- the new state of the observation validity checkingobserve(String, String)
,
observe(String, short)
,
observe(String, double)
,
setObservedProbabilities(String, double[])
,
setObservedMean(String, double, boolean)
public final java.lang.String getName()
public java.lang.String[] getNodeNames()
public final java.lang.String[] getSortedNodeNames(APIUtils.NODE_SORTING_METHOD sortingMethod, boolean increase)
APIUtils.NODE_SORTING_METHOD
sortingMethod
- the sorting methodincrease
- true if you want an increasing order, false if you want a decreasing orderpublic final java.lang.String[] getStandardNodeNames()
public final java.lang.String[] getDiscreteNodeNames()
public final java.lang.String[] getContinuousNodeNames()
public final java.lang.String[] getConstraintNodeNames()
public final java.lang.String[] getDecisionNodeNames()
public final java.lang.String[] getUtilityNodeNames()
public final java.lang.String[] getFunctionNodeNames()
public final boolean containsNode(java.lang.String nodeName)
nodeName
- the name of the nodepublic final int getNodeNumber()
public final java.lang.String getComment()
public final java.lang.String getStringComment()
public final ResizableIcon getBackgroundImage()
BufferedImage
or null if there is no imageResizableIcon
public final boolean hasTargetNode()
public final java.lang.String getTargetNodeName()
public final short getTargetState()
public final void setTargetNode(java.lang.String nodeName, short state)
nodeName
- the name of the node to be set as target or null to remove target nodestate
- the index of the target state. Ignored when removing target.public final boolean hasStandardNodes()
public final boolean hasDiscreteNodes()
public final boolean hasContinuousNodes()
public final boolean hasConstraintNodes()
public final boolean hasDecisionNodes()
public final boolean hasUtilityNodes()
public final boolean hasFunctionNodes()
public final java.lang.String[] getParents(java.lang.String nodeName)
nodeName
- the name of the node we want the parentspublic final java.lang.String[] getChildren(java.lang.String nodeName)
nodeName
- the name of the node we want the childrenpublic final boolean hasArcBetween(java.lang.String nodeName1, java.lang.String nodeName2)
nodeName1
- the name of one of the nodesnodeName2
- the name of the other nodepublic final boolean hasTemporalArcBetween(java.lang.String nodeName1, java.lang.String nodeName2)
nodeName1
- the name of one of the nodesnodeName2
- the name of the other nodepublic final boolean isParentOf(java.lang.String nodeName1, java.lang.String nodeName2)
nodeName1
to nodeName2
nodeName1
- the name of the supposed parentnodeName2
- the name of the supposed childnodeName1
is parent of nodeName2
public final boolean isChildOf(java.lang.String nodeName1, java.lang.String nodeName2)
nodeName2
to nodeName1
nodeName1
- the name of the supposed childnodeName2
- the name of the supposed parentnodeName1
is child of nodeName2
public final int getArcOrientationBetween(java.lang.String nodeName1, java.lang.String nodeName2)
nodeName1
and nodeName2
. The possible values are : -1 if there is no arc, 0 if there is an arc from nodeName1
to nodeName2
and 1 if there is an arc from nodeName2
to nodeName1
nodeName1
- the name of one of the nodesnodeName2
- the name of the other nodenodeName1
and nodeName2
public final java.lang.String getNodeLongName(java.lang.String nodeName)
nodeName
- the name of the node we want the long namepublic final java.lang.String getNodeComment(java.lang.String nodeName)
nodeName
- the name of the node we want the html commentpublic final java.lang.String getNodeCommentAsString(java.lang.String nodeName)
nodeName
- the name of the node we want the commentpublic 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 nodepublic final java.lang.String getArcCommentAsString(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 nodepublic final boolean isInteger(java.lang.String nodeName)
nodeName
- the name of the tested nodepublic final boolean isReal(java.lang.String nodeName)
nodeName
- the name of the tested nodepublic final boolean isBoolean(java.lang.String nodeName)
nodeName
- the name of the tested nodepublic final boolean isInterval(java.lang.String nodeName)
nodeName
- the name of the tested nodepublic final boolean isStandard(java.lang.String nodeName)
nodeName
- the name of the tested nodepublic final boolean isDecision(java.lang.String nodeName)
nodeName
- the name of the tested nodepublic final boolean isUtility(java.lang.String nodeName)
nodeName
- the name of the tested nodepublic final boolean isConstraint(java.lang.String nodeName)
nodeName
- the name of the tested nodepublic final boolean isFunction(java.lang.String nodeName)
nodeName
- the name of the tested nodepublic final int getStateCount(java.lang.String nodeName)
nodeName
- the name of the nodepublic final boolean hasFilteredState(java.lang.String nodeName)
nodeName
- the name of the nodepublic final java.lang.String getFilteredState(java.lang.String nodeName)
nodeName
- the name of the nodegetFilteredIndex(String)
,
hasFilteredState(String)
public final short getFilteredIndex(java.lang.String nodeName)
nodeName
- the name of the nodegetFilteredState(String)
,
hasFilteredState(String)
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 nodepublic final int[] getIntValues(java.lang.String nodeName)
nodeName
- the name of the nodepublic final double[] getRealValues(java.lang.String nodeName)
nodeName
- the name of the nodepublic final double[][] getIntervals(java.lang.String nodeName)
nodeName
- the name of the nodepublic 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 nodeString
representing the formula of the nodepublic final java.awt.geom.Point2D getNodePosition(java.lang.String nodeName)
nodeName
- the name of the nodepublic final java.awt.Color getNodeColor(java.lang.String nodeName)
Color
associated to the node or null if there is no associated color.nodeName
- the name of the nodeColor
or null if no color is associatedpublic final ResizableIcon getNodeImage(java.lang.String nodeName)
ResizableIcon
associated to the node or null if there is no associated image.nodeName
- the name of the nodeBufferedImage
if there is an image or null otherwiseResizableIcon
public final java.lang.Double getNodeCost(java.lang.String nodeName)
nodeName
- the node of the namepublic final short getNodeFilteredState(java.lang.String nodeName)
nodeName
- the name of the nodepublic final short getNodeReferenceState(java.lang.String nodeName)
nodeName
- the name of the nodepublic final java.lang.String[] getStateLongNames(java.lang.String nodeName)
String
containing the long name for each state of the specified node. A state can have a long name or not. In this last case, the value will be null.nodeName
- the name of the nodeString
containing the state long namespublic final java.lang.String getStateLongNameAt(java.lang.String nodeName, int state)
nodeName
- the name of the nodestate
- the index of the stateString
representing the long namepublic final java.lang.Double[] getStateValues(java.lang.String nodeName)
Double
containing the values associated to each state of the given node. If a state has no value associated, the corresponding Double
will be null in the array. If no state has an associated value, null is returned.nodeName
- the name of the nodeDouble
or null if there is no values associated to any statepublic final java.lang.Double getStateValueAt(java.lang.String nodeName, int state)
nodeName
- the name of the nodestate
- the index of the state we want the valueDouble
representing the associated valuepublic final java.lang.Double[] getCompletedStateValues(java.lang.String nodeName)
Double
with a value or null for each state of the node.
null
.nodeName
- the name of the nodeDouble
representing values of the states. Some of these values can be null
public final java.lang.String[] getClasses()
String
representing the list of the classes or null if there is no class in the networkpublic final boolean containsClass(java.lang.String className)
className
- the name of the classpublic final java.lang.String[] getNodeClasses(java.lang.String nodeName)
nodeName
- the name of the nodeString
representing the list of the classes or null if there is no class in which the node is involvedpublic final boolean nodeContainsClass(java.lang.String nodeName, java.lang.String className)
nodeName
- the name of the nodeclassName
- the name of the classpublic final java.lang.String[] getClassNodes(java.lang.String className)
className
- the name of the classString
containing the name of the nodes belonging to the classpublic final boolean isObserved(java.lang.String nodeName)
nodeName
- the name of the nodeisHardObserved(String)
,
isLikelihoodObserved(String)
,
isProbabilityObserved(String)
,
isMeanObserved(String)
public final boolean isHardObserved(java.lang.String nodeName)
nodeName
- the name of the nodeobserve(String, String)
,
observe(String, short)
,
observe(String, double)
public final boolean isLikelihoodObserved(java.lang.String nodeName)
nodeName
- the name of the nodesetLikelihood(String, short, double)
,
setLikelihood(String, String, double)
,
setLikelihoods(String, double[])
,
setLikelihoodFromProbabilities(String, double[])
,
setLikelihoodFromMean(String, double, boolean)
public final boolean isProbabilityObserved(java.lang.String nodeName)
nodeName
- the name of the nodesetObservedProbabilities(String, double[])
public final boolean isMeanObserved(java.lang.String nodeName)
nodeName
- the name of the nodesetObservedMean(String, double, boolean)
public final java.lang.String getObservedValue(java.lang.String nodeName)
nodeName
- the name of the nodeisHardObserved(String)
,
observe(String, String)
,
observe(String, short)
,
observe(String, double)
public final short getObservedIndex(java.lang.String nodeName)
nodeName
- the name of the nodeisHardObserved(String)
,
observe(String, String)
,
observe(String, short)
,
observe(String, double)
public final double[] getObservedProbabilities(java.lang.String nodeName)
nodeName
- the name of the nodeisProbabilityObserved(String)
,
setObservedProbabilities(String, double[])
public final java.lang.Double getObservedMean(java.lang.String nodeName)
nodeName
- the name of the nodeisMeanObserved(String)
,
setObservedMean(String, double, boolean)
public final boolean isObservedMeanBinary(java.lang.String nodeName)
nodeName
- the name of the nodeisMeanObserved(String)
,
setObservedMean(String, double, boolean)
,
getObservedMean(String)
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 observeisObservationValidityEnabled()
,
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 observeisObservationValidityEnabled()
,
setObservationValidityEnabled(boolean)
public final boolean observe(java.lang.String nodeName, double 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 observegetIntervalForValue(java.lang.String, double)
,
isObservationValidityEnabled()
,
setObservationValidityEnabled(boolean)
public final short getIntervalForValue(java.lang.String nodeName, double value)
nodeName
- the name of the interval node we want to find the intervalvalue
- the valuepublic 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 valuepublic 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 valuepublic final boolean setLikelihoods(java.lang.String nodeName, double[] likelihoods)
nodeName
- the name of the nodelikelihoods
- the wanted likelihood distributionpublic final boolean setLikelihoodFromProbabilities(java.lang.String nodeName, double[] probabilities)
nodeName
- the name of the nodeprobabilities
- the wanted probability distributionpublic final boolean setLikelihoodFromMean(java.lang.String nodeName, double mean, boolean binaryDistribution)
The mean is computed with the values obtained by getValues(nodeName)
.
Warning:There is no guarantee that the wanted mean can be obtained exactly.
nodeName
- the name of the nodemean
- the wanted meanbinaryDistribution
- true if the associated distribution is binary, false if the distribution is found by using MinXEntpublic final boolean setObservedProbabilities(java.lang.String nodeName, double[] probabilities)
Warning:There is no guarantee that the wanted probability distribution can be obtained exactly.
nodeName
- the name of the nodeprobabilities
- the wanted probability distributionisObservationValidityEnabled()
,
setObservationValidityEnabled(boolean)
public final boolean setObservedMean(java.lang.String nodeName, double mean, boolean binaryDistribution)
The mean is computed with the values obtained by getValues(nodeName)
.
Warning:There is no guarantee that the wanted mean can be obtained exactly.
nodeName
- the name of the nodemean
- the wanted meanbinaryDistribution
- true if the associated distribution is binary, false if the distribution is found by using MinXEntisObservationValidityEnabled()
,
setObservationValidityEnabled(boolean)
public final double[] getLikelihoods(java.lang.String nodeName)
nodeName
- the name of the nodepublic final double getLikelihood(java.lang.String nodeName, java.lang.String value)
nodeName
- the name of the nodevalue
- the value of the nodepublic final void unobserve(java.lang.String nodeName)
nodeName
- the name of the node to unobservepublic final void unobserveAll()
public 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 getJointProbability()
Warning:This method is only available for EXACT_INFERENCE
.
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 state.
nodeName
- the name of the nodepublic 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 state.
nodeName
- the name of the nodevalue
- the value of the nodepublic 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 nodepublic final double[] getGlobalUtility()
Warning:If isObservationValidityEnabled()
returns false and an observation on a node was illegal, the method will return the global minimum utility as global utility.
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 nodepublic final double getMean(java.lang.String nodeName)
nodeName
- the name of the nodegetValues(String)
,
getMean(Double[],double[])
public final double getStandardDeviation(java.lang.String nodeName)
nodeName
- the name of the nodegetValues(String)
,
getStandardDeviation(double,Double[],double[])
public final java.lang.Double[] getValues(java.lang.String nodeName)
These values are use to compute the mean of the node
nodeName
- the name of the nodegetStateValues(String)
,
getStateValueAt(String, int)
,
getMean(Double[],double[])
,
getStandardDeviation(double,Double[],double[])
public final FunctionValue getFunctionValue(java.lang.String nodeName)
FunctionValue
.nodeName
- the name of the function nodepublic static final double getMean(java.lang.Double[] values, double[] probabilities)
null
values are allowed if there is at least one existing value. If the sum of the probabilities is 0, Double.NaN
is returned.values
- an array of Double
. Some of them can be null
probabilities
- a normalized to 1 probability distributiondouble
representing the mean computed according to the values and the probabilitiespublic static final double getStandardDeviation(double mean, java.lang.Double[] values, double[] probabilities)
null
values are allowed if there is at least one existing value. If the mean
is Double.NaN
, Double.NaN
is returned.mean
- the already computed meanvalues
- an array of Double
. Some of them can be null
probabilities
- a normalized to 1 probability distributionpublic final double[] getMinXEntProbabilities(java.lang.String nodeName, double[] initialProbabilities, double targetMean)
nodeName
- the name of the nodeinitialProbabilities
- the initial probability distribution, normalized to 1targetMean
- the target mean to obtain.public final void save(java.lang.String path)
EXACT_INFERENCE
) into the file specified by the given path.
This method is useful when you start with a network without junction tree and the junction tree is created on the fly.
The newly created junction tree is saved with the network and will be loaded the next time the file is used.
The extension of the file must be xbl
.
The name of the network is now the name of the file.path
- the path to an xbl filepublic final void save(java.io.OutputStream stream)
EXACT_INFERENCE
) into the specified OutputStream
.
This method is useful when you start with a network without junction tree and the junction tree is created on the fly.
The newly created junction tree is saved with the network and will be loaded the next time the stream is used.stream
- the output stream where the network is savedpublic final BayesianNetworkTransferHandler exportNetwork(java.lang.String networkName)
EXACT_INFERENCE
) with the specified name into a BayesianNetworkTransferHandler
in order to used it with the APIInference
, APIModeling
or APILearning
for example. The name of the network must be terminated by .xbl
networkName
- the new name of the network with the xbl extensionpublic 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.
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable