2
$\begingroup$

I have the data for graph nodes as:

graphComponents = {{"blood", "pressur"}, {"harvard", "oxford"}, {"help",  "lower"},
{"oxford", "benefit"}, {"harvard", "benefit"}, {"lower",  "level"}, {"faceoff", "benefit"}
, {"oxford", "faceoff"}, {"harvard", "faceoff"}, {"over", "benefit"}, {"faceoff", "over"},
{"oxford", "over"}, {"harvard", "over"}, {"benefit", "drug"}, 
{"oxford",  "drug"}, {"harvard", "drug"}, {"faceoff", "drug"}, {"fast",  "test"},
{"over", "drug"}, {"test", "test2"}};

Then I want to make a Manipulate to show the communities of the graph:

Manipulate[
  components = graphComponents[[1 ;; L]];
  rawGraph = Graph[#[[1]] <-> #[[2]] & /@ graphComponents[[1 ;; L]]];
  communities = FindGraphCommunities[rawGraph];
  H = HighlightGraph[rawGraph, Subgraph[rawGraph, communities[[i]]]],
  {{L, 15, "Number of Tuples: "}, 5, 20, 5}, 
  {{i, 2, "Cluster number: "}, 1, 3, 1}, 
  LocalizeVariables -> False]

The question is as the value of L changes the number of communities change as well. So the control list for variable i should be updated when L changes. How should this be done?

$\endgroup$
9
  • $\begingroup$ Please consider giving a minimal working example. I'm sure graphComponents can be reduced to a few words. $\endgroup$
    – Öskå
    Commented Jul 17, 2014 at 13:55
  • $\begingroup$ As I need to show the number of communities changing, 19 is the minimum to have three possible outcomes! $\endgroup$
    – Morry
    Commented Jul 17, 2014 at 14:06
  • $\begingroup$ The less code there is, the better it is :) $\endgroup$
    – Öskå
    Commented Jul 17, 2014 at 14:09
  • $\begingroup$ Please don't provide a code that produces endless errors.. :) $\endgroup$
    – Öskå
    Commented Jul 17, 2014 at 14:13
  • $\begingroup$ Corrected.... Thanks $\endgroup$
    – Morry
    Commented Jul 17, 2014 at 14:19

2 Answers 2

3
$\begingroup$

Is this what you want?

graphComponents = 
  {{"blood", "pressur"}, {"harvard", "oxford"}, {"help", "lower"}, {"oxford", "benefit"}, 
   {"harvard", "benefit"}, {"lower", "level"}, {"faceoff", "benefit"}, {"oxford", "faceoff"}, 
   {"harvard", "faceoff"}, {"over", "benefit"}, {"faceoff", "over"}, {"oxford", "over"}, 
   {"harvard", "over"}, {"benefit", "drug"}, {"oxford", "drug"}, {"harvard", "drug"}, 
   {"faceoff", "drug"}, {"fast", "test"}, {"over", "drug"}, {"test", "test2"}};
com =
  {{{"harvard", "oxford", "benefit"}, {"blood", "pressur"}, {"help", "lower"}}, 
   {{"harvard", "oxford", "benefit","faceoff", "over"}, {"help", "lower", "level"}, {"blood", "pressur"}}, 
   {{"harvard", "oxford", "benefit", "faceoff", "over", "drug"}, {"help", "lower", "level"}, {"fast", "test", "test2"}, {"blood", "pressur"}}};

Manipulate[HighlightGraph[rawGraph[L], Subgraph[rawGraph[L], com[[i]]]], 
  {{L, 20, "Number of Tuples: "}, {5, 10, 20}}, {{i, 2, "Cluster number: "}, 1, 3, 1}, 
  Initialization :> 
    (rawGraph[n_] := Graph[#[[1]] <-> #[[2]] & /@ graphComponents[[1 ;; n]]];)]

enter image description here

$\endgroup$
3
  • $\begingroup$ This is not good as I cannot generate the com object for huge list of elements! $\endgroup$
    – Morry
    Commented Jul 17, 2014 at 23:07
  • $\begingroup$ @Morry Well, com = FindGraphCommunities[rawGraph[#]]&/@{5,10,20};. Put it in where ever you want. $\endgroup$
    – Öskå
    Commented Jul 17, 2014 at 23:30
  • $\begingroup$ The fact is I have a huge data and the L may have many possibilities.... This is going to be a function...I do not want the to compute com for every possibility! $\endgroup$
    – Morry
    Commented Jul 18, 2014 at 0:01
2
$\begingroup$

You could use Dynamic to update i:

graphComponents = {{"blood", "pressur"}, {"harvard", 
    "oxford"}, {"help", "lower"}, {"oxford", "benefit"}, {"harvard", 
    "benefit"}, {"lower", "level"}, {"faceoff", "benefit"}, {"oxford",
     "faceoff"}, {"harvard", "faceoff"}, {"over", 
    "benefit"}, {"faceoff", "over"}, {"oxford", "over"}, {"harvard", 
    "over"}, {"benefit", "drug"}, {"oxford", "drug"}, {"harvard", 
    "drug"}, {"faceoff", "drug"}, {"fast", "test"}, {"over", 
    "drug"}, {"test", "test2"}};

l = 3;
Manipulate[components = graphComponents[[1 ;; L]];
 rawGraph = Graph[#[[1]] <-> #[[2]] & /@ graphComponents[[1 ;; L]]];
 communities = FindGraphCommunities[rawGraph];
 l = Length[communities];
 i = Min[l, i];
 H = HighlightGraph[rawGraph, 
   Subgraph[rawGraph, communities[[i]]]], {{L, 15, 
   "Number of Tuples: "}, 5, 20, 5}, {{i, 2, "Cluster number: "}, 1, 
  Dynamic[l], 1}, LocalizeVariables -> False]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.