Given a database in matrix format:
SeedRandom[6]; mat = RandomInteger[5, {27, 30}]; mat[[1, All]] = {"", a1, a2, a3, a4, a5, b1, b2, b3, b4, b5, c1, c2, c3, c4, c5, d1, d2, d3, d4, d5, afd1, afd2, bfd1, bfd2, cfd1, cfd2, dfd1, dfd2, TD}; mat[[All, 1]] = {"", a1, a2, a3, a4, a5, b1, b2, b3, b4, b5, c1, c2, c3, c4, c5, d1, d2, d3, d4, d5, aT, bT, cT, dT, VA, TS}; Each row and column has a name, e.g., a1, a2, .... Suppose the following operations on mat.
- Drop the columns
{a1, a3, b1, b2, c4, c5, d2, d5}and the rows with the same names. - Create a weighted directed graph using the columns
{a2, a4, a5, b3, b4, b5, c1, c2, c3, d1, d3, d4}and the rows with the same names.
My question is not about the operations referred to in 1 and 2. I like to know how to keep the linkage between a string vertex name and a numeric vertex name. String names for the list in 2 are {a2, a4, a5, b3, b4, b5, c1, c2, c3, d1, d3, d4} and the associated numeric names are {2, 4, 5, 8, 9, 10, 11, 12, 13, 16, 18, 19}.
Because my original matrix is large, with the operation in item 1, I lose the linkage between numeric and string names, which I need in later stages of output formatting. For example, I can easily find Cliques with numeric vertex names but I need to know the string names linked to the numeric vertices.
Any suggestion?
EDIT 1
Suppose that
mat1 = Drop[Take[mat,21,21], {3,15},{3,15}]; MatrixForm@mat1 Using mat1, a directed graph given below is constructed by:
select[matrix_, lB_, uB_] := matrix*Map[Boole[lB <= # <= uB] &, matrix,{-1}]; (*due to @KGLR*) mat2 = Abs[Inverse[Drop[mat1, 1, 1]]] // N; sa = SparseArray[select[mat2, .1, .6]]; weightedG = Graph[sa["NonzeroPositions"], EdgeWeight -> sa["NonzeroValues"],DirectedEdges -> True]; GraphPlot[weightedG] Even if I use VertexLabels->"Name" in Graph[...], the names (vertex numbers do not appear) on the graph. Most important of all, I like to use the column names a1, c5, d1,... as vertex names.
How can I make the entire process described above an automatic procedure? That is to say: when I plot the directed graph after row/column elimination, I like to keep track of the vertex string names and see those names on the final graph.
A more difficult task is: assigning the string column names to group names such as
G1={a1,c5,d1}, G2={d2,d3}, G3={d4,d5}and zoom in the part of the graph including only selected groups such as{G1, G3}, meaning thatgroup 2G2is excluded from the final digraph.







names) is duplicate-free, then you can create mappings:nameToIndex = AssociationThread[names, Range@Length@names]and/orindexToName = AssociationThread[Range@Length@names, names]? $\endgroup$