Class Variable<T>
A typed variable in a model.
Inherited Members
Variable.Constrain<T1, T2, T3, T4>(Action<T1, T2, T3, T4>, Variable<T1>, Variable<T2>, Variable<T3>, Variable<T4>)
Assembly: Microsoft.ML.Probabilistic.Compiler.dll
Syntax
public class Variable<T> : Variable, IVariable, CanGetContainers, IModelExpression<T>, IModelExpression, SettableTo<Variable<T>>, ICloneable, HasObservedValue
Type Parameters
Name |
Description |
T |
The domain of the variable.
|
Constructors
Variable(Variable<T>)
Declaration
protected Variable(Variable<T> that)
Parameters
Fields
declaration
Cache of GetDeclaration. Stores the name and type of the variable.
Declaration
protected object declaration
Field Value
isReadOnly
Declaration
protected bool isReadOnly
Field Value
observedValue
Declaration
protected T observedValue
Field Value
Properties
IsReadOnly
Declaration
public override bool IsReadOnly { get; set; }
Property Value
Overrides
Name
Declaration
public override string Name { get; set; }
Property Value
Overrides
ObservedValue
Declaration
public T ObservedValue { get; set; }
Property Value
Methods
Array(Range)
Create a 1D random variable array with a specified size.
Declaration
public static VariableArray<T> Array(Range r)
Parameters
Type |
Name |
Description |
Range |
r |
A Range object that specifies the array length.
|
Returns
Type |
Description |
VariableArray<T> |
Returns a VariableArray object whose size is specified by r .
|
Attrib(ICompilerAttribute)
Inline method for adding an attribute to a variable. This method
returns the variable object, so that is can be used in an inline expression.
e.g. Variable.GaussianFromMeanAndVariance(0,1).Attrib(new MyAttribute());
Declaration
public Variable<T> Attrib(ICompilerAttribute attr)
Parameters
Returns
Type |
Description |
Variable<T> |
The variable object
|
Attrib(QueryType)
Helper to add a query type attribute to this variable.
Declaration
public Variable<T> Attrib(QueryType queryType)
Parameters
Type |
Name |
Description |
QueryType |
queryType |
The query type to use to create the attribute
|
Returns
ClearObservedValue()
Clear the observed value.
Declaration
public void ClearObservedValue()
Clone()
Declaration
public virtual object Clone()
Returns
Factor(Func<T>)
Creates a random variable from a factor method with no arguments.
Declaration
public static Variable<T> Factor(Func<T> factorDelegate)
Parameters
Type |
Name |
Description |
Func<T> |
factorDelegate |
The method that represents the factor
|
Returns
Factor<T1>(Func<T1, T>, T1)
Creates a random variable from a factor method with one argument.
Declaration
public static Variable<T> Factor<T1>(Func<T1, T> factorDelegate, T1 arg1)
Parameters
Type |
Name |
Description |
Func<T1, T> |
factorDelegate |
The method that represents the factor
|
T1 |
arg1 |
|
Returns
Type Parameters
Factor<T1>(Func<T1, T>, Variable<T1>)
Creates a random variable from a factor method with one argument.
Declaration
public static Variable<T> Factor<T1>(Func<T1, T> factorDelegate, Variable<T1> arg1)
Parameters
Type |
Name |
Description |
Func<T1, T> |
factorDelegate |
The method that represents the factor
|
Variable<T1> |
arg1 |
|
Returns
Type Parameters
Factor<T1, T2>(FuncOut<T1, T2, T>, Variable<T1>, Variable<T2>)
Creates a random variable from a factor method with two arguments.
Declaration
public static Variable<T> Factor<T1, T2>(FuncOut<T1, T2, T> factorDelegate, Variable<T1> arg1, Variable<T2> arg2)
Parameters
Type |
Name |
Description |
FuncOut<T1, T2, T> |
factorDelegate |
The method that represents the factor
|
Variable<T1> |
arg1 |
|
Variable<T2> |
arg2 |
|
Returns
Type Parameters
Factor<T1, T2>(Func<T1, T2, T>, T1, T2)
Creates a random variable from a factor method with two arguments.
Declaration
public static Variable<T> Factor<T1, T2>(Func<T1, T2, T> factorDelegate, T1 arg1, T2 arg2)
Parameters
Type |
Name |
Description |
Func<T1, T2, T> |
factorDelegate |
The method that represents the factor
|
T1 |
arg1 |
Variable first argument
|
T2 |
arg2 |
Variable second argument
|
Returns
Type Parameters
Factor<T1, T2>(Func<T1, T2, T>, T1, Variable<T2>)
Creates a random variable from a factor method with two arguments.
Declaration
public static Variable<T> Factor<T1, T2>(Func<T1, T2, T> factorDelegate, T1 arg1, Variable<T2> arg2)
Parameters
Type |
Name |
Description |
Func<T1, T2, T> |
factorDelegate |
The method that represents the factor
|
T1 |
arg1 |
Fixed first argument
|
Variable<T2> |
arg2 |
Variable second argument
|
Returns
Type Parameters
Factor<T1, T2>(Func<T1, T2, T>, Variable<T1>, T2)
Creates a random variable from a factor method with two arguments.
Declaration
public static Variable<T> Factor<T1, T2>(Func<T1, T2, T> factorDelegate, Variable<T1> arg1, T2 arg2)
Parameters
Type |
Name |
Description |
Func<T1, T2, T> |
factorDelegate |
The method that represents the factor
|
Variable<T1> |
arg1 |
Variable first argument
|
T2 |
arg2 |
Fixed second argument
|
Returns
Type Parameters
Factor<T1, T2>(Func<T1, T2, T>, Variable<T1>, Variable<T2>)
Creates a random variable from a factor method with two arguments.
Declaration
public static Variable<T> Factor<T1, T2>(Func<T1, T2, T> factorDelegate, Variable<T1> arg1, Variable<T2> arg2)
Parameters
Type |
Name |
Description |
Func<T1, T2, T> |
factorDelegate |
The method that represents the factor
|
Variable<T1> |
arg1 |
|
Variable<T2> |
arg2 |
|
Returns
Type Parameters
Factor<T1, T2, T3>(Func<T1, T2, T3, T>, T1, T2, T3)
Creates a random variable from a factor method with three arguments.
Declaration
public static Variable<T> Factor<T1, T2, T3>(Func<T1, T2, T3, T> factorDelegate, T1 arg1, T2 arg2, T3 arg3)
Parameters
Type |
Name |
Description |
Func<T1, T2, T3, T> |
factorDelegate |
The method that represents the factor
|
T1 |
arg1 |
Variable first argument
|
T2 |
arg2 |
Fixed second argument
|
T3 |
arg3 |
Fixed third argument
|
Returns
Type Parameters
Name |
Description |
T1 |
|
T2 |
|
T3 |
|
Factor<T1, T2, T3>(Func<T1, T2, T3, T>, T1, T2, Variable<T3>)
Creates a random variable from a factor method with three arguments.
Declaration
public static Variable<T> Factor<T1, T2, T3>(Func<T1, T2, T3, T> factorDelegate, T1 arg1, T2 arg2, Variable<T3> arg3)
Parameters
Type |
Name |
Description |
Func<T1, T2, T3, T> |
factorDelegate |
The method that represents the factor
|
T1 |
arg1 |
Fixed first argument
|
T2 |
arg2 |
Fixed second argument
|
Variable<T3> |
arg3 |
Variable third argument
|
Returns
Type Parameters
Name |
Description |
T1 |
|
T2 |
|
T3 |
|
Factor<T1, T2, T3>(Func<T1, T2, T3, T>, T1, Variable<T2>, T3)
Creates a random variable from a factor method with three arguments.
Declaration
public static Variable<T> Factor<T1, T2, T3>(Func<T1, T2, T3, T> factorDelegate, T1 arg1, Variable<T2> arg2, T3 arg3)
Parameters
Type |
Name |
Description |
Func<T1, T2, T3, T> |
factorDelegate |
The method that represents the factor
|
T1 |
arg1 |
Fixed first argument
|
Variable<T2> |
arg2 |
Variable second argument
|
T3 |
arg3 |
Fixed third argument
|
Returns
Type Parameters
Name |
Description |
T1 |
|
T2 |
|
T3 |
|
Factor<T1, T2, T3>(Func<T1, T2, T3, T>, T1, Variable<T2>, Variable<T3>)
Creates a random variable from a factor method with three arguments.
Declaration
public static Variable<T> Factor<T1, T2, T3>(Func<T1, T2, T3, T> factorDelegate, T1 arg1, Variable<T2> arg2, Variable<T3> arg3)
Parameters
Type |
Name |
Description |
Func<T1, T2, T3, T> |
factorDelegate |
The method that represents the factor
|
T1 |
arg1 |
Fixed first argument
|
Variable<T2> |
arg2 |
Variable second argument
|
Variable<T3> |
arg3 |
Variable third argument
|
Returns
Type Parameters
Name |
Description |
T1 |
|
T2 |
|
T3 |
|
Factor<T1, T2, T3>(Func<T1, T2, T3, T>, Variable<T1>, T2, T3)
Creates a random variable from a factor method with three arguments.
Declaration
public static Variable<T> Factor<T1, T2, T3>(Func<T1, T2, T3, T> factorDelegate, Variable<T1> arg1, T2 arg2, T3 arg3)
Parameters
Type |
Name |
Description |
Func<T1, T2, T3, T> |
factorDelegate |
The method that represents the factor
|
Variable<T1> |
arg1 |
Variable first argument
|
T2 |
arg2 |
Fixed second argument
|
T3 |
arg3 |
Fixed third argument
|
Returns
Type Parameters
Name |
Description |
T1 |
|
T2 |
|
T3 |
|
Factor<T1, T2, T3>(Func<T1, T2, T3, T>, Variable<T1>, T2, Variable<T3>)
Creates a random variable from a factor method with three arguments.
Declaration
public static Variable<T> Factor<T1, T2, T3>(Func<T1, T2, T3, T> factorDelegate, Variable<T1> arg1, T2 arg2, Variable<T3> arg3)
Parameters
Type |
Name |
Description |
Func<T1, T2, T3, T> |
factorDelegate |
The method that represents the factor
|
Variable<T1> |
arg1 |
Variable first argument
|
T2 |
arg2 |
Fixed second argument
|
Variable<T3> |
arg3 |
Variable third argument
|
Returns
Type Parameters
Name |
Description |
T1 |
|
T2 |
|
T3 |
|
Factor<T1, T2, T3>(Func<T1, T2, T3, T>, Variable<T1>, Variable<T2>, T3)
Creates a random variable from a factor method with three arguments.
Declaration
public static Variable<T> Factor<T1, T2, T3>(Func<T1, T2, T3, T> factorDelegate, Variable<T1> arg1, Variable<T2> arg2, T3 arg3)
Parameters
Type |
Name |
Description |
Func<T1, T2, T3, T> |
factorDelegate |
The method that represents the factor
|
Variable<T1> |
arg1 |
Variable first argument
|
Variable<T2> |
arg2 |
Variable second argument
|
T3 |
arg3 |
Fixed third argument
|
Returns
Type Parameters
Name |
Description |
T1 |
|
T2 |
|
T3 |
|
Factor<T1, T2, T3>(Func<T1, T2, T3, T>, Variable<T1>, Variable<T2>, Variable<T3>)
Creates a random variable from a factor method with three arguments.
Declaration
public static Variable<T> Factor<T1, T2, T3>(Func<T1, T2, T3, T> factorDelegate, Variable<T1> arg1, Variable<T2> arg2, Variable<T3> arg3)
Parameters
Type |
Name |
Description |
Func<T1, T2, T3, T> |
factorDelegate |
The method that represents the factor
|
Variable<T1> |
arg1 |
Variable first argument
|
Variable<T2> |
arg2 |
Variable second argument
|
Variable<T3> |
arg3 |
Variable third argument
|
Returns
Type Parameters
Name |
Description |
T1 |
|
T2 |
|
T3 |
|
Factor<T1, T2, T3, T4>(Func<T1, T2, T3, T4, T>, Variable<T1>, Variable<T2>, Variable<T3>, Variable<T4>)
Creates a random variable from a factor method with four arguments.
Declaration
public static Variable<T> Factor<T1, T2, T3, T4>(Func<T1, T2, T3, T4, T> factorDelegate, Variable<T1> arg1, Variable<T2> arg2, Variable<T3> arg3, Variable<T4> arg4)
Parameters
Type |
Name |
Description |
Func<T1, T2, T3, T4, T> |
factorDelegate |
Factor delegate
|
Variable<T1> |
arg1 |
Variable first argument
|
Variable<T2> |
arg2 |
Variable second argument
|
Variable<T3> |
arg3 |
Variable third argument
|
Variable<T4> |
arg4 |
Variable fourth argument
|
Returns
Type Parameters
Name |
Description |
T1 |
|
T2 |
|
T3 |
|
T4 |
|
FactorUntyped(MethodInfo, Variable[])
Creates a random variable from a factor
Declaration
public static Variable<T> FactorUntyped(MethodInfo methodInfo, params Variable[] args)
Parameters
Returns
ForEach(Range)
Create multiple variables with the same definition.
Declaration
public Variable<T> ForEach(Range range)
Parameters
Type |
Name |
Description |
Range |
range |
The desired range.
|
Returns
Type |
Description |
Variable<T> |
this , modified to range over the newly created items.
|
ForEach(Range[])
Create multiple variables with the same definition.
Declaration
public Variable<T> ForEach(params Range[] ranges)
Parameters
Type |
Name |
Description |
Range[] |
ranges |
The desired ranges.
|
Returns
Type |
Description |
Variable<T> |
this , modified to range over the newly created items.
|
GreaterThan(Variable<T>, Variable<T>)
Declaration
protected static Variable<bool> GreaterThan(Variable<T> a, Variable<T> b)
Parameters
Returns
GreaterThanOrEqual(Variable<T>, Variable<T>)
Declaration
protected static Variable<bool> GreaterThanOrEqual(Variable<T> a, Variable<T> b)
Parameters
Returns
InitialiseBackwardTo<TDist>(TDist)
Provide a backward distribution to initialize inference.
Declaration
public Variable<T> InitialiseBackwardTo<TDist>(TDist initialBackward)
where TDist : IDistribution<T>
Parameters
Type |
Name |
Description |
TDist |
initialBackward |
|
Returns
Type Parameters
InitialiseBackwardTo<TDist>(IModelExpression<TDist>)
Set the initialiseBackwardTo field if it is valid to do so
Declaration
protected Variable<T> InitialiseBackwardTo<TDist>(IModelExpression<TDist> initialBackward)
where TDist : IDistribution<T>
Parameters
Returns
Type Parameters
InitialiseBackwardTo<TDist>(Variable<TDist>)
Provide a backward distribution to initialize inference.
Declaration
public Variable<T> InitialiseBackwardTo<TDist>(Variable<TDist> initialBackward)
where TDist : IDistribution<T>
Parameters
Type |
Name |
Description |
Variable<TDist> |
initialBackward |
|
Returns
Type Parameters
InitialiseTo<TDist>(TDist)
Provide a marginal distribution to initialize inference.
Declaration
public Variable<T> InitialiseTo<TDist>(TDist initialMarginal)
where TDist : IDistribution<T>
Parameters
Type |
Name |
Description |
TDist |
initialMarginal |
|
Returns
Type Parameters
InitialiseTo<TDist>(IModelExpression<TDist>)
Set the initialiseTo field if it is valid to do so
Declaration
protected Variable<T> InitialiseTo<TDist>(IModelExpression<TDist> initialMarginal)
where TDist : IDistribution<T>
Parameters
Returns
Type Parameters
InitialiseTo<TDist>(Variable<TDist>)
Provide a marginal distribution to initialize inference.
Declaration
public Variable<T> InitialiseTo<TDist>(Variable<TDist> initialMarginal)
where TDist : IDistribution<T>
Parameters
Type |
Name |
Description |
Variable<TDist> |
initialMarginal |
|
Returns
Type Parameters
Named(String)
Set the name of the variable.
Declaration
public Variable<T> Named(string name)
Parameters
Type |
Name |
Description |
String |
name |
|
Returns
OperatorUntyped(Variable.Operator, MethodInfo, Variable[])
Creates a random variable from an operator
Declaration
public static Variable<T> OperatorUntyped(Variable.Operator op, MethodInfo methodInfo, params Variable[] args)
Parameters
Returns
Random<TDist>(Variable<TDist>)
Creates a random variable with the specified prior distribution
Declaration
public static Variable<T> Random<TDist>(Variable<TDist> dist)
where TDist : IDistribution<T>
Parameters
Type |
Name |
Description |
Variable<TDist> |
dist |
The distribution to use
|
Returns
Type Parameters
Name |
Description |
TDist |
The type of the distribution
|
SetMarginalPrototype<TDist>(IModelExpression<TDist>)
Add a MarginalPrototype attribute
Declaration
public void SetMarginalPrototype<TDist>(IModelExpression<TDist> prototype)
where TDist : IDistribution<T>
Parameters
Type |
Name |
Description |
IModelExpression<TDist> |
prototype |
An expression for the marginal prototype
|
Type Parameters
Name |
Description |
TDist |
A distribution type
|
SetTo(Variable<T>)
Sets the value of a random variable. Should only be invoked on variables created using New() which
do not yet have a value.
Declaration
public void SetTo(Variable<T> variable)
Parameters
Type |
Name |
Description |
Variable<T> |
variable |
A variable whose definition will be consumed by this and no longer available for use
|
Operators
Addition(Variable<T>, T)
Operator overload for addition
Declaration
public static Variable<T> operator +(Variable<T> a, T b)
Parameters
Returns
Addition(Variable<T>, Variable<T>)
Operator overload for addition
Declaration
public static Variable<T> operator +(Variable<T> a, Variable<T> b)
Parameters
Returns
Addition(Variable<T>, Variable<Char>)
Declaration
public static Variable<T> operator +(Variable<T> a, Variable<char> b)
Parameters
Returns
Addition(Variable<T>, Char)
Declaration
public static Variable<T> operator +(Variable<T> a, char b)
Parameters
Returns
Addition(Variable<Char>, Variable<T>)
Declaration
public static Variable<T> operator +(Variable<char> a, Variable<T> b)
Parameters
Returns
Addition(Char, Variable<T>)
Declaration
public static Variable<T> operator +(char a, Variable<T> b)
Parameters
Returns
BitwiseAnd(Variable<T>, Variable<T>)
Operator overload for AND
Declaration
public static Variable<T> operator &(Variable<T> a, Variable<T> b)
Parameters
Returns
BitwiseOr(Variable<T>, Variable<T>)
Declaration
public static Variable<T> operator |(Variable<T> a, Variable<T> b)
Parameters
Returns
Division(T, Variable<T>)
Operator overload for division
Declaration
public static Variable<T> operator /(T a, Variable<T> b)
Parameters
Returns
Division(Variable<T>, T)
Operator overload for division
Declaration
public static Variable<T> operator /(Variable<T> a, T b)
Parameters
Returns
Division(Variable<T>, Variable<T>)
Operator overload for division
Declaration
public static Variable<T> operator /(Variable<T> a, Variable<T> b)
Parameters
Returns
Equality(Variable<T>, T)
Returns a new variable that is true when a variable equals a given value.
Declaration
public static Variable<bool> operator ==(Variable<T> a, T b)
Parameters
Type |
Name |
Description |
Variable<T> |
a |
A variable
|
T |
b |
A value
|
Returns
Type |
Description |
Variable<Boolean> |
A new variable that is true when a equals b.
|
Equality(Variable<T>, Variable<T>)
Returns a new variable that is true when two variables are equal.
Declaration
public static Variable<bool> operator ==(Variable<T> a, Variable<T> b)
Parameters
Returns
Type |
Description |
Variable<Boolean> |
A new variable that is true when a and b are equal.
|
ExclusiveOr(Variable<T>, Variable<T>)
Operator overload for XOR
Declaration
public static Variable<T> operator ^(Variable<T> a, Variable<T> b)
Parameters
Returns
GreaterThan(Variable<T>, T)
Operator overload for greater than
Declaration
public static Variable<bool> operator>(Variable<T> a, T b)
Parameters
Returns
GreaterThan(Variable<T>, Variable<T>)
Operator overload for greater than
Declaration
public static Variable<bool> operator>(Variable<T> a, Variable<T> b)
Parameters
Returns
GreaterThanOrEqual(Variable<T>, T)
Operator overload for greater than or equal
Declaration
public static Variable<bool> operator >=(Variable<T> a, T b)
Parameters
Returns
GreaterThanOrEqual(Variable<T>, Variable<T>)
Operator overload for greater than or equal
Declaration
public static Variable<bool> operator >=(Variable<T> a, Variable<T> b)
Parameters
Returns
Implicit(T to Variable<T>)
Provides implicit conversion from .NET instances to constant Infer.NET variables.
Declaration
public static implicit operator Variable<T>(T value)
Parameters
Type |
Name |
Description |
T |
value |
|
Returns
Inequality(Variable<T>, T)
Returns a new variable that is true when a variable does not equal a given value.
Declaration
public static Variable<bool> operator !=(Variable<T> a, T b)
Parameters
Type |
Name |
Description |
Variable<T> |
a |
A variable
|
T |
b |
A value
|
Returns
Type |
Description |
Variable<Boolean> |
A new variable that is true when a does not equal b.
|
Inequality(Variable<T>, Variable<T>)
Returns a new variable that is true when two variables are not equal.
Declaration
public static Variable<bool> operator !=(Variable<T> a, Variable<T> b)
Parameters
Returns
Type |
Description |
Variable<Boolean> |
A new variable that is true when a and b are not equal.
|
LessThan(Variable<T>, T)
Operator overload for less than
Declaration
public static Variable<bool> operator <(Variable<T> a, T b)
Parameters
Returns
LessThan(Variable<T>, Variable<T>)
Operator overload for less than
Declaration
public static Variable<bool> operator <(Variable<T> a, Variable<T> b)
Parameters
Returns
LessThanOrEqual(Variable<T>, T)
Operator overload for less than or equal
Declaration
public static Variable<bool> operator <=(Variable<T> a, T b)
Parameters
Returns
LessThanOrEqual(Variable<T>, Variable<T>)
Operator overload for less than or equal
Declaration
public static Variable<bool> operator <=(Variable<T> a, Variable<T> b)
Parameters
Returns
LogicalNot(Variable<T>)
Operator overload for NOT
Declaration
public static Variable<T> operator !(Variable<T> a)
Parameters
Returns
Modulus(Variable<T>, T)
Operator overload for modulus
Declaration
public static Variable<T> operator %(Variable<T> a, T b)
Parameters
Returns
Modulus(Variable<T>, Variable<T>)
Operator overload for modulus
Declaration
public static Variable<T> operator %(Variable<T> a, Variable<T> b)
Parameters
Returns
Multiply(T, Variable<T>)
Operator overload for multiplication
Declaration
public static Variable<T> operator *(T a, Variable<T> b)
Parameters
Returns
Multiply(Variable<T>, T)
Operator overload for multiplication
Declaration
public static Variable<T> operator *(Variable<T> a, T b)
Parameters
Returns
Multiply(Variable<T>, Variable<T>)
Operator overload for multiplication
Declaration
public static Variable<T> operator *(Variable<T> a, Variable<T> b)
Parameters
Returns
OnesComplement(Variable<T>)
Operator overload for NOT
Declaration
public static Variable<T> operator ~(Variable<T> a)
Parameters
Returns
Subtraction(T, Variable<T>)
Operator overload for subtraction
Declaration
public static Variable<T> operator -(T a, Variable<T> b)
Parameters
Returns
Subtraction(Variable<T>, T)
Operator overload for subtraction
Declaration
public static Variable<T> operator -(Variable<T> a, T b)
Parameters
Returns
Subtraction(Variable<T>, Variable<T>)
Operator overload for subtraction
Declaration
public static Variable<T> operator -(Variable<T> a, Variable<T> b)
Parameters
Returns
UnaryNegation(Variable<T>)
Operator overload for unary negation
Declaration
public static Variable<T> operator -(Variable<T> a)
Parameters
Returns
Explicit Interface Implementations
HasObservedValue.ObservedValue
Declaration
object HasObservedValue.ObservedValue { get; set; }
Returns
IModelExpression.Name
Declaration
string IModelExpression.Name { get; }
Returns
Implements