mxfusion.inference.grad_based_inference

Members

class mxfusion.inference.grad_based_inference.GradBasedInference(inference_algorithm, grad_loop=None, constants=None, hybridize=False, dtype=None, context=None)

Bases: mxfusion.inference.inference.Inference

The abstract class for gradient-based inference methods. An inference method consists of a few components: the applied inference algorithm, the model definition (optionally a definition of posterior approximation), the inference parameters.

Parameters:
  • inference_algorithm (InferenceAlgorithm) – The applied inference algorithm
  • graphs ([FactorGraph]) – a list of graph definitions required by the inference method. It includes the model definition and necessary posterior approximation.
  • observed ([Variable]) – A list of observed variables
  • grad_loop (GradLoop) – The reference to the main loop of gradient optmization
  • constants ({Variable: mxnet.ndarray}) – Specify a list of model variables as constants
  • hybridize (boolean) – Whether to hybridize the MXNet Gluon block of the inference method.
  • dtype ({numpy.float64, numpy.float32, 'float64', 'float32'}) – data type for internal numberical representation
  • context ({mxnet.cpu or mxnet.gpu}) – The MXNet context
create_executor()

Return a MXNet Gluon block responsible for the execution of the inference method.

run(optimizer='adam', learning_rate=0.001, max_iter=2000, verbose=False, **kw)

Run the inference method.

Parameters:
  • optimizer (str) – the choice of optimizer (default: ‘adam’)
  • learning_rate (float) – the learning rate of the gradient optimizer (default: 0.001)
  • max_iter (int) – the maximum number of iterations of gradient optimization
  • verbose (boolean) – whether to print per-iteration messages.
  • **kwargs – The keyword arguments specify the data for inferences. The key of each argument is the name of the corresponding variable in model definition and the value of the argument is the data in numpy array format.