org.encog.ml.bayesian

## Class BayesianNetwork

- java.lang.Object
- - org.encog.ml.BasicML
  - - org.encog.ml.bayesian.BayesianNetwork

- All Implemented Interfaces:
    Serializable, MLClassification, MLError, MLInput, MLInputOutput, MLMethod, MLOutput, MLProperties, MLResettable

      public class BayesianNetwork
      extends BasicML
      implements MLClassification, MLResettable, 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 String[]` | `CHOICES_TRUE_FALSE` Default choices for a boolean event.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `BayesianNetwork()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `double` | `calculateError(MLDataSet data)` Calculate the error of the ML method, given a dataset.
    `int` | `calculateParameterCount()`
    `int` | `classify(MLData input)` Classify the input.
    `double` | `computeProbability(MLData input)`
    `void` | `createDependency(BayesianEvent parentEvent, BayesianEvent... children)` Create a dependency between a parent and multiple children.
    `void` | `createDependency(BayesianEvent parentEvent, BayesianEvent childEvent)` Create a dependency between two events.
    `void` | `createDependency(String parentEventLabel, String childEventLabel)` Create a dependency between two labels.
    `void` | `createEvent(BayesianEvent event)` Create, or register, the specified event with this bayesian network.
    `BayesianEvent` | `createEvent(String label, List<BayesianChoice> options)` Create an event specified on the label and options provided.
    `BayesianEvent` | `createEvent(String label, String... options)` Create the specified events based on a variable number of options, or choices.
    `void` | `defineClassificationStructure(String line)` Define a classification structure of the form P(A|B) = P(C)
    `void` | `defineProbability(String line)` Define a probability.
    `void` | `defineProbability(String line, double probability)` Define the probability for an event.
    `void` | `defineRelationship(String line)` Define a relationship.
    `int[]` | `determineClasses(MLData input)` Determine the classes for the specified input.
    `boolean` | `eventExists(String label)` Return true if the specified event exists.
    `void` | `finalizeStructure()` Finalize the structure of this Bayesian network.
    `String` | `getClassificationStructure()`
    `int` | `getClassificationTarget()` Get the classification target.
    `BayesianEvent` | `getClassificationTargetEvent()`
    `String` | `getContents()`
    `BayesianEvent` | `getEvent(String label)` Get an event based on the string label.
    `BayesianEvent` | `getEventError(String label)` Get an event based on label, throw an error if not found.
    `int` | `getEventIndex(BayesianEvent event)`
    `Map<String,BayesianEvent>` | `getEventMap()`
    `List<BayesianEvent>` | `getEvents()`
    `int` | `getInputCount()`
    `int` | `getOutputCount()`
    `BayesianQuery` | `getQuery()`
    `boolean` | `hasValidClassificationTarget()`
    `boolean` | `isCondIndependent(BayesianEvent a, BayesianEvent b, BayesianEvent... given)`
    `boolean` | `isDescendant(BayesianEvent a, BayesianEvent b)` Determine if one event is a descendant of another.
    `boolean` | `isInputPresent(int idx)` Determine if the specified input is present.
    `double` | `performQuery(String line)` Perform a query.
    `void` | `removeAllRelations()` Remove all relations between nodes.
    `BayesianEvent` | `requireEvent(String label)` Require the specified event, thrown an error if it does not exist.
    `void` | `reset()` Reset the weights.
    `void` | `reset(int seed)` Reset the weights with a seed.
    `void` | `setContents(String line)` Define the structure of the Bayesian network as a string.
    `void` | `setQuery(BayesianQuery query)`
    `String` | `toString()`
    `void` | `updateProperties()` Update any objeccts when a property changes.
    `void` | `validate()` Validate the structure of this Bayesian network.

    - ### Methods inherited from class org.encog.ml.BasicML

      `getProperties, getPropertyDouble, getPropertyLong, getPropertyString, setProperty, setProperty, setProperty`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### CHOICES_TRUE_FALSE

          public static final String[] CHOICES_TRUE_FALSE

      Default choices for a boolean event.

  - ### Constructor Detail

    - #### BayesianNetwork

          public BayesianNetwork()

  - ### Method Detail

    - #### getEventMap

          public Map<String,BayesianEvent> getEventMap()

      Returns:
        The mapping from string names to events.

    - #### getEvents

          public List<BayesianEvent> getEvents()

      Returns:
        The events.

    - #### getEvent

          public BayesianEvent getEvent(String label)

      Get an event based on the string label.
      Parameters:
        `label` - The label to locate.
      Returns:
        The event found.

    - #### getEventError

          public BayesianEvent getEventError(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(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(String label,
                                  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(String label,
                                  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(String parentEventLabel,
                              String childEventLabel)

      Create a dependency between two labels.
      Parameters:
        `parentEventLabel` - The parent event.
        `childEventLabel` - The child event.

    - #### getContents

          public String getContents()

      Returns:
        The contents as a string. Shows both events and dependences.

    - #### setContents

          public void setContents(String line)

      Define the structure of the Bayesian network as a string.
      Parameters:
        `line` - The string to define events and relations.

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `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:
        `getInputCount` in interface `MLInput`
      Returns:
        The input.

    - #### getOutputCount

          public int getOutputCount()

      Specified by:
        `getOutputCount` in interface `MLOutput`
      Returns:
        The output count.

    - #### computeProbability

          public double computeProbability(MLData input)

    - #### defineProbability

          public void defineProbability(String line,
                               double probability)

      Define the probability for an event.
      Parameters:
        `line` - The event.
        `probability` - The probability.

    - #### defineProbability

          public void defineProbability(String line)

      Define a probability.
      Parameters:
        `line` - The line to define the probability.

    - #### requireEvent

          public BayesianEvent requireEvent(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(String line)

      Define a relationship.
      Parameters:
        `line` - The relationship to define.

    - #### performQuery

          public double performQuery(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:
        `updateProperties` in interface `MLProperties`
      Specified by:
        `updateProperties` in class `BasicML`

    - #### getEventIndex

          public int getEventIndex(BayesianEvent event)

    - #### removeAllRelations

          public void removeAllRelations()

      Remove all relations between nodes.

    - #### reset

          public void reset()

      Reset the weights.
      Specified by:
        `reset` in interface `MLResettable`

    - #### reset

          public void reset(int seed)

      Reset the weights with a seed.
      Specified by:
        `reset` in interface `MLResettable`
      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:
        `classify` in interface `MLClassification`
      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(String line)

      Define a classification structure of the form P(A|B) = P(C)
      Parameters:
        `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:
        `calculateError` in interface `MLError`
      Parameters:
        `data` - The dataset.
      Returns:
        The error.

    - #### getClassificationStructure

          public 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.

Copyright © 2014. All Rights Reserved.