# Machine learning with graph as input and output

In my application, I have inputs and outputs that could be represented as graphs. I have a number of acceptable pairs of input and output graphs. I want to use these to train a model.

I am looking for pointers where simple examples of learning methods with graphs as input are discussed. Please note that the graph size is not fixed.

A sample input is

Graph:
Node A: Component X with parameter size = 12
Node B: Component Y with parameter size = 30
Node C: Component Y with parameter size = 30
A connects to B
A connects to C


Sample output:

Node A: x=0, y=0
Node B: x=-21, y=0
Node C: x=21, y=0


In this case, we expect the model to understand that input graph is symmetric and a particular way of arranging them is preferred. We want to train the model over a large set of such input-output pairs and then use it to generate output on new inputs.

• Could you elaborate on the problem you are trying to solve? What does your data represent? Commented Sep 15, 2017 at 9:18
• The input graph represents a circuit - the nodes being components and nets/connections are the edges. I thought providing these details in the question might confuse people. Commented Sep 15, 2017 at 9:40
• Very interesting problem, so you're trying to verify the circuit and component values or is it like auto routing the circuit copper track? Commented Sep 15, 2017 at 9:50
• Mostly to infer patterns in the input, and to generate the an acceptable output which we think depends on these patterns. Commented Sep 15, 2017 at 13:30
• Does this answer your question? Are there neural networks that accept graphs or trees as inputs? Commented Apr 25, 2020 at 18:20

## 2 Answers

You can flatten the graph into a matrix and then train it like a normal neural network input. Perhaps an adjacency graph or maybe simply a series of linear equations representing the nodes and convert it into matrix form.

If the circuit has only passive electronic components like resistor, capacitor or coil then ML can figure out their characters with sufficient training but if there are programmable active components like MCU/FPGA then it will be a tricky problem to solve. Even active components like transistors, SCR, TRIAC have well-defined response characteristics under a normal working condition, but programmable components could run different firmware and behave differently.

I think you should see this as a time series problem where you will find out the possible output signal for a given component values in the mesh and the input signal parameters like Voltage and Current.

And if your circuits are really big you might want to break it down into isolated sections, then run a model for each of them separately, feed the output of one model as input to next one and so on. I guess this is where you got the graph idea.