News for hackers. Stuff that matters.
Re:Infinite procedurally-generated city with the Wave Functi... by mrspeaker on Tuesday November 13, 2018 @01:46PM (#18443579)
Amazing work! I've been excited about this technique since I first saw the original demos of it (https://github.com/mxgmn/WaveFunctionCollapse) - but can someone explain (at a very high level) how Wave Function Collapse works? I've read through some of the documentation on various repos - it starts with the nitty-gritty details, and I haven't been able to grasp the concepts.
Re:Infinite procedurally-generated city with the Wave Functi... by BorisTheBrave on Tuesday November 13, 2018 @05:19PM (#18445466)
Have you ever written a Sudoku solver. It works like that.

You start with an array where every tile is possible in every location. Then you pick a random cell and assign a tile to it. That tile implies some choices are impossible, so you set those possibilities to false. That further implies some other possibilities are false and so on. You propogate that as far as it goes, and when you are done, pick another random cell and assign a random possible tile to it.

Because you are propogating information as much as possible before making the next choice, the algorithm very rarely needs to backtrack. You can run WFC without any backtracking at all and it'll still find a solution most of the time.

Some animated examples I put together might illustrate things more: https://boristhebrave.github.io/DeBroglie/articles/gallery.h...

Re:Infinite procedurally-generated city with the Wave Functi... by doubleunplussed on Tuesday November 13, 2018 @05:26PM (#18445506)
As a physicist who works with quantum mechanics, I have to say, "wave function collapse", is an extremely apt name for what you're describing. Usually when quantumy things are used in names of things it's just 'cause it sounds cool, but this is spot-on.
Re:Infinite procedurally-generated city with the Wave Functi... by BorisTheBrave on Tuesday November 13, 2018 @05:44PM (#18445624)
It's really not. There's no probability field (unless you count booleans as a scalar), no complex numbers, and no entanglement.

It's just constraint propogation, optimized for certain conditions and given a fancy name.

I guess you could call it a markov random field, but I don't think it does unbiased sampling.

Re:Infinite procedurally-generated city with the Wave Functi... by doubleunplussed on Tuesday November 13, 2018 @06:12PM (#18445780)
There kind of is entanglement though!

You 'measure' one cell, and then all the other ones 'collapse' to values consistent with the result, because they have a hidden relationship with the cell you measured.

That's what happens in quantum mechanics. When you measure one thing, all the other things its entangled with collapse somewhat too - but not necessarily completely, it depends on the entanglement they had with the measured system.

It's a metaphor, I'm just saying it's very apt, not that it's mathematically equivalent.

Re:Infinite procedurally-generated city with the Wave Functi... by gus_massa on Tuesday November 13, 2018 @07:49PM (#18446364)
I agree. My main objection of the QM metaphor is that in QM you can have interference. For example in version more similar to QM if you have a 2x2 map like this

  1) X ?    2) X Y    3) X ?    4) X Y
     ? ?       ? ?       Z ?       Z ?
The probability of some particular tile in the bottom right corner may be bigger in 2) and 3) because somehow Y and Z make this tile more probable, but perhaps in 4) the probability decrease.

The trick is that you must calculate amplitudes, not probabilities. For example, Y may contribute an amplitude of .5 to the bottom right corner , and the probability is (.5)^2=.25. And Z may contribute an amplitude of -.3 to the bottom right corner , and the probability is (-.3)^2=.09. But when both are there the amplitudes must be added and the probability is (.5-.3)^2=.04.

This is a case of destructive interference that reduces the probability of a particular tile when both are present, but if both have the same sign it can be a constructive interference and increase the probability of that tile.

This type of interference is what produce the weird interference lines in the double slit experiment (and even in the single slit experiment).

This project just add probabilities, without squaring the numbers, so it's more difficult to have quantum-like weird things.

Anyway, I like the result very much. Nice project. Nice name.

Re:Infinite procedurally-generated city with the Wave Functi... by madhadron on Tuesday November 13, 2018 @05:34PM (#18445565)
As an ex-physicist, I would say "Markov random field sampling" would be the right name.
Re:Infinite procedurally-generated city with the Wave Functi... by srtjstjsj on Tuesday November 13, 2018 @06:53PM (#18446018)
How is that different from regular constraint propagation?
Re:Infinite procedurally-generated city with the Wave Functi... by dkural on Tuesday November 13, 2018 @08:37PM (#18446649)
It's not.
Re:Infinite procedurally-generated city with the Wave Functi... by JazzXP on Tuesday November 13, 2018 @08:26PM (#18446589)
Thank you. This description is what cleared it all up for me. I totally understand how this works now.
Re:Infinite procedurally-generated city with the Wave Functi... by justinpombrio on Tuesday November 13, 2018 @01:56PM (#18443683)
Here's my high-level understanding.

You're going to tile (say) the plane with a set of tiles you've chosen beforehand. (In this example, it looks like the tiles are 3d.) There are rules for which tiles can go next to each other---the edges must match.

As you go, there are two regions: a region in which you've settled on which tiles to use, and a boundary region in which you haven't. In the boundary region, you keep track of a probability distribution over the tiles. This distribution is influenced by the neighboring tiles (exactly how is probably the most interesting bit of the algorithm; I don't know).

The algorithm proceeds by repeatedly (i) picking a tile on the boundary that has a very skewed probability distribution, and fixing it to be the most likely tile; and (ii) updating the probability distributions of the neighboring tiles in the boundary.

It's possible that you end up making poor tile placements at the beginning that gets you stuck later, so the algorithm must sometimes backtrack to undo past decisions. You want to pick a set of tiles such that the algorithm doesn't need to backtrack too often, or it will take too long.

Note that the distribution is an ordinary probability distribution, not a sum of complex amplitudes like the name "Wave Function Collapse" would make you think.

Re:Infinite procedurally-generated city with the Wave Functi... by Qwertystop on Tuesday November 13, 2018 @02:35PM (#18444100)
Two additions to this: - AFAIK, the probability distribution is based on how common any particular adjacency is in the input. If the input is just rules rather than a small sample map, they'd all be equal, but if the input is an image that shows (for example) that only one in ten roads dead-end, that would carry over to generated stuff. - It can also do an "overlapping" model, where it sets one pixel at a time but considers overlapping tiles of 2x2 or 3x3 pixels. This breaks away from the grid structure, but requires a full sample image, not just a list of tiles.
Re:Infinite procedurally-generated city with the Wave Functi... by marian42 on Tuesday November 13, 2018 @03:55PM (#18444813)
In my case, the probabilites for each block are supplied manually.
Re:Infinite procedurally-generated city with the Wave Functi... by sophistication on Tuesday November 13, 2018 @03:55PM (#18444812)
This sounds like standard procedures for sampling from a Markov random field.

https://en.wikipedia.org/wiki/Markov_random_field

Re:Infinite procedurally-generated city with the Wave Functi... by vokep on Tuesday November 13, 2018 @03:32PM (#18444621)
Oh my....perhaps this backtracking to fix past inconsistencies could allow for a game environment in which "Mandela effect" events happen naturally from time to time. Could make for an interesting game mechanic.
Re:Infinite procedurally-generated city with the Wave Functi... by marian42 on Tuesday November 13, 2018 @03:56PM (#18444823)
You're right. There is backtracking in the demo and when it happens it looks quite eerie. The world around you just decides it wants to look different and changes.
Re:Infinite procedurally-generated city with the Wave Functi... by yoklov on Tuesday November 13, 2018 @04:55PM (#18445277)
That sounds like it could be mechanically cool. Or at least lead to a cool setting.
Re:Infinite procedurally-generated city with the Wave Functi... by minkzilla on Wednesday November 14, 2018 @10:20PM (#18456626)
It seems like it would work very well in a horror game. Though random generation doesn’t lend itself too well to horror.
Re:Infinite procedurally-generated city with the Wave Functi... by jbattle on Tuesday November 13, 2018 @02:34PM (#18444078)
Maybe this is a dumb comparison, but it sounds like an algorithm for solving minesweeper. The big difference is there's no "right" answer, the puzzle emerges from the outplaying of probabilities.
Re:Infinite procedurally-generated city with the Wave Functi... by c3534l on Tuesday November 13, 2018 @05:08PM (#18445392)
Basically.
Re:Infinite procedurally-generated city with the Wave Functi... by teddyknox on Tuesday November 13, 2018 @04:56PM (#18445285)
I wonder if machine learning could be used to model the probability distributions at a greater capacity, and thus reduce backtracking.

One might also consider placing the algorithm in the context of a generative adversarial network (GAN) to adapt the tile probability modeling ML component towards a pattern that is less distinguishable from a real city.

Re:Infinite procedurally-generated city with the Wave Functi... by platz on Tuesday November 13, 2018 @02:09PM (#18443836)
Re:Infinite procedurally-generated city with the Wave Functi... by tobr on Tuesday November 13, 2018 @05:14PM (#18445427)
A while back I hacked together a crossword generator that works almost exactly like this, but using a wordlist to provide probabilities.