Package com.bayesserver
Class Network
- java.lang.Object
-
- com.bayesserver.Network
-
- All Implemented Interfaces:
Cloneable
public final class Network extends Object implements Cloneable
Represents a Bayesian Network, or a Dynamic Bayesian Network. To perform inference with a network see thecom.bayesserver.inferencenamespace. A Bayesian network consists of nodes which contain one or more variables. Each node can be connected with a directedlink(A link in a Dynamic Bayesian Network can have an associated order which links nodes in different time slices).Each node in a Bayesian network must have a distribution specified over its own variables conditional on its parents variables. For example if a network contains nodes A and B each with a single variable of the same name, and A is a parent of B, then the distribution at A equals P(A), since A has no parents, and the distribution at B equals P(B|A).
Once the nodes, links, and distributions in a Bayesian network have been specified, one or more inference engines can be created based on the network, to perform probabilistic inference. See
Inference.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddMonitor(NetworkMonitor monitor)For internal use only.Networkcopy()Makes a copy of the network.CustomPropertyCollectiongetCustomProperties()Gets custom properties associated with this instance.StringgetDescription()An optional description for the Bayesian network.booleangetIsInternal()For internal use only.NetworkLinkCollectiongetLinks()The collection of links in the Bayesian network.StringgetName()An optional name for the Bayesian network.NetworkNodeGroupCollectiongetNodeGroups()Gets groups which nodes can belong to.NetworkNodeCollectiongetNodes()The collection of nodes in the Bayesian network.static booleangetSyncNodeVariableName()NetworkVariableCollectiongetVariables()The collection of variables in the Bayesian network.booleanisDag()Determines whether this instance is a Directed Acyclic Graph (DAG) which is a requirement for Bayesian networks.booleanisTree()Determines whether this instance is a tree (singly connected).voidload(InputStream input)Loads aNetworkfrom the specified inputInputStream.voidload(String path)Loads aNetworkfrom the specified [path].voidloadFromString(String value)Loads a network from a string using UTF-8 encoding.voidloadFromString(String value, String charSetName)Loads a network from a string using the specified encoding.voidremoveMonitor(NetworkMonitor monitor)For internal use.voidsave(OutputStream output)Saves thisNetworkto the specified outputOutputStream.voidsave(String path)Saves thisNetworkto the specified [path] overwriting the file if it already exists.StringsaveToString()Saves the network to a string, with UTF-8 encoding.StringsaveToString(String charSetName)Saves the network to a string, with the specified encoding.voidsetDescription(String value)An optional description for the Bayesian network.voidsetIsInternal(boolean value)For internal use only.voidsetName(String value)An optional name for the Bayesian network.static voidsetSyncNodeVariableName(boolean value)voidvalidate(ValidationOptions options)Validates that the Bayesian network is correctly specified.static voidvalidateTrialSession()Evaluation version only.
-
-
-
Method Detail
-
validateTrialSession
public static void validateTrialSession()
Evaluation version only.
-
getCustomProperties
public CustomPropertyCollection getCustomProperties()
Gets custom properties associated with this instance. Custom properties allow storage of custom information, which will be saved with the network.
-
getNodeGroups
public NetworkNodeGroupCollection getNodeGroups()
Gets groups which nodes can belong to. Each node can belong to one or more groups.
-
getSyncNodeVariableName
public static boolean getSyncNodeVariableName()
-
setSyncNodeVariableName
public static void setSyncNodeVariableName(boolean value)
-
copy
public Network copy()
Makes a copy of the network.- Returns:
- The copy.
-
getIsInternal
public boolean getIsInternal()
For internal use only. May be removed in future versions.
-
setIsInternal
public void setIsInternal(boolean value)
For internal use only. May be removed in future versions.
-
validate
public void validate(ValidationOptions options)
Validates that the Bayesian network is correctly specified.- Parameters:
options- Specifies options to control the validation process.- Throws:
InvalidNetworkException- Raised when the network is not correctly specified, containing the error message.
-
isDag
public boolean isDag()
Determines whether this instance is a Directed Acyclic Graph (DAG) which is a requirement for Bayesian networks.- Returns:
trueif this instance is a DAG; otherwise,false.
-
isTree
public boolean isTree()
Determines whether this instance is a tree (singly connected).- Returns:
trueif this instance is a tree; otherwise,false.
-
addMonitor
public void addMonitor(NetworkMonitor monitor)
For internal use only.- Parameters:
monitor-- Throws:
NullPointerException- Raised if [monitor] is null.
-
removeMonitor
public void removeMonitor(NetworkMonitor monitor)
For internal use.- Parameters:
monitor-- Throws:
NullPointerException- Raised if [monitor] is null.
-
getNodes
public NetworkNodeCollection getNodes()
The collection of nodes in the Bayesian network.- See Also:
Node
-
getVariables
public NetworkVariableCollection getVariables()
The collection of variables in the Bayesian network.- See Also:
Variable
-
getLinks
public NetworkLinkCollection getLinks()
The collection of links in the Bayesian network. Note that if aNodeis removed from the network, all of its links are automatically removed.- See Also:
Link
-
getName
public String getName()
An optional name for the Bayesian network.
-
setName
public void setName(String value)
An optional name for the Bayesian network.
-
getDescription
public String getDescription()
An optional description for the Bayesian network.
-
setDescription
public void setDescription(String value)
An optional description for the Bayesian network.
-
saveToString
public String saveToString(String charSetName) throws XMLStreamException
Saves the network to a string, with the specified encoding. For large networks consider saving to file or a stream.- Parameters:
charSetName- The encoding to use.- Returns:
- The network persisted to a string.
- Throws:
XMLStreamException
-
saveToString
public String saveToString() throws XMLStreamException
Saves the network to a string, with UTF-8 encoding. For large networks consider saving to file or a stream.- Returns:
- The network persisted to a string.
- Throws:
XMLStreamException
-
loadFromString
public void loadFromString(String value, String charSetName) throws UnsupportedEncodingException, XMLStreamException
Loads a network from a string using the specified encoding.- Parameters:
value- The persisted string value of the network.charSetName- The encoding the network was originally saved in.- Throws:
UnsupportedEncodingExceptionXMLStreamException
-
loadFromString
public void loadFromString(String value) throws UnsupportedEncodingException, XMLStreamException
Loads a network from a string using UTF-8 encoding.- Parameters:
value- The persisted string value of the network.- Throws:
UnsupportedEncodingExceptionXMLStreamException
-
save
public void save(OutputStream output) throws XMLStreamException
Saves thisNetworkto the specified outputOutputStream. When saving to file, .bayes is the recommended file extension.- Parameters:
output- TheOutputStreamto save to.- Throws:
XMLStreamException
-
save
public void save(String path) throws IOException, XMLStreamException
Saves thisNetworkto the specified [path] overwriting the file if it already exists. The recommended file extension is .bayes- Parameters:
path- The path and name of the file to save to.- Throws:
IOExceptionXMLStreamException
-
load
public void load(String path) throws IOException, XMLStreamException
Loads aNetworkfrom the specified [path].- Parameters:
path- The path and file name to load from.- Throws:
IOExceptionXMLStreamException
-
load
public void load(InputStream input) throws XMLStreamException
Loads aNetworkfrom the specified inputInputStream.- Parameters:
input- TheInputStreamto load from.- Throws:
XMLStreamException
-
-