A comprehensive analysis framework for testing Chebyshev polynomial approximations of indicator functions, with focus on performance under input noise and domain variations.
This project evaluates how well Chebyshev polynomial approximations of indicator functions perform when evaluated on "approximate integer" points with varying epsilon values. The system supports multiple indicator function types, domain rescaling between [0,8] and [-1,1], and comprehensive error analysis across different polynomial degrees.
Key Features:
- 4 different indicator function implementations
- Dual domain support (original [0,8] and rescaled [-1,1])
- Configurable Chebyshev polynomial degrees (59, 119, 247+)
- Comprehensive error analysis for desired vs non-desired regions
- Automated visualization and comparison generation
- Extensive parameter sweep capabilities
- Configure parameters: Edit
config.py(see Configuration section) - Run tests:
python main.py - Verify system:
python verify_tests.py - View results: Check
graphs/{DATE_FOLDER}/{FUNCTION_TYPE}/
All parameters are centralized in config.py:
- Line 13:
FUNCTION_TYPE- Choose function:"impulse","plateau_sine","plateau_reg" - Line 15:
USE_RESCALED- Domain:Truefor [-1,1],Falsefor [0,8] - Line 25:
SINGLE_EPSILON- Single value orNonefor range testing
- Line 14:
POINTS_PER_VALUE- How many test points per integer (0,1,2,...,8)
- Description: Gaussian probability density centered at desired value
- Output: Peak of 1.0 at desired value, decays smoothly
- Parameters:
IMPULSE_SIGMA,IMPULSE_MU,IMPULSE_SCALING - Use case: Smooth, differentiable indicator
- Description: Smooth plateau with internal ripples and sigmoid edges
- Output: Plateau region with sine wave ripples, smooth transitions
- Parameters:
SP_AMPLITUDE,SP_STEEPNESS,SP_FREQ,SP_WIDTH - Use case: Complex function with multiple frequency components
- Description: Hard cutoff indicator function
- Output:
1for x ∈ [desired_value-0.5, desired_value+0.5],0elsewhere - Parameters: Uses
DESIRED_VALUEonly - Use case: Traditional step function indicator
The system supports two domains:
- When:
USE_RESCALED = False - Function evaluation: Direct on [0,8]
- Test points: Approximate integers 0,1,2,3,4,5,6,7,8 ± epsilon
- When:
USE_RESCALED = True - Mapping:
x_rescaled = x_original / 4.0 - 1.0 - Key mappings: 0→-1, 2→-0.5, 4→0, 8→1
- Function evaluation: Functions adapted to work on [-1,1]
- Total points:
POINTS_PER_VALUE × 9(for integers 0-8) - Point distribution: Equal number of points near each integer
- Noise: Each point =
integer + uniform_noise(-epsilon, +epsilon) - Categories:
- Desired points: Near integer 2 (should map to target 1)
- Excluding points: Near other integers (should map to target 0)
- Domain: [0,8] or [-1,1] depending on
USE_RESCALED - Degree: Configurable via
CHEB_DEGREE(default: 119) - Method: Discrete cosine transform approach with Clenshaw evaluation
- Point Error: |Chebyshev_output - expected_target|
- Green Error: Error for points that should equal 1
- Red Error: Error for points that should equal 0
- Metrics: Max error, RMS error, separate tracking by category
Test how approximation accuracy changes with input noise:
SINGLE_EPSILON = 0.02 # Test just this epsilon valueSINGLE_EPSILON = None # Enable range mode
MIN_EPSILON = 0.001 # Start of range
MAX_EPSILON = 0.05 # End of range
NUM_EPSILON_VALUES = 20 # Number of values to testResults are saved to graphs/{DATE_FOLDER}/{FUNCTION_TYPE}/:
- Function plots: Visual representation of the indicator function
- Error plots: Epsilon vs error curves (3 types: desired, excluding, combined)
- CSV logs: Detailed numerical results for each epsilon value
- Summary files: Aggregated statistics
Run python verify_tests.py to verify the system works correctly:
- ✓ Rescaling: Confirms [0,8] ↔ [-1,1] mapping
- ✓ Functions: Verifies different functions produce different outputs
- ✓ Epsilon: Confirms epsilon affects point generation
- ✓ Domains: Tests rescaled vs original domain consistency
main.py- Main application entry point that orchestrates the complete analysis workflowconfig.py- Centralized configuration file containing all adjustable parameters for the systemutils.py- Common utility functions including statistics, file handling, and ID generation
indicator_functions.py- Implementation of various indicator functions (impulse, plateau_sine, plateau_reg, plateau_sine_impulse)chebyshev_approximation.py- Chebyshev polynomial coefficient computation and evaluation using optimized NumPy implementationdata_generation.py- Generation of approximate integer test data with domain rescaling capabilities
error_analysis.py- Comprehensive error calculation and analysis between polynomial approximations and true function valuescreate_graphs.py- All plotting and visualization functionality including function plots, error analysis, and comparison chartscompare_runs.py- Cross-run comparison utilities and batch analysis tools
graphs/- Organized output directory structure:{DATE_FOLDER}/- Date-based run organization (e.g.,aug21_deg119/){FUNCTION_TYPE}/- Function-specific results (impulse, plateau_sine, plateau_reg)*_function_approximation_*.png- Function vs approximation comparison*_function_*_errors_*.png- Function-based error analysis plots*_chebyshev_*_errors_*.png- Chebyshev-based error analysis plots*_detailed_results_*.csv- Raw numerical results dataanalysis_summary_*.txt- Statistical analysis summaries
comparisons/- Cross-function comparison plotsverification/- System verification and validation plots
archive/- Historical versions and experimental code
- Python 3.7+
- NumPy - Mathematical operations and polynomial computations
- Matplotlib - Plotting and visualization
- Pathlib - File system operations
# Configure in config.py:
FUNCTION_TYPE = "impulse"
CHEB_DEGREE = 119
USE_RESCALED = True
# Run analysis
python main.py# Configure in config.py:
MIN_EPSILON = 0.001
MAX_EPSILON = 0.45
NUM_EPSILON_VALUES = 50
# Results automatically saved to graphs/{DATE_FOLDER}/# Run multiple function types with compare_runs.py
# Automatically generates comparison visualizations- Rescaling works correctly: Both domains produce consistent results
- Functions are distinct: Each function type has unique characteristics
- Epsilon sensitivity: Larger epsilon → larger point deviations as expected
- Constant errors: High-degree polynomials (119) may saturate accuracy