I am working on a sample data containing several papers, the topics they belong to, and the publication years of those papers, it looks like this:
| paper_id | topic | pub_year |
|---|---|---|
| 2031361154 | 0 | 1998 |
| 2088633475 | 1 | 1995 |
| 1987003396 | 2 | 1995 |
| 2246118404 | 3 | 1992 |
| 2017547909 | 1 | 1996 |
| 2032449907 | 4 | 1993 |
| 2053684599 | 0 | 1991 |
| 1968369145 | 1 | 1997 |
| 2160198778 | 4 | 1997 |
| 2026639487 | 3 | 1991 |
I am trying to reshuffle the publication years of those papers (keep the number of papers in each topic and published in each year constant) as preparation for a null model. If without constraints, this can be done simples by np.random.permutation. An example table after reshuffling the publication year is like this:
| paper_id | topic | reshuffled_pub_year |
|---|---|---|
| 2031361154 | 0 | 1998 |
| 2088633475 | 1 | 1997 |
| 1987003396 | 2 | 1995 |
| 2246118404 | 3 | 1992 |
| 2017547909 | 1 | 1996 |
| 2032449907 | 4 | 1993 |
| 2053684599 | 0 | 1991 |
| 1968369145 | 1 | 1997 |
| 2160198778 | 4 | 1995 |
| 2026639487 | 3 | 1991 |
But I want to ensure that the reshuffled years of those papers stay inside the period of the corresponding topics. For example, in the first table, there are papers about topic 1 published only in 1995, 1996, and 1997, so the reshuffled years of all papers about topic 1 stay the period from 1995 to 1997. Similarly, topic 0 in [1991,1998], topic 2 in [1995], topic 3 in [1991,1992] and topic 4 in [1993,1997]. But in the second table, the reshuffled publication year of paper 2246118404 is 1998, as this paper is about topic 3, the year can only be 1991 or 1992. So I need to specify the constraints during the reshuffle.
I have searched web pages and papers about this, I think this question can be modeled as a bipartite network degree-preserving randomization with constraints. The two node types in this bipartite network are topic and pub_year and an example network is given as the following figure:
To reshuffle the links in this bipartite network, I tried configuration_model in networkx using python. So I can guarantee the degrees of topics and years (But this is not different from np.random.permutation?). But as far as I know, configuration_model does not accept any constraint. In this example, tp1 has links to y1 and y2. So, in a desired reshuffled network, tp1 cannot have links to y3 and y4. Similarly, no links between (tp2,y4), (tp3,y1/y3), (tp4,y1/y2).
I would like to know if I am going in the right direction, i.e., modeling this task as a bipartite network reshuffle problem. If so, is there any tool that I can use for this task?