Search Results for

    Show / Hide Table of Contents

    Class Variable

    Represents a discrete or continuous random variable.

    Inheritance
    System.Object
    Variable
    Implements
    System.ComponentModel.INotifyPropertyChanged
    System.IComparable<Variable>
    Inherited Members
    System.Object.Equals(System.Object)
    System.Object.Equals(System.Object, System.Object)
    System.Object.GetHashCode()
    System.Object.GetType()
    System.Object.MemberwiseClone()
    System.Object.ReferenceEquals(System.Object, System.Object)
    Namespace: BayesServer
    Assembly: BayesServer.dll
    Syntax
    public sealed class Variable : INotifyPropertyChanged, IComparable<Variable>
    Remarks

    Note that variable names must be unique per network, and are case sensitive.

    A Node in a Bayesian network can contain one or more variables.

    Although a discrete variable can contain a different number of states, a continuous variable always contains a single state.

    Constructors

    Variable()

    Initializes a new instance of the Variable class, with VariableValueType discrete and zero states.

    Declaration
    public Variable()

    Variable(String)

    Initializes a new instance of the Variable class, with VariableValueType discrete, zero states, and the specified name.

    Declaration
    public Variable(string name)
    Parameters
    Type Name Description
    System.String name

    The name of the variable. Can be null.

    Variable(String, State[])

    Initializes a new instance of the Variable class, with VariableValueType discrete and the specified name and adds the states specified in states.

    Declaration
    public Variable(string name, params State[] states)
    Parameters
    Type Name Description
    System.String name

    The name of the node and variable.

    State[] states

    The states to add to the associated Variable.

    Exceptions
    Type Condition
    System.ArgumentNullException

    Raised when states is null.

    System.ArgumentException

    Raised when the names in states are not unique, or are null or empty.

    Variable(String, VariableValueType)

    Initializes a new instance of the Variable class with the specified name and value type. If discrete, no states are added.

    Declaration
    public Variable(string name, VariableValueType valueType)
    Parameters
    Type Name Description
    System.String name

    The name of the variable. Can be null.

    VariableValueType valueType

    The value type, e.g. continuous or discrete.

    Variable(String, VariableValueType, VariableKind)

    Initializes a new instance of the Variable class with the specified name, kind and value type. If discrete, no states are added.

    Declaration
    public Variable(string name, VariableValueType valueType, VariableKind kind)
    Parameters
    Type Name Description
    System.String name

    The name of the variable. Can be null.

    VariableValueType valueType

    The value type, e.g. continuous or discrete.

    VariableKind kind

    The kind of Variable, e.g. Probability, Decision or Utility.

    Variable(String, Int32)

    Initializes a new instance of the Variable class, with VariableValueType discrete and the specified name and adds the number of states specified in states.

    Declaration
    public Variable(string name, int states)
    Parameters
    Type Name Description
    System.String name

    The name to give the Variable, which can be null or empty.

    System.Int32 states

    The number of states to add to the Variable. States will be given default names.

    Exceptions
    Type Condition
    System.ArgumentOutOfRangeException

    Raised when the states parameter is less than zero.

    Variable(String, String[])

    Initializes a new instance of the Variable class, with VariableValueType discrete and the specified name and adds the states specified in states.

    Declaration
    public Variable(string name, string[] states)
    Parameters
    Type Name Description
    System.String name

    The name of the node and variable.

    System.String[] states

    The states to add to the associated Variable, specified by their names.

    Exceptions
    Type Condition
    System.ArgumentNullException

    Raised when states is null.

    System.ArgumentException

    Raised when the names in states are not unique, or are null or empty.

    Properties

    CustomProperties

    Gets custom properties associated with this instance.

    Declaration
    public CustomPropertyCollection CustomProperties { get; }
    Property Value
    Type Description
    CustomPropertyCollection
    Remarks

    Custom properties allow storage of custom information, which will be saved with the network.

    Description

    An optional description for the variable.

    Declaration
    public string Description { get; set; }
    Property Value
    Type Description
    System.String

    ExpressionAlias

    Gets or sets a c-style name for a variable that can be used as an alias in expressions.

    Declaration
    public string ExpressionAlias { get; set; }
    Property Value
    Type Description
    System.String

    Function

    Gets or sets an expression, which is evaluated during a query, and can be based on other queries and expressions.

    Declaration
    public IQueryExpression Function { get; set; }
    Property Value
    Type Description
    IQueryExpression

    Index

    The Index of this instance in the collection of variables belonging to a network, or -1 if the variable does not belong to a node and hence a network.

    Declaration
    public int Index { get; }
    Property Value
    Type Description
    System.Int32

    Kind

    Gets the kind of variable, such as Probability, Decision, Utility or Function.

    Declaration
    public VariableKind Kind { get; }
    Property Value
    Type Description
    VariableKind

    Name

    Gets or sets the name of the variable.

    Declaration
    public string Name { get; set; }
    Property Value
    Type Description
    System.String
    Remarks

    When a variable is added to a network, its name must be unique. Comparisons are case sensitive.

    Node

    Gets the Node this instance belongs to, if any.

    Declaration
    public Node Node { get; }
    Property Value
    Type Description
    Node

    The node the instance belongs to, if any.

    States

    Returns the collection of states belonging to the variable.

    Declaration
    [TypeConverter(typeof(ExpandableObjectConverter))]
    public StateCollection States { get; }
    Property Value
    Type Description
    StateCollection
    Remarks

    Continuous variables always have a single state.

    See Also
    State

    StateValueType

    Gets or sets the type of value that states belonging to this variable can represent. For example an interval.

    Declaration
    public StateValueType StateValueType { get; set; }
    Property Value
    Type Description
    StateValueType

    ValueType

    Gets the variable's value type, e.g. continuous or discrete.

    Declaration
    public VariableValueType ValueType { get; }
    Property Value
    Type Description
    VariableValueType

    The variable's value type.

    Methods

    CompareTo(Variable)

    Declaration
    public int CompareTo(Variable other)
    Parameters
    Type Name Description
    Variable other
    Returns
    Type Description
    System.Int32

    Copy()

    Copies this instance.

    Declaration
    public Variable Copy()
    Returns
    Type Description
    Variable

    A new Variable instance.

    FindStateByValue(Object)

    Finds a state based on a state value. E.g. finds the state who's interval contains the supplied value, or who's integer state value matches the supplied integer.

    Declaration
    public State FindStateByValue(object value)
    Parameters
    Type Name Description
    System.Object value

    The value to test against state values. Type will depend on StateValueType. e.g. pass a double if the state value type is a double interval.

    Returns
    Type Description
    State

    The matching state or null.

    ToString()

    Returns the name of the variable, or an empty string if the name is null.

    Declaration
    public override string ToString()
    Returns
    Type Description
    System.String

    A System.String containing the name of the variable which is empty if the name is null.

    Overrides
    System.Object.ToString()

    Events

    PropertyChanged

    Declaration
    public event PropertyChangedEventHandler PropertyChanged
    Event Type
    Type Description
    System.ComponentModel.PropertyChangedEventHandler

    Implements

    System.ComponentModel.INotifyPropertyChanged
    System.IComparable<T>
    In This Article
    Back to top Copyright Bayes Server Ltd. All rights Reserved.