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.delta_distrib([graph, elist, num, ...])

Delta distribution for edge attributes.

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.is_integer(obj)

Return whether the object is an integer

nngt.lib.is_iterable(obj)

Return whether the object is iterable

nngt.lib.lin_correlated_distrib(graph[, ...])

nngt.lib.log_correlated_distrib(graph[, ...])

nngt.lib.lognormal_distrib(graph[, elist, ...])

Lognormal distribution for edge attributes.

nngt.lib.nonstring_container(obj)

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

nngt.lib.uniform_distrib(graph[, elist, ...])

Uniform distribution for edge attributes.

Details#

class nngt.lib.InvalidArgument[source]#

Error raised when an argument is invalid.

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 (list of edges, optional (default: all edges)) – Generate values for only a subset of edges.

  • 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 (list of edges, optional (default: all edges)) – Generate values for only a subset of edges.

  • 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.

nngt.lib.is_integer(obj)[source]#

Return whether the object is an integer

nngt.lib.is_iterable(obj)[source]#

Return whether the object is iterable

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]#

Lognormal distribution for edge attributes.

Parameters:
  • graph (Graph or subclass) – Graph for which an edge attribute will be generated.

  • elist (list of edges, optional (default: all edges)) – Generate values for only a subset of edges.

  • position (float, optional (default: 0.)) – Average of the normal distribution (i.e. log of the actual mean of the lognormal distribution).

  • scale (float, optional (default: 1.5)) – Standard deviation of the normal distribution.

  • Returns (numpy.ndarray) – Attribute value for each edge in graph.

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 (list of edges, optional (default: all edges)) – Generate values for only a subset of edges.

  • 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.