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.inference
namespace. 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 void
addMonitor(NetworkMonitor monitor)
For internal use only.Network
copy()
Makes a copy of the network.CustomPropertyCollection
getCustomProperties()
Gets custom properties associated with this instance.String
getDescription()
An optional description for the Bayesian network.boolean
getIsInternal()
For internal use only.NetworkLinkCollection
getLinks()
The collection of links in the Bayesian network.String
getName()
An optional name for the Bayesian network.NetworkNodeGroupCollection
getNodeGroups()
Gets groups which nodes can belong to.NetworkNodeCollection
getNodes()
The collection of nodes in the Bayesian network.static boolean
getSyncNodeVariableName()
NetworkVariableCollection
getVariables()
The collection of variables in the Bayesian network.boolean
isDag()
Determines whether this instance is a Directed Acyclic Graph (DAG) which is a requirement for Bayesian networks.boolean
isTree()
Determines whether this instance is a tree (singly connected).void
load(InputStream input)
Loads aNetwork
from the specified inputInputStream
.void
load(String path)
Loads aNetwork
from the specified [path].void
loadFromString(String value)
Loads a network from a string using UTF-8 encoding.void
loadFromString(String value, String charSetName)
Loads a network from a string using the specified encoding.void
removeMonitor(NetworkMonitor monitor)
For internal use.void
save(OutputStream output)
Saves thisNetwork
to the specified outputOutputStream
.void
save(String path)
Saves thisNetwork
to the specified [path] overwriting the file if it already exists.String
saveToString()
Saves the network to a string, with UTF-8 encoding.String
saveToString(String charSetName)
Saves the network to a string, with the specified encoding.void
setDescription(String value)
An optional description for the Bayesian network.void
setIsInternal(boolean value)
For internal use only.void
setName(String value)
An optional name for the Bayesian network.static void
setSyncNodeVariableName(boolean value)
void
validate(ValidationOptions options)
Validates that the Bayesian network is correctly specified.static void
validateTrialSession()
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:
true
if this instance is a DAG; otherwise,false
.
-
isTree
public boolean isTree()
Determines whether this instance is a tree (singly connected).- Returns:
true
if 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 aNode
is 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:
UnsupportedEncodingException
XMLStreamException
-
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:
UnsupportedEncodingException
XMLStreamException
-
save
public void save(OutputStream output) throws XMLStreamException
Saves thisNetwork
to the specified outputOutputStream
. When saving to file, .bayes is the recommended file extension.- Parameters:
output
- TheOutputStream
to save to.- Throws:
XMLStreamException
-
save
public void save(String path) throws IOException, XMLStreamException
Saves thisNetwork
to 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:
IOException
XMLStreamException
-
load
public void load(String path) throws IOException, XMLStreamException
Loads aNetwork
from the specified [path].- Parameters:
path
- The path and file name to load from.- Throws:
IOException
XMLStreamException
-
load
public void load(InputStream input) throws XMLStreamException
Loads aNetwork
from the specified inputInputStream
.- Parameters:
input
- TheInputStream
to load from.- Throws:
XMLStreamException
-
-