Interface Evidence

  • All Known Implementing Classes:
    DefaultEvidence

    public interface Evidence
    Represents the evidence, or case data (e.g. row in a database) used in a query. Evidence is always associated with a particular network, however if necessary can be detached or attached to an instance of an inference engine. This has the follwing advantages: - Evidence can be set before an inference engine is created, or retained when an inference engine is destroyed. - Evidence can be switched between inference engines. - An inference engine can switch between different evidence instances.
    • Method Detail

      • size

        int size()
        Gets the count of variables with either hard, soft or temporal evidence set.
        Returns:
        The count of variables with evidence.
      • getNetwork

        Network getNetwork()
        Gets the Bayesian network that is the the target of the evidence.
        Returns:
        The Network.
      • getWeight

        double getWeight()
        Gets a weight that can be applied to the evidence. Default value is 1. Value must be positive. A weight can be applied to a case, to give it more or less importance during learning or inference. For example, if a database has groups of records that are identical, each group can be represented by a single case with a weight equal to the number in that group.

        Note that setting the weight to anything but 1, will effect the QueryOutput.getLogLikelihood() statistic.

      • setWeight

        void setWeight​(double value)
        Sets a weight that can be applied to the evidence. Default value is 1. Value must be positive. A weight can be applied to a case, to give it more or less importance during learning or inference. For example, if a database has groups of records that are identical, each group can be represented by a single case with a weight equal to the number in that group.

        Note that setting the weight to anything but 1, will effect the QueryOutput.getLogLikelihood() statistic.

      • getLogWeight

        double getLogWeight()
        Gets the natural logarithm of getWeight().
      • setLogWeight

        void setLogWeight​(double value)
        Sets the natural logarithm of getWeight().
      • beginUpdate

        void beginUpdate()
        Disables change notifications (if present), until endUpdate() is called. Calls to beginUpdate() can be nested, in which case notifications only continue after the final call to endUpdate().
      • clear

        void clear()
        Clears any evidence on all variables, and resets the getWeight() to 1.
      • clear

        void clear​(Variable variable)
        Clears evidence on a variable.
        Parameters:
        variable - The variable whose evidence you want to clear.
      • clear

        void clear​(Variable variable,
                   Integer time)
        Clears evidence on a variable at the specified time.
        Parameters:
        variable - The variable whose evidence you want to clear.
        time - The time at which to clear evidence. Can be null.
      • clear

        void clear​(Node node,
                   Integer time)
        Clears evidence on a node's single variable.
        Parameters:
        node - A node with a single variable whose evidence you want to clear.
        time - The time at which to clear evidence. Can be null.
      • clear

        void clear​(Node node)
        Clears evidence on a node's variables.
        Parameters:
        node - The node whose variables you want to clear evidence on.
      • copy

        void copy​(Evidence evidence)
        Replaces the current evidence, with that from another Evidence instance.
        Parameters:
        evidence - The source evidence to copy from.
      • copy

        void copy​(Evidence evidence,
                  Variable variable)
        Replaces the current evidence for an individual variable, with that from another Evidence instance. For temporal variables, evidence is copied from the source at all times.
        Parameters:
        evidence - The source evidence to copy from.
        variable - The variable to copy evidence for.
      • copy

        void copy​(Evidence evidence,
                  Variable variable,
                  Integer time)
        Replaces the current evidence for an individual variable at a specific time, with that from another Evidence instance.
        Parameters:
        evidence - The source evidence to copy from.
        variable - The variable to copy evidence for.
        time - The time at which to copy evidence.
      • endUpdate

        void endUpdate()
        Enables change notifications (if available). A corresponding call must first be made to beginUpdate() to disable notifications.
      • getVariables

        void getVariables​(Variable[] buffer)
        Fills out a buffer with all variables that have either hard or soft evidence. The buffer must have length equal to or greater than the current size().
        Parameters:
        buffer - A container for any variables with evidence. It must have length equal to or greater than the current size().
      • saveToString

        String saveToString​(String charSetName)
                     throws XMLStreamException
        Saves evidence to a string, with the specified encoding.
        Parameters:
        charSetName - The encoding to use.
        Returns:
        The evidence persisted to a string.
        Throws:
        XMLStreamException
      • getMaxTime

        Integer getMaxTime​(Variable variable)
        Gets the maximum time containing evidence for a variable.
        Parameters:
        variable - The variable to check.
        Returns:
        The maximum zero based time at which evidence is present for the variable or null if no evidence is present.
      • getMaxTime

        Integer getMaxTime()
        Gets the maximum time containing evidence.
        Returns:
        The maximum zero based time at which evidence is present for any variable or null if no evidence is present.
      • getEvidenceType

        EvidenceType getEvidenceType​(Variable variable)
        Returns the type of evidence currently set for a variable (if any).
        Parameters:
        variable - The variable in question.
        Returns:
        The EvidenceType.
      • getEvidenceType

        EvidenceType getEvidenceType​(Node node)
        Returns the type of evidence currently set for a node with a single variable.
        Parameters:
        node - The node in question.
        Returns:
        The EvidenceType.
      • getEvidenceTypes

        EvidenceTypes getEvidenceTypes​(Variable variable)
        Gets the type of evidence (if any) and whether or not it is an intervention (do-operator).
        Parameters:
        variable - The variable in question.
        Returns:
        The EvidenceTypes.
      • getEvidenceTypes

        EvidenceTypes getEvidenceTypes​(Node node)
        Gets the type of evidence (if any) and whether or not it is an intervention (do-operator).
        Parameters:
        node - The node in question.
        Returns:
        The EvidenceTypes.
      • getEvidenceTypes

        EvidenceTypes getEvidenceTypes​(Node node,
                                       Integer time)
        Gets the type of evidence (if any) and whether or not it is an intervention (do-operator).
        Parameters:
        node - The node in question.
        time - The time at which evidence is set. Can be null.
        Returns:
        The EvidenceTypes.
      • getEvidenceTypes

        EvidenceTypes getEvidenceTypes​(Variable variable,
                                       Integer time)
        Gets the type of evidence (if any) and whether or not it is an intervention (do-operator).
        Parameters:
        variable - The variable in question.
        time - The time at which evidence is set. Can be null.
        Returns:
        The EvidenceTypes.
      • getEvidenceType

        EvidenceType getEvidenceType​(Node node,
                                     Integer time)
        Returns the type of evidence currently set for a node with a single variable at a given time.
        Parameters:
        node - The node in question.
        time - The time at which evidence is set. Can be null.
        Returns:
        The EvidenceType.
      • getEvidenceType

        EvidenceType getEvidenceType​(Variable variable,
                                     Integer time)
        Returns the type of evidence currently set for a variable at a given time.
        Parameters:
        variable - The variable in question.
        time - The time at which evidence is set. Can be null.
        Returns:
        The EvidenceType.
      • setState

        void setState​(Variable variable,
                      Integer state)
        Sets a discrete variable to a particular state (hard evidence).
        Parameters:
        variable - The discrete variable to set evidence on.
        state - The zero based index of the state to set, or null to clear the evidence.
      • setState

        void setState​(Variable variable,
                      Integer state,
                      Integer time)
        Sets a discrete variable to a particular state (hard evidence), specifiying a time if the state belongs to a variable whose node is temporal.
        Parameters:
        variable - The discrete variable to set evidence on.
        state - The zero based index of the state to set, or null to clear the evidence.
        time - The time at which to set evidence, if the state belongs to a variable whose node is temporal, otherwise null.
      • setState

        void setState​(State state)
        Sets evidence on a discrete state (hard evidence).
        Parameters:
        state - The state to set, cannot be null.
      • setState

        void setState​(State state,
                      Integer time,
                      InterventionType interventionType)
        Sets evidence on a discrete state (hard evidence), in the form of an intervention (do-operator).
        Parameters:
        state - The state to set, cannot be null.
        time - The time at which to set evidence, if the node is temporal, otherwise null.
        interventionType - Whether or not the evidence is an intervention.
      • set

        void set​(Variable variable,
                 Double value,
                 Integer time,
                 InterventionType interventionType)
        Sets evidence on the variable, in the form of an intervention (do-operator).
        Parameters:
        variable - The variable to set evidence on.
        value - The value to set, or null to clear the evidence.
        time - The time at which to set evidence, if the node is temporal, otherwise null.
        interventionType - Whether or not the evidence is an intervention.
      • setState

        void setState​(State state,
                      Integer time)
        Sets evidence on a discrete state (hard evidence) at a particular time (zero based).
        Parameters:
        state - The state to set, cannot be null.
        time - The time at which to set evidence, if the node is temporal, otherwise null.
      • setState

        void setState​(Node node,
                      Integer state)
        Sets evidence on a node with a single discrete variable to a particular state (hard evidence).
        Parameters:
        node - The node with a single discrete variable to set evidence on.
        state - The zero based index of the state to set, or null to clear the evidence.
      • setState

        void setState​(Node node,
                      Integer state,
                      Integer time)
        Sets evidence on a node with a single discrete variable to a particular state (hard evidence) specifiying a time if the node is temporal.
        Parameters:
        node - The node with a single discrete variable to set evidence on.
        state - The zero based index of the state to set, or null to clear the evidence.
        time - The time at which to set evidence, if the node is temporal, otherwise null.
      • get

        Double get​(Variable variable,
                   Integer time)
        Gets the evidence for a discrete variable at the specified time.
        Parameters:
        variable - The variable.
        time - The time at which to retrieve evidence. Can be null.
        Returns:
        The evidence for the variable at the specified time.
      • get

        void get​(Variable variable,
                 Double[] destination,
                 int destinationStart,
                 int startTime,
                 int count)
        Gets the evidence for a temporal variable.
        Parameters:
        variable - The temporal variable.
        destination - The destination buffer which will be filled with the evidence values.
        destinationStart - The position in the buffer to start copying.
        startTime - The time to start copying from.
        count - The number of evidence values to copy.
      • get

        void get​(Node node,
                 Double[] destination,
                 int destinationStart,
                 int startTime,
                 int count)
        Gets the evidence for a node's single temporal variable.
        Parameters:
        node - A node with a single temporal variable.
        destination - The destination buffer which will be filled with the evidence values.
        destinationStart - The position in the buffer to start copying.
        startTime - The time to start copying from.
        count - The number of evidence values to copy.
      • get

        Double get​(Node node,
                   Integer time)
        Gets the evidence for a node with a single variable at the specified time.
        Parameters:
        node - A node with a single variable.
        time - The time to retrieve evidence for. Can be null.
        Returns:
        The evidence. Can be null.
      • set

        void set​(Variable variable,
                 Double value)
        Sets a variable to a particular value (hard evidence).
        Parameters:
        variable - The variable to set evidence on.
        value - The value to set, or null to clear the evidence.
      • set

        void set​(Variable variable,
                 Double value,
                 Integer time)
        Sets evidence on a variable at a specified time.
        Parameters:
        variable - The variable to set evidence on.
        value - The value to set, or null to clear the evidence.
        time - The time at which to set evidence. Can be null.
      • set

        void set​(Node node,
                 Double value,
                 Integer time)
        Sets evidence on a node's single variable at a specified time.
        Parameters:
        node - A node with a single variable to set evidence on.
        value - The value to set, or null to clear the evidence.
        time - The time at which to set evidence. Can be null.
      • set

        void set​(Variable variable,
                 Double[] source,
                 int sourceStart,
                 int startTime,
                 int count)
        Sets temporal evidence on a variable.
        Parameters:
        variable - The variable to set evidence on.
        source - The evidence values.
        sourceStart - The position in [source] to start copying from.
        startTime - The time to start copying at.
        count - The number of values to copy.
      • set

        void set​(Node node,
                 Double[] source,
                 int sourceStart,
                 int startTime,
                 int count)
        Sets temporal evidence on a node with a single variable.
        Parameters:
        node - A node with a single variable to set evidence on.
        source - The evidence values.
        sourceStart - The position in [source] to start copying from.
        startTime - The time to start copying at.
        count - The number of values to copy.
      • set

        void set​(Node node,
                 Double value)
        Sets a node's variable to a particular value (hard evidence).
        Parameters:
        node - A node with a single variable to set evidence on.
        value - The value to set, or null to clear the evidence.
      • getStates

        void getStates​(Variable variable,
                       double[] buffer)
        Fills out a buffer containing the soft evidence for a particular variable. If the variable does not have soft evidence, the method will succeed, however it is better to use another version of Get. The resulting values will depend on the current EvidenceType for the variable:EvidenceType.NONE - All values will equal 1.EvidenceType.HARD - All values will equal 0, except at the hard evidence state, where the value will equal 1.EvidenceType.NONE - The soft evidence values will be used.
        Parameters:
        variable - The variable to retrieve evidence for.
        buffer - A buffer whose values are replaced with the current evidence.
      • getStates

        void getStates​(Node node,
                       double[] buffer)
        Fills out a buffer containing the soft evidence for a node with a single variable. If the variable does not have soft evidence, the method will succeed, however it is better to use another version of Get. The resulting values will depend on the current EvidenceType for the variable:EvidenceType.NONE - All values will equal 1.EvidenceType.HARD - All values will equal 0, except at the hard evidence state, where the value will equal 1.EvidenceType.NONE - The soft evidence values will be used.
        Parameters:
        node - A node with a single variable to retrieve evidence for.
        buffer - A buffer whose values are replaced with the current evidence.
      • getStates

        void getStates​(Variable variable,
                       double[] buffer,
                       Integer time)
        Fills out a buffer containing the soft evidence for a particular variable at a specified time. If the variable does not have soft evidence, the method will succeed, however it is better to use another version of Get. The resulting values will depend on the current EvidenceType for the variable:EvidenceType.NONE - All values will equal 1.EvidenceType.HARD - All values will equal 0, except at the hard evidence state, where the value will equal 1.EvidenceType.NONE - The soft evidence values will be used.
        Parameters:
        variable - The variable to retrieve evidence for.
        buffer - A buffer whose values are replaced with the current evidence.
        time - The time at which to retrieve evidence. Can be null. Used by Dynamic Bayesian networks.
      • getStates

        void getStates​(Node node,
                       double[] buffer,
                       Integer time)
        Fills out a buffer containing the soft evidence for a node with a single variable at a specified time. If the variable does not have soft evidence, the method will succeed, however it is better to use another version of Get. The resulting values will depend on the current EvidenceType for the variable:EvidenceType.NONE - All values will equal 1.EvidenceType.HARD - All values will equal 0, except at the hard evidence state, where the value will equal 1.EvidenceType.NONE - The soft evidence values will be used.
        Parameters:
        node - A node with a single variable to retrieve evidence for.
        buffer - A buffer whose values are replaced with the current evidence.
        time - The time at which to retrieve evidence. Can be null. Used by Dynamic Bayesian networks.
      • getStates

        void getStates​(Table table)
        Fills out a table containing the soft evidence for a particular variable. If the variable does not have soft evidence, the method will succeed, however it is better to use another version of Get. The resulting values will depend on the current EvidenceType for the variable:EvidenceType.NONE - All values will equal 1.EvidenceType.HARD - All values will equal 0, except at the hard evidence state, where the value will equal 1.EvidenceType.NONE - The soft evidence values will be used.
        Parameters:
        table - A Table containing a single Variable.
      • setStates

        void setStates​(Variable variable,
                       double[] values)
        Sets soft evidence for a particular discrete variable. If the evidence [values] are not actual soft evidence (e.g. {1, 0, 0} or {1, 1, 1} then the evidence will be stored correctly but the EvidenceType will not be EvidenceType.SOFT.
        Parameters:
        variable - The variable to set evidence on.
        values - An array of soft evidence values.
      • setStates

        void setStates​(Node node,
                       double[] values)
        Sets soft evidence for a discrete node with a single variable. If the evidence [values] are not actual soft evidence (e.g. {1, 0, 0} or {1, 1, 1} then the evidence will be stored correctly but the EvidenceType will not be EvidenceType.SOFT.
        Parameters:
        node - The node with a single variable to set evidence on.
        values - An array of soft evidence values.
      • setStates

        void setStates​(Variable variable,
                       double[] values,
                       Integer time)
        Sets soft evidence for a particular discrete variable at a specified time. If the evidence [values] are not actual soft evidence (e.g. {1, 0, 0} or {1, 1, 1} then the evidence will be stored correctly but the EvidenceType will not be EvidenceType.SOFT.
        Parameters:
        variable - The variable to set evidence on.
        values - An array of soft evidence values.
        time - The time at which to set evidence. Can be null. Used by Dynamic Bayesian networks.
      • setStates

        void setStates​(Node node,
                       double[] values,
                       Integer time)
        Sets soft evidence for a discrete node with a single variable, at a specified time. If the evidence [values] are not actual soft evidence (e.g. {1, 0, 0} or {1, 1, 1} then the evidence will be stored correctly but the EvidenceType will not be EvidenceType.SOFT.
        Parameters:
        node - The node with a single variable to set evidence on.
        values - An array of soft evidence values.
        time - The time at which to set evidence. Can be null. Used by Dynamic Bayesian networks.