18
$\begingroup$

Problem

I have a very large graph of 65,536 vertices. GraphPlot yields:

enter image description here

But the vertices are too dense to see in any detail, and attempting to use any of the on-the-fly image options leads to Mathematica hanging.

First, I decided to try removing all vertex graphics (leaving only edges), to "thin" the graph. While trying different things, I improperly set VertexStyle->None. This threw a load of errors (probably 65,536 of them), but achieved the effect I desired, so I took a screenshot, which you can see below.

enter image description here

To get those zoomed views, I had to set ImageSize->{192000,108000}—a hundred times my screen resolution—and take screenshots at the regions, as exporting was not possible (more on this below). To give a sense of how unwieldy the size of this image was, it took me 10 minutes to find the cycle labeled C3; I ended up taking a screenshot of the overall view, drawing a horizontal line from C3 to C2, and using this latitudinal reference to start at C2 and scroll horizontally until I hit C3.

Furthermore, attempting to export this image via

Export["output.jpg", %29, "JPEG"]

resulted in

Rasterize::bigraster: Not enough memory available to rasterize Graphics expression. >>

for JPG, GIF, BMP, and PNG. (I did try restarting Mathematica to clear some memory, as another post suggested.)

It did export as an SVG, and Chrome and Internet Explorer was able to render the zoomed-out view, but would hang or crash upon attempting to zoom in.

I thought, "Well, all this is an independent issue I'll have to solve eventually. But meanwhile, I also need to add vertex labels." So, I went ahead and enabled VertexLabeling->True. As you can anticipate, the labels were all atop one another, even at 200 times my screen resolution, ImageSize->{384000,216000}:

enter image description here

I'm not sure if it's the introduction of VertexLabeling or the sheer size of the image (or both), but the image was also wrapped in a

A very large output was generated. Here is a sample of it:

box, which didn't appear before. And the image was so gigantic, that it appeared to have "disappeared" into the right and bottom borders of the cell, such that the familiar Show more... button was not even accessible, as odd as that might seem.

Question

How can I render and / or manipulate this graph so that I can have a fully detailed, exported view (BMP, JPG, GIF, PNG), including vertex labels, that anyone can open, pan, and zoom?

I'm actively experimenting, but having to wait 45-60 seconds for each trial to finish makes the process very painful. Not all vertices actually need to be labeled, if in the end, I can use VertexLabeling->TrueQ to label just some important nodes, and there's a way to display a summary label, e.g. 347 nodes, for a count of unimportant nodes between important ones. (But that's an entirely separate challenge to tackle.) In the worst case, I'm thinking I'll have to manually segment the graph into several pieces, i.e. programmatically obtain, say, all vertices in the left half of the C1 structure, and have several plots. However, this would be extremely inconvenient, as later on I'll want to inject "special" edges that connect the separate "islands."

Is there some other way to draw or export this graph I may not know? Whether it be altering drawing rules, altering node or label graphics, or employing some segment-by-segment rendering technique.

Code & Background

In case it's helpful to replicate the issues I'm having, here's the (surprisingly concise) code:

  Hex[exp_] := FromDigits[exp, 16];
  LByte[exp_] := BitAnd[exp, Hex@"00ff"];
  HByte[exp_] := BitAnd[exp, Hex@"ff00"]~BitShiftRight~8;
  PRNG[v_] := Module[{L5, H5, v1, v2, carry},
    L5 = LByte@v*5;
    H5 = HByte@v*5;
    v1 = LByte@H5 + HByte@L5 + 1;
    carry = HByte@v1~BitGet~0;
    v2 = BitShiftLeft[LByte@v1, 8] + LByte@L5;
    Mod[v2 + Hex@"0011" + carry, Hex@"ffff" + 1]
    ];
  mappings = # -> PRNG@# & /@ Range[0, Hex@"ffff"];
  GraphPlot[mappings]

To give some background, I'm studying the geometry of a 16-bit pseudo-random number generator, i.e. a function that maps a number $[0..65535]$ to another number $[0..65535]$. The code above almost matches a simple LCG (linear congruential generator) by the formula $$f(x)=5x+273\mod{65536}$$ except the pesky carry bit sometimes makes it $274$ (for 766 cases, to be precise).

Also, I'm running Mathematica 9.0.1.0. If there were a solution available only in version 10, I would strongly consider an upgrade.


EDIT: I've also run the above on Mathematica 10.4, unfortunately with the same results.

$\endgroup$
6
  • $\begingroup$ I don't have time just now to give a detailed answer specific to your question, but regarding the version: It would make a huge difference, potentially, if you upgrade to v10. There are significant changes to Graphs, Combinatorica, etc. in v10. See: wolfram.com/mathematica/new-in-10/enhanced-graphs-and-networks $\endgroup$ Commented Apr 24, 2016 at 23:01
  • $\begingroup$ Thanks for the advice, @KellenMyers. I finally upgraded to v10 and reproduced my steps, but I'm still unable to export an image. Perhaps another solution to my problem would be the answer to, "Is there a way to get Mathematica to export chunks at a time and stitch them together afterward, so as not to hit a memory limit?" $\endgroup$ Commented Apr 30, 2016 at 3:23
  • $\begingroup$ Have you tried other vector formats? PDF? Is there a limit in terms of elements where your approach works? Do you need to run all trials at full complexity? $\endgroup$
    – Yves Klett
    Commented Apr 30, 2016 at 8:21
  • $\begingroup$ Hi @YvesKlett, I did. In MMA 9.x, the PDF exported quickly but was blank upon opening. (I zoomed in and scrolled around quite a bit, too, in case the points drawn were microscopic and edges invisibly thin.) In MMA 10.x I get the same behavior, except it took over half an hour to produce the PDF. The size of the PDF is 3.32 MB, so there's definitely something in there. I can upload the PDF if it would be of interest. $\endgroup$ Commented Apr 30, 2016 at 22:29
  • $\begingroup$ Uploading may help, as well as adding the exact code you used. $\endgroup$
    – Yves Klett
    Commented May 1, 2016 at 7:55

1 Answer 1

2
$\begingroup$

(Incomplete answer containing only references.)

Is there a way to get Mathematica to export chunks at a time and stitch them together afterward, so as not to hit a memory limit?

Yes, I already published (see "EDIT 4" section) such a technique on this site. Another method is suggested by Vitaliy Kaurov (search for "3dImagePartitionExport.nb" in this Wolfram Community thread).

$\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.