Data can be locally loaded/saved when you use JavaBayes as an application. Applets cannot load/save data.
You can create an applet that reads Bayesian networks through the Internet by writing some code that uses the available constructors in the BayesNet class. There are methods that load data from any point in the world-wide-web; the same interface can load a local file or a remote file in a foreign server. This opens the possibility that Bayesian reasoning be used to process and organize the huge amounts of data in the internet. JavaBayes provides a mechanism to interface with the internet; since the source code is available, users can adapt it for particular internet applications.
To work with local files, you have to use JavaBayes as an application. At this point, JavaBayes does not use the methods that load data across the Internet, as it does not use the full functionality available in the BayesNet class.
If you use JavaBayes as an application, load/save are options in the Network menu. The InterchangeFormat format used by JavaBayes is an implementation of the proposed BayesNet Interchange Format (BIF), which is in discussion by the Association for Uncertainty in Artificial Intelligence. The JavaBayes InterchangeFormat implements all the guidelines of the BIF, except Noisy functions (since JavaBayes does not support those functions yet). The BIF format also proposes the general concept of a property; implementations of the BIF format can use specific properties. The JavaBayes InterchangeFormat uses some properties, observed, decision and credal-set, which are explained below.
This page describes the JavaBayes InterchangeFormat; for completeness, most of the relevant discussion in the BayesNet Interchange Format (BIF) page is reproduced here. The JavaBayes InterchangeFormat uses only ASCII symbols and expects one stream to contain a single network (a stream is either a file, a socket, etc). For files, any extension is possible, but the extension bif is recommended.
White spaces, tabs and newlines are ignored; the C/C++ style of comments is adopted. Two other characters are also ignored when they occur between tokens: ``,'' and ``|''. These characters can be used to separate variables in the definition of a probability distribution.
The basic unit of information is a block: a piece of text which starts with a keyword and ends with the end of an attribute list (to be explained later). Arbitrary characters are allowed between blocks. This allows the user to insert arbitrarily long comments outside the blocks. It also allows user-specific blocks and commands to be placed outside the standard blocks.
Other than blocks, the JavaBayes InterchangeFormat refers to three entities: words, non-negative integers and non-negative reals.
A word is a contiguous sequence of characters, with the restriction that the first character be a letter. Characters are letters plus numbers plus the underline symbol (_) plus the dash symbol (-).
A non-negative number is a sequence of numeric characters, containing a decimal point or an exponent or both.
A block is a unit of information. The general format of a block is:
block-type block-name {
attribute-name attribute-value;
attribute-name attribute-value;
attribute-name attribute-value;
}
with as many attributes as necessary. The closing semicolon is mandatory
after each attribute.
There are three possible blocks: network, variable and probability blocks.
network Robot-Planning {
property version 1.1;
property author Nobody;
} variable Leg {
type discrete[2] { long, short };
property temporary yes;
} probability ( Leg | Arm ) {
table 0.1 0.9 0.9 0.1;
}
The blocks must be placed in the following order:
Several attributes are defined at this point: property, type, table, default and entry attributes (the entry attribute is not associated with any keyword).
The attribute property can appear in all types of blocks. A property is just a string of arbitrary text to be associated with a block. Examples of properties:
property size 12;
property name "Trial number ten";
Any text is valid between the keyword property and
the ending semicolon. The idea is to store information that is specific
to a particular system or network in the properties. Any number
of property attributes can appear in a block.
The type attribute is specific to variable blocks. The property type lists the values of a discrete variable:
type discrete[ number-of-values ] { list-of-values };
The number-of-values token is a non-negative integer which
indicates how many different values this variable may assume
(the size of the list-of-values).
The list-of-values is a sequence of words, each one the name of
a variable value.
There are attributes that are specific to probability blocks (these attributes are discussed in the next section):
JavaBayes uses a number of properties to load and save information about Bayesian networks:
variable light-on{//2 values
type discrete[2] { true false };
property position = (218, 195) ;
}
and you want to indicate that variable light-on is observed
with value true (i.e., light-on = true is the evidence).
You do this with the observed property:
variable light-on{//2 values
property observed true;
type discrete[2] { true false };
property position = (218, 195) ;
}
You can set as many variables as you want as observed;
the syntax is simple:
property observed [ observed-value ];
variable light-on{//2 values
type discrete[2] { true false };
property position = (218, 195) ;
}
and you want to indicate that variable light-on is to be estimated.
You can set light-on as a decision variable, i.e., a variable
which will be estimated. The name decision variable is a bit
unfortunate here, and it may change in the future. The meaning
of a decision variable is that you would like to know which
value for the variable would produce the highest probability
or expectation. It is not necessarily true that you can operate
on the variable and change it at will; it is just that you
want to know which value would be best in the face of evidence.
You do set decision variables with the decision property:
variable light-on{//2 values
property decision;
type discrete[2] { true false };
property position = (218, 195) ;
}
If you request JavaBayes to produce the ``best'' configuration
for the decision variables, JavaBayes will only process the
variables that are marked through a decision property.
You can set as many variables as you want as decision variables;
the syntax is simple:
property decision;
There are also properties that are related to robustness analysis in JavaBayes. Since robustness analysis is still an ongoing research project, the support for it is minimal. If you want to use robustness analysis now, please send me email. The properties related to robustness analysis always start with the keyword credal-set; if you are defining your own properties, please do not use this keyword.
Probability blocks are used to define the actual network topology and conditional probability tables.
An example of a standard probability block is:
probability(GasGauge | Gas, BatteryPower) {
(yes, high) 0.999 0.001;
(yes, low) 0.850 0.150;
(yes, medium) 0.000 1.000;
(no, high) 0.000 1.000;
(no, low) 0.000 1.000;
(no, medium) 0.000 1.000;
}
As explained before, the symbols ``|'' and ``,'' are ignored between
tokens so they do not affect the list of variables given after the
keyword probability. The variables however must be enclosed
by parenthesis.
The example above uses the entry attribute, which is different from the other attributes in that it has no keyword. It simply starts with an opening parenthesis, and has a list of values for all the conditioning variables. After the closing parenthesis, a list of probability values for the first variable is given (the user must provide numbers that add to 1, but this is not mandatory).
The probability vectors can be listed in any order, since the names in parentheses uniquely identify the parent instantiation.
In addition to the entry attribute, the JavaBayes InterchangeFormat supports the concept of a default entry. So the above CPT could have been specified equivalently as:
probability(GasGauge | Gas, BatteryPower) {
default 0.000 1.000;
(yes, low) 0.850 0.150;
(no, medium) 0.000 1.000;
}
Note that each number is a separate token, so we can use ``,'' and ``|'' between
numbers; these symbols are ignored.
Another way to define a probability distribution is through the table attribute. The body of such attribute is a sequence of non-negative real numbers, in the counting order of the declared variables (if all variables were binary, we would say binary counting with least significant digit in the right). So, for the example above, we could simply say:
probability(GasGauge | Gas, BatteryPower) {
table 0.999 0.850 0.0 0.0 0.0 0.0 0.001 0.15 1.0 1.0 1.0 1.0;
}
There are some subtle rules that regulate these declarations.
The following examples are available:
Here is the dog-problem.bif network:
// Bayesian Network in the Interchange Format
// Produced by BayesianNetworks package in JavaBayes
// Output created Tue Feb 25 12:55:25 1997
// Bayesian network
network Internal-Network{ //5 variables and 5 probability distributions
}
variable light-on{//2 values
type discrete[2] { true false };
property position = (218, 195) ;
}
variable bowel-problem{//2 values
type discrete[2] { true false };
property position = (335, 99) ;
}
variable dog-out{//2 values
type discrete[2] { true false };
property position = (300, 195) ;
}
variable hear-bark{//2 values
type discrete[2] { true false };
property position = (296, 268) ;
}
variable family-out{//2 values
type discrete[2] { true false };
property position = (257, 99) ;
}
probability ( light-on family-out ) { //2 variable(s) and 4 values
table 0.6 0.05 0.4 0.95 ;
}
probability ( bowel-problem ) { //1 variable(s) and 2 values
table 0.01 0.99 ;
}
probability ( dog-out bowel-problem family-out ) { //3 variable(s) and 8 values
table 0.99 0.97 0.9 0.3 0.01 0.03 0.1 0.7 ;
}
probability ( hear-bark dog-out ) { //2 variable(s) and 4 values
table 0.7 0.01 0.3 0.99 ;
}
probability ( family-out ) { //1 variable(s) and 2 values
table 0.15 0.85 ;
}
A more formal description of the JavaBayes InterchangeFormat is given here. The notation used by the JavaCC parser generator is used here.
In the description below, the patterns used by the lexer to define tokens are very similar to regular expressions used by the Unix regexp facility. Non-terminals have a parenthesis pair "()" after their names; terminals are usually capitalized. Some structures that may appear in expansions are:
( e )? : An optional occurrence of e e1 | e2 | e3 | ... : A choice of e1, e2, e3, etc. ( e )+ : One or more occurrences of e ( e )* : Zero or more occurrences of e ["a"-"z"] matches all lower case letters ~["\n","\r"] matches any character except the new line characters
The following patterns are ignored when they appear between tokens:
" "
"\t"
"\n"
"\r"
"//" (~["\n","\r"])* ("\n"|"\r\n")
"/*" (~["*"])* "*" (~["/"] (~["*"])* "*")* "/"
","
"|"
The definition of a word is:
WORD: LETTER (LETTER | DIGIT)* LETTER: ["a"-"z","A"-"Z","_","-"] DIGIT: ["0"-"9"]
The definition of a non-negative integer number is:
DECIMAL_LITERAL: ["1"-"9"] (["0"-"9"])*
The definition of a non-negative real number is:
FLOATING_POINT_LITERAL: (["0"-"9"])+ "." (["0"-"9"])* (EXPONENT)?
| "." (["0"-"9"])+ (EXPONENT)?
| (["0"-"9"])+ (EXPONENT)?
#EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+
The following words are keywords:
NETWORK: "network" VARIABLE: "variable" PROBABILITY: "probability" PROPERTY: "property" VARIABLETYPE: "type" DISCRETE: "discrete" DEFAULTVALUE: "default" TABLEVALUES: "table"
A property is defined as:
PROPERTYSTRING: PROPERTY (~[";"])* ";"
\end{verbatim]
The productions of the grammar are:
\begin{verbatim}
CompilationUnit() :
NetworkDeclaration()
( VariableDeclaration() | ProbabilityDeclaration() )*
EOF
NetworkDeclaration() :
NETWORK WORD NetworkContent()
NetworkContent() :
"{" ( Property() )* "}"
VariableDeclaration() :
VARIABLE ProbabilityVariableName() VariableContent()
VariableContent(String name) :
"{" ( Property() | VariableDiscrete() )* "}"
VariableDiscrete() :
VARIABLETYPE DISCRETE
"[" DECIMAL_LITERAL "]" "{" VariableValuesList() "}" ";"
void VariableValuesList() :
ProbabilityVariableValue()
( ProbabilityVariableValue() )*
ProbabilityVariableValue() : WORD
ProbabilityDeclaration() :
PROBABILITY ProbabilityVariablesList() ProbabilityContent()
ProbabilityVariablesList() :
"(" ProbabilityVariableName() ( ProbabilityVariableName() )* ")"
ProbabilityVariableName() : <WORD>
ProbabilityContent()
"{" ( Property() | ProbabilityDefaultEntry() | ProbabilityEntry() |
ProbabilityTable() )* "}"
ProbabilityEntry() :
ProbabilityValuesList() FloatingPointList() ";"
ProbabilityValuesList() :
"(" ProbabilityVariableValue() ( ProbabilityVariableValue() )* ")"
ProbabilityDefaultEntry() :
<DEFAULTVALUE> FloatingPointList() ";"
ProbabilityTable() :
<TABLEVALUES> FloatingPointList() ";"
FloatingPointList() :
FloatingPointToken() ( FloatingPointToken() )*
FloatingPointToken() : <FLOATING_POINT_LITERAL>
Property() : <PROPERTYSTRING>
© Fabio Cozman[Send Mail?] Sat Aug 9 21:32:23 EDT 1997