Get startedGet started for free

Concept of projection

1. Concept of projection

I’m hoping you learned something new in Chapter 1! In chapter 2, we will explore bipartite graph projections and matrix operations. It’s going to be challenging, but ultimately, you will definitely find it useful!

2. Projection

Let’s start with the concept of a projection. If you have a bipartite graph, it may be useful to investigate the relationship between nodes on one partition, conditioned on the connections to the nodes on the other partition. For example,

3. Projection

if we have this toy graph of customers and products, let’s say we wanted to see which customers were related to one another because they were connected to the same products on the other partition.

4. Projection

Customers 1 and 2 would be connected to one another on the basis of sharing a connection to product 2.

5. Projection

Customer 3, being only connected to product 1, which is not connected to any other customers, would not be connected to any other customer in this graph. As such, the “customer” projection of the bipartite graph is given by

6. Projection

a set of 3 customer nodes, and a single edge between customer 1 and 2. In the exercises that follow, you will be computing and analyzing projections of other bipartite graphs. In this chapter, apart from learning about bipartite graphs, we have added in as bonus material example code on loading data from human-readable files on disk.

7. Graphs on Disk

This includes plain edge lists (without node metadata), and separate node and edge lists (each containing appropriate metadata).

8. Reading network data

NetworkX comes with I/O functions that allow us to read and write edgelists. In the text in gray, I have shown you what the original text file looks like. This is a space-delimited file, with the first string of each line being the name of a person, the second string being a club, and the third string encoding the metadata dictionary. Inspecting this file, the first element is a node, the second element is the other node that the node is connected to, and the third element is the metadata dictionary. NetworkX’s read_edgelist function can digest this into a graph into memory, resulting in a graph that we can query for, say, its edges.

9. Bipartite projection

How do we get the bipartite projection of a graph? I showed it earlier briefly, but here I’ll go through it in a little bit more detail. Let’s say I have the toy graph G that you saw earlier, connecting customers to products. In order to get the customers projection like you saw earlier, I have to first collect the customer nodes into a single container, say, cust_nodes,

10. Bipartite projection

using a list comprehension similar to what you’ve seen before for filtering graph nodes. Having done that, I then pass G and cust_nodes into

11. Bipartite projection

the bipartite projected_graph function, which returns a graph containing only the nodes that belong to the “customers” partition, and the edges between them, which if you remember from before, there’s only one between customer1 and customer2. Now, let’s recall a bit from what you learned in the first chapter. Recall that I mentioned that

12. Degree centrality

the degree centrality metric as defined for bipartite graphs was a bit different - the denominator, which is the total number of possible neighbors, is the number of nodes on the opposite partition. As such,

13. Bipartite degree centrality

this explains why we have to pass in the list of nodes from one partition into, say, the NetworkX bipartite degree centrality function, as shown in the code above. Note also that the bipartite degree centrality scores may very well

14. Bipartite degree centrality

be different from the regular degree centrality scores in the projection, as shown here.

15. Let's practice!

Okay! Let’s go get some practice with graph projections, graph I/O, and bipartite centrality metrics!

Create Your Free Account

or

By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.