Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plotter: add HeatMap and Contour implementation #15

Merged
merged 2 commits into from
Feb 24, 2015
Merged

plotter: add HeatMap and Contour implementation #15

merged 2 commits into from
Feb 24, 2015

Conversation

kortschak
Copy link
Member

No description provided.


// GlyphBoxes implements the GlyphBoxes method
// of the plot.GlyphBoxer interface.
func (h *HeatMap) GlyphBoxes(plt *plot.Plot) []plot.GlyphBox {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not currently do what I want for this type, but is blocked on #14.

@kortschak kortschak force-pushed the heat branch 2 times, most recently from 6c2c053 to 48aaca3 Compare February 12, 2015 02:52
@eaburns
Copy link
Member

eaburns commented Feb 12, 2015

Not sure who's supposed to be reviewing this. We should probably assign people so that it's clear. If it's supposed to be me then I will probably have to wait until this weekend so that I can really look at it. Hope that's OK.

@kortschak
Copy link
Member Author

That's fine. I have a partner for it which may go in the same PR - contours. I'm happy to accept any reviewers though.

@kortschak
Copy link
Member Author

This is now a WIP.

Running go test generates a small svg file that shows what it looks like so far. TODO is actually making the Contour plotter and sorting out level shading (the majority of the contour.go code is needed for that).

@vladimir-ch I have the GridMesh implementation and I can change this to a GridFunc by rearranging the r/c order. PTAL and let me know.

@kortschak kortschak force-pushed the heat branch 6 times, most recently from 1a55d31 to a2d4617 Compare February 14, 2015 10:45
@kortschak kortschak mentioned this pull request Feb 14, 2015
@kortschak kortschak force-pushed the heat branch 4 times, most recently from c5fd278 to 27c6e60 Compare February 15, 2015 06:31
@kortschak
Copy link
Member Author

I've decided the GridFunc approach is nicer and more general. The cost of plugging a matrix in is not onerous and we can provide a helper type if needed.

@egonelbre
Copy link

I did a quick mockup of a way to avoid list.List and code that should be simpler to understand and faster: http://play.golang.org/p/YiLMQ2tdIP.

@kortschak
Copy link
Member Author

kortschak commented Feb 15, 2015 via email

@kortschak
Copy link
Member Author

kortschak commented Feb 15, 2015 via email

@egonelbre
Copy link

Indeed using points instead of lines makes it much simpler. This is my first time writing this kind of code, I'm not quite sure what you mean by "loop excision" -- although I would expect that it can be incorporated.

Current progress so far: https://gist.github.com/egonelbre/5770469d6d7b955a4559. It still has some bugs, but can output something that looks like a contour graph :D.

@kortschak
Copy link
Member Author

kortschak commented Feb 15, 2015 via email

@egonelbre
Copy link

Finally have a version where I'm unable to tell the difference visually, although there is some differences... https://gist.github.com/egonelbre/5770469d6d7b955a4559

I'm not sure what to do with the lines that connect to a contour in the middle? See lines 374/378

@kortschak
Copy link
Member Author

I've added a benchmark for contourPaths and relaxed the test for
contourPaths to accept vg.Paths in either direction for the test data.

@kortschak kortschak force-pushed the heat branch 2 times, most recently from db68447 to 600c601 Compare February 15, 2015 23:45
@kortschak
Copy link
Member Author

@gonum/developers PTAL

I think this is ready (except for the volcano example issue which I have skirted by not even mentioning go generate - when/if someone can demonstrate that the data are not subject to the GPL a PR can provide the example complete).

@kortschak kortschak force-pushed the heat branch 12 times, most recently from 7ae3f1a to 387b80a Compare February 22, 2015 22:55

cases = [3][3][3]int{
{{0, 0, 8}, {0, 2, 5}, {7, 6, 9}},
{{0, 3, 4}, {1, 0, 1}, {4, 3, 0}},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The middle point of this is "3" in the conrec.c algorithm, but is 0 here. Is that intentional?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I wrote to Paul about that, but haven't had a reply.

I believe the 3 in that position is incorrect when considering the commentary in the paper.

axiom: When we have a section of the grid where all the Z values are equal, and equal to a contour height we would expect to have no internal segments to draw.

This is covered by case g) in his description of the algorithm (a triangle with three vertices the lie on the contour level). He says "... case g above has no really satisfactory solution and fortunately will occur rarely with real arithmetic." and then goes on to show the following:

conrec cases

which shows case g) in the set where no edge is drawn.

However, in the iteration over sh at conrec.c +44 (conrec.go +74), a triangle with all vertices on the plane is given sh = {0,0,0,0,0} and then when the switch at conrec.c +93 (conrec.go +128) happens, castab/cases resolves that to case 3 for all values of m. This is fixed by replacing castab/cases[1][1][1] with 0.

@btracey
Copy link
Member

btracey commented Feb 23, 2015

I don't fully comprehend a lot of the contour code, but otherwise LGTM

@kortschak
Copy link
Member Author

Are there sections that are a concern in particular wrt comprehension. I would like to make this as clear as possible. If comments in any sections would help, I'll add them.

@kortschak
Copy link
Member Author

@egonelbre would you please take a quick look at this?

@egonelbre
Copy link

I took a quick look and based on that quick look LGTM. Basically, didn't notice anything sticking out.

@kortschak kortschak force-pushed the heat branch 2 times, most recently from 0ad5f75 to 82c9a8e Compare February 24, 2015 23:49
Replace list-based approach with bi-directional slice-based approach
suggested by Egon Elbre.

Also add complete graph-based analysis for contour path reconstruction
with optimisation checks for simple or no-work cases.

Comparison between list and current path reconstruction:

benchmark                     old ns/op     new ns/op     delta
BenchmarkComplexContour0      12813961      6131752       -52.15%
BenchmarkComplexContour1      23735387      10794846      -54.52%
BenchmarkComplexContour2      36366033      17146897      -52.85%
BenchmarkComplexContour4      57171163      29761464      -47.94%
BenchmarkComplexContour8      107407179     58964940      -45.10%
BenchmarkComplexContour16     181637216     112427754     -38.10%
BenchmarkComplexContour32     293213592     175411602     -40.18%

A naive plotting option is retained to allow debugging.
@kortschak
Copy link
Member Author

Thank you everyone.

@btracey
Copy link
Member

btracey commented Feb 25, 2015

Thank you for putting that together! Contour maps are very useful (now I feel worse about the lack of a quadrature package).

@kortschak kortschak deleted the heat branch February 25, 2015 00:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants