mxfusion.inference.inference_alg

Members

class mxfusion.inference.inference_alg.ObjectiveBlock(infr_method, constants, data_def, var_trans, var_ties, excluded, prefix='', params=None)

Bases: mxnet.gluon.block.HybridBlock

Wrapping the MXNet codes with a MXNet Gluon HybridBlock for execution.

Parameters:
  • infr_method (a pointer to a function) – the pointer to a function that contains the actual MXNet codes.
  • constants ({Variable UUID: int or float or mxnet.ndarray}) – the variables with constant values
  • data_def ([UUID]) – a list of variable UUID, which corresponds to the order of variables expected as the positional arguments in “hybrid_forward”.
  • var_trans – the transformations applied variables
  • var_ties ({ UUID of source variable: UUID of target variable}) – A dictionary of variables that are tied and use the MXNet Parameter of the dict value uuid.
  • excluded (set(UUID) or [UUID]) – a set of variables excluded from being set as Block parameters.
  • prefix (str) – the prefix of this Gluon block
  • params (mxnet.gluon.ParameterDict) – the ParameterDict of this Gluon block
hybrid_forward(F, x, *args, **kw)

Overrides to construct symbolic graph for this Block.

Parameters:
  • x (Symbol or NDArray) – The first input tensor.
  • *args (list of Symbol or list of NDArray) – Additional input tensors.
class mxfusion.inference.inference_alg.InferenceAlgorithm(model, observed, extra_graphs=None)

Bases: abc.ABC

The abstract class for an inference algorithm. A concrete inference algorithm will inherit this class and overload the “compute” function with the actual computation logic.

Parameters:
  • model (Model) – the definition of the probabilistic model
  • observed ([Variable]) – A list of observed variables
  • extra_graphs ([FactorGraph]) – a list of extra FactorGraph used in the inference algorithm.
observed_variables
observed_variable_UUIDs
observed_variable_names
model

return the model definition.

graphs
create_executor(data_def, params, var_ties, rv_scaling=None)

Create a MXNet Gluon block to carry out the computation.

Parameters:
  • data_def ([UUID of Variable (str)]) – a list of unique ID of data variables. The order of variables in the list corresponds to the order of variable in the positional arguments when calling the Gluon Block.
  • params (InferenceParameters) – The parameters of model involved in inference.
  • var_ties ({ UUID of source variable: UUID of target variable}) – A dictionary of variables that are tied and use the MXNet Parameter of the dict value uuid.
  • rv_scaling ({UUID: scaling factor}) – the scaling factor of random variables
Returns:

the Gluon block computing the outcome of inference

Return type:

mxnet.gluon.HybridBlock

compute(F, data, parameters, constants)

The abstract method for the computation of the inference algorithm

Parameters:
  • F (Python module) – the execution context (mxnet.ndarray or mxnet.symbol)
  • data ({Variable: mxnet.ndarray.ndarray.NDArray or mxnet.symbol.symbol.Symbol}) – the data variables for inference
  • parameters ({Variable: mxnet.ndarray.ndarray.NDArray or mxnet.symbol.symbol.Symbol}) – the parameters for inference
  • constants – the constants for inference
Returns:

the outcome of the inference algorithm

Return type:

mxnet.ndarray.ndarray.NDArray or mxnet.symbol.symbol.Symbol