Class SharedVariable<DomainType>
Abstract base class for shared variables. Shared variables allow a model to be split into submodels in which variables are shared. Each submodel can have many copies.
Implements
Inherited Members
Namespace: Microsoft.ML.Probabilistic.Models
Assembly: Microsoft.ML.Probabilistic.Compiler.dll
Syntax
public abstract class SharedVariable<DomainType> : ISharedVariable
Type Parameters
Name | Description |
---|---|
DomainType | Domian type of the variable |
Remarks
A typical use of this is for large data sets where the likelihood parts of the model cannot all fit in memory. The solution is to divide the data into chunks (or 'batches'), and specify a single submodel which includes the likelihood factors and variables for one chunk, along with the shared parameters; the number of copies of the submodel is set to the number of chunks. In a related pattern, there are one or more additional submodels for defining the parameter variables.
Fields
Name
Name of the shared variable.
Declaration
public string Name
Field Value
Type | Description |
---|---|
String |
Properties
IsEvidenceVariable
Marks this shared variable as one that calculates evidence
Declaration
public bool IsEvidenceVariable { get; set; }
Property Value
Type | Description |
---|---|
Boolean |
Methods
GetCopyFor(Model)
Gets a copy of the variable for the specified model.
Declaration
public abstract Variable<DomainType> GetCopyFor(Model model)
Parameters
Type | Name | Description |
---|---|---|
Model | model | Model id. |
Returns
Type | Description |
---|---|
Variable<DomainType> |
GetEvidenceCorrection()
Gets the evidence correction for this shared variable.
Declaration
public abstract double GetEvidenceCorrection()
Returns
Type | Description |
---|---|
Double |
InferOutput(IGeneratedAlgorithm, Model, Int32)
Infer the shared variable's output message for the given model and batch number.
Declaration
public abstract void InferOutput(IGeneratedAlgorithm ca, Model modelNumber, int batchNumber)
Parameters
Type | Name | Description |
---|---|---|
IGeneratedAlgorithm | ca | The compiled algorithm. |
Model | modelNumber | The model id. |
Int32 | batchNumber | The batch number. |
InferOutput(InferenceEngine, Model, Int32)
Infer the shared variable's output message for the given model and batch number.
Declaration
public abstract void InferOutput(InferenceEngine engine, Model modelNumber, int batchNumber)
Parameters
Type | Name | Description |
---|---|---|
InferenceEngine | engine | The inference engine. |
Model | modelNumber | The model id. |
Int32 | batchNumber | The batch number. |
Marginal<T>()
Get the marginal distribution for the shared variable, converted to type T.
Declaration
public abstract T Marginal<T>()
Returns
Type | Description |
---|---|
T |
Type Parameters
Name | Description |
---|---|
T | The desired type |
Named(String)
Inline method for naming a shared variable.
Declaration
public SharedVariable<DomainType> Named(string name)
Parameters
Type | Name | Description |
---|---|---|
String | name | The name |
Returns
Type | Description |
---|---|
SharedVariable<DomainType> | this |
Random<DistributionType>(DistributionType, Boolean)
Creates a shared random variable with the specified prior distribution.
Declaration
public static SharedVariable<DomainType> Random<DistributionType>(DistributionType prior, bool divideMessages = true)
where DistributionType : IDistribution<DomainType>, Sampleable<DomainType>, SettableToProduct<DistributionType>, ICloneable, SettableToUniform, SettableTo<DistributionType>, SettableToRatio<DistributionType>, CanGetLogAverageOf<DistributionType>
Parameters
Type | Name | Description |
---|---|---|
DistributionType | prior | Prior |
Boolean | divideMessages | Use division (the faster default) for calculating messages to batches |
Returns
Type | Description |
---|---|
SharedVariable<DomainType> |
Type Parameters
Name | Description |
---|---|
DistributionType | Distribution type |
Random<DistributionArrayType>(Range, DistributionArrayType, Boolean)
Creates a 1D array of shared random variables of size given by the specified range.
Declaration
public static SharedVariableArray<DomainType> Random<DistributionArrayType>(Range range, DistributionArrayType prior, bool divideMessages = true)
where DistributionArrayType : IDistribution<DomainType[]>, Sampleable<DomainType[]>, SettableToProduct<DistributionArrayType>, ICloneable, SettableToUniform, SettableTo<DistributionArrayType>, SettableToRatio<DistributionArrayType>, CanGetLogAverageOf<DistributionArrayType>
Parameters
Type | Name | Description |
---|---|---|
Range | range | Range. |
DistributionArrayType | prior | A distribution over an array, to use as the prior. |
Boolean | divideMessages | Use division (the faster default) for calculating messages to batches |
Returns
Type | Description |
---|---|
SharedVariableArray<DomainType> |
Type Parameters
Name | Description |
---|---|
DistributionArrayType | The type of the supplied prior |
Random<DistributionArrayType>(VariableArray<DomainType>, Range, DistributionArrayType, Boolean)
Creates a 1D jagged array of shared random variables.
Declaration
public static ISharedVariableArray<VariableArray<DomainType>, DomainType[][]> Random<DistributionArrayType>(VariableArray<DomainType> itemPrototype, Range range, DistributionArrayType prior, bool divideMessages = true)
where DistributionArrayType : IDistribution<DomainType[][]>, Sampleable<DomainType[][]>, SettableToProduct<DistributionArrayType>, ICloneable, SettableToUniform, SettableTo<DistributionArrayType>, SettableToRatio<DistributionArrayType>, CanGetLogAverageOf<DistributionArrayType>
Parameters
Type | Name | Description |
---|---|---|
VariableArray<DomainType> | itemPrototype | A fresh variable object representing an array element. |
Range | range | Outer range. |
DistributionArrayType | prior | Prior for the array. |
Boolean | divideMessages | Use division (the faster default) for calculating messages to batches |
Returns
Type | Description |
---|---|
ISharedVariableArray<VariableArray<DomainType>, DomainType[][]> |
Type Parameters
Name | Description |
---|---|
DistributionArrayType |
Random<ItemType, DistributionArrayType>(ItemType, Range, DistributionArrayType, Boolean)
Creates a generic jagged array of shared random variables.
Declaration
public static ISharedVariableArray<ItemType, DomainType> Random<ItemType, DistributionArrayType>(ItemType itemPrototype, Range range, DistributionArrayType prior, bool divideMessages = true)
where ItemType : Variable, SettableTo<ItemType>, ICloneable where DistributionArrayType : IDistribution<DomainType>, Sampleable<DomainType>, SettableToProduct<DistributionArrayType>, ICloneable, SettableToUniform, SettableTo<DistributionArrayType>, SettableToRatio<DistributionArrayType>, CanGetLogAverageOf<DistributionArrayType>
Parameters
Type | Name | Description |
---|---|---|
ItemType | itemPrototype | A fresh variable object representing an array element. |
Range | range | Outer range |
DistributionArrayType | prior | Prior for the array. |
Boolean | divideMessages | Use division (the faster default) for calculating messages to batches |
Returns
Type | Description |
---|---|
ISharedVariableArray<ItemType, DomainType> |
Type Parameters
Name | Description |
---|---|
ItemType | Item type |
DistributionArrayType | Distribution array type |
SetDefinitionTo(Model, Variable<DomainType>)
Sets the definition of the shared variable.
Declaration
public abstract void SetDefinitionTo(Model model, Variable<DomainType> definition)
Parameters
Type | Name | Description |
---|---|---|
Model | model | Model id. |
Variable<DomainType> | definition | Defining variable. |
Remarks
Use this method if the model is defining the shared variable rather than using one defined in this or another model.
SetInput(Model, Int32)
Sets the shared variable's inbox for a given model and batch.
Declaration
public abstract void SetInput(Model modelNumber, int batchNumber)
Parameters
Type | Name | Description |
---|---|---|
Model | modelNumber | |
Int32 | batchNumber |
ToString()
ToString override.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
String |