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

repeatable results? #2

Closed
Fil opened this issue Aug 4, 2018 · 4 comments
Closed

repeatable results? #2

Fil opened this issue Aug 4, 2018 · 4 comments

Comments

@Fil
Copy link

Fil commented Aug 4, 2018

I don't think there is any random element in the following observable
https://beta.observablehq.com/@fil/voronoi-weighted-maps
yet the results vary between runs.

@michaschwab
Copy link

See Kcnarf/d3-voronoi-treemap#4.

I'm working on a pull request to fix this.

@Kcnarf
Copy link
Owner

Kcnarf commented Aug 7, 2018

@Fil: I see you use the 'pie' initial position, which actually removes the randomness at initilization. It works fine when there is no too much data. In your use case, it doesn't produce the same arrangement because during the iterative process producing the final arrangement, some of your data (the lightest) are completely overweighted (they are too close to other heavier cells, and they are assigned an empty area). In such a case, the algorithm randomly choose a new position where such cell still exists. This is why you get different Voronoï maps when reloading.

The PR from @michaschwab is the solution: re-positioning of overweighted cells will become repeatable. It is orthogonal to the 'pie' initial positioning, and both codes will perfectly work together. Nevertheless, the doc of the 'pie' initial positioning have to be updated.

I will not be able to work on @michaschwab's PR before next week (from 13th aug. 2018).

@Kcnarf
Copy link
Owner

Kcnarf commented Aug 13, 2018

After some googling, I found another way to make a repeatable Voronoï map with the help of seedrandom.

As the @michaschwab's PR does, it defines a PRNG. It may be used to replace/overwrite Math.random(). You can see it in action in https://beta.observablehq.com/@kcnarf/repeatable-voronoi-weighted-maps (focus on https://beta.observablehq.com/@kcnarf/repeatable-voronoi-weighted-maps#voronoiMap). Indeed, the initial 'pie' positioning is no longer required for the sake of repeatability.

Seedrandom can also be used without overwriting Math.random(), and without introducing any side effect, by defining a new standalone PRNG. Enhancing d3-voronoi-map by providing an API that allows the user to set its preferred random generator (see d3-random) is another implementation that allows repeatable Voronoï map.

@Kcnarf
Copy link
Owner

Kcnarf commented Aug 14, 2018

The new version 1.2.0 of the d3-voronoi-map plugin now provides a new 'prng' API. It allows to define a prng. If this one is seeded, then randomness becomes repeatable, leading to repeatable outputs/arrangements.

You can see it in action in https://beta.observablehq.com/@kcnarf/repeatable-voronoi-weighted-maps (focus on https://beta.observablehq.com/@kcnarf/repeatable-voronoi-weighted-maps#voronoiMap). Indeed, the initial 'pie' positioning is no longer required for the sake of repeatability.

@Kcnarf Kcnarf closed this as completed Aug 14, 2018
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

No branches or pull requests

3 participants