오늘의 인기 글
최근 글
최근 댓글
Today
Total
05-09 00:00
관리 메뉴

우노

[Matrix] MATLAB을 사용한 정방형 Sparse Matrix 만들기 본문

Data/Graph & Matrix

[Matrix] MATLAB을 사용한 정방형 Sparse Matrix 만들기

운호(Noah) 2020. 7. 6. 11:04
SCALE=15
edgefactor=32
  %% Set number of vertices.
  N = 2^SCALE;
  %% Set number of edges.
  M = edgefactor * N;
  %% Set initiator probabilities.
  [A, B, C] = deal (0.57, 0.19, 0.19);
  %% Create index arrays.
  ijw = ones (3, M);
  %% Loop over each order of bit.
  ab = A + B;
  c_norm = C/(1 - (A + B));
  a_norm = A/(A + B);
  for ib = 1:SCALE,
    %% Compare with probabilities and set bits of indices.
    ii_bit = rand (1, M) > ab;
    jj_bit = rand (1, M) > ( c_norm * ii_bit + a_norm * not (ii_bit) );
    ijw(1:2,:) = ijw(1:2,:) + 2^(ib-1) * [ii_bit; jj_bit];
  end
  %% Generate weights
  ijw(3,:) = unifrnd(0, 1, 1, M);
  %% Permute vertex labels
  p = randperm (N);
  ijw(1:2,:) = p(ijw(1:2,:));
  %% Permute the edge list (shuffle)
  p = randperm (M);
  ijw = ijw(:, p);
  %% Adjust to zero-based labels.
  ijw(1:2,:) = ijw(1:2,:) - 1;
jiw = transpose(ijw);
writematrix(jiw,'텍스트명.txt','Delimiter',' ')
  • Kronecker Generator 알고리즘 기반

    • SCALE = 노드 수를 결정하는 변수
    • edgefactor = 엣지 수를 결정하는 변수
    • N = 노드 수(원하는 정방형 메트릭스의 행렬 크기)
    • M = 엣지 수(요소수, number of nonzero)
    • Density = M / N^2
Comments