1
$\begingroup$

I'm doing a lot of simulation runs of graphs in order to compare the simulated data with the data of a real world network (links among websites), according to my calculations I have to run close to a 1000 simulations in order to get enough significance.

The simulations code is something on the line of:

<<IGraphM`
simrun1=Table[IGBarabasiAlbertGame[1032, 2], 1000];
simrun2=TableIGStaticPowerLawGame [1032,144, 2.889], 1000];

But it can be closelly approximated by:

simrun=Table[RandomGraph[BarabasiAlbertGraphDistribution[1032, 2]], 1000]

If I suppress the output using ; in the end of the lines. The problem is that I need this data to continue to be stored in the notebook after I close the nb file, so using suppressed output isn't working well for me. I really need a way for the output to persist after I close the notebook.

The only way I could find to do it, was to evaluate the code without the suppressed output and to manually transform the output into an input cell, but the only way I found to do it was to take out the ; at the end of the lines.

But this creates another problem, since it will render 2000 graphs. Using AbsoluteTimming each line spends about 0,2s on total computation time, but the the rendering and formatting of the notebook afterwards ranges from 5 to 30 minutes. It is an awful a lot of time, and in the end I have little or no use to this visualization.

I just need the graph objects in order to map functions that take measures on them, like local, global and mean clustering coefficient, mean distance, vertex degree, number of edges, centrality measures for each node, and so on. So is there a way to generate these graphs and store on a way that would persist after closing the notebook without having to render the output without wasting so much time with rendering?

Thanks in advance for your answers.

$\endgroup$
14
  • 5
    $\begingroup$ Don't display them. It doesn't sound like there's a need to. $\endgroup$
    – Michael E2
    Commented Apr 27, 2017 at 1:25
  • 2
    $\begingroup$ Maybe DumpSave[] and Get[] would help. $\endgroup$
    – Michael E2
    Commented Apr 27, 2017 at 2:09
  • 2
    $\begingroup$ could you give small version of simulation you are doing? In general, graph analysis doesn't need to see output. $\endgroup$
    – halmir
    Commented Apr 27, 2017 at 13:22
  • 1
    $\begingroup$ so you want to store Table[RandomGraph[BarabasiAlbertGraphDistribution[1032, 2]], 1000]? $\endgroup$
    – halmir
    Commented Apr 28, 2017 at 0:39
  • 1
    $\begingroup$ and GraphPropertyDistribution might be helpful .. for example, dist = GraphPropertyDistribution[GlobalClusteringCoefficient[g], g [Distributed] BarabasiAlbertGraphDistribution[1032, 2]]; RandomVariate[dist, 1000] or Mean[dist] $\endgroup$
    – halmir
    Commented Apr 28, 2017 at 0:45

1 Answer 1

1
$\begingroup$

So is there a way to generate these graphs and store on a way that would persist after closing the notebook without having to render the output without wasting so much time with rendering?

This question isn't really about graphs. It could be about any other kind of data. The answer is that if you are going to need the data in a later session, then you should export it to a file.

myGraphs = Table[..., {1000}];

Export["graphs.mx", myGraphs]

This will write the result into graphs.mx, and you can later re-import it using

myGraphs = Import["graphs.mx"];

The MX format has limited compatibility. It cannot be read in earlier versions or on different platforms (32 vs 64 bit).

When compatibility is a concern, I usually Compress the data and export it as "String": https://mathematica.stackexchange.com/a/1960/12


Generally, I recommend exporting to a separate file. If you are in a hurry or for some reason it is really much better to store everything in the notebook, you can use the method I blogged about here:

(Earlier version also shown here.)

I do not recommend this for data larger than a few megabytes.

$\endgroup$
3
  • $\begingroup$ Ow! @Szabolcs, thanks a lot for your reply. This is the first time I've seen this explained on a way that makes sense to someone new to coding. I've already thought that I had to save a lot of the stuff I do (functions, simulations, etc.) on other files, I even tried to make sense of the documentation on Files, Streams, and External Operations, but it ended up more lost than before reading it. You finally put it on a way that is easy to understand. $\endgroup$
    – nicholas80
    Commented May 4, 2017 at 4:19
  • $\begingroup$ following on this, to add stuff to the .mx file I just need to use PutAppend, right? If I create an .mx file with multiple variables for simulation runs or with multiple functions when I use Import["graphs.mx"], do I import the whole file, or do I need to Import each variable? $\endgroup$
    – nicholas80
    Commented May 4, 2017 at 4:20
  • $\begingroup$ For a "simple" graph, I wonder if just saving the adjacency matrix might be better? Additionally, since it seems that the user doesn't need to display the graphs, adding GraphLayout -> None might be useful. $\endgroup$ Commented May 11, 2017 at 13:23

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.