This project provides tools to generate sample points for the Mandelbrot set using different sampling techniques, including pure random sampling, Latin Hypercube Sampling (LHS), and orthogonal sampling. It uses a C library to perform efficient orthogonal sampling and provides Python bindings to utilize the generated points for further visualization and analysis.
project_root/
├── images/ # visulization results
├── simulation_results # our simulation results
├── ortho-pack/
│ ├── lib/
│ │ ├── ortho_sampling_generate.dll # Compiled library for Windows
│ │ ├── libortho_sampling_generate.so # Compiled library for Linux
│ │ └── libortho_sampling_generate.dylib # Compiled library for macOS, not implemented yet
│ ├── mt19937ar.c # MT19937 random number generator source
│ ├── ortho_sampling_generate.c # Sampling generation source
│ ├── rand_support.c # Support functions for random number generation
│ └── *.h # Header files for the C/C++ sources
├── src/
│ ├── main.py # Main Python script for executing the sampling
│ ├── mandelbrot_analysis.py # Class implementation for Mandelbrot analysis
│ ├── metrics.py # Some statistical function for analysis
│ └── utils.py # Some helpful function for analysis
├── README.md
├── Assignment 1 - MANDELBROT.pdf # Assignment descripition
└── CMakeLists.txt # CMake build configuration file
Install Dependencies:
numpy
, joblib
pip install numpy joblib
Run the Main Script:
python src/main.py
src/main.py
) uses the MandelbrotAnalysis
class to generate points on the complex plane using different sampling methods..dll
, or .so
) is dynamically loaded using ctypes
to call the underlying C functions for point generation.Upon running src/main.py
, the following options are presented:
Run Mandelbrot color plottings: Generate visualizations of the Mandelbrot set using different color mappings to highlight the structure of the set.
Run Generate True Area: Use a high sample size (9 million points) and high iteration count (1000 iterations) to estimate the true area of the Mandelbrot set with maximal accuracy.
Run Mandelbrot area calculation for visualization: Generate different types of plots (heatmaps, 3D plots, planar views) to visualize how the sampled area estimates vary with different sample sizes and iteration counts.
Run Mandelbrot convergence analysis for s and i: Analyze convergence by fixing either the sample size or iteration count and study the difference between calculated and true area values.
Run Mandelbrot statistic sample generate: Generate area distribution samples under specific parameters (optimal sample size and iteration count) to understand statistical characteristics.
Run Mandelbrot statistic metrics and plots: Compute statistical metrics such as confidence intervals (CI), mean squared error (MSE), and means, and conduct hypothesis testing to validate results.
Run Mandelbrot statistic improvement converge: Use adaptive resampling to accelerate convergence and compare with other sampling methods.
Exit: Exit the program.
Initial Visualization:
True Area Calculation:
Area Visualization with Different Parameters:
Convergence Analysis:
Statistical Sample Generation:
Statistical Analysis:
Accelerated Convergence with Adaptive Sampling:
The orthogonal sampling library has already been generated and placed in the appropriate directory ortho-pack/lib/
, so typically you don't need to recompile it yourself. However, if you wish to compile it or encounter issues due to platform-specific differences, the following guide will help you generate the dynamic/shared library (.dll, .so, or .dylib) based on your operating system.
To compile the library, CMake is used for cross-platform compatibility. This guide explains how to generate the dynamic/shared library (.dll
, .so
, or .dylib
) based on your operating system.
Navigate to the project root directory:
cd path/to/project_root
Run CMake to generate the build system:
cmake -B build -S .
-B build
argument specifies that the build output should be placed in a folder called build
.-S .
argument specifies that the source is the current directory.Build the library:
cmake --build build
This will generate the appropriate shared library in the ortho-pack/lib
folder depending on your system:
ortho_sampling_generate.dll
libortho_sampling_generate.so
libortho_sampling_generate.dylib
Set the Output Directory
In the CMakeLists.txt
file, the output directory for the compiled libraries is set as follows:
set_target_properties(ortho_sampling_generate PROPERTIES
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/ortho-pack/lib
)
Library Not Found:
.dll
, .so
, .dylib
) is located in the ortho-pack/lib
directory.Serialization Errors with joblib
:
joblib
for parallel execution, make sure not to pass ctypes
objects, as they cannot be serialized. Load the dynamic library inside the worker function.Feel free to submit pull requests or open issues if you encounter any problems or have suggestions for improvement.
This project is open-sourced under the MIT License. See the LICENSE file for details.