Questions tagged [adjacency-matrix]

A means of representing which vertices (or nodes) of a graph are adjacent to which other vertices.

The adjacency matrix of a finite graph G on n vertices is the n×n matrix where the non-diagonal entry aij is the number of edges from vertex i to vertex j, and the diagonal entry aii, depending on the convention, is either once or twice the number of edges (loops) from vertex i to itself.

Undirected graphs often use the latter convention of counting loops twice, whereas directed graphs typically use the former convention.
There exists a unique adjacency matrix for each isomorphism class of graphs (up to permuting rows and columns), and it is not the adjacency matrix of any other isomorphism class of graphs.
In the special case of a finite simple graph, the adjacency matrix is a (0,1)-matrix with zeros on its diagonal.

If the graph is undirected, the adjacency matrix is symmetric.

The relationship between a graph and the eigenvalues and eigenvectors of its adjacency matrix is studied in spectral graph theory.

http://en.wikipedia.org/wiki/Adjacency_matrix

900 questions
5
votes
2 answers

Calculating the trace of a matrix to the power k

I need to calculate the trace of a matrix to the power of 3 and 4 and it needs to be as fast as it can get. The matrix here is an adjacency matrix of a simple graph, therefore it is square, symmetric, its entries are always 1 or 0 and the diagonal…
5
votes
1 answer

Construct graph connectivity matrices in COO format

I have faced the following subtask while working with graph data: I need to construct graph connectivity matrices in COO format for graphs with several fully-connected components from arrays of "border" indices. As an example, given array borders =…
Oiale
  • 434
  • 4
  • 17
5
votes
2 answers

Pytorch Geometric sparse adjacency matrix to edge index tensor

My data object has the data.adj_t parameter, giving me the sparse adjacency matrix. How can I get the edge_index tensor of size [2, num_edges] from this?
Qubix
  • 4,161
  • 7
  • 36
  • 73
5
votes
1 answer

convert Pandas dataframe into adjacency matrix

I have a Pandas dataframe (930 rows × 50 columns) that looks like this: index Keyword A Keyword B Keyword c Page 1 1 3 1 Page 2 4 0 2 Page 3 0 1 1 I would like to convert it into an adjacency Matrix / Weighted Graph, where each…
Clemclem
  • 81
  • 5
5
votes
1 answer

Construction of an adjacency matrix through staggered replication of pages of a 3D array

Background I am trying to model a system that can change its configurations each time step. The variety of configurations is known in advance and does not depend on the time step. Transitions are allowed between certain configurations and forbidden…
Dev-iL
  • 23,742
  • 7
  • 57
  • 99
5
votes
2 answers

multiplicative distance between graph nodes

I want to find the distance between all nodes in a graph, but rather than summing the edge weights I want to multiply them. As an example: library(igraph) # create a weighted adjacency matrix mx <- structure(c(0, 0.5, 0, 0, 0, 0.5, 0, 0.5, 0.5, 0,…
flee
  • 1,253
  • 3
  • 17
  • 34
5
votes
2 answers

Generating all possible n*n binary matrix in python

I'm playing with graphs and python, and I'm trying to test some code on all the possible square matrix that represent an adjacency matrix (i.e. matrix with 0 and 1). We know that there are 2^{n^2} possible matrix of nxn. What's the best code for…
asdf
  • 685
  • 7
  • 23
5
votes
1 answer

Spatial weights: asymmetric adjacency matrix?

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…
5
votes
1 answer

R create adjacency matrix according to columns from data.frame

I have a data.frame for 10 videos, and each column is a tag indicating the category of the video. For example, the data will look like this: data <- data.frame(id=paste0("r", 1:10), A=sample(0:1,10,TRUE), B=sample(0:1,10,TRUE),…
Boxuan
  • 4,937
  • 6
  • 37
  • 73
5
votes
1 answer

How to implement an adjacency matrix in java producing hamilton cycles

I am trying to implement an adjacency matrix in java that will produce an output for a Hamiltonian cycle, which can then be solved with different algorithms such as kruskurals, djikstras and the 2opt approach. i know that i need a 2d array but i…
alchemey89
  • 485
  • 2
  • 6
  • 8
5
votes
2 answers

How to create a symmetric matrix of 1's and 0's with constant row and column sum

I'm trying to find an elegant algorithm for creating an N x N matrix of 1's and 0's, under the restrictions: each row and each column must sum to Q (to be picked freely) the diagonal must be 0's the matrix must be symmetrical. It is not strictly…
Kaare
  • 531
  • 1
  • 7
  • 26
5
votes
4 answers

MATLAB identify adjacient regions in 3D image

I have a 3D image, divided into contiguous regions where each voxel has the same value. The value assigned to this region is unique to the region and serves as a label. The example image below describes the 2D case: 1 1 1 1 2 2 2 1 1 1 2 2…
Lisa
  • 3,365
  • 3
  • 19
  • 30
5
votes
1 answer

Time Complexity of breadth first search with adjacency matrix representation?

In bfs we have to look up each node and for each node we have to look all elements of row.Doesn't this require O(V^2)(number of elements in adjacency matrix) time and hence for adjacency matrix shouldn't total time be O(V^2+E).
nikhil_vyas
  • 513
  • 5
  • 16
5
votes
1 answer

Computation of Path Matrix from the adjacency Matrix

I am learning the way of computing Path Matrix from Adjacency Matrix(say AM1). A Path Matrix of a graph G with n vertices is a Boolean n*n matrix whose elements can be defined as: p[i][j]=1(if there is a path from i to j) …
poorvank
  • 7,524
  • 19
  • 60
  • 102
5
votes
2 answers

The fastest way to calculate eigenvalues of large matrices

Until now I used numpy.linalg.eigvals to calculate the eigenvalues of quadratic matrices with at least 1000 rows/columns and, for most cases, about a fifth of its entries non-zero (I don't know if that should be considered a sparse matrix). I found…
alice
  • 254
  • 2
  • 4
  • 9
1 2
3
59 60