Peak Locator

Logo

Deterministic Peak Detection for Multi-Dimensional Data

View the Project on GitHub chiraag-kakar/peak-locator

N-Dimensional Peak Detection Concepts

Theoretical and practical aspects of peak detection in higher dimensions.

Overview

PeakFinder provides conceptual support for N-dimensional peak detection. While 1D and 2D have efficient algorithms, higher dimensions present unique challenges.

What is an N-D Peak?

An N-dimensional peak is an element that is greater than or equal to all its neighbors in all dimensions. In 3D, a peak has up to 6 neighbors (up, down, left, right, forward, backward).

Basic Usage

3D Example

from peak_locator import PeakDetector
import numpy as np

# Create a 3D tensor
tensor = np.array([
    [[1, 2], [3, 4]],
    [[5, 6], [7, 8]]
])

detector = PeakDetector(tensor)
peak = detector.find_peak_nd()
print(f"Peak at {peak}")
# Output: Peak at (1, 1, 1)

4D Example

# 4D tensor
tensor = np.random.rand(5, 5, 5, 5)
detector = PeakDetector(tensor)
peak = detector.find_peak_nd()
print(f"Peak at {peak}")

Algorithm Approach

The N-dimensional implementation uses:

  1. Greedy Maximum: Finds the maximum element in the tensor
  2. Neighbor Verification: Checks if it’s a peak by comparing with all neighbors
  3. Fallback: Returns the maximum index if verification fails

This is a simplified approach. A full divide-and-conquer implementation would be more complex.

Limitations

Current Implementation

Theoretical Challenges

  1. Curse of Dimensionality: As dimensions increase, the number of neighbors grows exponentially
  2. Algorithm Complexity: Efficient divide-and-conquer becomes more complex
  3. Practical Use Cases: Most real-world applications use 1D or 2D data

When to Use N-D Peak Detection

Suitable Cases

Alternatives for High Dimensions

  1. Flatten and Use 1D: For some use cases, flattening may be appropriate
  2. Dimensionality Reduction: Reduce dimensions before peak detection
  3. Specialized Algorithms: Use domain-specific algorithms for your use case

Example: 3D Image Analysis

import numpy as np
from peak_locator import PeakDetector

# 3D image data (e.g., medical imaging)
image_3d = np.random.rand(50, 50, 50) * 255
image_3d[25, 25, 25] = 300  # Add a bright spot

detector = PeakDetector(image_3d)
peak = detector.find_peak_nd()
print(f"Brightest voxel at {peak}")

Performance Considerations

Time Complexity

Space Complexity

Best Practices

  1. Prefer 1D/2D: Use specialized 1D/2D functions when possible
  2. Limit Dimensions: Keep dimensions reasonable (≤ 4D for practical use)
  3. Consider Alternatives: Evaluate if N-D peak detection is the right approach
  4. Test Thoroughly: Verify results for your specific use case

Future Improvements

Potential enhancements for N-D peak detection:

  1. Efficient Divide-and-Conquer: Implement proper recursive algorithm
  2. Parallel Processing: Utilize multiple cores for large tensors
  3. Sparse Support: Handle sparse tensors efficiently
  4. Domain-Specific Optimizations: Specialized algorithms for common use cases

Next Steps