Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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?

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

2 Answers 2

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

share|improve this answer
    
This is not good as I cannot generate the com object for huge list of elements! –  Morry Jul 17 at 23:07
    
@Morry Well, com = FindGraphCommunities[rawGraph[#]]&/@{5,10,20};. Put it in where ever you want. –  Öskå Jul 17 at 23:30
    
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! –  Morry Jul 18 at 0:01

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]
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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