Main functions

nngt.generate(di_instructions, **kwargs)[source]

Generate a Graph or one of its subclasses from a dict containing all the relevant informations.

Parameters:di_instructions (dict) – Dictionary containing the instructions to generate the graph. It must have at least "graph_type" in its keys, with a value among "distance_rule", "erdos_renyi", "fixed_degree", "newman_watts", "price_scale_free", "random_scale_free". Depending on the type, di_instructions should also contain at least all non-optional arguments of the generator function.

See also

generation

nngt.get_config(key=None)[source]

Get the NNGT configuration as a dictionary.

nngt.load_from_file(filename, fmt='neighbour', separator=' ', secondary=';', attributes=[], notifier='@', ignore='#')[source]

Load the main properties (edges, attributes...) from a file.

Warning

To import a graph directly from a file, use the from_file() classmethod.

Parameters:
  • filename (str) – The path to the file.
  • fmt (str, optional (default: “neighbour”)) – The format used to save the graph. Supported formats are: “neighbour” (neighbour list, default if format cannot be deduced automatically), “ssp” (scipy.sparse), “edge_list” (list of all the edges in the graph, one edge per line, represented by a source target-pair), “gml” (gml format, default if filename ends with ‘.gml’), “graphml” (graphml format, default if filename ends with ‘.graphml’ or ‘.xml’), “dot” (dot format, default if filename ends with ‘.dot’), “gt” (only when using graph_tool`<http://graph-tool.skewed.de/>_ as library, detected if `filename ends with ‘.gt’).
  • separator (str, optional (default ” ”)) – separator used to separate inputs in the case of custom formats (namely “neighbour” and “edge_list”)
  • secondary (str, optional (default: ”;”)) – Secondary separator used to separate attributes in the case of custom formats.
  • attributes (list, optional (default: [])) – List of names for the attributes present in the file. If a notifier is present in the file, names will be deduced from it; otherwise the attributes will be numbered.
  • notifier (str, optional (default: “@”)) – Symbol specifying the following as meaningfull information. Relevant information are formatted @info_name=info_value, where info_name is in (“attributes”, “directed”, “name”, “size”) and associated info_value``s are of type (``list, bool, str, int). Additional notifiers are @type=SpatialGraph/Network/SpatialNetwork, which must be followed by the relevant notifiers among @shape, @population, and @graph.
  • ignore (str, optional (default: “#”)) – Ignore lines starting with the ignore string.
Returns:

  • edges (list of 2-tuples) – Edges of the graph.
  • di_attributes (dict) – Dictionary containing the attribute name as key and its value as a list sorted in the same order as edges.
  • pop (NeuralPop) – Population (None if not present in the file).
  • shape (Shape) – Shape of the graph (None if not present in the file).
  • positions (array-like of shape (N, d)) – The positions of the neurons (None if not present in the file).

nngt.save_to_file(graph, filename, fmt='auto', separator=' ', secondary=';', attributes=None, notifier='@')[source]

Save a graph to file. @todo: implement population and shape saving, implement gml, dot, xml, gt

Parameters:
  • graph (Graph or subclass) – Graph to save.
  • filename (str) – The path to the file.
  • fmt (str, optional (default: “auto”)) – The format used to save the graph. Supported formats are: “neighbour” (neighbour list, default if format cannot be deduced automatically), “ssp” (scipy.sparse), “edge_list” (list of all the edges in the graph, one edge per line, represented by a source target-pair), “gml” (gml format, default if filename ends with ‘.gml’), “graphml” (graphml format, default if filename ends with ‘.graphml’ or ‘.xml’), “dot” (dot format, default if filename ends with ‘.dot’), “gt” (only when using graph_tool`<http://graph-tool.skewed.de/>_ as library, detected if `filename ends with ‘.gt’).
  • separator (str, optional (default ” ”)) – separator used to separate inputs in the case of custom formats (namely “neighbour” and “edge_list”)
  • secondary (str, optional (default: ”;”)) – Secondary separator used to separate attributes in the case of custom formats.
  • attributes (list, optional (default: None)) – List of names for the edge attributes present in the graph that will be saved to disk; by default (None), all attributes will be saved.
  • notifier (str, optional (default: “@”)) – Symbol specifying the following as meaningfull information. Relevant information are formatted @info_name=info_value, with info_name in (“attributes”, “attr_types”, “directed”, “name”, “size”). Additional notifiers are @type=SpatialGraph/Network/SpatialNetwork, which are followed by the relevant notifiers among @shape, @population, and @graph to separate the sections.
  • .. warning :: – For now, all formats lead to dataloss if your graph is a subclass of SpatialGraph or Network (the Shape and NeuralPop attributes will not be saved).
  • .. note :: – Positions are saved as bytes by numpy.nparray.tostring()
nngt.seed(seed=None)[source]

Seed the random generator used by NNGT (i.e. the numpy RandomState: for details, see numpy.random.RandomState).

Parameters:seed (int or array_like, optional) – Seed for RandomState. Must be convertible to 32 bit unsigned integers.
nngt.set_config(config, value=None)[source]

Set NNGT’s configuration.

Parameters:
  • config (dict or str) – Either a full configuration dictionary or one key to be set together with its associated value.
  • value (object, optional (default: None)) – Value associated to config if config is a key.

Examples

>>> nngt.set_config({'multithreading': True, 'omp': 4})
>>> nngt.set_config('multithreading', False)

Note

See the config file nngt/nngt.conf.default or ~/.nngt/nngt.conf for details about your configuration.

See also

get_config()

nngt.use_library(library, reloading=True)[source]

Allows the user to switch to a specific graph library.

Parameters:
  • library (string) – Name of a graph library among ‘graph_tool’, ‘igraph’, ‘networkx’.
  • reload_moduleing (bool, optional (default: True)) – Whether the graph objects should be reload_moduleed (this should always be set to True except when NNGT is first initiated!)