Class InferenceEngine
An inference engine, used to perform inference tasks in Infer.NET.
Implements
Inherited Members
Namespace: Microsoft.ML.Probabilistic.Models
Assembly: Microsoft.ML.Probabilistic.Compiler.dll
Syntax
public class InferenceEngine : SettableTo<InferenceEngine>
Remarks
The Debug class may be used to get debug messages for the inference engine. For example, use
Debug.Listeners.Add(new TextWriterTraceListener(Console.Out));
to get debug information for when compiled models and marginals are re-used.
Constructors
InferenceEngine()
Creates an inference engine which uses the default inference algorithm (currently this is expectation propagation).
Declaration
public InferenceEngine()
InferenceEngine(IAlgorithm)
Creates an inference engine which uses the specified inference algorithm.
Declaration
public InferenceEngine(IAlgorithm algorithm)
Parameters
Type | Name | Description |
---|---|---|
IAlgorithm | algorithm |
Fields
compiler
The Compiler used to compile MSL into a compiled algorithm.
Declaration
protected ModelCompiler compiler
Field Value
Type | Description |
---|---|
ModelCompiler |
DefaultEngine
Default inference engine whose settings will be copied onto newly created engines.
Declaration
public static readonly InferenceEngine DefaultEngine
Field Value
Type | Description |
---|---|
InferenceEngine |
Properties
Algorithm
The default inference algorithm to use. This can be overridden for individual variables or factors using the Algorithm attribute.
Declaration
public IAlgorithm Algorithm { get; set; }
Property Value
Type | Description |
---|---|
IAlgorithm |
Compiler
The model compiler that this inference engine uses.
Declaration
public ModelCompiler Compiler { get; }
Property Value
Type | Description |
---|---|
ModelCompiler |
Groups
List of groups
Declaration
public IList<VariableGroup> Groups { get; }
Property Value
Type | Description |
---|---|
IList<VariableGroup> |
ModelName
Model name, used when naming generated classes.
Declaration
public string ModelName { get; set; }
Property Value
Type | Description |
---|---|
String |
ModelNamespace
Model namespace, used when naming generated classes.
Declaration
public string ModelNamespace { get; set; }
Property Value
Type | Description |
---|---|
String |
Name
The full name of the inference engine, including version
Declaration
public static string Name { get; }
Property Value
Type | Description |
---|---|
String |
NumberOfIterations
The number of iterations to use when executing the compiled inference algorithm.
Declaration
public int NumberOfIterations { get; set; }
Property Value
Type | Description |
---|---|
Int32 |
OptimiseForVariables
The variables to optimize the engine to infer. If set to a list of variables, only the specified variables can be inferred by this engine. If set to null, any variable can be inferred by this engine.
Declaration
public IList<IVariable> OptimiseForVariables { get; set; }
Property Value
Type | Description |
---|---|
IList<IVariable> |
Remarks
Setting this property to a list of variables can improve performance by removing redundent computation and storage needed to infer marginals for variables which are not on the list.
ResetOnObservedValueChanged
If true (default), Infer resets messages to their initial values if an observed value has changed.
Declaration
public bool ResetOnObservedValueChanged { get; set; }
Property Value
Type | Description |
---|---|
Boolean |
SaveFactorGraphToFolder
If not null, the factor graph will be saved (in DGML format) to a file in the specified folder (created if necessary) under the model name and the extension ".dgml"
Declaration
public string SaveFactorGraphToFolder { get; set; }
Property Value
Type | Description |
---|---|
String |
ShowFactorGraph
If true, displays the factor graph for the model, prior to compiling it.
Declaration
public bool ShowFactorGraph { get; set; }
Property Value
Type | Description |
---|---|
Boolean |
ShowMsl
If true, prints the model definition in Model Specification Language (MSL), prior to compiling the model.
Declaration
public bool ShowMsl { get; set; }
Property Value
Type | Description |
---|---|
Boolean |
ShowProgress
If true, prints progress information to the console during inference.
Declaration
public bool ShowProgress { get; set; }
Property Value
Type | Description |
---|---|
Boolean |
ShowSchedule
If true, displays the schedule for the model, after the scheduler has run.
Declaration
public bool ShowSchedule { get; set; }
Property Value
Type | Description |
---|---|
Boolean |
ShowTimings
If true, prints timing information to the console during inference.
Declaration
public bool ShowTimings { get; set; }
Property Value
Type | Description |
---|---|
Boolean |
ShowWarnings
If true, any warnings encountered during model compilation will be printed to the console.
Declaration
public bool ShowWarnings { get; set; }
Property Value
Type | Description |
---|---|
Boolean |
Visualizer
Provides the implementation of ShowFactorGraph, ShowSchedule, and BrowserMode.
Declaration
public static Visualizer Visualizer { get; set; }
Property Value
Type | Description |
---|---|
Visualizer |
Methods
GetBuiltInAlgorithms()
Returns an array of the built-in inference algorithms.
Declaration
public static IAlgorithm[] GetBuiltInAlgorithms()
Returns
Type | Description |
---|---|
IAlgorithm[] |
GetCodeToInfer(IVariable)
Get the abstract syntax tree for the generated code.
Declaration
public List<ITypeDeclaration> GetCodeToInfer(IVariable var)
Parameters
Type | Name | Description |
---|---|---|
IVariable | var |
Returns
Type | Description |
---|---|
List<ITypeDeclaration> | A list of type declaration objects. |
GetCompiledInferenceAlgorithm(IVariable[])
Returns a compiled algorithm which can later be used to infer marginal distributions for the specified variables. This method allows more fine-grained control over the inference procedure.
Declaration
public IGeneratedAlgorithm GetCompiledInferenceAlgorithm(params IVariable[] vars)
Parameters
Type | Name | Description |
---|---|---|
IVariable[] | vars | The variables whose marginals are to be computed by the returned algorithm. |
Returns
Type | Description |
---|---|
IGeneratedAlgorithm | An IGeneratedAlgorithm object |
Remarks
This method should not be used unless fine-grained control over the inference is required. Infer.NET will cache the last compiled algorithm and re-use it if possible.
GetOutputMessage<Distribution>(IVariable)
Computes the output message (message to the prior) for the specified variable.
Declaration
public Distribution GetOutputMessage<Distribution>(IVariable var)
Parameters
Type | Name | Description |
---|---|---|
IVariable | var | The variable whose output message is to be inferred |
Returns
Type | Description |
---|---|
Distribution | The output message (or an approximation to it) |
Type Parameters
Name | Description |
---|---|
Distribution | Desired distribution type |
GetRelevantModelExpressions(IVariable[])
For advanced use. Returns all the model expressions that are relevant to inferring the set of variables provided. This may be useful for constructing visualisations of the model.
Declaration
public IReadOnlyCollection<IModelExpression> GetRelevantModelExpressions(params IVariable[] vars)
Parameters
Type | Name | Description |
---|---|---|
IVariable[] | vars | The variables to build a model for |
Returns
Type | Description |
---|---|
IReadOnlyCollection<IModelExpression> | A collection of model expressions |
Remarks
The returned collection includes Variable and VariableArray objects which the engine has determined are relevant to inferring marginals over the variables provided. This will at least include the provided variables, but may include other relevant variables as well. It will also include MethodInvoke objects which act as priors, constraints or factors in the model.
Group(Variable[])
Add a variable group
Declaration
public VariableGroup Group(params Variable[] variables)
Parameters
Type | Name | Description |
---|---|---|
Variable[] | variables |
Returns
Type | Description |
---|---|
VariableGroup |
Infer(IVariable)
Infers the marginal distribution for the specified variable.
Declaration
public object Infer(IVariable var)
Parameters
Type | Name | Description |
---|---|---|
IVariable | var | The variable whose marginal is to be inferred |
Returns
Type | Description |
---|---|
Object | The marginal distribution (or an approximation to it) |
Infer(IVariable, QueryType)
Performs an inference query for the specified variable, given a query type.
Declaration
public object Infer(IVariable var, QueryType queryType)
Parameters
Type | Name | Description |
---|---|---|
IVariable | var | The variable whose marginal is to be inferred |
QueryType | queryType | The type of query |
Returns
Type | Description |
---|---|
Object | The marginal distribution (or an approximation to it) |
Infer<TReturn>(IVariable)
Infers the marginal distribution for the specified variable.
Declaration
public TReturn Infer<TReturn>(IVariable var)
Parameters
Type | Name | Description |
---|---|---|
IVariable | var | The variable whose marginal is to be inferred |
Returns
Type | Description |
---|---|
TReturn | The marginal distribution (or an approximation to it) |
Type Parameters
Name | Description |
---|---|
TReturn | Desired return type which may be a distribution type or an array type if the argument is a VariableArray |
Infer<TReturn>(IVariable, QueryType)
Infers the marginal distribution for the specified variable, and the specified query type
Declaration
public TReturn Infer<TReturn>(IVariable var, QueryType queryType)
Parameters
Type | Name | Description |
---|---|---|
IVariable | var | The variable whose marginal is to be inferred |
QueryType | queryType | The query type |
Returns
Type | Description |
---|---|
TReturn | The marginal distribution (or an approximation to it) |
Type Parameters
Name | Description |
---|---|
TReturn | Desired return type |
InferAll(Boolean, IVariable)
Declaration
protected IGeneratedAlgorithm InferAll(bool inferOnlySpecifiedVars, IVariable var)
Parameters
Type | Name | Description |
---|---|---|
Boolean | inferOnlySpecifiedVars | |
IVariable | var |
Returns
Type | Description |
---|---|
IGeneratedAlgorithm |
InferAll(Boolean, IEnumerable<IVariable>)
Declaration
protected IGeneratedAlgorithm InferAll(bool inferOnlySpecifiedVars, IEnumerable<IVariable> vars)
Parameters
Type | Name | Description |
---|---|---|
Boolean | inferOnlySpecifiedVars | |
IEnumerable<IVariable> | vars |
Returns
Type | Description |
---|---|
IGeneratedAlgorithm |
Reset()
For message passing algorithms, reset all messages to their initial values.
Declaration
protected void Reset()
SetTo(InferenceEngine)
Configures this inference engine by copying the settings from the supplied inference engine.
Declaration
public void SetTo(InferenceEngine engine)
Parameters
Type | Name | Description |
---|---|---|
InferenceEngine | engine |
ShowFactorManager(Boolean)
Shows the factor manager, indicating which factors are available in Infer.NET and which are supported for each built-in inference algorithm.
Declaration
public static void ShowFactorManager(bool showMissingEvidences)
Parameters
Type | Name | Description |
---|---|---|
Boolean | showMissingEvidences |
ShowFactorManager(Boolean, IAlgorithm[])
Shows the factor manager, indicating which factors are available in Infer.NET and which are supported for the supplied list of inference algorithms.
Declaration
public static void ShowFactorManager(bool showMissingEvidences, params IAlgorithm[] algorithms)
Parameters
Type | Name | Description |
---|---|---|
Boolean | showMissingEvidences | |
IAlgorithm[] | algorithms |
Events
MessageUpdated
Event that is fired when a message that has been marked with ListenToMessages has been updated.
Declaration
public event MessageUpdatedEventHandler MessageUpdated
Event Type
Type | Description |
---|---|
MessageUpdatedEventHandler |
ProgressChanged
Event that is fired when the progress of inference changes, typically at the end of one iteration of the inference algorithm.
Declaration
public event InferenceProgressEventHandler ProgressChanged
Event Type
Type | Description |
---|---|
InferenceProgressEventHandler |