Package weka.classifiers.bayes.net
Class EditableBayesNet
java.lang.Object
weka.classifiers.AbstractClassifier
weka.classifiers.bayes.BayesNet
weka.classifiers.bayes.net.EditableBayesNet
- All Implemented Interfaces:
Serializable
,Cloneable
,Classifier
,AdditionalMeasureProducer
,BatchPredictor
,CapabilitiesHandler
,CapabilitiesIgnorer
,CommandlineRunnable
,Drawable
,OptionHandler
,RevisionHandler
,WeightedInstancesHandler
- Direct Known Subclasses:
BayesNetGenerator
Bayes Network learning using various search
algorithms and quality measures.
Base class for a Bayes Network classifier. Provides datastructures (network structure, conditional probability distributions, etc.) and facilities common to Bayes Network learning algorithms like K2 and B.
For more information see:
http://www.cs.waikato.ac.nz/~remco/weka.pdf Valid options are:
Base class for a Bayes Network classifier. Provides datastructures (network structure, conditional probability distributions, etc.) and facilities common to Bayes Network learning algorithms like K2 and B.
For more information see:
http://www.cs.waikato.ac.nz/~remco/weka.pdf Valid options are:
-D Do not use ADTree data structure
-B <BIF file> BIF file to compare with
-Q weka.classifiers.bayes.net.search.SearchAlgorithm Search algorithm
-E weka.classifiers.bayes.net.estimate.SimpleEstimator Estimator algorithm
- Version:
- $Revision: 10153 $
- Author:
- Remco Bouckaert (rrb@xm.co.nz)
- See Also:
-
Field Summary
Fields inherited from class weka.classifiers.bayes.BayesNet
m_Distributions, m_Instances
Fields inherited from class weka.classifiers.AbstractClassifier
BATCH_SIZE_DEFAULT, NUM_DECIMAL_PLACES_DEFAULT
Fields inherited from interface weka.core.Drawable
BayesNet, Newick, NOT_DRAWABLE, TREE
-
Constructor Summary
ConstructorDescriptionstandard constructor *EditableBayesNet
(boolean bSetInstances) constructor that potentially initializes instances as wellEditableBayesNet
(BIFReader other) constructor, copies Bayesian network structure from a Bayesian network encapsulated in a BIFReaderEditableBayesNet
(Instances instances) constructor, creates empty network with nodes based on the attributes in a data set -
Method Summary
Modifier and TypeMethodDescriptionvoid
addArc
(int nParent, int nChild) Add arc between two nodes Distributions are updated by duplication for every value of the parent node.void
Add arc between two nodes Distributions are updated by duplication for every value of the parent node.void
Add arc between parent node and each of the nodes in a given list.void
Add new node to the network, initializing instances, parentsets, distributions.void
Add node to network at a given position, initializing instances, parentsets, distributions.void
addNodeValue
(int nTargetNode, String sNewValue) Add node value to a node.void
alignBottom
(ArrayList<Integer> nodes) align set of nodes with the bottom most node in the listvoid
align set of nodes with the left most node in the listvoid
alignRight
(ArrayList<Integer> nodes) align set of nodes with the right most node in the listvoid
align set of nodes with the top most node in the listboolean
canRedo()
return whether there is something on the undo stack that can be performedboolean
canUndo()
return whether there is something on the undo stack that can be performedvoid
centerHorizontal
(ArrayList<Integer> nodes) center set of nodes half way between left and right most node in the listvoid
centerVertical
(ArrayList<Integer> nodes) center set of nodes half way between top and bottom most node in the listvoid
remove all actions from the undo stackvoid
deleteArc
(int nParent, int nChild) Delete arc between two nodes.void
Delete arc between two nodes.void
deleteNode
(int nTargetNode) Delete node from the network, updating instances, parentsets, distributions Conditional distributions are condensed by taking the values for the target node to be its first value.void
deleteNode
(String sName) Delete node from the network, updating instances, parentsets, distributions Conditional distributions are condensed by taking the values for the target node to be its first value.void
deleteSelection
(ArrayList<Integer> nodes) Delete nodes with indexes in selection from the network, updating instances, parentsets, distributions Conditional distributions are condensed by taking the values for the target node to be its first value.void
delNodeValue
(int nTargetNode, String sValue) Delete node value from a node.getChildren
(int nTargetNode) return list of children of a nodegetContent
(Element node) XML helper function.double[][]
getDistribution
(int nTargetNode) returns distribution of a node in matrix form with matrix representing distribution with P[i][j] = P(node = j | parent configuration = i)double[][]
getDistribution
(String sName) returns distribution of a node in matrix form with matrix representing distribution with P[i][j] = P(node = j | parent configuration = i)int
getEvidence
(int iNode) get evidence state of a node.double[]
getMargin
(int iNode) return marginal distibution for a nodeint
returns index of node with given name.int
returns index of node with given name, or -1 if no such node existsint
getPositionX
(int iNode) get x position of a nodeint
getPositionY
(int iNode) get y position of a nodeReturns the revision string.getValueName
(int nTargetNode, int iValue) returns value of a nodeString[]
getValues
(int nTargetNode) returns array of values of a nodeString[]
returns array of values of a nodeboolean
return true when current state differs from the state the network was last savedvoid
isSaved()
indicate the network state was savedget message representing the last action performed on the networkvoid
layoutGraph
(ArrayList<Integer> nPosX, ArrayList<Integer> nPosY) set positions of all nodesstatic void
void
Apply paste operation with XMLBIF fragment.redo()
redo the last edit action performed on the network.void
renameNodeValue
(int nTargetNode, String sValue, String sNewValue) change the name of a value of a nodevoid
Assuming a network structure is defined and we want to learn from data, the data set must be put if correct order first and possibly discretized/missing values filled in before proceeding to CPT learning.void
setDistribution
(int nTargetNode, double[][] P) specify distribution of a nodevoid
setDistribution
(String sName, double[][] P) specify distribution of a nodevoid
setEvidence
(int iNode, int iValue) set evidence state of a node.void
setMargin
(int iNode, double[] fMarginP) set marginal distibution for a nodevoid
setNodeName
(int nTargetNode, String sName) change the name of a nodevoid
setPosition
(int iNode, int nX, int nY) set position of nodevoid
setPosition
(int nNode, int nX, int nY, ArrayList<Integer> nodes) Set position of node.void
spaceHorizontal
(ArrayList<Integer> nodes) space out set of nodes evenly between left and right most node in the listvoid
spaceVertical
(ArrayList<Integer> nodes) space out set of nodes evenly between top and bottom most node in the listreturns network in XMLBIF formattoXMLBIF03
(ArrayList<Integer> nodes) return fragment of network in XMLBIF formatundo()
undo the last edit action performed on the network.Methods inherited from class weka.classifiers.bayes.BayesNet
BIFFileTipText, buildClassifier, buildStructure, countsForInstance, distributionForInstance, enumerateMeasures, estimateCPTs, estimatorTipText, getADTree, getBIFFile, getBIFHeader, getCapabilities, getCardinality, getDistributions, getEstimator, getMeasure, getName, getNodeName, getNodeValue, getNrOfNodes, getNrOfParents, getNumInstances, getOptions, getParent, getParentCardinality, getParentSet, getParentSets, getProbability, getSearchAlgorithm, getUseADTree, globalInfo, graph, graphType, initCPTs, initStructure, listOptions, measureAICScore, measureBayesScore, measureBDeuScore, measureDivergence, measureEntropyScore, measureExtraArcs, measureMDLScore, measureMissingArcs, measureReversedArcs, partitionOptions, searchAlgorithmTipText, setBIFFile, setEstimator, setOptions, setSearchAlgorithm, setUseADTree, toString, updateClassifier, useADTreeTipText
Methods inherited from class weka.classifiers.AbstractClassifier
batchSizeTipText, classifyInstance, debugTipText, distributionsForInstances, doNotCheckCapabilitiesTipText, forName, getBatchSize, getDebug, getDoNotCheckCapabilities, getNumDecimalPlaces, implementsMoreEfficientBatchPrediction, makeCopies, makeCopy, numDecimalPlacesTipText, postExecution, preExecution, run, runClassifier, setBatchSize, setDebug, setDoNotCheckCapabilities, setNumDecimalPlaces
-
Constructor Details
-
EditableBayesNet
public EditableBayesNet()standard constructor * -
EditableBayesNet
constructor, creates empty network with nodes based on the attributes in a data set -
EditableBayesNet
constructor, copies Bayesian network structure from a Bayesian network encapsulated in a BIFReader -
EditableBayesNet
public EditableBayesNet(boolean bSetInstances) constructor that potentially initializes instances as well- Parameters:
bSetInstances
- flag indicating whether to initialize instances or not
-
-
Method Details
-
setData
Assuming a network structure is defined and we want to learn from data, the data set must be put if correct order first and possibly discretized/missing values filled in before proceeding to CPT learning.- Parameters:
instances
- data set to learn from- Throws:
Exception
- when data sets are not compatible, e.g., a variable is missing or a variable has different nr of values.
-
getNode2
returns index of node with given name, or -1 if no such node exists- Parameters:
sNodeName
- name of the node to get index for
-
getNode
returns index of node with given name. Throws exception if no such node exists- Parameters:
sNodeName
- name of the node to get index for- Throws:
Exception
-
addNode
Add new node to the network, initializing instances, parentsets, distributions. Used for manual manipulation of the Bayesian network.- Parameters:
sName
- name of the node. If the name already exists, an x is appended to the namenCardinality
- number of values for this node- Throws:
Exception
-
addNode
Add node to network at a given position, initializing instances, parentsets, distributions. Used for manual manipulation of the Bayesian network.- Parameters:
sName
- name of the node. If the name already exists, an x is appended to the namenCardinality
- number of values for this nodenPosX
- x-coordiate of the position to place this nodenPosY
- y-coordiate of the position to place this node- Throws:
Exception
-
deleteNode
Delete node from the network, updating instances, parentsets, distributions Conditional distributions are condensed by taking the values for the target node to be its first value. Used for manual manipulation of the Bayesian network.- Parameters:
sName
- name of the node. If the name does not exists an exception is thrown- Throws:
Exception
-
deleteNode
Delete node from the network, updating instances, parentsets, distributions Conditional distributions are condensed by taking the values for the target node to be its first value. Used for manual manipulation of the Bayesian network.- Parameters:
nTargetNode
- index of the node to delete.- Throws:
Exception
-
deleteSelection
Delete nodes with indexes in selection from the network, updating instances, parentsets, distributions Conditional distributions are condensed by taking the values for the target node to be its first value. Used for manual manipulation of the Bayesian network.- Parameters:
nodes
- array of indexes of nodes to delete.- Throws:
Exception
-
getContent
XML helper function. Returns all TEXT children of the given node in one string. Between the node values new lines are inserted.- Parameters:
node
- the node to return the content for- Returns:
- the content of the node
-
paste
Apply paste operation with XMLBIF fragment. This adds nodes in the XMLBIF fragment to the network, together with its parents. First, paste in test mode to verify no problems occur, then execute paste operation. If a problem occurs (e.g. parent does not exist) then a exception is thrown.- Parameters:
sXML
- XMLBIF fragment to paste into the network- Throws:
Exception
-
addArc
Add arc between two nodes Distributions are updated by duplication for every value of the parent node.- Parameters:
sParent
- name of the parent nodesChild
- name of the child node- Throws:
Exception
- if parent or child cannot be found in network
-
addArc
Add arc between two nodes Distributions are updated by duplication for every value of the parent node.- Parameters:
nParent
- index of the parent nodenChild
- index of the child node- Throws:
Exception
-
addArc
Add arc between parent node and each of the nodes in a given list. Distributions are updated as above.- Parameters:
sParent
- name of the parent nodenodes
- array of indexes of child nodes- Throws:
Exception
-
deleteArc
Delete arc between two nodes. Distributions are updated by condensing for the parent node taking its first value.- Parameters:
sParent
- name of the parent nodesChild
- name of the child node- Throws:
Exception
- if parent or child cannot be found in network
-
deleteArc
Delete arc between two nodes. Distributions are updated by condensing for the parent node taking its first value.- Parameters:
nParent
- index of the parent nodenChild
- index of the child node- Throws:
Exception
-
setDistribution
specify distribution of a node- Parameters:
sName
- name of the node to specify distribution forP
- matrix representing distribution with P[i][j] = P(node = j | parent configuration = i)- Throws:
Exception
- if parent or child cannot be found in network
-
setDistribution
specify distribution of a node- Parameters:
nTargetNode
- index of the node to specify distribution forP
- matrix representing distribution with P[i][j] = P(node = j | parent configuration = i)- Throws:
Exception
- if parent or child cannot be found in network
-
getDistribution
returns distribution of a node in matrix form with matrix representing distribution with P[i][j] = P(node = j | parent configuration = i)- Parameters:
sName
- name of the node to get distribution from
-
getDistribution
public double[][] getDistribution(int nTargetNode) returns distribution of a node in matrix form with matrix representing distribution with P[i][j] = P(node = j | parent configuration = i)- Parameters:
nTargetNode
- index of the node to get distribution from
-
getValues
returns array of values of a node- Parameters:
sName
- name of the node to get values from
-
getValues
returns array of values of a node- Parameters:
nTargetNode
- index of the node to get values from
-
getValueName
returns value of a node- Parameters:
nTargetNode
- index of the node to get values fromiValue
- index of the value
-
setNodeName
change the name of a node- Parameters:
nTargetNode
- index of the node to set name forsName
- new name to assign
-
renameNodeValue
change the name of a value of a node- Parameters:
nTargetNode
- index of the node to set name forsValue
- current name of the valuesNewValue
- new name of the value
-
addNodeValue
Add node value to a node. Distributions for the node assign zero probability to the new value. Child nodes duplicate CPT conditioned on the new value.- Parameters:
nTargetNode
- index of the node to add value forsNewValue
- name of the value
-
delNodeValue
Delete node value from a node. Distributions for the node are scaled up proportional to existing distribution (or made uniform if zero probability is assigned to remainder of values). .* Child nodes delete CPTs conditioned on the new value.- Parameters:
nTargetNode
- index of the node to delete value fromsValue
- name of the value to delete- Throws:
Exception
-
setPosition
public void setPosition(int iNode, int nX, int nY) set position of node- Parameters:
iNode
- index of node to set position fornX
- x position of new positionnY
- y position of new position
-
setPosition
Set position of node. Move set of nodes with the same displacement as a specified node.- Parameters:
nNode
- index of node to set position fornX
- x position of new positionnY
- y position of new positionnodes
- array of indexes of nodes to move
-
layoutGraph
set positions of all nodes- Parameters:
nPosX
- new x positions for all nodesnPosY
- new y positions for all nodes
-
getPositionX
public int getPositionX(int iNode) get x position of a node- Parameters:
iNode
- index of node of interest
-
getPositionY
public int getPositionY(int iNode) get y position of a node- Parameters:
iNode
- index of node of interest
-
alignLeft
align set of nodes with the left most node in the list- Parameters:
nodes
- list of indexes of nodes to align
-
alignRight
align set of nodes with the right most node in the list- Parameters:
nodes
- list of indexes of nodes to align
-
alignTop
align set of nodes with the top most node in the list- Parameters:
nodes
- list of indexes of nodes to align
-
alignBottom
align set of nodes with the bottom most node in the list- Parameters:
nodes
- list of indexes of nodes to align
-
centerHorizontal
center set of nodes half way between left and right most node in the list- Parameters:
nodes
- list of indexes of nodes to center
-
centerVertical
center set of nodes half way between top and bottom most node in the list- Parameters:
nodes
- list of indexes of nodes to center
-
spaceHorizontal
space out set of nodes evenly between left and right most node in the list- Parameters:
nodes
- list of indexes of nodes to space out
-
spaceVertical
space out set of nodes evenly between top and bottom most node in the list- Parameters:
nodes
- list of indexes of nodes to space out
-
getMargin
public double[] getMargin(int iNode) return marginal distibution for a node- Parameters:
iNode
- index of node of interest
-
setMargin
public void setMargin(int iNode, double[] fMarginP) set marginal distibution for a node- Parameters:
iNode
- index of node to set marginal distribution forfMarginP
- marginal distribution
-
getEvidence
public int getEvidence(int iNode) get evidence state of a node. -1 represents no evidence set, otherwise the index of a value of the node- Parameters:
iNode
- index of node of interest
-
setEvidence
public void setEvidence(int iNode, int iValue) set evidence state of a node. -1 represents no evidence set, otherwise the index of a value of the node- Parameters:
iNode
- index of node of interestiValue
- evidence value to set
-
getChildren
return list of children of a node- Parameters:
nTargetNode
- index of node of interest
-
toXMLBIF03
returns network in XMLBIF format- Overrides:
toXMLBIF03
in classBayesNet
- Returns:
- an XML BIF 0.3 description of the classifier as a string.
-
toXMLBIF03
return fragment of network in XMLBIF format- Parameters:
nodes
- array of indexes of nodes that should be in the fragment
-
canUndo
public boolean canUndo()return whether there is something on the undo stack that can be performed -
canRedo
public boolean canRedo()return whether there is something on the undo stack that can be performed -
isChanged
public boolean isChanged()return true when current state differs from the state the network was last saved -
isSaved
public void isSaved()indicate the network state was saved -
lastActionMsg
get message representing the last action performed on the network -
undo
undo the last edit action performed on the network. returns message representing the action performed. -
redo
redo the last edit action performed on the network. returns message representing the action performed. -
clearUndoStack
public void clearUndoStack()remove all actions from the undo stack -
getRevision
Returns the revision string.- Specified by:
getRevision
in interfaceRevisionHandler
- Overrides:
getRevision
in classBayesNet
- Returns:
- the revision
-
main
- Parameters:
args
-
-