Add Multifractal Fractional Noise Generator#110
Merged
Conversation
…ral density Implements mfnoise_generator.py with functions to generate n-dimensional multifractal noise fields using piecewise power-law spectral density. The generator supports multiple Hurst exponents with configurable crossover points, enabling creation of signals with varying fractal properties across different frequency ranges. Includes proper spectral density calculation with continuity at crossover boundaries and optional normalization.
The mfnoise generator was incorrectly applying np.diff twice - once during signal processing and again before returning the result. This caused incorrect scaling of the output signals. Removed the redundant diff operation in the return statement since differences are already computed earlier in the function.
This commit introduces a complete test suite for the mfnoise_generator module, including tests for the internal _calculate_spectral_density function and the main mfnoise generator. The tests cover single and multiple Hurst exponents, crossover points, multiple track generation, normalization behavior, and edge cases. The test suite uses pytest with numpy and scipy for validation and includes statistical property verification to ensure the generated noise has expected multifractal characteristics.
Contributor
Code Review SummaryStatus: No New Issues Found | Recommendation: Merge Overview
The existing inline comments adequately address the issues in this PR:
Files Reviewed (3 files)
NotesThe implementation appears sound. The code correctly handles:
|
Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
Renamed the variable `alpha` to `beta` in the `_calculate_spectral_density` function to better reflect its mathematical meaning as the spectral exponent (β = 2H + 1) rather than the alpha parameter. This improves code clarity and aligns with standard notation in spectral analysis where beta represents the power-law exponent in the frequency domain.
MayaGavrichenkova
approved these changes
Mar 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR introduces a comprehensive multifractal fractional noise generator to the StatTools library, enabling the creation of signals with piecewise power-law spectral densities and multiple Hurst exponents.
Key Features
Core Implementation
mfnoise()function inStatTools/generators/mfnoise_generator.py_calculate_spectral_density()for piecewise power-law spectraFunctionality
Mathematical Foundation
Usage Examples
Basic Usage
Visualization
The included Jupyter notebook (
examples/mfnoise_visualization.ipynb) demonstrates:Testing
Comprehensive test suite in
tests/test_mfnoise_generator.pycovering:Files Modified
StatTools/generators/mfnoise_generator.py- Core implementationtests/test_mfnoise_generator.py- Comprehensive test suiteexamples/mfnoise_visualization.ipynb- Visualization examplesTechnical Details
Applications
This generator is particularly useful for:
Validation
The implementation has been validated through:
This addition significantly expands the library's capabilities for generating complex noise signals with controllable multifractal properties.