Skip to main content
1 of 6
Tugrul Temel
  • 6.4k
  • 3
  • 15
  • 35

How can I generate a tailor-made directed graph from a given matrix

Given a matrix mat:

mat = {{1, 5, 2, 6}, {4, 3, 4, 1}, {0, 1, 4, 0}, {2, 1, 3, 4}}; 

I want to apply the following conditions to generate various directed graphs.

  1. Denote columns by A, B, C, D
  2. Choose a column, say A (1st column), and find the binary relations between A and those cells with a number higher than 25% (threshold) of the respective column total. For example, for column A, BA and DA will be selected as the ratios (4/7 and 2/7) will be higher than 25%, respectively.
  3. Then choose column B because we obtained BA at step 2 and repeat the same procedure at step 2 to find those relations above 25% of the total of column B; next do the same operation for the second relation obtained in step 2, which is DA.
  4. Next, choose column C and follow the same operations in step 2 end so on...
  5. Generate a directed graph of all the significant relations obtained from the matrix mat.

After completing the visits to all of the columns, then apply the same steps (1-4 above) to the transpose of the matrix mat to generate another directed graph of the resulting relations.

I want to generate:

  1. two directed graphs: one for column-wise operation (subgraph1) and another for row-wise operation (subgraph2) and
  2. another directed graph combining the two directed graphs in (1) with different colors to differentiate the column-wise and row-wise graphs.

I like to produce these directed graphs using a function f[mat,th] for automated generation of the directed graphs for mat and a given threshold th, and another function g[subgraph1,subgraph2]to combine the individual graphs.

Tugrul Temel
  • 6.4k
  • 3
  • 15
  • 35