inferpy.util package

Submodules

inferpy.util.error module

Module implementing custom exceptions and errors

exception inferpy.util.error.ScopeException[source]

Bases: exceptions.Exception

This exception is raised when an InferPy object is declared in a non-valid scope

inferpy.util.format module

Module implementing text formatting operaionts

inferpy.util.format.np_str(s)[source]

Shorten string representation of a numpy object

Parameters:s – numpy object.

inferpy.util.ops module

Module implementing some useful operations over tensors and random variables

inferpy.util.ops.case(d, default=None, exclusive=True, strict=False, name='case')[source]

Control flow operation depending of the outcome of a tensor. Any expression in tensorflow giving as a result a boolean is allowed as condition.

Internally, the operation tensorflow.case is invoked. Unlike the tensorflow operation, this one accepts InferPy variables as input parameters.

Parameters:
  • d – dictionary where the keys are the conditions (i.e. boolean tensor).
  • exclusive – True iff at most one case is allowed to evaluate to True.
  • name – name of the resulting tensor.
Returns:

Tensor implementing the case operation. This is the output of the operation tensorflow.case internally invoked.

inferpy.util.ops.case_states(var, d, default=None, exclusive=True, strict=False, name='case')[source]

Control flow operation depending of the outcome of a discrete variable.

Internally, the operation tensorflow.case is invoked. Unlike the tensorflow operation, this one accepts InferPy variables as input parameters.

Parameters:
  • var – Control InferPy discrete random variable.
  • d – dictionary where the keys are each of the possible values of control variable
  • the values are returning tensors for each case. (and) –
  • exclusive – True iff at most one case is allowed to evaluate to True.
  • name – name of the resulting tensor.
Returns:

Tensor implementing the case operation. This is the output of the operation tensorflow.case internally invoked.

inferpy.util.ops.dot(x, y)[source]

Compute dot product between an InferPy or Tensor object. The number of batches N equal to 1 for one of them, and higher for the other one.

If necessarily, the order of the operands may be changed.

Args:
x: first operand. This could be an InferPy variable, a Tensor, a numpy object or a numeric Python list. x: second operand. This could be an InferPy variable, a Tensor, a numpy object or a numeric Python list.
Retruns:
An InferPy variable of type Deterministic encapsulating the resulting tensor of the multiplications.
inferpy.util.ops.fix_shape(s)[source]

Transforms a shape list into a standard InferPy shape format.

inferpy.util.ops.gather(params, indices, validate_indices=None, name=None, axis=0)[source]

Operation for selecting some of the items in a tensor.

Internally, the operation tensorflow.gather is invoked. Unlike the tensorflow operation, this one accepts InferPy variables as input parameters.

Parameters:
  • params – A Tensor. The tensor from which to gather values. Must be at least rank axis + 1.
  • indices – A Tensor. Must be one of the following types: int32, int64. Index tensor. Must be in range
  • params.shape[axis]) ([0,) –
  • axis – A Tensor. Must be one of the following types: int32, int64. The axis in params to gather indices
  • Defaults to the first dimension. Supports negative indexes. (from.) –
  • name – A name for the operation (optional).
Returns:

A Tensor. Has the same type as params.. This is the output of the operation tensorflow.gather internally invoked.

inferpy.util.ops.matmul(a, b, transpose_a=False, transpose_b=False, adjoint_a=False, adjoint_b=False, a_is_sparse=False, b_is_sparse=False, name=None)[source]

Matrix multiplication.

Input objects may be tensors but also InferPy variables.

Parameters:
  • a – Tensor of type float16, float32, float64, int32, complex64, complex128 and rank > 1.
  • b – Tensor with same type and rank as a.
  • transpose_a – If True, a is transposed before multiplication.
  • transpose_b – If True, b is transposed before multiplication.
  • adjoint_a – If True, a is conjugated and transposed before multiplication.
  • adjoint_b – If True, b is conjugated and transposed before multiplication.
  • a_is_sparse – If True, a is treated as a sparse matrix.
  • b_is_sparse – If True, b is treated as a sparse matrix.
  • name – Name for the operation (optional).
Retruns:
An InferPy variable of type Deterministic encapsulating the resulting tensor of the multiplications.
inferpy.util.ops.param_to_tf(x)[source]

Transforms either a scalar or a random variable into a Tensor

inferpy.util.ops.shape_to_list(a)[source]

Transforms the shape of an object into a list

Parameters:a – object whose shape will be transformed. This could be an InferPy variable, a Tensor, a numpy object or a numeric Python list.

inferpy.util.runtime module

Module with useful definitions to be used in runtime

inferpy.util.runtime.get_session()[source]

Get the default tensorflow session

inferpy.util.wrappers module

Module with useful wrappers used for the development of InferPy.

inferpy.util.wrappers.input_model_data(f)[source]

wrapper that transforms, if required, a dataset object, making it suitable for InferPy inference process.

inferpy.util.wrappers.multishape(f)[source]

This wrapper allows to apply a function with simple parameters, over multidimensional ones.

inferpy.util.wrappers.singleton(class_)[source]

wrapper that allows to define a singleton class

inferpy.util.wrappers.static_multishape(f)[source]

This wrapper allows to apply a function with simple parameters, over multidimensional ones.

inferpy.util.wrappers.tf_run_wrapper(f)[source]

When setted to a function f, this wrappers replaces the output tensor of f by its evaluation in the default tensorflow session. In doing so, the API user will only work with standard Python types.