nfp.preprocessing.preprocessor.PreprocessorMultiGraph¶
- class PreprocessorMultiGraph(output_dtype='int32')[source]¶
Bases:
nfp.preprocessing.preprocessor.Preprocessor
,abc.ABC
Class to handle graphs with parallel edges and self-loops
Methods
Deprecated since version 0.3.0.
Given an input structure object, convert it to a networkx digraph with node, edge, and graph features assigned.
Set's the class's data with attributes taken from the save file
Get the graph connectivity from the networkx graph
Given a list of edge features from the nx.Graph, processes and concatenates them to an array.
Process the nx.graph features into a dictionary of arrays.
Given a list of node features from the nx.Graph, processes and concatenates them to an array.
Serialize the classes's data to a json file
Attributes
output_signature
padding_values
Useful feature for storing preprocessed outputs in tfrecord files
- Parameters
output_dtype (str) –
- abstract create_nx_graph(structure, **kwargs)[source]¶
Given an input structure object, convert it to a networkx digraph with node, edge, and graph features assigned.
- Parameters
structure (Any) – Any input graph object
kwargs – keyword arguments passed from __call__, useful for specifying additional features in addition to the graph object.
- Returns
A networkx graph with the node, edge, and graph features set
- Return type
nx.DiGraph
- static get_connectivity(graph, max_num_edges)[source]¶
Get the graph connectivity from the networkx graph
- Parameters
graph (networkx.classes.digraph.DiGraph) – The input graph
max_num_edges (int) – len(graph.edges), or the specified maximum number of graph edges
- Returns
A dictionary of with the single ‘connectivity’ key, containing an (n,2) array of (node_index, node_index) pairs indicating the start and end nodes for each edge.
- Return type
Dict[str, np.ndarray]
- __call__(structure, *args, train=False, max_num_nodes=None, max_num_edges=None, **kwargs)¶
- Convert an input graph structure into a featurized set of node, edge,
and graph-level features.
- Parameters
structure (Any) – An input graph structure (i.e., molecule, crystal, etc.)
train (bool) – A training flag passed to Tokenizer member attributes
max_num_nodes (Optional[int]) – A size attribute passed to get_node_features, defaults to the number of nodes in the current graph
max_num_edges (Optional[int]) – A size attribute passed to get_edge_features, defaults to the number of edges in the current graph
kwargs – Additional features or parameters passed to construct_nx_graph
- Returns
A dictionary of key, array pairs as a single sample.
- Return type
Dict[str, np.ndarray]
- construct_feature_matrices(*args, train=False, **kwargs)¶
Deprecated since version 0.3.0: construct_feature_matrices will be removed in 0.4.0, use __call__ instead
- from_json(filename)¶
Set’s the class’s data with attributes taken from the save file
- Parameters
filename (str) –
- Return type
None
- abstract get_edge_features(edge_data, max_num_edges)¶
Given a list of edge features from the nx.Graph, processes and concatenates them to an array.
- Parameters
- Returns
a dictionary of feature, array pairs, where array contains features for all edges in the graph.
- Return type
Dict[str, np.ndarray]
- abstract get_graph_features(graph_data)¶
Process the nx.graph features into a dictionary of arrays.
- abstract get_node_features(node_data, max_num_nodes)¶
Given a list of node features from the nx.Graph, processes and concatenates them to an array.
- Parameters
- Returns
a dictionary of feature, array pairs, where array contains features for all nodes in the graph.
- Return type
Dict[str, np.ndarray]