gsnn.gsnn.proc.construct
construct.py - Build pruned constraint networks for the GSNN model
This helper stitches together several edge lists into a directed heterogeneous graph, removes nodes that do not lie on any path from an input to an output, and returns the result as a PyTorch-Geometric HeteroData object ready for use in GSNN.
Accepted edge tables (all pd.DataFrame with columns src, dst)
input_edges - critical inputs → function nodes
mediator_edges - (optional) mediator inputs → function nodes. Mediators are only retained if they target a function node that survives the pruning step.
function_edges - function → function (latent logic)
output_edges - function → output
ASCII toy graph
``` input_A mediator_M
│ │ ▼ │
- func_X ◀────────┘
│ ▼
out_Y
``` mediator_M is kept only if func_X remains on a viable input_A → … → out_Y path.
Quick usage example
```python from gsnn.proc.construct import GSNNNetworkConstructor
builder = GSNNNetworkConstructor(depth=10, verbose=True) data = builder.build(input_edges, function_edges,
output_edges, mediator_edges)
Returned attributes
data.node_names_dict - mapping of node types to names
data.edge_index_dict - edge indices (PyTorch tensors)
data.graph_summary - pruning statistics & graph metrics
data.build_args - parameters used to build the graph
Functions
|
Subset a graph to include only nodes that lie on paths from roots to leaves. |
Classes
|
- class gsnn.gsnn.proc.construct.GSNNNetworkConstructor(depth=10, verbose=True)[source]
Bases:
object- build(input_edges, function_edges, output_edges, mediator_edges=None, input_names=None, output_names=None, function_names=None, mediator_names=None)[source]
Construct and filter constraint network for GSNN model.
Behavior of fixed node name arguments: - input_names, mediator_names, function_names, output_names specify nodes that MUST
be included in the final node lists, even if they have no incident edges.
Additional nodes of each type that are inferred from the provided edge tables are also included. In other words, the final node sets are supersets of the fixed names.
Inputs and mediators are combined into a single ‘input’ type in the order input_names + mediator_names, followed by any additional discovered inputs.
- Parameters:
input_edges – DataFrame with columns ‘src’, ‘dst’ for input→function edges
function_edges – DataFrame with columns ‘src’, ‘dst’ for function→function edges
output_edges – DataFrame with columns ‘src’, ‘dst’ for function→output edges
mediator_edges – Optional DataFrame with columns ‘src’, ‘dst’ for mediator→function edges (only retained if they target a function node retained in the pruned graph)
input_names – Optional list of input node names to force-include
mediator_names – Optional list of mediator node names to force-include (combined with inputs)
function_names – Optional list of function node names to force-include
output_names – Optional list of output node names to force-include
- Returns:
HeteroData object with filtered network structure and metadata