Lib module#

Tools for the other modules.

Warning

These tools have been designed primarily for internal use throughout the library and often work only in very specific situations (e.g. find_idx_nearest() works only on sorted arrays), so make sure you read their doc carefully before using them.

Content#

nngt.lib.InvalidArgument Error raised when an argument is invalid.
nngt.lib.custom(graph[, values, elist])
nngt.lib.decorate(func, caller[, extras]) decorate(func, caller) decorates a function using a caller.
nngt.lib.delta_distrib([graph, elist, num, …]) Delta distribution for edge attributes.
nngt.lib.deprecated(version[, reason, …]) Decorator to mark deprecated functions.
nngt.lib.find_idx_nearest(array, values) Find the indices of the nearest elements of values in a sorted array.
nngt.lib.gaussian_distrib(graph[, elist, …]) Gaussian distribution for edge attributes.
nngt.lib.graph_tool_check(version_min) Raise an error for function not working with old versions of graph-tool.
nngt.lib.is_integer(obj)
nngt.lib.lin_correlated_distrib(graph[, …])
nngt.lib.log_correlated_distrib(graph[, …])
nngt.lib.lognormal_distrib(graph[, elist, …])
nngt.lib.mpi_barrier(func)
nngt.lib.mpi_checker([logging]) Decorator used to check for mpi and make sure only rank zero is used to store and generate the graph if the mpi algorithms are activated.
nngt.lib.mpi_random(func) Decorator asserting that all processes start with same random seed when using mpi.
nngt.lib.nonstring_container(obj) Returns true for any iterable which is not a string or byte sequence.
nngt.lib.not_implemented(*args, **kwargs)
nngt.lib.num_mpi_processes() Returns the number of MPI processes (1 if MPI is not used)
nngt.lib.on_master_process() Check whether the current code is executing on the master process (rank 0) if MPI is used.
nngt.lib.seed([msd, seeds]) Seed the random generator used by NNGT (i.e.
nngt.lib.uniform_distrib(graph[, elist, …]) Uniform distribution for edge attributes.

Details#

Various tools for random number generation, array searching and type testing.

nngt.lib.delta_distrib(graph=None, elist=None, num=None, value=1.0, **kwargs)[source]#

Delta distribution for edge attributes.

Parameters:
  • graph (Graph or subclass) – Graph for which an edge attribute will be generated.
  • elist (@todo)
  • value (float, optional (default: 1.)) – Value of the delta distribution.
  • Returns (numpy.ndarray) – Attribute value for each edge in graph.
nngt.lib.find_idx_nearest(array, values)[source]#

Find the indices of the nearest elements of values in a sorted array.

Warning

Both array and values should be numpy.array objects and array MUST be sorted in increasing order.

Parameters:
  • array (reference list or np.ndarray)
  • values (double, list or array of values to find in array)
Returns:

idx (int or array representing the index of the closest value in array)

nngt.lib.gaussian_distrib(graph, elist=None, num=None, avg=None, std=None, **kwargs)[source]#

Gaussian distribution for edge attributes.

Parameters:
  • graph (Graph or subclass) – Graph for which an edge attribute will be generated.
  • elist (@todo)
  • avg (float, optional (default: 0.)) – Average of the Gaussian distribution.
  • std (float, optional (default: 1.5)) – Standard deviation of the Gaussian distribution.
  • Returns (numpy.ndarray) – Attribute value for each edge in graph.
exception nngt.lib.InvalidArgument[source]#

Error raised when an argument is invalid.

nngt.lib.is_integer(obj)[source]#
nngt.lib.lin_correlated_distrib(graph, elist=None, correl_attribute='betweenness', noise_scale=None, lower=None, upper=None, slope=None, offset=0.0, last_edges=False, **kwargs)[source]#
nngt.lib.log_correlated_distrib(graph, elist=None, correl_attribute='betweenness', noise_scale=None, lower=0.0, upper=2.0, **kwargs)[source]#
nngt.lib.lognormal_distrib(graph, elist=None, num=None, position=None, scale=None, **kwargs)[source]#
nngt.lib.nonstring_container(obj)[source]#

Returns true for any iterable which is not a string or byte sequence.

nngt.lib.uniform_distrib(graph, elist=None, num=None, lower=None, upper=None, **kwargs)[source]#

Uniform distribution for edge attributes.

Parameters:
  • graph (Graph or subclass) – Graph for which an edge attribute will be generated.
  • elist (@todo)
  • lower (float, optional (default: 0.)) – Min value of the uniform distribution.
  • upper (float, optional (default: 1.5)) – Max value of the uniform distribution.
  • Returns (numpy.ndarray) – Attribute value for each edge in graph.