<jupyter_start><jupyter_text>An example of layered data interpolation Source function and scattered data locations<jupyter_code>def foo(c):
    return sin(c[0]/100) + sin(c[1]*3)

cmin = [0.0, 0.0]
cmax = [1000.0, 10.0]

C = mgrid[0:cmax[0]:1e-1,0:cmax[1]:1e-1]
F = foo(C)

coo = uniform(cmin, cmax, (128,2))
val = foo(coo.transpose())

figure(figsize=(13,4))
pcolormesh(C[0], C[1], F)
scatter(coo[:,0], coo[:,1], c='k', s=1)
xlim([cmin[0], cmax[0]])
ylim([cmin[1], cmax[1]])
tight_layout()<jupyter_output><empty_output><jupyter_text>Size of the target grid:<jupyter_code>C.shape[1:]<jupyter_output><empty_output><jupyter_text>Anysotropy in target data should be reflected in the initial grid size Reduction in horizontal grid size leads to better results:<jupyter_code>ny = 16
for nx in (16, 8, 4):
    interp = mba2(cmin, cmax, [nx,ny], coo, val)
    error = amax(abs(val - interp(coo))) / amax(abs(val))
    print(interp)

    G = interp(C.transpose((1,2,0)).copy())
    figure(figsize=(12,4))
    pcolormesh(C[0], C[1], G)
    scatter(coo[:,0], coo[:,1], c='k', s=1)
    xlim([cmin[0], cmax[0]])
    ylim([cmin[1], cmax[1]])
    title(f'$n_0=[{nx},{ny}], \\quad \\varepsilon={error:e}$')
    tight_layout()<jupyter_output>level 1: initial approximation
level 2: dense  [63, 63] (31752 bytes)
level 3: sparse [123, 123] (45360 bytes, compression: 0.37)
level 4: sparse [243, 243] (48120 bytes, compression: 0.10)
level 5: sparse [483, 483] (48912 bytes, compression: 0.03)
level 6: sparse [963, 963] (49152 bytes, compression: 0.01)

level 1: initial approximation
level 2: dense  [59, 123] (58056 bytes)
level 3: sparse [115, 243] (47136 bytes, compression: 0.21)
level 4: sparse [227, 483] (48600 bytes, compression: 0.06)
level 5: sparse [451, 963] (49056 bytes, compression: 0.01)

level 1: initial approximation
level 2: dense  [27, 123] (26568 bytes)
level 3: sparse [51, 243] (44928 bytes, compression: 0.45)
level 4: sparse [99, 483] (47832 bytes, compression: 0.13)
level 5: sparse [195, 963] (48624 bytes, compression: 0.03)
level 6: sparse [387, 1923] (49056 bytes, compression: 0.01)<jupyter_text>Increase in vertical grid size may lead to the initial grid being too sparse:<jupyter_code>nx = 16
for ny in (16, 32, 64):
    interp = mba2(cmin, cmax, [nx,ny], coo, val)
    error = amax(abs(val - interp(coo))) / amax(abs(val))
    print(interp)

    G = interp(C.transpose((1,2,0)).copy())
    figure(figsize=(12,4))
    pcolormesh(C[0], C[1], G)
    scatter(coo[:,0], coo[:,1], c='k', s=1)
    xlim([cmin[0], cmax[0]])
    ylim([cmin[1], cmax[1]])
    title(f'$n_0=[{nx},{ny}], \\quad \\varepsilon={error:e}$')
    tight_layout()<jupyter_output>level 1: initial approximation
level 2: dense  [63, 63] (31752 bytes)
level 3: sparse [123, 123] (45360 bytes, compression: 0.37)
level 4: sparse [243, 243] (48120 bytes, compression: 0.10)
level 5: sparse [483, 483] (48912 bytes, compression: 0.03)
level 6: sparse [963, 963] (49152 bytes, compression: 0.01)

level 1: initial approximation
level 2: dense  [63, 127] (64008 bytes)
level 3: sparse [123, 251] (47304 bytes, compression: 0.19)
level 4: sparse [243, 499] (48480 bytes, compression: 0.05)
level 5: sparse [483, 995] (49056 bytes, compression: 0.01)
level 6: sparse [963, 1987] (49152 bytes, compression: 0.00)

level 1: initial approximation
level 2: dense  [33, 129] (34056 bytes)
level 3: sparse [63, 255] (45600 bytes, compression: 0.35)
level 4: sparse [123, 507] (48072 bytes, compression: 0.10)
level 5: sparse [243, 1011] (48792 bytes, compression: 0.02)
level 6: sparse [483, 2019] (49080 bytes, compression: 0.01)
level 7: sparse [963, 4035] (49152 bytes, compression: 0.00)
{'fraction_non_alphanumeric': 0.17473338802296964, 'fraction_numerical': 0.1430133989608969, 'mean_word_length': 4.99672131147541, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '564774', 'license': 'MIT', 'n_tokens_mistral': 1796, 'n_tokens_neox': 1440, 'n_words': 434, 'path': 'python/layered.ipynb', 'repo_name': 'yonch/mba', 'size': '3657'}