josecelano / c-mandelbrot-arbitrary-precision

Proof of concept project about adding arbitrary precision math to Fractal generation software GNofract4D.
6 stars 3 forks source link

Improve periodicity checking #2

Open josecelano opened 4 years ago

josecelano commented 4 years ago

If you enable "periodicity checking" the application will try to find periods in the fractal loop. The pre-defined periods for the Mandelbrot Set are:

image

But if you execute the application you will get something like:

image

The period detection is worse near to the fractal border and and when you zoom in.

That's because there are 3 parameters that are fixed in the algorithm that should be calculated dynamically. These parameters are:

  1. Minimum number of iterations before detecting cycles.

  2. Period tolerance.

  3. Maximum number of iterations.

  4. Minimum number of iterations

Param: https://github.com/josecelano/c-mandelbrot-arbitrary-precision/blob/master/src/mandelbrot/domain/optimisation/periodicity_checking.c#L59

The more you are closer to the border the more chaos you will have before the orbit gets stable. For example, this is the orbit for a period 1 next to the main cardioid center:

image

And this is the orbit for a point closer to the border where the application is not detecting the rigth cycle:

image

As you can see the orbit get stable after the first 60 iterations and the hard coded value is 20.

  1. Period tolerance

Param: https://github.com/josecelano/c-mandelbrot-arbitrary-precision/blob/master/src/mandelbrot/domain/optimisation/periodicity_checking.c#L88

In this image:

image

you can see a point in the main main circle (period-2) close to the border. You can see the cycle but the peaks are not exactly the same value, you can see there is a difference and the cycle length is not well detected. In this case the problem is we need to adjust the period tolerance. It should be greater.

  1. Maximum number of iterations

Param: https://github.com/josecelano/c-mandelbrot-arbitrary-precision/blob/master/src/mandelbrot/domain/optimisation/periodicity_checking.c#L92

This is a point in the main cardioid next to the border.

image

You can see that tends to a fix value but it takes more iterations than a point closer to the center like:

image

In order to detect the right cycle length, the application should start detecting the cycle later and increase the number of iterations.

And finally if you want to try different point you can use this site I built to find out how to calculate these 3 parameters dynamically.

https://mandelbrot-set-periods.online/

You can also take a look at this program: https://github.com/fract4d/gnofract4d or any other fractal generation software to find out how to calculate the right values for those parameters.

jeremy-rifkin commented 3 years ago

Hey Jose, I've recently been working on this same problem and your linkedin post (I've also just commented there) has come up during my research. I ran into similar issues with coloring when I approached the problem using k-means and trajectory history/threshold but I solved the problem with complex dynamics: https://github.com/jeremy-rifkin/mandelbrot-orbits. Perhaps some similar ideas can be applied here too.