inferpy.util package

Submodules

inferpy.util.common module

Obtained from Keras GitHub repository: https://github.com/keras-team/keras/blob/master/keras/backend/common.py

inferpy.util.common.floatx()[source]

Returns the default float type, as a string. (e.g. float16, float32, float64).

Returns:

the current default float type.

Return type:

String

Example

>>> inf.floatx()
'float32'
inferpy.util.common.is_float(dtype)[source]
inferpy.util.common.set_floatx(floatx)[source]

Sets the default float type.

Parameters:

floatx – String, ‘float16’, ‘float32’, or ‘float64’.

Example

>>> from keras import backend as K
>>> inf.floatx()
'float32'
>>> inf.set_floatx('float16')
>>> inf..floatx()
'float16'

inferpy.util.interceptor module

inferpy.util.interceptor.disallow_conditions()[source]
inferpy.util.interceptor.enable_interceptor(enable_globals, enable_locals)[source]
inferpy.util.interceptor.make_predictable_variables(initial_value, rv_name)[source]
inferpy.util.interceptor.set_values(**model_kwargs)[source]

Creates a value-setting interceptor. Usable as a parameter of the ed2.interceptor.

Model_kwargs:

The name of each argument must be the name of a random variable to intercept, and the value is the element which intercepts the value of the random variable.

Returns:

The random variable with the intercepted value

inferpy.util.interceptor.set_values_condition(var_condition, var_value)[source]

Creates a value-setting interceptor. Usable as a parameter of the ed2.interceptor.

Var_condition (tf.Variable)tf.Variable):

The boolean tf.Variable, used to intercept the value property with value_var or the variable value property itself

Var_value (tf.Variable)tf.Variable):

The tf.Variable used to intercept the value property when var_condition is True

Returns:

The random variable with the intercepted value

inferpy.util.iterables module

inferpy.util.iterables.get_plate_size(variables, sample_dict)[source]
inferpy.util.iterables.get_shape(x)[source]

Get the shape of an element x. If it is an element with a shape attribute, return it. If it is a list with more than one element, compute the shape by checking the len, and the shape of internal elements. In that case, the shape must be consistent. Finally, in other case return () as shape.

Parameters:

x – The element to compute its shape

Raises:

class `ValueError` – list shape not consistent

Returns:

A tuple with the shape of x

inferpy.util.name module

inferpy.util.name.generate(prefix)[source]

This function is used to generate names based on an incremental counter (global variable in this module) dependent on the prefix (staring from 0 index)

Prefix (str)str):

The begining of the random generated name

Returns:

The generated random name

inferpy.util.runtime module

Module focused on evaluating tensors to makes the usage easier, forgetting about tensors and sessions

inferpy.util.runtime.runner_scope()[source]
inferpy.util.runtime.set_tf_run(enable)[source]
inferpy.util.runtime.tf_run_allowed(f)[source]

A function might return a tensor or not. In order to decide if the result of this function needs to be evaluated in a tf session or not, use the tf_run extra parameter or the tf_run_default value. If True, and this function is in the first level of execution depth, use a tf Session to evaluate the tensor or other evaluable object (like dicts)

inferpy.util.runtime.tf_run_ignored(f)[source]

A function might call other functions decorated with tf_run_allowed. This decorator is used to avoid that such functions are evaluated.

inferpy.util.runtime.try_run(obj)[source]

inferpy.util.session module

inferpy.util.session.clear_session()[source]
inferpy.util.session.get_session()[source]
inferpy.util.session.init_uninit_vars()[source]
inferpy.util.session.new_session(gpu_memory_fraction=0.0)[source]
inferpy.util.session.set_session(session)[source]
inferpy.util.session.swap_session(new_session)[source]

inferpy.util.startup module

inferpy.util.tf_graph module

inferpy.util.tf_graph.get_empty_graph()[source]
inferpy.util.tf_graph.get_graph(varnames)[source]

Module contents

Package with modules defining functions, classes and variables which are useful for the main functionality provided by inferpy

inferpy.util.floatx()[source]

Returns the default float type, as a string. (e.g. float16, float32, float64).

Returns:

the current default float type.

Return type:

String

Example

>>> inf.floatx()
'float32'
inferpy.util.set_floatx(floatx)[source]

Sets the default float type.

Parameters:

floatx – String, ‘float16’, ‘float32’, or ‘float64’.

Example

>>> from keras import backend as K
>>> inf.floatx()
'float32'
>>> inf.set_floatx('float16')
>>> inf..floatx()
'float16'
inferpy.util.set_tf_run(enable)[source]
inferpy.util.tf_run_allowed(f)[source]

A function might return a tensor or not. In order to decide if the result of this function needs to be evaluated in a tf session or not, use the tf_run extra parameter or the tf_run_default value. If True, and this function is in the first level of execution depth, use a tf Session to evaluate the tensor or other evaluable object (like dicts)

inferpy.util.tf_run_ignored(f)[source]

A function might call other functions decorated with tf_run_allowed. This decorator is used to avoid that such functions are evaluated.

inferpy.util.get_session()[source]
inferpy.util.set_session(session)[source]
inferpy.util.clear_session()[source]
inferpy.util.new_session(gpu_memory_fraction=0.0)[source]
inferpy.util.init_uninit_vars()[source]