org.encog.ml.bayesian
Class BayesianNetwork
- java.lang.Object
-
- org.encog.ml.BasicML
-
- org.encog.ml.bayesian.BayesianNetwork
-
- All Implemented Interfaces:
- java.io.Serializable, MLClassification, MLError, MLInput, MLInputOutput, MLMethod, MLOutput, MLProperties, MLResettable
public class BayesianNetwork extends BasicML implements MLClassification, MLResettable, java.io.Serializable, MLError
The Bayesian Network is a machine learning method that is based on probability, and particularly Bayes' Rule. The Bayesian Network also forms the basis for the Hidden Markov Model and Naive Bayesian Network. The Bayesian Network is either constructed directly or inferred from training data using an algorithm such as K2. http://www.heatonresearch.com/wiki/Bayesian_Network- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field and Description static java.lang.String[]CHOICES_TRUE_FALSEDefault choices for a boolean event.
-
Constructor Summary
Constructors Constructor and Description BayesianNetwork()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description doublecalculateError(MLDataSet data)Calculate the error of the ML method, given a dataset.intcalculateParameterCount()intclassify(MLData input)Classify the input.doublecomputeProbability(MLData input)voidcreateDependency(BayesianEvent parentEvent, BayesianEvent... children)Create a dependency between a parent and multiple children.voidcreateDependency(BayesianEvent parentEvent, BayesianEvent childEvent)Create a dependency between two events.voidcreateDependency(java.lang.String parentEventLabel, java.lang.String childEventLabel)Create a dependency between two labels.voidcreateEvent(BayesianEvent event)Create, or register, the specified event with this bayesian network.BayesianEventcreateEvent(java.lang.String label, java.util.List<BayesianChoice> options)Create an event specified on the label and options provided.BayesianEventcreateEvent(java.lang.String label, java.lang.String... options)Create the specified events based on a variable number of options, or choices.voiddefineClassificationStructure(java.lang.String line)Define a classification structure of the form P(A|B) = P(C)voiddefineProbability(java.lang.String line)Define a probability.voiddefineProbability(java.lang.String line, double probability)Define the probability for an event.voiddefineRelationship(java.lang.String line)Define a relationship.int[]determineClasses(MLData input)Determine the classes for the specified input.booleaneventExists(java.lang.String label)Return true if the specified event exists.voidfinalizeStructure()Finalize the structure of this Bayesian network.java.lang.StringgetClassificationStructure()intgetClassificationTarget()Get the classification target.BayesianEventgetClassificationTargetEvent()java.lang.StringgetContents()BayesianEventgetEvent(java.lang.String label)Get an event based on the string label.BayesianEventgetEventError(java.lang.String label)Get an event based on label, throw an error if not found.intgetEventIndex(BayesianEvent event)java.util.Map<java.lang.String,BayesianEvent>getEventMap()java.util.List<BayesianEvent>getEvents()intgetInputCount()intgetOutputCount()BayesianQuerygetQuery()booleanhasValidClassificationTarget()booleanisCondIndependent(BayesianEvent a, BayesianEvent b, BayesianEvent... given)booleanisDescendant(BayesianEvent a, BayesianEvent b)Determine if one event is a descendant of another.booleanisInputPresent(int idx)Determine if the specified input is present.doubleperformQuery(java.lang.String line)Perform a query.voidremoveAllRelations()Remove all relations between nodes.BayesianEventrequireEvent(java.lang.String label)Require the specified event, thrown an error if it does not exist.voidreset()Reset the weights.voidreset(int seed)Reset the weights with a seed.voidsetContents(java.lang.String line)Define the structure of the Bayesian network as a string.voidsetQuery(BayesianQuery query)java.lang.StringtoString()voidupdateProperties()Update any objeccts when a property changes.voidvalidate()Validate the structure of this Bayesian network.-
Methods inherited from class org.encog.ml.BasicML
getProperties, getPropertyDouble, getPropertyLong, getPropertyString, setProperty, setProperty, setProperty
-
-
-
-
Field Detail
-
CHOICES_TRUE_FALSE
public static final java.lang.String[] CHOICES_TRUE_FALSE
Default choices for a boolean event.
-
-
Method Detail
-
getEventMap
public java.util.Map<java.lang.String,BayesianEvent> getEventMap()
- Returns:
- The mapping from string names to events.
-
getEvents
public java.util.List<BayesianEvent> getEvents()
- Returns:
- The events.
-
getEvent
public BayesianEvent getEvent(java.lang.String label)
Get an event based on the string label.- Parameters:
label- The label to locate.- Returns:
- The event found.
-
getEventError
public BayesianEvent getEventError(java.lang.String label)
Get an event based on label, throw an error if not found.- Parameters:
label- THe event label to find.- Returns:
- The event.
-
eventExists
public boolean eventExists(java.lang.String label)
Return true if the specified event exists.- Parameters:
label- The label we are searching for.- Returns:
- True, if the event exists by label.
-
createEvent
public void createEvent(BayesianEvent event)
Create, or register, the specified event with this bayesian network.- Parameters:
event- The event to add.
-
createEvent
public BayesianEvent createEvent(java.lang.String label, java.util.List<BayesianChoice> options)
Create an event specified on the label and options provided.- Parameters:
label- The label to create this event as.options- The options, or states, that this event can have.- Returns:
- The newly created event.
-
createEvent
public BayesianEvent createEvent(java.lang.String label, java.lang.String... options)
Create the specified events based on a variable number of options, or choices.- Parameters:
label- The label of the event to create.options- The states that the event can have.- Returns:
- The newly created event.
-
createDependency
public void createDependency(BayesianEvent parentEvent, BayesianEvent childEvent)
Create a dependency between two events.- Parameters:
parentEvent- The parent event.childEvent- The child event.
-
createDependency
public void createDependency(BayesianEvent parentEvent, BayesianEvent... children)
Create a dependency between a parent and multiple children.- Parameters:
parentEvent- The parent event.children- The child events.
-
createDependency
public void createDependency(java.lang.String parentEventLabel, java.lang.String childEventLabel)Create a dependency between two labels.- Parameters:
parentEventLabel- The parent event.childEventLabel- The child event.
-
getContents
public java.lang.String getContents()
- Returns:
- The contents as a string. Shows both events and dependences.
-
setContents
public void setContents(java.lang.String line)
Define the structure of the Bayesian network as a string.- Parameters:
line- The string to define events and relations.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
calculateParameterCount
public int calculateParameterCount()
- Returns:
- The number of parameters in this Bayesian network.
-
finalizeStructure
public void finalizeStructure()
Finalize the structure of this Bayesian network.
-
validate
public void validate()
Validate the structure of this Bayesian network.
-
isDescendant
public boolean isDescendant(BayesianEvent a, BayesianEvent b)
Determine if one event is a descendant of another.- Parameters:
a- The event to check.b- The event that has children.- Returns:
- True if a is amoung b's children.
-
isCondIndependent
public boolean isCondIndependent(BayesianEvent a, BayesianEvent b, BayesianEvent... given)
-
getQuery
public BayesianQuery getQuery()
-
setQuery
public void setQuery(BayesianQuery query)
-
getInputCount
public int getInputCount()
- Specified by:
getInputCountin interfaceMLInput- Returns:
- The input.
-
getOutputCount
public int getOutputCount()
- Specified by:
getOutputCountin interfaceMLOutput- Returns:
- The output count.
-
computeProbability
public double computeProbability(MLData input)
-
defineProbability
public void defineProbability(java.lang.String line, double probability)Define the probability for an event.- Parameters:
line- The event.probability- The probability.
-
defineProbability
public void defineProbability(java.lang.String line)
Define a probability.- Parameters:
line- The line to define the probability.
-
requireEvent
public BayesianEvent requireEvent(java.lang.String label)
Require the specified event, thrown an error if it does not exist.- Parameters:
label- The label.- Returns:
- The event.
-
defineRelationship
public void defineRelationship(java.lang.String line)
Define a relationship.- Parameters:
line- The relationship to define.
-
performQuery
public double performQuery(java.lang.String line)
Perform a query.- Parameters:
line- The query.- Returns:
- The probability.
-
updateProperties
public void updateProperties()
Update any objeccts when a property changes.- Specified by:
updatePropertiesin interfaceMLProperties- Specified by:
updatePropertiesin classBasicML
-
getEventIndex
public int getEventIndex(BayesianEvent event)
-
removeAllRelations
public void removeAllRelations()
Remove all relations between nodes.
-
reset
public void reset()
Reset the weights.- Specified by:
resetin interfaceMLResettable
-
reset
public void reset(int seed)
Reset the weights with a seed.- Specified by:
resetin interfaceMLResettable- Parameters:
seed- The seed value.
-
determineClasses
public int[] determineClasses(MLData input)
Determine the classes for the specified input.- Parameters:
input- The input.- Returns:
- An array of class indexes.
-
classify
public int classify(MLData input)
Classify the input.- Specified by:
classifyin interfaceMLClassification- Parameters:
input- The input to classify.- Returns:
- The group that the data was classified into.
-
getClassificationTarget
public int getClassificationTarget()
Get the classification target.- Returns:
- The index of the classification target.
-
isInputPresent
public boolean isInputPresent(int idx)
Determine if the specified input is present.- Parameters:
idx- The index of the input.- Returns:
- True, if the input is present.
-
defineClassificationStructure
public void defineClassificationStructure(java.lang.String line)
Define a classification structure of the form P(A|B) = P(C)- Parameters:
line- The line.
-
getClassificationTargetEvent
public BayesianEvent getClassificationTargetEvent()
- Returns:
- The classification target.
-
calculateError
public double calculateError(MLDataSet data)
Calculate the error of the ML method, given a dataset.- Specified by:
calculateErrorin interfaceMLError- Parameters:
data- The dataset.- Returns:
- The error.
-
getClassificationStructure
public java.lang.String getClassificationStructure()
- Returns:
- Returns a string representation of the classification structure. Of the form P(a|b,c,d)
-
hasValidClassificationTarget
public boolean hasValidClassificationTarget()
- Returns:
- True if this network has a valid classification target.
-
-
DMelt 3.0 © DataMelt by jWork.ORG