public class EditableBayesNet extends BayesNet
-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
m_Distributions, m_Instances
BayesNet, Newick, NOT_DRAWABLE, TREE
Constructor and Description |
---|
EditableBayesNet()
standard constructor *
|
EditableBayesNet(BIFReader other)
constructor, copies Bayesian network structure from a Bayesian network
encapsulated in a BIFReader
|
EditableBayesNet(boolean bSetInstances)
constructor that potentially initializes instances as well
|
EditableBayesNet(Instances instances)
constructor, creates empty network with nodes based on the attributes in a data set
|
Modifier and Type | Method and Description |
---|---|
void |
addArc(int nParent,
int nChild)
Add arc between two nodes Distributions are updated by duplication for
every value of the parent node.
|
void |
addArc(java.lang.String sParent,
FastVector nodes)
Add arc between parent node and each of the nodes in a given list.
|
void |
addArc(java.lang.String sParent,
java.lang.String sChild)
Add arc between two nodes Distributions are updated by duplication for
every value of the parent node.
|
void |
addNode(java.lang.String sName,
int nCardinality)
Add new node to the network, initializing instances, parentsets,
distributions.
|
void |
addNode(java.lang.String sName,
int nCardinality,
int nPosX,
int nPosY)
Add node to network at a given position, initializing instances, parentsets,
distributions.
|
void |
addNodeValue(int nTargetNode,
java.lang.String sNewValue)
Add node value to a node.
|
void |
alignBottom(FastVector nodes)
align set of nodes with the bottom most node in the list
|
void |
alignLeft(FastVector nodes)
align set of nodes with the left most node in the list
|
void |
alignRight(FastVector nodes)
align set of nodes with the right most node in the list
|
void |
alignTop(FastVector nodes)
align set of nodes with the top most node in the list
|
boolean |
canRedo()
return whether there is something on the undo stack that can be performed
|
boolean |
canUndo()
return whether there is something on the undo stack that can be performed
|
void |
centerHorizontal(FastVector nodes)
center set of nodes half way between left and right most node in the list
|
void |
centerVertical(FastVector nodes)
center set of nodes half way between top and bottom most node in the list
|
void |
clearUndoStack()
remove all actions from the undo stack
|
void |
deleteArc(int nParent,
int nChild)
Delete arc between two nodes.
|
void |
deleteArc(java.lang.String sParent,
java.lang.String sChild)
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(java.lang.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(FastVector 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,
java.lang.String sValue)
Delete node value from a node.
|
FastVector |
getChildren(int nTargetNode)
return list of children of a node
|
java.lang.String |
getContent(org.w3c.dom.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(java.lang.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 node
|
int |
getNode(java.lang.String sNodeName)
returns index of node with given name.
|
int |
getNode2(java.lang.String sNodeName)
returns index of node with given name, or -1 if no such node exists
|
int |
getPositionX(int iNode)
get x position of a node
|
int |
getPositionY(int iNode)
get y position of a node
|
java.lang.String |
getRevision()
Returns the revision string.
|
java.lang.String |
getValueName(int nTargetNode,
int iValue)
returns value of a node
|
java.lang.String[] |
getValues(int nTargetNode)
returns array of values of a node
|
java.lang.String[] |
getValues(java.lang.String sName)
returns array of values of a node
|
boolean |
isChanged()
return true when current state differs from the state the network was last saved
|
void |
isSaved()
indicate the network state was saved
|
java.lang.String |
lastActionMsg()
get message representing the last action performed on the network
|
void |
layoutGraph(FastVector nPosX,
FastVector nPosY)
set positions of all nodes
|
static void |
main(java.lang.String[] args) |
void |
paste(java.lang.String sXML)
Apply paste operation with XMLBIF fragment.
|
java.lang.String |
redo()
redo the last edit action performed on the network.
|
void |
renameNodeValue(int nTargetNode,
java.lang.String sValue,
java.lang.String sNewValue)
change the name of a value of a node
|
void |
setData(Instances instances)
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 node
|
void |
setDistribution(java.lang.String sName,
double[][] P)
specify distribution of a node
|
void |
setEvidence(int iNode,
int iValue)
set evidence state of a node.
|
void |
setMargin(int iNode,
double[] fMarginP)
set marginal distibution for a node
|
void |
setNodeName(int nTargetNode,
java.lang.String sName)
change the name of a node
|
void |
setPosition(int iNode,
int nX,
int nY)
set position of node
|
void |
setPosition(int nNode,
int nX,
int nY,
FastVector nodes)
Set position of node.
|
void |
spaceHorizontal(FastVector nodes)
space out set of nodes evenly between left and right most node in the list
|
void |
spaceVertical(FastVector nodes)
space out set of nodes evenly between top and bottom most node in the list
|
java.lang.String |
toXMLBIF03()
returns network in XMLBIF format
|
java.lang.String |
toXMLBIF03(FastVector nodes)
return fragment of network in XMLBIF format
|
java.lang.String |
undo()
undo the last edit action performed on the network.
|
BIFFileTipText, buildClassifier, buildStructure, countsForInstance, distributionForInstance, enumerateMeasures, estimateCPTs, estimatorTipText, getADTree, getBIFFile, getBIFHeader, getCapabilities, getCardinality, getDistributions, getEstimator, getMeasure, getName, getNodeName, getNodeValue, getNrOfNodes, getNrOfParents, 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
classifyInstance, debugTipText, forName, getDebug, makeCopies, makeCopy, setDebug
public EditableBayesNet()
public EditableBayesNet(Instances instances)
public EditableBayesNet(BIFReader other)
public EditableBayesNet(boolean bSetInstances)
bSetInstances
- flag indicating whether to initialize instances or notpublic void setData(Instances instances) throws java.lang.Exception
instances
- data set to learn fromjava.lang.Exception
- when data sets are not compatible, e.g., a variable is missing
or a variable has different nr of values.public int getNode2(java.lang.String sNodeName)
sNodeName
- name of the node to get index forpublic int getNode(java.lang.String sNodeName) throws java.lang.Exception
sNodeName
- name of the node to get index forjava.lang.Exception
public void addNode(java.lang.String sName, int nCardinality) throws java.lang.Exception
sName
- name of the node. If the name already exists, an x is appended
to the namenCardinality
- number of values for this nodejava.lang.Exception
public void addNode(java.lang.String sName, int nCardinality, int nPosX, int nPosY) throws java.lang.Exception
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 nodejava.lang.Exception
public void deleteNode(java.lang.String sName) throws java.lang.Exception
sName
- name of the node. If the name does not exists an exception is
thrownjava.lang.Exception
public void deleteNode(int nTargetNode) throws java.lang.Exception
nTargetNode
- index of the node to delete.java.lang.Exception
public void deleteSelection(FastVector nodes)
nodes
- array of indexes of nodes to delete.java.lang.Exception
public java.lang.String getContent(org.w3c.dom.Element node)
node
- the node to return the content forpublic void paste(java.lang.String sXML) throws java.lang.Exception
sXML
- XMLBIF fragment to paste into the networkjava.lang.Exception
public void addArc(java.lang.String sParent, java.lang.String sChild) throws java.lang.Exception
sParent
- name of the parent nodesChild
- name of the child nodejava.lang.Exception
- if parent or child cannot be found in networkpublic void addArc(int nParent, int nChild) throws java.lang.Exception
nParent
- index of the parent nodenChild
- index of the child nodejava.lang.Exception
public void addArc(java.lang.String sParent, FastVector nodes) throws java.lang.Exception
sParent
- name of the parent nodenodes
- array of indexes of child nodesjava.lang.Exception
public void deleteArc(java.lang.String sParent, java.lang.String sChild) throws java.lang.Exception
sParent
- name of the parent nodesChild
- name of the child nodejava.lang.Exception
- if parent or child cannot be found in networkpublic void deleteArc(int nParent, int nChild) throws java.lang.Exception
nParent
- index of the parent nodenChild
- index of the child nodejava.lang.Exception
public void setDistribution(java.lang.String sName, double[][] P) throws java.lang.Exception
sName
- name of the node to specify distribution forP
- matrix representing distribution with P[i][j] = P(node = j | parent configuration = i)java.lang.Exception
- if parent or child cannot be found in networkpublic void setDistribution(int nTargetNode, double[][] P) throws java.lang.Exception
nTargetNode
- index of the node to specify distribution forP
- matrix representing distribution with P[i][j] = P(node = j | parent configuration = i)java.lang.Exception
- if parent or child cannot be found in networkpublic double[][] getDistribution(java.lang.String sName)
sName
- name of the node to get distribution frompublic double[][] getDistribution(int nTargetNode)
nTargetNode
- index of the node to get distribution frompublic java.lang.String[] getValues(java.lang.String sName)
sName
- name of the node to get values frompublic java.lang.String[] getValues(int nTargetNode)
nTargetNode
- index of the node to get values frompublic java.lang.String getValueName(int nTargetNode, int iValue)
nTargetNode
- index of the node to get values fromiValue
- index of the valuepublic void setNodeName(int nTargetNode, java.lang.String sName)
nTargetNode
- index of the node to set name forsName
- new name to assignpublic void renameNodeValue(int nTargetNode, java.lang.String sValue, java.lang.String sNewValue)
nTargetNode
- index of the node to set name forsValue
- current name of the valuesNewValue
- new name of the valuepublic void addNodeValue(int nTargetNode, java.lang.String sNewValue)
nTargetNode
- index of the node to add value forsNewValue
- name of the valuepublic void delNodeValue(int nTargetNode, java.lang.String sValue) throws java.lang.Exception
nTargetNode
- index of the node to delete value fromsValue
- name of the value to deletejava.lang.Exception
public void setPosition(int iNode, int nX, int nY)
iNode
- index of node to set position fornX
- x position of new positionnY
- y position of new positionpublic void setPosition(int nNode, int nX, int nY, FastVector nodes)
iNode
- index of node to set position fornX
- x position of new positionnY
- y position of new positionnodes
- array of indexes of nodes to movepublic void layoutGraph(FastVector nPosX, FastVector nPosY)
nPosX
- new x positions for all nodesnPosY
- new y positions for all nodespublic int getPositionX(int iNode)
iNode
- index of node of interestpublic int getPositionY(int iNode)
iNode
- index of node of interestpublic void alignLeft(FastVector nodes)
nodes
- list of indexes of nodes to alignpublic void alignRight(FastVector nodes)
nodes
- list of indexes of nodes to alignpublic void alignTop(FastVector nodes)
nodes
- list of indexes of nodes to alignpublic void alignBottom(FastVector nodes)
nodes
- list of indexes of nodes to alignpublic void centerHorizontal(FastVector nodes)
nodes
- list of indexes of nodes to centerpublic void centerVertical(FastVector nodes)
nodes
- list of indexes of nodes to centerpublic void spaceHorizontal(FastVector nodes)
nodes
- list of indexes of nodes to space outpublic void spaceVertical(FastVector nodes)
nodes
- list of indexes of nodes to space outpublic double[] getMargin(int iNode)
iNode
- index of node of interestpublic void setMargin(int iNode, double[] fMarginP)
iNode
- index of node to set marginal distribution forfMarginP
- marginal distributionpublic int getEvidence(int iNode)
iNode
- index of node of interestpublic void setEvidence(int iNode, int iValue)
iNode
- index of node of interestiValue
- evidence value to setpublic FastVector getChildren(int nTargetNode)
iNode
- index of node of interestpublic java.lang.String toXMLBIF03()
toXMLBIF03
in class BayesNet
public java.lang.String toXMLBIF03(FastVector nodes)
nodes
- array of indexes of nodes that should be in the fragmentpublic boolean canUndo()
public boolean canRedo()
public boolean isChanged()
public void isSaved()
public java.lang.String lastActionMsg()
public java.lang.String undo()
public java.lang.String redo()
public void clearUndoStack()
public java.lang.String getRevision()
getRevision
in interface RevisionHandler
getRevision
in class BayesNet
public static void main(java.lang.String[] args)
args
-