adjacency-matrix

Build a square adjacency matrix from data.frame or data.table

别来无恙 提交于 2019-12-04 01:15:22
问题 I am trying to build a square adjacency matrix from a data.table . Here is a reproducible example of what I already have : require(data.table) require(plyr) require(reshape2) # Build a mock data.table dt <- data.table(Source=as.character(rep(letters[1:3],2)),Target=as.character(rep(letters[4:2],2))) dt # Source Target #1: a d #2: b c #3: c b #4: a d #5: b c #6: c b sry <- ddply(dt, .(Source,Target), summarize, Frequency=length(Source)) sry # Source Target Frequency #1 a d 2 #2 b c 2 #3 c b 2

Adjacency matrix in Python

冷暖自知 提交于 2019-12-03 13:34:03
问题 I cannot find any clear explanation as to how to create an adjacency matrix in Python, with weights taken into consideration. I assume it should be relatively simple to create. I have the following matrix... 1 2 3 4 5 6 1 0 15 0 7 10 0 2 15 0 9 11 0 9 3 0 9 0 0 12 7 4 7 11 0 0 8 14 5 10 0 12 8 0 8 6 0 9 7 14 8 0 The numbers 1 through 6 are vertices, and the numbers within are the weights between each neighbouring vertex. For example, edge 1-2 has weight 15. How would I implement this in

Adjacency matrix in Python

≡放荡痞女 提交于 2019-12-03 08:18:00
I cannot find any clear explanation as to how to create an adjacency matrix in Python, with weights taken into consideration. I assume it should be relatively simple to create. I have the following matrix... 1 2 3 4 5 6 1 0 15 0 7 10 0 2 15 0 9 11 0 9 3 0 9 0 0 12 7 4 7 11 0 0 8 14 5 10 0 12 8 0 8 6 0 9 7 14 8 0 The numbers 1 through 6 are vertices, and the numbers within are the weights between each neighbouring vertex. For example, edge 1-2 has weight 15. How would I implement this in python? I just need a simple example, not necessarily using the one I provided. I know how to create an

Generate an Adjacency Matrix for a Weighted Graph

百般思念 提交于 2019-12-03 05:15:41
问题 I am trying to implement Floyd-Warshall Algorithm. To do this it requires me to set up an adjacency matrix of a weighted graph. How would I go about doing this? I know the values and have attached a picture of the weighted graph. I have tried to look for some online examples of this, but I cannot seem to find anything. I understand Floyd-Warshall algorithm I just need help getting it set up so I am able to implement it. Here is one that I have built before, but I didn't have to use specific

Generate an Adjacency Matrix for a Weighted Graph

血红的双手。 提交于 2019-12-02 18:32:10
I am trying to implement Floyd-Warshall Algorithm . To do this it requires me to set up an adjacency matrix of a weighted graph. How would I go about doing this? I know the values and have attached a picture of the weighted graph. I have tried to look for some online examples of this, but I cannot seem to find anything. I understand Floyd-Warshall algorithm I just need help getting it set up so I am able to implement it. Here is one that I have built before, but I didn't have to use specific values. Code: public static void buildAdjMatrix() { for (int i = 0; i < 100; i++) { for (int j = 0; j <

How to create an adjacency matrix from raw data which is non-numeric in nature [duplicate]

泪湿孤枕 提交于 2019-12-01 11:04:00
This question already has an answer here: How to calculate adjacency matrices in R 2 answers An example of the input I am working on is given below: User ID 1 --- Artist 5 User ID 2 --- Artist 1 User ID 3 --- Artist 7 User ID 4 --- Artist 2 User ID 5 --- Artist 3 User ID 1 --- Artist 2 User ID 3 --- Artist 1 The above data is a record of music listened to by users of an app. I would like to generate an adjacency matrix corresponding to the below given example: ARTIST 1 ARTIST 2 ARTIST 3 ARTIST 4 ARTIST 5 ARTIST 6 ARTIST 7 USER ID 1 0 1 0 0 1 0 0 USER ID 2 1 0 0 0 0 0 0 USER ID 3 1 0 0 0 0 0 1

Boggle cheat… erm… solutioning with graphs in R

风格不统一 提交于 2019-12-01 08:47:14
I have seen a few others posts relating to this game, but none of them was centered around the type of algorithm I've opted for, at least not in much details yet. This is also a pretense for me to learn more about graphs (such as with the igraph package). Needless to say, I don't encourage people to cheat in any situation. This is really a learning challenge I set for myself - it's often through those things I learn the most in the end. My plan involves some prep work besides the obvious collection of French dictionary . First big step was to construct an igraph that looks like this,

Boggle cheat… erm… solutioning with graphs in R

别来无恙 提交于 2019-12-01 07:16:38
问题 I have seen a few others posts relating to this game, but none of them was centered around the type of algorithm I've opted for, at least not in much details yet. This is also a pretense for me to learn more about graphs (such as with the igraph package). Needless to say, I don't encourage people to cheat in any situation. This is really a learning challenge I set for myself - it's often through those things I learn the most in the end. My plan involves some prep work besides the obvious

Build a square adjacency matrix from data.frame or data.table

我的梦境 提交于 2019-12-01 04:02:31
I am trying to build a square adjacency matrix from a data.table . Here is a reproducible example of what I already have : require(data.table) require(plyr) require(reshape2) # Build a mock data.table dt <- data.table(Source=as.character(rep(letters[1:3],2)),Target=as.character(rep(letters[4:2],2))) dt # Source Target #1: a d #2: b c #3: c b #4: a d #5: b c #6: c b sry <- ddply(dt, .(Source,Target), summarize, Frequency=length(Source)) sry # Source Target Frequency #1 a d 2 #2 b c 2 #3 c b 2 mtx <- as.matrix(dcast(sry, Source ~ Target, value.var="Frequency", fill=0)) rownames(mtx) <- mtx[,1]

matlab adjacency list to adjacency matrix

不打扰是莪最后的温柔 提交于 2019-12-01 02:00:48
How to convert adjacency list to adjacency matrix via matab For example: Here is the adjacency list(undirected), the third column is the weight. 1 2 3 1 3 4 1 4 5 2 3 4 2 5 8 2 4 7 ++++++++++++++++++++++ that should be converted to: 1 2 3 4 5 1 0 4 5 0 2 3 4 7 8 3 4 7 0 0 4 0 7 0 0 5 0 8 0 0 You can use sparse matrix. Let rows be the first column, cols the second, and s the weight. A = sparse([rows; cols],[cols; rows],[s; s]); If you want to see the matrix. use full() . UPDATE: I made the answer a bit simpler (everything in one line, instead of adding the transposed, and included explanations,