create a random matrix that satisfies specific criteria (graph theory)

조회 수: 2 (최근 30일)
Georgette Argiris
Georgette Argiris 2022년 9월 29일
댓글: Matt J 2022년 9월 29일
Hello everyone, I have a 264 x 264 undirected (binary) adjacency matrix on which I calculate the nodal degree (or the number of edges connected to each node), which results in a 264 x 1 vector indicating the "degrees", or number of edges/connections, per node. Now what I would like to do is create a series of random matrices that have the same number of nodes with connections and nodal degree as the original matrix. As it will be random, it shouldn't matter what nodes those are, just that the overall nodal degree count is maintained. For instance, if I take a count of the original 264 x 1 vector, I have 79 nodes with no edges/connections, 58 nodes with 1 edge/connection, 23 nodes with 2 edges/connections, 22 nodes with 3 edges/connections, etc. So I need to generate a matrix that satisfies these criteria. I imagine that the code might be rather extensive to achieve this in MATLAB, but I would appreciate any guidance on this issue. Thank you so very much.

답변 (1개)

Matt J
Matt J 2022년 9월 29일
편집: Matt J 2022년 9월 29일
Just permute the rows and columns of the original adjacency matrix, A,
[~,is]=sort(rand(264),2);
for k=1:264
A(k,:)=A(k,is(k,:));
end
A=A(randperm(264),:);
  댓글 수: 2
Georgette Argiris
Georgette Argiris 2022년 9월 29일
Hi Matt, thank you very much for your quick response. I might be wrong, but it doesn't seem to solve my issue because nodal degree changes. Sorry for the crude code...I hope it's understandable:
A = randi([0 1], 264, 264);
deg1 = sort(sum(A)); %gives sorted nodal degree
A2 = A; %just to compare output for your code below
[~,is]=sort(rand(264),2);
for k=1:264
A2(k,:)=A2(k,is(k ,:));
end
A2 = A2(randperm(264),:);
deg2 = sort(sum(A2));
min(deg1 == deg2) %this should be 1 as the nodal degree vector should be %the same
Matt J
Matt J 2022년 9월 29일
Here's another possibility,
p=randperm(264);
A2=A(p,p);
though I don't know if this spans the full space of possible solutions.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by