<p>The naive way is to generate connections randomly as you would for a cyclic graph, but then perform a test to reject any connections that form a cycle. This is the current approach in SharpNEAT and there has been some effort directed at improving the performance of the cycle test in the work-in-progress refactor branch.</p>

<p>One alternative would be to track the depth of all nodes, store a list of node IDs sorted by depth, and sample the connection endpoint nodes in such a way that the target node depth is always higher than the source node. Now I think about it that's probably the better method.</p>

CC BY-SA 4.0
2018-05-16T21:55:49.003Z
2018-05-16T21:55:49.003Z
redcalx
<p>I also struggled with this when I was implementing NEAT.</p>
<p>What worked for me was cycle detection using DFS search in this video <a href="https://www.youtube.com/watch?v=tg96sZqhXyU" rel="nofollow noreferrer">https://www.youtube.com/watch?v=tg96sZqhXyU</a></p>
<p>Simply put, I did DFS on all my input nodes recording all the nodes visited if I encounter a node I've already visited then its a cycle thereby I for my neat to discard this and attempt to make another connection.</p>

CC BY-SA 4.0
2020-08-13T13:55:49.107Z
2020-08-13T13:55:49.107Z
Lester Dela Cruz
<p>I want my neural network structure to not have a circular/looping structure something similar like a directed acyclic graph (DAG). How do I do that?</p>

<neural-networks><machine-learning><genetic-algorithms><neat>
How do I restrict the neural network structure to be acyclic in NEAT?
Neil Nahid
# How do I restrict the neural network structure to be acyclic in NEAT?

(Asked by: username_0 on 2018-05-10)

I want my neural network structure to not have a circular/looping structure something similar like a directed acyclic graph (DAG). How do I do that?

**Tags:** neural-networks, machine-learning, genetic-algorithms, neat


---

## 2 answers

### Answer by username_1 on 2018-05-16. Score: 2

The naive way is to generate connections randomly as you would for a cyclic graph, but then perform a test to reject any connections that form a cycle. This is the current approach in SharpNEAT and there has been some effort directed at improving the performance of the cycle test in the work-in-progress refactor branch.

One alternative would be to track the depth of all nodes, store a list of node IDs sorted by depth, and sample the connection endpoint nodes in such a way that the target node depth is always higher than the source node. Now I think about it that's probably the better method.


---

### Answer by username_2 on 2020-08-13. Score: 1

I also struggled with this when I was implementing NEAT.

What worked for me was cycle detection using DFS search in this video <https://www.youtube.com/watch?v=tg96sZqhXyU>

Simply put, I did DFS on all my input nodes recording all the nodes visited if I encounter a node I've already visited then its a cycle thereby I for my neat to discard this and attempt to make another connection.


---

