adjacency-matrix

R - How to make 2 adjacency matrices compatible to eachother

跟風遠走 提交于 2020-01-04 05:04:34
问题 I have 2 adjacency matrices with different dimesnsions. I want to make their dimensions compatible so that when I replace any column of one matrix from any column of second matrix then I don't get the following error message: Error: number of items to replace is not a multiple of replacement length Here are my matrices: > mat1 Tommy Roy Addy Sam Tommy 0 1 0 -1 Roy -1 -1 1 0 Addy 1 0 -1 0 Sam 0 0 -1 1 > mat2 Mike Roy Addy Sam Dan Mike 0 1 0 -1 0 Roy -1 -1 1 0 1 Addy 1 0 -1 0 -1 Sam 0 0 -1 1 0

Spatial weights: asymmetric adjacency matrix?

情到浓时终转凉″ 提交于 2020-01-04 04:27:05
问题 I am creating an adjacency matrix to do spatial analysis in R. The data are all counties in the continental US. I've got the counties spatial polygons from US Census Tiger files. I am able to create the neighbors list, and it is symmetric. But when I convert that to an adjacency matrix it is not symmetric. This is a problem because my goal is to run a spatial autologistic model using ngspatial::autologistic , and I get an error that I must supply a symmetric binary adjacency matrix. Here is

how to convert any arbitrary list to an adjaceny matrix in python?

六眼飞鱼酱① 提交于 2020-01-03 05:25:08
问题 I have 684 nodes and its corresponding temperature data.I calculated the correlation between all nodes and then reshape correlation list in adjacency matrix for further calculation. But after introducing lag in correlation I am not able to reshape the list in adjacency matrix. I am able to reshape the list to adjacency matrix without lag but having problem when introducing the lag. I tried corr_k= [] for k in range(4): for i in range(len(lat)): for j in range(len(lon)): for m in range(len(lat

matlab adjacency list to adjacency matrix

时光毁灭记忆、已成空白 提交于 2019-12-30 07:51:27
问题 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 回答1: 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

matlab adjacency list to adjacency matrix

拜拜、爱过 提交于 2019-12-30 07:51:12
问题 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 回答1: 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

DFS and BFS with adjacency matrix counted in Java

泄露秘密 提交于 2019-12-25 01:32:34
问题 Currently trying to build a program that can implement both DFS and BFS in Java by taking in an adjacency matrix from a file and printing out the following info: order that vertices are first encountered, order that vertices become dead ends, number of components, and the tree edges. Here is my code: import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Scanner; public class ProjectDriver { public static int count; public static void main

Mapping dataframe column values to a n by n matrix

纵饮孤独 提交于 2019-12-24 21:23:43
问题 I'm trying to map column values of a data.frame object (consisting of large number of bilateral trade data among 161 countries) to a 161 x 161 adjacency matrix (also of data.frame class) such that each cell represents the dyadic trade flows between any two countries. The data looks like this # load the data from dropbox folder library(foreign) example_data <- read.csv("https://www.dropbox.com/s/hf0ga22tdjlvdvr/example_data.csv?dl=1") head(example_data, n = 10) rid pid TradeValue 1 2 3 500 2 2

R: Update adjacency matrix/data frame using pairwise combinations

半城伤御伤魂 提交于 2019-12-24 20:46:09
问题 Question Let's say I have this dataframe: # mock data set df.size = 10 cluster.id<- sample(c(1:5), df.size, replace = TRUE) letters <- sample(LETTERS[1:5], df.size, replace = TRUE) test.set <- data.frame(cluster.id, letters) Will be something like: cluster.id letters <int> <fctr> 1 5 A 2 4 B 3 4 B 4 3 A 5 3 E 6 3 D 7 3 C 8 2 A 9 2 E 10 1 A Now I want to group these per cluster.id and see what kind of letters I can find within a cluster, so for example cluster 3 contains the letters A,E,D,C .

How to avoid nested for loops in matlab?

别说谁变了你拦得住时间么 提交于 2019-12-24 16:52:36
问题 I am constructing an adjacency list based on intensity difference of the pixels in an image. The code snippet in Matlab is as follows: m=1; len = size(cur_label, 1); for j=1:len for k=1:len if(k~=j) % avoiding diagonal elements intensity_diff = abs(indx_intensity(j)-indx_intensity(k)); %intensity defference of two pixels. if intensity_diff<=10 % difference thresholded by 10 adj_list(m, 1) = j; % storing the vertices of the edge adj_list(m, 2) = k; m = m+1; end end end end y = sparse(adj_list(

How to avoid nested for loops in matlab?

£可爱£侵袭症+ 提交于 2019-12-24 16:51:18
问题 I am constructing an adjacency list based on intensity difference of the pixels in an image. The code snippet in Matlab is as follows: m=1; len = size(cur_label, 1); for j=1:len for k=1:len if(k~=j) % avoiding diagonal elements intensity_diff = abs(indx_intensity(j)-indx_intensity(k)); %intensity defference of two pixels. if intensity_diff<=10 % difference thresholded by 10 adj_list(m, 1) = j; % storing the vertices of the edge adj_list(m, 2) = k; m = m+1; end end end end y = sparse(adj_list(