Handling the isolated nodes in DGL graphs

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in this video let's see how dgl handles isolated nodes in the graph so what do we mean by the isolated nodes so whenever any node is completely disconnected from the graph that is if you observe this node 5 this node 5 don't have any incoming edges also this node 5 does not have any outgoing edges so this is a isolated node in the graph okay i just took the same example that we had earlier with the same number of edges but i just added one more additional node earlier we had only five nodes now we have six nodes ranging from zero to five so let's see how dgl handles these isolated nodes okay so i'll just create a simple graph okay so i'm just creating the graph here so what do we pass so we need to pass the tuple of two tensors right so the first is the source node ids okay so we have eight different edges so obviously the length of these source node ids and destination node ids will also be equivalent to the number of edges so the first tensor is source node ids the second tensor is destination node ids okay so now let's just print the graph let's see what happens so if we see the number of nodes 5 and number of edges as 8 number of edges yes we have 8 edges that's fine but in this graph the number of nodes are not equivalent to 5 the number of nodes are 6 so let's see the ids so if we print graph dot nodes we see that the ids are ranging from 0 to 4 but it should ideally range from 0 to 5 because we have 6 different nodes in this graph but as this is an isolated node dgl graph method was not able to capture this because this 5 is not part of the source node ids also it is not part of the destination node ids so dcl does not know about this node so how do we make dcl to handle this node okay so it's very simple so what do we do here is that so so along by passing the source node ids and destination node ids we can also mention the number of nodes explicitly okay so i'll just mention the number of nodes as uh six okay we have six nodes right and you can see also see the documentation here so if we go to the parameters we have something called number of nodes it says the number of nodes in the graph okay this is an optional parameter so if not given that means if we do not pass this number of nodes okay then it will take the largest node id plus one from the data argument so we are passing this node ids right so from this node ids it will take the maximum node id okay it will take the maximum node id and it will add plus 1 to that and that will be taken as the number of nodes by default even before this let's try to see whether we can see this default parameter okay we already created the graph right so let's see uh the number of nodes graph dot let's try to access the parameter num nodes okay so okay this is a method i'll just call so you can see 5 okay because by default it is taking 5 because the maximum integer id here is 4 in this data in the data input that we pass and dcl dgl graph method is internally adding plus 1 to the maximum id and assigning that as the number of nodes so now what i'll do here is that i'll explicitly pass the number of nodes as 6 okay i'll explicitly pass the number of nodes as six now i will print the graph now we can see the number of nodes as six and we can see again the number of nodes it will range from zero to five right and also you can see the number of nodes now it will be equivalent to 6 okay so in case if we have any of these kind of you know isolated nodes with the maximum id then we can use the explicit parameter called number of nodes and let's say instead of five let's say you have some number graph uh less than the maximum connected node okay so let's say instead of five uh let's say instead in place of four we have five and let's say 4 is isolated in that case we don't need to explicitly mention because the 5 will be part of this data input right if if we have 5 in place of 4 then in place of 4 will be having five okay so this problem happens only this problem happens only if the isolated node having the maximum integer id okay this this problem occurs only if the isolated node happens to be the largest node id okay otherwise you know uh like i mentioned earlier the digital graph method by default it will take the maximum id from the input and it'll add plus 1 to that okay but it's always good practice to add a number of nodes explicitly you know if we already know the number of nodes it would be good to you know add this explicitly thanks
Info
Channel: SriharshAI
Views: 434
Rating: undefined out of 5
Keywords: iMovie
Id: IW9dWWfM4uk
Channel Id: undefined
Length: 5min 35sec (335 seconds)
Published: Mon Sep 05 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.