Giter VIP home page Giter VIP logo

fractal-jax's Introduction

Fractal Jax

Generate figures of the Julia and Mandelbrot sets with Jax.

z = z**2 + c

Install

This package requires Jax - see the official Jax documentation.

pip install --upgrade "jax[cuda]" -f https://storage.googleapis.com/jax-releases/jax_cuda_releases.html
cd fractal-jax
pip install .

Generate Mandelbrot set figures

from fractal_jax import FractalJax

# specify number of iterations, divergence threshold and backend
m = FractalJax(iterations=50, divergence_threshold=2, backend="gpu")
import matplotlib.pyplot as plt
fig, ax = plt.subplots(1, 1, figsize=(5, 5))
ax.imshow(
    m.generate_mandelbrot(x_range=[-2, 1], y_range=[-1.5, 1.5], pixel_res=300)
)

Figure 1

You can adjust the region which you care about (x_range and y_range) and the pixel resolution (pixel_res):

fig, ax = plt.subplots(1, 1, figsize=(5, 5))
ax.imshow(
    m.generate_mandelbrot(x_range=[-1, -0.9], y_range=[-.3, -.2], pixel_res=30000))
)

Figure 2

Generate Julia set figures

You can generate figures of the Julia set by specifying the complex constant c:

fig, ax = plt.subplots(1, 1, figsize=(5, 5))
c=complex(-0.5792518264067199, 0.5448363340450433)
ax.imshow(
    m.generate_julia(c=c, x_range=[-1.5, 1.5], y_range=[-1.5, 1.5], pixel_res=300)
)

Figure 2

Credits

This implementation is based on the analysis made by jpivarski in mandelbrot-on-all-accelerators.ipynb

fractal-jax's People

Contributors

flpgrz avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

fractal-jax's Issues

Bug: performance falls off a cliff as iterations increase moderately

The given code examples use 50 iterations, which executes performantly on the GPU, but is only useful for "toy" fractal renderings.

With just a little bit of zoom, you'll quickly be wanting 1,000 or 10,000 iterations (or far more).

Unfortunately GPU compilation of the function then takes minutes and/or runs out of memory completely, due to "loop unrolling". I've commented on the code Fractal Jax uses as a model (which suffers the same issue), and a solution is given here.

I'm not expecting Fractal Jax to be updated, but I just want to leave this issue open as a warning in case anyone else struggles with Fractal Jax performance, and these links explain how to fix it.

Bug in line 55 - Julia sets don't draw correctly

Just wanted to let you know that line 55 reads:

fractal = jax.numpy.where(diverging_now, i / self.iterations, fractal)

I'm not sure where the / self.iterations came from, but it's incorrect and producing Julia sets with no color variation at all. You can see that the analagous Mandelbrot line on line 43 does not include that part and functions correctly:

fractal = jax.numpy.where(diverging_now, i, fractal)

blood vessel like fractals

Hello I am looking for a 3d dichotomic irregular fractal that would look like branching blood vessels and similar to branching planes - to simulate connective tissue layers
The algorithm would need to be parameterized and differentiable.
The basic plan is to learn the parameters of the fractal by comparing l2 similarity between the original and fractal-generated image (additionally for fine-grained texture Fourier will be used.

Would it be possible to use your tool for it ?)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.