Content¶
-
nngt.lib.
as_string
(graph, format='neighbour', delimiter=' ', secondary=';', attributes=None, notifier='@', return_info=False)[source]¶ Full string representation of the graph.
Parameters: - graph (
Graph
or subclass) – Graph to save. - format (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 asource 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’). - delimiter (str, optional (default ” ”)) – Delimiter used to separate inputs in the case of custom formats (namely “neighbour” and “edge_list”)
- secondary (str, optional (default: ”;”)) – Secondary delimiter 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
, withinfo_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.
Returns: str_graph (string) – The full graph representation as a string.
- graph (
-
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.
- graph (
-
nngt.lib.
gaussian_distrib
(graph, elist=None, num=None, avg=1.0, std=0.2, **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.
- graph (
-
nngt.lib.
load_from_file
(filename, format='neighbour', delimiter=' ', secondary=';', attributes=[], notifier='@', ignore='#')[source]¶ Import a saved graph as a (set of)
csr_matrix
from a file. @todo: implement population and shape loading, implement gml, dot, xml, gtParameters: - filename (str) – The path to the file.
- format (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’). - delimiter (str, optional (default ” ”)) – Delimiter used to separate inputs in the case of custom formats (namely “neighbour” and “edge_list”)
- secondary (str, optional (default: ”;”)) – Secondary delimiter 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
, whereinfo_name
is in (“attributes”, “directed”, “name”, “size”) and associatedinfo_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-tuple) – 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).
-
nngt.lib.
nonstring_container
(obj)[source]¶ Returns true for any iterable which is not a string or byte sequence.
-
nngt.lib.
save_to_file
(graph, filename, format='auto', delimiter=' ', 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.
- format (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’). - delimiter (str, optional (default ” ”)) – Delimiter used to separate inputs in the case of custom formats (namely “neighbour” and “edge_list”)
- secondary (str, optional (default: ”;”)) – Secondary delimiter 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
, withinfo_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
orNetwork
(theShape
andNeuralPop
attributes will not be saved).
- graph (
-
nngt.lib.
uniform_distrib
(graph, elist=None, num=None, lower=0.0, upper=1.5, **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.
- graph (