""" Analyze the support structure of our best function and try to modify it. """ import numpy as np f = np.load('/workspace/best_f_10000.npy') N = len(f) dx = 0.5 / N print(f"N = {N}") print(f"Nonzero entries (>1e-8): {np.sum(f > 1e-8)}") print(f"Nonzero fraction: {np.mean(f > 1e-8):.4f}") # Find connected nonzero runs runs = [] in_run = False run_start = 0 for i in range(N): if f[i] > 1e-8: if not in_run: run_start = i in_run = True else: if in_run: runs.append((run_start, i - 1, i - run_start)) in_run = False if in_run: runs.append((run_start, N - 1, N - run_start)) print(f"\nNumber of runs: {len(runs)}") print(f"Run lengths: min={min(r[2] for r in runs)}, max={max(r[2] for r in runs)}, " f"mean={np.mean([r[2] for r in runs]):.1f}") # Show gaps gaps = [] for i in range(1, len(runs)): gap = runs[i][0] - runs[i-1][1] - 1 gaps.append(gap) if gaps: print(f"\nGaps: min={min(gaps)}, max={max(gaps)}, mean={np.mean(gaps):.1f}") # Show the run/gap pattern as a binary string pattern = ''.join(['1' if f[i] > 1e-8 else '0' for i in range(0, N, N//100)]) print(f"\nBinary pattern (100 chars, 1=nonzero): {pattern}") # Autoconvolution analysis M = 2 * N fft_f = np.fft.rfft(f, n=M) conv = np.fft.irfft(fft_f * fft_f, n=M) * dx integral_sq = (np.sum(f) * dx) ** 2 c1_profile = conv / integral_sq max_c1 = np.max(c1_profile) argmax = np.argmax(c1_profile) # Show the autoconvolution near the max print(f"\nAutoconvolution max: {max_c1:.12f}") print(f"Max position: {argmax} (of {len(c1_profile)})") print(f"Points within 0.01% of max: {np.sum(c1_profile > max_c1 * 0.9999)}") print(f"Points within 0.001% of max: {np.sum(c1_profile > max_c1 * 0.99999)}") # Show the top 20 height values print(f"\nTop 20 function values:") top_idx = np.argsort(f)[::-1][:20] for i, idx in enumerate(top_idx): print(f" f[{idx}] = {f[idx]:.6f}") # Show overall statistics print(f"\nFunction stats (nonzero only):") f_nz = f[f > 1e-8] print(f" Min: {f_nz.min():.6f}") print(f" Max: {f_nz.max():.6f}") print(f" Mean: {f_nz.mean():.6f}") print(f" Std: {f_nz.std():.6f}") print(f" Median: {np.median(f_nz):.6f}") # Histogram of nonzero values hist, edges = np.histogram(f_nz, bins=20) print(f"\nHistogram of nonzero values:") for i in range(len(hist)): bar = '#' * (hist[i] * 50 // max(hist)) print(f" [{edges[i]:.3f}, {edges[i+1]:.3f}]: {hist[i]:5d} {bar}")