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.

(MMA 9.0.0 on Mac OS/X 10.8)

Please consider the following snippet (this is as SMALL as I could make it -- my attempts at making a smaller repro-case eliminated the effect that I am investigating)

Manipulate[
 With[{img = 
    Image@RandomVariate[
      NormalDistribution[0.5 + p - p, 0.25], {25, 25}]},
  With[{grf =
     (* comment the following line to stop
     the double-evaluation *)
     MorphologicalGraph@
      ColorNegate@
       Image@
        WatershedComponents@
         Binarize@
          img},
   GraphicsGrid[{{img, grf}}]
   ]],
 (* click the + on the controller, wait a second,
 and you will see double-evaluation *)
 {p, 1, 10, 1, 
  Appearance -> "Open"}]

In the interactive block that results, press the + and - keys to advance or retract the value of p. If you are patient, on each press of + or -, after a delay of 1 second or so, the entire display will evaluate a second time. This behavior is rather obvious and jarring since the generated image and graph are random.

If you remove the call of MorphologicalGraph, the behavior does not happen. Somehow, MorphologicalGraph seems to be (hypothetically) causing an extra evaluation step after a 'settling time'.

I'd like to at least understand this behavior if not get rid of it.

share|improve this question
1  
I think this is an attempt of Manipulate to first calculate the result quickly, then calculate it accurately, thus having both responsiveness and accuracy. It's related to options such as PerformanceGoal and ControlActive but I can't find how to turn it off right now. Hope this info will help you search for the solution. Then there's also BlockRandom and SeedRandom for getting reproducible results from Random* functions. –  Szabolcs Feb 15 '13 at 16:20
1  
See this too please: mathematica.stackexchange.com/questions/8373/… –  Szabolcs Feb 15 '13 at 16:23
1  
2  
I'm not sure if this is a bug or not. Here's a more minimal test case: Manipulate[Column[{Pause[0.2]; x, $PerformanceGoal, $ControlActiveSetting}], {x, 0, 1}, ContinuousAction -> False]. ContinuousAction -> False fixes double evaluation when dragging the slider, but not when clicking the +/- buttons. The behaviour is the same in 8. –  Szabolcs Feb 15 '13 at 16:32
add comment

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.