-
-
Notifications
You must be signed in to change notification settings - Fork 504
Fix FeedForwardNetwork and output bug #282
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Finebouche
wants to merge
12
commits into
CodeReclaimers:master
Choose a base branch
from
Finebouche:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
d627049
Bug input node selection when adding connexion
Finebouche 24cdec1
Bug in feedfroward network
Finebouche 22e0a65
Cleanup
Finebouche 357b69f
Readded function documentation
Finebouche 7182716
Can now change configuration when using a checkpoint
Finebouche 5f11932
Add WandbReporter
Finebouche a6bff53
Removed WandbReporter
Finebouche e67aaf8
Added initializer
Finebouche 91748a9
add tqmd
Finebouche 4f58020
graph visualisation
Finebouche 7115af5
add wann option for feedforward network activation
Finebouche 5fd3142
correct implementation for wann
Finebouche File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
"""Directed graph algorithm implementations.""" | ||
|
||
from collections import defaultdict, deque | ||
|
||
def creates_cycle(connections, test): | ||
""" | ||
|
@@ -38,20 +38,35 @@ def required_for_output(inputs, outputs, connections): | |
""" | ||
assert not set(inputs).intersection(outputs) | ||
|
||
# Create a graph representation of the connections | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The previous function wasn't working as intended |
||
graph = defaultdict(list) | ||
reverse_graph = defaultdict(list) | ||
for a, b in connections: | ||
graph[a].append(b) | ||
reverse_graph[b].append(a) | ||
|
||
# Perform a breadth-first search (BFS) from each input to find all reachable nodes | ||
reachable = set(inputs) | ||
queue = deque(inputs) | ||
|
||
while queue: | ||
node = queue.popleft() | ||
for neighbor in graph[node]: | ||
if neighbor not in reachable: | ||
reachable.add(neighbor) | ||
queue.append(neighbor) | ||
|
||
# Now, traverse from the outputs and find all nodes that are required to reach the outputs | ||
required = set(outputs) | ||
s = set(outputs) | ||
while 1: | ||
# Find nodes not in s whose output is consumed by a node in s. | ||
t = set(a for (a, b) in connections if b in s and a not in s) | ||
while True: | ||
# Find nodes not in s whose output is consumed by a node in s and is reachable from inputs | ||
t = set(a for (a, b) in connections if b in s and a not in s and a in reachable) | ||
|
||
if not t: | ||
break | ||
|
||
layer_nodes = set(x for x in t if x not in inputs) | ||
if not layer_nodes: | ||
break | ||
|
||
required = required.union(layer_nodes) | ||
required = required.union(t) | ||
s = s.union(t) | ||
|
||
return required | ||
|
@@ -63,7 +78,6 @@ def feed_forward_layers(inputs, outputs, connections): | |
:param inputs: list of the network input nodes | ||
:param outputs: list of the output node identifiers | ||
:param connections: list of (input, output) connections in the network. | ||
|
||
Returns a list of layers, with each layer consisting of a set of node identifiers. | ||
Note that the returned layers do not contain nodes whose output is ultimately | ||
never used to compute the final network output. | ||
|
@@ -72,21 +86,24 @@ def feed_forward_layers(inputs, outputs, connections): | |
required = required_for_output(inputs, outputs, connections) | ||
|
||
layers = [] | ||
s = set(inputs) | ||
while 1: | ||
potential_input = set(inputs) | ||
while True: | ||
# Find candidate nodes c for the next layer. These nodes should connect | ||
# a node in s to a node not in s. | ||
c = set(b for (a, b) in connections if a in s and b not in s) | ||
c = set(b for (a, b) in connections if a in potential_input and b not in potential_input) | ||
# Keep only the used nodes whose entire input set is contained in s. | ||
t = set() | ||
next_layer = set() | ||
for n in c: | ||
if n in required and all(a in s for (a, b) in connections if b == n): | ||
t.add(n) | ||
# select connections (a, b) where b == n | ||
connections_to_n = [(a, b) for (a, b) in connections if b == n and a in required] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the change here is that a as to be in required nodes to be considered |
||
if n in required and all(a in potential_input for (a, b) in connections_to_n): | ||
next_layer.add(n) | ||
|
||
if not t: | ||
if not next_layer: | ||
break | ||
|
||
layers.append(t) | ||
s = s.union(t) | ||
layers.append(next_layer) | ||
potential_input = potential_input.union(next_layer) | ||
|
||
return layers, required | ||
|
||
return layers |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fixes new node from taking output nodes as inputs