mxfusion.components.factor

Factor module.

Members

class mxfusion.components.factor.Factor(inputs, outputs, input_names, output_names)

Bases: mxfusion.components.model_component.ModelComponent

A factor represents a relation among multiple variables in a model such as a distribution, a function or a module. It consists of a list of output variables and optionally a list of input variables.

The inputs and outputs argument of __init__ holds the input and output of the factor, which are represented in Python dict. The key of a variable in the dict is the name of the variable referred in the context of the factor, e.g., the mean and variance of a normal distribution. The value of a variable is the reference to the variable in memory. Both input and output variables are accessible as class attributes.

The inputs and outputs argument of __init__ can be:

  • A list of variables
  • An empty list (no input/output variables)
  • None (the input/output variables are not provided yet.)

Note that the outputs argument should never be an empty list, as a factor always outputs some variables.

Parameters:
  • inputs (List of tuples of name to node e.g. [('random_variable': Variable y)] or None) – the input variables of the factor.
  • outputs (List of tuples of name to node e.g. [('random_variable': Variable y)] or None) – the output variables of the factor.
replicate_self(attribute_map=None)

This functions is a copy constructor for the object. In order to perform copy construction we first call __new__() on the class which creates a blank object. We then initialize that object using the method’s standard init procedures, and do any extra copying of attributes.

Replicates this Factor, using new inputs, outputs, and a new uuid. Used during model replication to functionally replicate a factor into a new graph.

Parameters:
  • inputs (List of tuples of name to node e.g. [('random_variable': Variable y)] or None) – new input variables of the factor.
  • outputs (List of tuples of name to node e.g. [('random_variable': Variable y)] or None) – new output variables of the factor.
inputs

Return a list of nodes whose edges point into this node.

outputs

Return a list of nodes pointed to by the edges of this node.

set_outputs(variables)

TODO We don’t actually support multi-output.

set_single_input(key, value)

Set a single input variable of a factor.

Parameters:
  • key (str) – the name of the input variable in the factor
  • value (Variable) – the variable to be set
input_names

Return Input names.

output_names

Return Output names.

fetch_runtime_inputs(params)

The helper function to fetch the input variables from a set of variables according to the UUIDs of the input variables. It returns a dictionary of variables at runtime, where the keys are the name of the input variables and the values are the MXNet array at runtime. The returned dict can be directly passed into runtime functions of factors such as eval for functions and log_pdf and draw_samples for distributions.

Parameters:params – the set of variables where the input variables are

fetched from. :type params: {str (UUID): MXNet NDArray or MXNet Symbol} :return: a dict of the input variables, where the keys are the name of the input variables and the values are the MXNet array at runtime. :rtype: {str (kernel name): MXNet NDArray or MXNet Symbol}

fetch_runtime_outputs(params)

The helper function to fetch the output variables from a set of variables according to the UUIDs of the output variables. It returns a dictionary of variables at runtime, where the keys are the name of the output variables and the values are the MXNet array at runtime. The returned dict can be directly passed into runtime functions of factors such as eval for functions and log_pdf and draw_samples for distributions.

Parameters:params – the set of variables where the output variables are

fetched from. :type params: {str (UUID): MXNet NDArray or MXNet Symbol} :return: a dict of the output variables, where the keys are the name of the output variables and the values are the MXNet array at runtime. :rtype: {str (kernel name): MXNet NDArray or MXNet Symbol}