From 1cdf899a104bd094235d984eb602d49a1bf0f7bd Mon Sep 17 00:00:00 2001 From: Alexandre De Zotti Date: Fri, 30 Apr 2021 12:31:00 +0100 Subject: [PATCH 01/22] Added Julia sets drawing --- fractals/julia_sets | 108 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 fractals/julia_sets diff --git a/fractals/julia_sets b/fractals/julia_sets new file mode 100644 index 000000000000..b2c0f6bb1afd --- /dev/null +++ b/fractals/julia_sets @@ -0,0 +1,108 @@ +"""Author Alexandre De Zotti + +Draws Julia sets of quadratic polynomials and exponential maps. More + specifically, this iterates the function a fixed number of times then plot + the absolute value of the last iterate and whether the absolute value of the + last iterate is greater than a fixed threshold (named "escape radius"). For + the exponential map this is not really an escape radius but rather a + convenient way to approximate the Julia set with bounded orbits. +""" + + +import numpy +from matplotlib import pyplot + +c_polynomial = 0.25 + 0.0j +c_exponential = -2.0 +nb_iterations = 56 +window_size = 2.0 +nb_pixels = 666 + + +def eval_exponential(c, z): + """ + >>> eval_exponential(0, 0) + 1.0 + """ + return numpy.exp(z) + c + + +def eval_quadratic_polynomial(c, z): + """ + >>> eval_quadratic_polynomial(0, 2) + 4 + >>> eval_quadratic_polynomial(-1, 1) + 0 + >>> eval_quadratic_polynomial(1.j, 0) + 1j + """ + return z * z + c + + +def prepare_grid(window_size, nb_pixels) -> numpy.array: + """ + Create a grid of complex values of size nb_pixels*nb_pixels with real and + imaginary parts ranging from -window_size to window_size (inclusive). + Returns a numpy array. + + >>> prepare_grid(1,3) + array([[-1.-1.j, -1.+0.j, -1.+1.j], + [ 0.-1.j, 0.+0.j, 0.+1.j], + [ 1.-1.j, 1.+0.j, 1.+1.j]]) + """ + x = numpy.linspace(-window_size, window_size, nb_pixels) + x = x.reshape((nb_pixels, 1)) + y = numpy.linspace(-window_size, window_size, nb_pixels) + y = y.reshape((1, nb_pixels)) + return x + 1.0j * y + + +def iterate_function(eval_function, function_params, nb_iterations, z_0): + """ + Iterate the function "eval_function" exactly nb_iterations times. + The first argument of the function is a parameter which is contained in + function_params. The variable z_0 is an array that contains the initial + values to iterate from. + This function returns the final iterates. + + >>> iterate_function(eval_quadratic_polynomial, 0, 3, numpy.array([0,1,2])) + array([ 0, 1, 256]) + """ + + z_n = z_0 + for i in range(nb_iterations): + z_n = eval_function(function_params, z_n) + return z_n + + +def show_results(function_label, function_params, escape_radius, z_final): + """ + Plots the absolute value of z_final as well as whether it is greater than + the value of escape_radius. Adds the function_label and function_params to + the title. + """ + + abs_z_final = (abs(z_final)).transpose() + pyplot.matshow(abs_z_final) + pyplot.title( + f"Absolute value of last iterate\n{function_label}, c={function_params}" + ) + pyplot.colorbar() + pyplot.show() + pyplot.matshow(abs_z_final < escape_radius) + pyplot.title(f"Escaped or not\n{function_label}, c={function_params}") + pyplot.show() + + +if __name__ == "__main__": + + z_0 = prepare_grid(window_size, nb_pixels) + z_final = iterate_function( + eval_quadratic_polynomial, c_polynomial, nb_iterations, z_0 + ) + escape_radius = 2 * abs(c_polynomial) + 1 + show_results("z²+c", c_polynomial, escape_radius, z_final) + + z_final = iterate_function(eval_exponential, c_exponential, nb_iterations, z_0 + 2) + escape_radius = 10000.0 + show_results("exp(z)+c", c_exponential, escape_radius, z_final) From f1fe663adea47625c6631f8a48cab469d57ed252 Mon Sep 17 00:00:00 2001 From: Alexandre De Zotti Date: Fri, 30 Apr 2021 12:40:29 +0100 Subject: [PATCH 02/22] Forgot the .py extension --- fractals/{julia_sets => julia_sets.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename fractals/{julia_sets => julia_sets.py} (100%) diff --git a/fractals/julia_sets b/fractals/julia_sets.py similarity index 100% rename from fractals/julia_sets rename to fractals/julia_sets.py From 45c1351c6acceaee49395238f69206d319f84878 Mon Sep 17 00:00:00 2001 From: Alexandre De Zotti Date: Tue, 4 May 2021 15:31:34 +0100 Subject: [PATCH 03/22] Update julia_sets.py Added online sources for comparison. Added more examples of fractal Julia sets. Added all type hints. Only show one picture Silented RuntuleWarning's (there's no way of avoiding them and they're not an issue per se) --- fractals/julia_sets.py | 77 +++++++++++++++++++++++++++++------------- 1 file changed, 54 insertions(+), 23 deletions(-) diff --git a/fractals/julia_sets.py b/fractals/julia_sets.py index b2c0f6bb1afd..998ccb380bbe 100644 --- a/fractals/julia_sets.py +++ b/fractals/julia_sets.py @@ -1,25 +1,30 @@ """Author Alexandre De Zotti -Draws Julia sets of quadratic polynomials and exponential maps. More - specifically, this iterates the function a fixed number of times then plot - the absolute value of the last iterate and whether the absolute value of the - last iterate is greater than a fixed threshold (named "escape radius"). For - the exponential map this is not really an escape radius but rather a - convenient way to approximate the Julia set with bounded orbits. +Draws Julia sets of quadratic polynomials and exponential maps. More specifically, this iterates the function a fixed number of times then plot whether the absolute value of the last iterate is greater than a fixed threshold (named "escape radius"). For the exponential map this is not really an escape radius but rather a convenient way to approximate the Julia set with bounded orbits. + +The examples presented here are: +- The Cauliflower Julia set, see e.g. https://en.wikipedia.org/wiki/File:Julia_z2%2B0,25.png +- Other examples from https://en.wikipedia.org/wiki/Julia_set +- An exponential map Julia set ambiantly homeomorphic to the examples from in http://www.math.univ-toulouse.fr/~cheritat/GalII/galery.html and https://ddd.uab.cat/pub/pubmat/02141493v43n1/02141493v43n1p27.pdf """ +import warnings +from typing import Any, Callable, NewType, Union import numpy from matplotlib import pyplot -c_polynomial = 0.25 + 0.0j +c_cauliflower = 0.25 + 0.0j +c_polynomial_1 = -0.4 + 0.6j +c_polynomial_2 = -0.7269 + 0.1889j +c_polynomial_2 = -0.1+0.651j c_exponential = -2.0 nb_iterations = 56 window_size = 2.0 nb_pixels = 666 -def eval_exponential(c, z): +def eval_exponential(c: complex, z: numpy.ndarray) -> numpy.ndarray: """ >>> eval_exponential(0, 0) 1.0 @@ -27,7 +32,7 @@ def eval_exponential(c, z): return numpy.exp(z) + c -def eval_quadratic_polynomial(c, z): +def eval_quadratic_polynomial(c: complex, z: numpy.ndarray) -> numpy.ndarray: """ >>> eval_quadratic_polynomial(0, 2) 4 @@ -39,7 +44,7 @@ def eval_quadratic_polynomial(c, z): return z * z + c -def prepare_grid(window_size, nb_pixels) -> numpy.array: +def prepare_grid(window_size: float, nb_pixels: int) -> numpy.ndarray: """ Create a grid of complex values of size nb_pixels*nb_pixels with real and imaginary parts ranging from -window_size to window_size (inclusive). @@ -57,7 +62,13 @@ def prepare_grid(window_size, nb_pixels) -> numpy.array: return x + 1.0j * y -def iterate_function(eval_function, function_params, nb_iterations, z_0): +# def iterate_function(eval_function, function_params, nb_iterations: int, z_0: numpy.array) -> numpy.array: +def iterate_function( + eval_function: Callable[[Any, numpy.ndarray], numpy.ndarray], + function_params: Any, + nb_iterations: int, + z_0: numpy.ndarray, +) -> numpy.ndarray: """ Iterate the function "eval_function" exactly nb_iterations times. The first argument of the function is a parameter which is contained in @@ -75,34 +86,54 @@ def iterate_function(eval_function, function_params, nb_iterations, z_0): return z_n -def show_results(function_label, function_params, escape_radius, z_final): +def show_results( + function_label: str, + function_params: Any, + escape_radius: float, + z_final: numpy.ndarray, +) -> None: """ - Plots the absolute value of z_final as well as whether it is greater than + Plots of whether the absolute value of z_final is greater than the value of escape_radius. Adds the function_label and function_params to the title. """ abs_z_final = (abs(z_final)).transpose() - pyplot.matshow(abs_z_final) - pyplot.title( - f"Absolute value of last iterate\n{function_label}, c={function_params}" - ) - pyplot.colorbar() - pyplot.show() + abs_z_final[:, :] = abs_z_final[::-1, :] pyplot.matshow(abs_z_final < escape_radius) - pyplot.title(f"Escaped or not\n{function_label}, c={function_params}") + pyplot.title(f"Julia set of {function_label}\n c={function_params}") pyplot.show() if __name__ == "__main__": + warnings.filterwarnings("ignore", category=RuntimeWarning) + + nb_iterations = 24 + z_0 = prepare_grid(window_size, nb_pixels) + z_final = iterate_function( + eval_quadratic_polynomial, c_cauliflower, nb_iterations, z_0 + ) + escape_radius = 2 * abs(c_cauliflower) + 1 + show_results("z²+c", c_cauliflower, escape_radius, z_final) + + nb_iterations = 64 + z_0 = prepare_grid(window_size, nb_pixels) + z_final = iterate_function( + eval_quadratic_polynomial, c_polynomial_1, nb_iterations, z_0 + ) + escape_radius = 2 * abs(c_polynomial_1) + 1 + show_results("z²+c", c_polynomial_1, escape_radius, z_final) + + nb_iterations = 161 z_0 = prepare_grid(window_size, nb_pixels) z_final = iterate_function( - eval_quadratic_polynomial, c_polynomial, nb_iterations, z_0 + eval_quadratic_polynomial, c_polynomial_2, nb_iterations, z_0 ) - escape_radius = 2 * abs(c_polynomial) + 1 - show_results("z²+c", c_polynomial, escape_radius, z_final) + escape_radius = 2 * abs(c_polynomial_2) + 1 + show_results("z²+c", c_polynomial_2, escape_radius, z_final) + nb_iterations = 12 z_final = iterate_function(eval_exponential, c_exponential, nb_iterations, z_0 + 2) escape_radius = 10000.0 show_results("exp(z)+c", c_exponential, escape_radius, z_final) From 0490d583a9e651821d5261501f3b12fb7f7ea754 Mon Sep 17 00:00:00 2001 From: Alexandre De Zotti Date: Tue, 4 May 2021 15:40:05 +0100 Subject: [PATCH 04/22] Added doctest example for "show_results" --- fractals/julia_sets.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fractals/julia_sets.py b/fractals/julia_sets.py index 998ccb380bbe..8e2cf5c5b7cb 100644 --- a/fractals/julia_sets.py +++ b/fractals/julia_sets.py @@ -96,6 +96,8 @@ def show_results( Plots of whether the absolute value of z_final is greater than the value of escape_radius. Adds the function_label and function_params to the title. + + >>> show_results('Test', 0, 1, numpy.array([[0,1,0.5],[0.4,2.,1.1],[.2,1.,1.3]])) """ abs_z_final = (abs(z_final)).transpose() From f69ee2a369c9a428decc7cbf256aa2a1c0e82fac Mon Sep 17 00:00:00 2001 From: Alexandre De Zotti Date: Thu, 6 May 2021 14:10:31 +0100 Subject: [PATCH 05/22] Filtering Nan's and infinites --- fractals/julia_sets.py | 67 +++++++++++++++++++++++++++++------------- 1 file changed, 46 insertions(+), 21 deletions(-) diff --git a/fractals/julia_sets.py b/fractals/julia_sets.py index 8e2cf5c5b7cb..768ae0f0d0d0 100644 --- a/fractals/julia_sets.py +++ b/fractals/julia_sets.py @@ -1,23 +1,30 @@ """Author Alexandre De Zotti -Draws Julia sets of quadratic polynomials and exponential maps. More specifically, this iterates the function a fixed number of times then plot whether the absolute value of the last iterate is greater than a fixed threshold (named "escape radius"). For the exponential map this is not really an escape radius but rather a convenient way to approximate the Julia set with bounded orbits. +Draws Julia sets of quadratic polynomials and exponential maps. + More specifically, this iterates the function a fixed number of times + then plots whether the absolute value of the last iterate is greater than + a fixed threshold (named "escape radius"). For the exponential map this is not + really an escape radius but rather a convenient way to approximate the Julia + set with bounded orbits. The examples presented here are: -- The Cauliflower Julia set, see e.g. https://en.wikipedia.org/wiki/File:Julia_z2%2B0,25.png +- The Cauliflower Julia set, see e.g. +https://en.wikipedia.org/wiki/File:Julia_z2%2B0,25.png - Other examples from https://en.wikipedia.org/wiki/Julia_set -- An exponential map Julia set ambiantly homeomorphic to the examples from in http://www.math.univ-toulouse.fr/~cheritat/GalII/galery.html and https://ddd.uab.cat/pub/pubmat/02141493v43n1/02141493v43n1p27.pdf +- An exponential map Julia set, ambiantly homeomorphic to the examples in +http://www.math.univ-toulouse.fr/~cheritat/GalII/galery.html + and +https://ddd.uab.cat/pub/pubmat/02141493v43n1/02141493v43n1p27.pdf """ -import warnings -from typing import Any, Callable, NewType, Union +from typing import Any, Callable import numpy from matplotlib import pyplot c_cauliflower = 0.25 + 0.0j c_polynomial_1 = -0.4 + 0.6j -c_polynomial_2 = -0.7269 + 0.1889j -c_polynomial_2 = -0.1+0.651j +c_polynomial_2 = -0.1 + 0.651j c_exponential = -2.0 nb_iterations = 56 window_size = 2.0 @@ -62,12 +69,12 @@ def prepare_grid(window_size: float, nb_pixels: int) -> numpy.ndarray: return x + 1.0j * y -# def iterate_function(eval_function, function_params, nb_iterations: int, z_0: numpy.array) -> numpy.array: def iterate_function( eval_function: Callable[[Any, numpy.ndarray], numpy.ndarray], function_params: Any, nb_iterations: int, z_0: numpy.ndarray, + infinity=None, ) -> numpy.ndarray: """ Iterate the function "eval_function" exactly nb_iterations times. @@ -83,6 +90,9 @@ def iterate_function( z_n = z_0 for i in range(nb_iterations): z_n = eval_function(function_params, z_n) + if infinity is not None: + numpy.nan_to_num(z_n, copy=False, nan=infinity) + z_n[abs(z_n) == numpy.inf] = infinity return z_n @@ -96,8 +106,8 @@ def show_results( Plots of whether the absolute value of z_final is greater than the value of escape_radius. Adds the function_label and function_params to the title. - - >>> show_results('Test', 0, 1, numpy.array([[0,1,0.5],[0.4,2.,1.1],[.2,1.,1.3]])) + + >>> show_results('80', 0, 1, numpy.array([[0,1,.5],[.4,2,1.1],[.2,1,1.3]])) """ abs_z_final = (abs(z_final)).transpose() @@ -109,33 +119,48 @@ def show_results( if __name__ == "__main__": - warnings.filterwarnings("ignore", category=RuntimeWarning) + z_0 = prepare_grid(window_size, nb_pixels) nb_iterations = 24 - z_0 = prepare_grid(window_size, nb_pixels) + escape_radius = 2 * abs(c_cauliflower) + 1 z_final = iterate_function( - eval_quadratic_polynomial, c_cauliflower, nb_iterations, z_0 + eval_quadratic_polynomial, + c_cauliflower, + nb_iterations, + z_0, + infinity=1.1 * escape_radius, ) - escape_radius = 2 * abs(c_cauliflower) + 1 show_results("z²+c", c_cauliflower, escape_radius, z_final) nb_iterations = 64 - z_0 = prepare_grid(window_size, nb_pixels) + escape_radius = 2 * abs(c_polynomial_1) + 1 z_final = iterate_function( - eval_quadratic_polynomial, c_polynomial_1, nb_iterations, z_0 + eval_quadratic_polynomial, + c_polynomial_1, + nb_iterations, + z_0, + infinity=1.1 * escape_radius, ) - escape_radius = 2 * abs(c_polynomial_1) + 1 show_results("z²+c", c_polynomial_1, escape_radius, z_final) nb_iterations = 161 - z_0 = prepare_grid(window_size, nb_pixels) + escape_radius = 2 * abs(c_polynomial_2) + 1 z_final = iterate_function( - eval_quadratic_polynomial, c_polynomial_2, nb_iterations, z_0 + eval_quadratic_polynomial, + c_polynomial_2, + nb_iterations, + z_0, + infinity=1.1 * escape_radius, ) - escape_radius = 2 * abs(c_polynomial_2) + 1 show_results("z²+c", c_polynomial_2, escape_radius, z_final) nb_iterations = 12 - z_final = iterate_function(eval_exponential, c_exponential, nb_iterations, z_0 + 2) escape_radius = 10000.0 + z_final = iterate_function( + eval_exponential, + c_exponential, + nb_iterations, + z_0 + 2, + infinity=1.0e10, + ) show_results("exp(z)+c", c_exponential, escape_radius, z_final) From e9bcc3e010565cace844a4a0ff6fe02b70d96b1a Mon Sep 17 00:00:00 2001 From: Alexandre De Zotti Date: Thu, 6 May 2021 14:13:43 +0100 Subject: [PATCH 06/22] added 1 missing type hint --- fractals/julia_sets.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fractals/julia_sets.py b/fractals/julia_sets.py index 768ae0f0d0d0..901f0a9a002d 100644 --- a/fractals/julia_sets.py +++ b/fractals/julia_sets.py @@ -74,7 +74,7 @@ def iterate_function( function_params: Any, nb_iterations: int, z_0: numpy.ndarray, - infinity=None, + infinity: float = None, ) -> numpy.ndarray: """ Iterate the function "eval_function" exactly nb_iterations times. From 75797b18c7c3139511fc2e7ba92f6da11615398e Mon Sep 17 00:00:00 2001 From: Alexandre De Zotti Date: Thu, 6 May 2021 23:09:52 +0100 Subject: [PATCH 07/22] in iterate_function, convert to dtype=complex64 --- fractals/julia_sets.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fractals/julia_sets.py b/fractals/julia_sets.py index 901f0a9a002d..5633a6de4583 100644 --- a/fractals/julia_sets.py +++ b/fractals/julia_sets.py @@ -87,7 +87,7 @@ def iterate_function( array([ 0, 1, 256]) """ - z_n = z_0 + z_n = z_0.astype('complex64') for i in range(nb_iterations): z_n = eval_function(function_params, z_n) if infinity is not None: From 1ffbd3da8dea9ef937d412f59953960f63fd516e Mon Sep 17 00:00:00 2001 From: Alexandre De Zotti Date: Fri, 7 May 2021 08:41:06 +0100 Subject: [PATCH 08/22] RuntimeWarning (fine) filtering --- fractals/julia_sets.py | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/fractals/julia_sets.py b/fractals/julia_sets.py index 5633a6de4583..47401eebd8eb 100644 --- a/fractals/julia_sets.py +++ b/fractals/julia_sets.py @@ -15,8 +15,13 @@ http://www.math.univ-toulouse.fr/~cheritat/GalII/galery.html and https://ddd.uab.cat/pub/pubmat/02141493v43n1/02141493v43n1p27.pdf + +Remark: Some overflow runtime warnings are suppressed. This is because of the + way the iterateion loop is implemented, using numpy's efficient computations. + Overflows and infinites are replaced after each step by a large number. """ +import warnings from typing import Any, Callable import numpy @@ -87,7 +92,7 @@ def iterate_function( array([ 0, 1, 256]) """ - z_n = z_0.astype('complex64') + z_n = z_0.astype("complex64") for i in range(nb_iterations): z_n = eval_function(function_params, z_n) if infinity is not None: @@ -117,10 +122,30 @@ def show_results( pyplot.show() +def ignore_overflow_warnings(): + # Fine grained filtering will make sure that we know what we are doing + warnings.filterwarnings( + "ignore", category=RuntimeWarning, message="overflow encountered in multiply" + ) + warnings.filterwarnings( + "ignore", + category=RuntimeWarning, + message="invalid value encountered in multiply", + ) + warnings.filterwarnings( + "ignore", category=RuntimeWarning, message="overflow encountered in absolute" + ) + warnings.filterwarnings( + "ignore", category=RuntimeWarning, message="overflow encountered in exp" + ) + + if __name__ == "__main__": z_0 = prepare_grid(window_size, nb_pixels) + ignore_overflow_warnings() # See file header for explanations + nb_iterations = 24 escape_radius = 2 * abs(c_cauliflower) + 1 z_final = iterate_function( From 1a1ece8dedd029a1483e7ee52ceb1b10817aa334 Mon Sep 17 00:00:00 2001 From: Alexandre De Zotti Date: Fri, 7 May 2021 08:46:24 +0100 Subject: [PATCH 09/22] Type hint, test for ignore_warnings function, typo in header --- fractals/julia_sets.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/fractals/julia_sets.py b/fractals/julia_sets.py index 47401eebd8eb..8ac3a6307a99 100644 --- a/fractals/julia_sets.py +++ b/fractals/julia_sets.py @@ -17,7 +17,7 @@ https://ddd.uab.cat/pub/pubmat/02141493v43n1/02141493v43n1p27.pdf Remark: Some overflow runtime warnings are suppressed. This is because of the - way the iterateion loop is implemented, using numpy's efficient computations. + way the iteration loop is implemented, using numpy's efficient computations. Overflows and infinites are replaced after each step by a large number. """ @@ -122,8 +122,12 @@ def show_results( pyplot.show() -def ignore_overflow_warnings(): - # Fine grained filtering will make sure that we know what we are doing +def ignore_overflow_warnings() -> None: + """ + Ignore some overflow and invalid value warnings. + + >>> ignore_overflow_warnings() + """ warnings.filterwarnings( "ignore", category=RuntimeWarning, message="overflow encountered in multiply" ) From f14bb43b6f811d4a6bdeed5e8289bda5cf09ce49 Mon Sep 17 00:00:00 2001 From: Alexandre De Zotti Date: Mon, 6 Sep 2021 23:39:54 +0100 Subject: [PATCH 10/22] Update julia_sets.py Type of expected output value for iterate function int array -> complex array (throws an error on test) --- fractals/julia_sets.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fractals/julia_sets.py b/fractals/julia_sets.py index 8ac3a6307a99..d62afb4d8221 100644 --- a/fractals/julia_sets.py +++ b/fractals/julia_sets.py @@ -51,7 +51,7 @@ def eval_quadratic_polynomial(c: complex, z: numpy.ndarray) -> numpy.ndarray: >>> eval_quadratic_polynomial(-1, 1) 0 >>> eval_quadratic_polynomial(1.j, 0) - 1j + 1.j """ return z * z + c @@ -89,7 +89,7 @@ def iterate_function( This function returns the final iterates. >>> iterate_function(eval_quadratic_polynomial, 0, 3, numpy.array([0,1,2])) - array([ 0, 1, 256]) + array([ 0.+0.j, 1.+0.j, 256.+0.j], dtype=complex) """ z_n = z_0.astype("complex64") From 3c8591433e7f7affaebe727fedf278b570dd6b65 Mon Sep 17 00:00:00 2001 From: Alexandre De Zotti Date: Thu, 23 Sep 2021 20:25:07 +0100 Subject: [PATCH 11/22] Update julia_sets.py - More accurate type for tests cases in eval_quadratic_polynomial and iterate_function - added more characters for variables c & z in eval_quadratic_polynomial and eval_exponential to silent bot warnings --- fractals/julia_sets.py | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/fractals/julia_sets.py b/fractals/julia_sets.py index d62afb4d8221..b6f3105975fe 100644 --- a/fractals/julia_sets.py +++ b/fractals/julia_sets.py @@ -36,24 +36,26 @@ nb_pixels = 666 -def eval_exponential(c: complex, z: numpy.ndarray) -> numpy.ndarray: +def eval_exponential(c_parameter: complex, z_values: numpy.ndarray) -> numpy.ndarray: """ >>> eval_exponential(0, 0) 1.0 """ - return numpy.exp(z) + c + return numpy.exp(z_values) + c_parameter -def eval_quadratic_polynomial(c: complex, z: numpy.ndarray) -> numpy.ndarray: +def eval_quadratic_polynomial(c_parameter: complex, z_values: numpy.ndarray) -> numpy.ndarray: """ >>> eval_quadratic_polynomial(0, 2) 4 >>> eval_quadratic_polynomial(-1, 1) 0 - >>> eval_quadratic_polynomial(1.j, 0) - 1.j + >>> round(eval_quadratic_polynomial(1.j, 0).imag) + 1 + >>> round(eval_quadratic_polynomial(1.j, 0).real) + 0 """ - return z * z + c + return z_values * z_values + c_parameter def prepare_grid(window_size: float, nb_pixels: int) -> numpy.ndarray: @@ -88,8 +90,14 @@ def iterate_function( values to iterate from. This function returns the final iterates. - >>> iterate_function(eval_quadratic_polynomial, 0, 3, numpy.array([0,1,2])) - array([ 0.+0.j, 1.+0.j, 256.+0.j], dtype=complex) + >>> iterate_function(eval_quadratic_polynomial, 0, 3, numpy.array([0,1,2])).shape + (3,) + >>> numpy.round(iterate_function(eval_quadratic_polynomial, 0, 3, numpy.array([0,1,2]))[0]) + 0j + >>> numpy.round(iterate_function(eval_quadratic_polynomial, 0, 3, numpy.array([0,1,2]))[1]) + (1+0j) + >>> numpy.round(iterate_function(eval_quadratic_polynomial, 0, 3, numpy.array([0,1,2]))[2]) + (256+0j) """ z_n = z_0.astype("complex64") From 45131276cbba3a8d0b01ddac6bc5cadf30918d50 Mon Sep 17 00:00:00 2001 From: Alexandre De Zotti Date: Fri, 24 Sep 2021 19:22:47 +0100 Subject: [PATCH 12/22] Function def formatting Blocked by black --- fractals/julia_sets.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fractals/julia_sets.py b/fractals/julia_sets.py index b6f3105975fe..4f7987f7920f 100644 --- a/fractals/julia_sets.py +++ b/fractals/julia_sets.py @@ -44,7 +44,9 @@ def eval_exponential(c_parameter: complex, z_values: numpy.ndarray) -> numpy.nda return numpy.exp(z_values) + c_parameter -def eval_quadratic_polynomial(c_parameter: complex, z_values: numpy.ndarray) -> numpy.ndarray: +def eval_quadratic_polynomial( + c_parameter: complex, z_values: numpy.ndarray +) -> numpy.ndarray: """ >>> eval_quadratic_polynomial(0, 2) 4 From 59013f1c89ade5a7c3450e7034549e3d842c50b1 Mon Sep 17 00:00:00 2001 From: Alexandre De Zotti Date: Sat, 25 Sep 2021 08:22:51 +0100 Subject: [PATCH 13/22] Update julia_sets.py --- fractals/julia_sets.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/fractals/julia_sets.py b/fractals/julia_sets.py index 4f7987f7920f..a060f497a4c8 100644 --- a/fractals/julia_sets.py +++ b/fractals/julia_sets.py @@ -94,11 +94,20 @@ def iterate_function( >>> iterate_function(eval_quadratic_polynomial, 0, 3, numpy.array([0,1,2])).shape (3,) - >>> numpy.round(iterate_function(eval_quadratic_polynomial, 0, 3, numpy.array([0,1,2]))[0]) + >>> numpy.round(iterate_function(eval_quadratic_polynomial, + 0, + 3, + numpy.array([0,1,2]))[0]) 0j - >>> numpy.round(iterate_function(eval_quadratic_polynomial, 0, 3, numpy.array([0,1,2]))[1]) + >>> numpy.round(iterate_function(eval_quadratic_polynomial, + 0, + 3, + numpy.array([0,1,2]))[1]) (1+0j) - >>> numpy.round(iterate_function(eval_quadratic_polynomial, 0, 3, numpy.array([0,1,2]))[2]) + >>> numpy.round(iterate_function(eval_quadratic_polynomial, + 0, + 3, + numpy.array([0,1,2]))[2]) (256+0j) """ From 2137469be0d2d92889c41005ea7ac022fdd5c42c Mon Sep 17 00:00:00 2001 From: Alexandre De Zotti Date: Tue, 28 Sep 2021 08:14:15 +0100 Subject: [PATCH 14/22] Update fractals/julia_sets.py Co-authored-by: John Law --- fractals/julia_sets.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fractals/julia_sets.py b/fractals/julia_sets.py index a060f497a4c8..dcde9cfffcad 100644 --- a/fractals/julia_sets.py +++ b/fractals/julia_sets.py @@ -95,9 +95,9 @@ def iterate_function( >>> iterate_function(eval_quadratic_polynomial, 0, 3, numpy.array([0,1,2])).shape (3,) >>> numpy.round(iterate_function(eval_quadratic_polynomial, - 0, - 3, - numpy.array([0,1,2]))[0]) + ... 0, + ... 3, + ... numpy.array([0,1,2]))[0]) 0j >>> numpy.round(iterate_function(eval_quadratic_polynomial, 0, From c3eac865650505dca4274f66478b71382d041332 Mon Sep 17 00:00:00 2001 From: Alexandre De Zotti Date: Tue, 28 Sep 2021 08:14:23 +0100 Subject: [PATCH 15/22] Update fractals/julia_sets.py Co-authored-by: John Law --- fractals/julia_sets.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fractals/julia_sets.py b/fractals/julia_sets.py index dcde9cfffcad..e491223055aa 100644 --- a/fractals/julia_sets.py +++ b/fractals/julia_sets.py @@ -178,7 +178,7 @@ def ignore_overflow_warnings() -> None: z_0, infinity=1.1 * escape_radius, ) - show_results("z²+c", c_cauliflower, escape_radius, z_final) + show_results("z^2+c", c_cauliflower, escape_radius, z_final) nb_iterations = 64 escape_radius = 2 * abs(c_polynomial_1) + 1 From 75fda09c66abc6a4139ef51ef2257eb7ee0f9d26 Mon Sep 17 00:00:00 2001 From: Alexandre De Zotti Date: Tue, 28 Sep 2021 08:14:32 +0100 Subject: [PATCH 16/22] Update fractals/julia_sets.py Co-authored-by: John Law --- fractals/julia_sets.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fractals/julia_sets.py b/fractals/julia_sets.py index e491223055aa..07a4739cbc1c 100644 --- a/fractals/julia_sets.py +++ b/fractals/julia_sets.py @@ -189,7 +189,7 @@ def ignore_overflow_warnings() -> None: z_0, infinity=1.1 * escape_radius, ) - show_results("z²+c", c_polynomial_1, escape_radius, z_final) + show_results("z^2+c", c_polynomial_1, escape_radius, z_final) nb_iterations = 161 escape_radius = 2 * abs(c_polynomial_2) + 1 From f8cb35c9d3d13d3bb391316281028aaaa93b484c Mon Sep 17 00:00:00 2001 From: Alexandre De Zotti Date: Tue, 28 Sep 2021 08:14:51 +0100 Subject: [PATCH 17/22] Update fractals/julia_sets.py Co-authored-by: John Law --- fractals/julia_sets.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fractals/julia_sets.py b/fractals/julia_sets.py index 07a4739cbc1c..bc0faa54f2c6 100644 --- a/fractals/julia_sets.py +++ b/fractals/julia_sets.py @@ -200,7 +200,7 @@ def ignore_overflow_warnings() -> None: z_0, infinity=1.1 * escape_radius, ) - show_results("z²+c", c_polynomial_2, escape_radius, z_final) + show_results("z^2+c", c_polynomial_2, escape_radius, z_final) nb_iterations = 12 escape_radius = 10000.0 From e149ac5ff3e199fdb72f6108b51a3165966644f9 Mon Sep 17 00:00:00 2001 From: Alexandre De Zotti Date: Tue, 28 Sep 2021 08:16:20 +0100 Subject: [PATCH 18/22] Update fractals/julia_sets.py Co-authored-by: John Law --- fractals/julia_sets.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fractals/julia_sets.py b/fractals/julia_sets.py index bc0faa54f2c6..a7253229d706 100644 --- a/fractals/julia_sets.py +++ b/fractals/julia_sets.py @@ -211,4 +211,4 @@ def ignore_overflow_warnings() -> None: z_0 + 2, infinity=1.0e10, ) - show_results("exp(z)+c", c_exponential, escape_radius, z_final) + show_results("e^z+c", c_exponential, escape_radius, z_final) From 8e972e91b7345241f1d5e2c9f372d2b5d35b22c1 Mon Sep 17 00:00:00 2001 From: Alexandre De Zotti Date: Tue, 28 Sep 2021 08:16:37 +0100 Subject: [PATCH 19/22] Update fractals/julia_sets.py Co-authored-by: John Law --- fractals/julia_sets.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fractals/julia_sets.py b/fractals/julia_sets.py index a7253229d706..97e616fcb153 100644 --- a/fractals/julia_sets.py +++ b/fractals/julia_sets.py @@ -137,7 +137,7 @@ def show_results( abs_z_final = (abs(z_final)).transpose() abs_z_final[:, :] = abs_z_final[::-1, :] pyplot.matshow(abs_z_final < escape_radius) - pyplot.title(f"Julia set of {function_label}\n c={function_params}") + pyplot.title(f"Julia set of ${function_label}$, $c={function_params}$") pyplot.show() From ca7a56b016ed4439132135ea4a2aaef713bb3cbe Mon Sep 17 00:00:00 2001 From: Alexandre De Zotti Date: Tue, 28 Sep 2021 08:18:08 +0100 Subject: [PATCH 20/22] Update fractals/julia_sets.py Co-authored-by: John Law --- fractals/julia_sets.py | 1 + 1 file changed, 1 insertion(+) diff --git a/fractals/julia_sets.py b/fractals/julia_sets.py index 97e616fcb153..81746f90bfff 100644 --- a/fractals/julia_sets.py +++ b/fractals/julia_sets.py @@ -38,6 +38,7 @@ def eval_exponential(c_parameter: complex, z_values: numpy.ndarray) -> numpy.ndarray: """ + Evaluate $e^z + c$. >>> eval_exponential(0, 0) 1.0 """ From f8d0123802ad5d0793a202a67bba42d2292665d8 Mon Sep 17 00:00:00 2001 From: Alexandre De Zotti Date: Tue, 28 Sep 2021 08:24:44 +0100 Subject: [PATCH 21/22] added more doctests for eval_exponential --- fractals/julia_sets.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fractals/julia_sets.py b/fractals/julia_sets.py index 81746f90bfff..37cc60f14d6e 100644 --- a/fractals/julia_sets.py +++ b/fractals/julia_sets.py @@ -41,6 +41,10 @@ def eval_exponential(c_parameter: complex, z_values: numpy.ndarray) -> numpy.nda Evaluate $e^z + c$. >>> eval_exponential(0, 0) 1.0 + >>> abs(eval_exponential(1, numpy.pi*1.j)) < 1e-15 + True + >>> abs(eval_exponential(1.j, 0)-1-1.j) < 1e-15 + True """ return numpy.exp(z_values) + c_parameter From 18346432a50fbbb4ce9c2cd0bae36c1701b72c70 Mon Sep 17 00:00:00 2001 From: Alexandre De Zotti Date: Tue, 28 Sep 2021 09:03:05 +0100 Subject: [PATCH 22/22] Update fractals/julia_sets.py Co-authored-by: John Law --- fractals/julia_sets.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/fractals/julia_sets.py b/fractals/julia_sets.py index 37cc60f14d6e..0168a0153de1 100644 --- a/fractals/julia_sets.py +++ b/fractals/julia_sets.py @@ -105,14 +105,14 @@ def iterate_function( ... numpy.array([0,1,2]))[0]) 0j >>> numpy.round(iterate_function(eval_quadratic_polynomial, - 0, - 3, - numpy.array([0,1,2]))[1]) + ... 0, + ... 3, + ... numpy.array([0,1,2]))[1]) (1+0j) >>> numpy.round(iterate_function(eval_quadratic_polynomial, - 0, - 3, - numpy.array([0,1,2]))[2]) + ... 0, + ... 3, + ... numpy.array([0,1,2]))[2]) (256+0j) """