<jupyter_start><jupyter_text>Number of Trials vs Coefficient Estimate ErrorTests the effect of Gaussian white noise on the estimated coefficients<jupyter_code>%load_ext autoreload
%autoreload 2

# Import Python packages
import pickle

# Package Imports
from sindy_bvp import SINDyBVP
from sindy_bvp.differentiators import PolyInterp
from sindy_bvp.library_builders import NoiseMaker
# Set file to load and stem for saving
load_stem = "./data/S2-NLSL-"
save_stem = "./data/Fig5b-NLSL-"
%%time

# Set a range of noise magnitudes to test
num_trials = [10, 20, 30, 40, 50,
              60, 70, 80, 90, 100,
              110, 120, 130, 140, 150,
              160, 170, 180, 190, 200]

# Since the data is noisy, we'll use a Polynomial Interpolation derivative method
poly = PolyInterp(diff_order=2, width=20, degree=5)

# Initialize NoiseMaker, which adds 1% noise then filters noisy signal
nm = NoiseMaker(noise_magnitude=0.01)

# Create an empty
results_list = []

print("Completed:", end=" ")
for trial_count in num_trials:
    # Initialize SINDyBVP object
    sbvp = SINDyBVP(file_stem = load_stem,
                    num_trials = trial_count,
                    differentiator = poly,
                    outcome_var = 'd^{2}u/dx^{2}',
                    noisemaker = nm,
                    known_vars = ['u', 'u^{2}', 'du/dx', 'f'],
                    dep_var_name = 'u',
                    ind_var_name = 'x')

    # Execute the optimization
    coeffs, plotter = sbvp.sindy_bvp()

    # Compute the S-L coeffs with Plotter analysis tool
    plotter.compute_sl_coeffs()
    
    # gather the learned coefficients and relevant metrics
    # And place into the results_list
    results_list.append({'num_trials': trial_count,
                         'loss': min(sbvp.groupreg.Losses),
                         'p': plotter.inferred_phi, 
                         'q': plotter.inferred_q,
                         'coeffs': coeffs})
    
    print(trial_count, end=" | ")
## Pickle the results
pickle.dump(results_list, open(save_stem+"results.pickle", "wb"))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.0977121067683508, 'fraction_numerical': 0.03098188751191611, 'mean_word_length': 2.5758091993185688, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '168362', 'license': 'MIT', 'n_tokens_mistral': 734, 'n_tokens_neox': 653, 'n_words': 187, 'path': 'Fig 5b Data - Trials vs Coeff Error - NLSL.ipynb', 'repo_name': 'sheadan/SINDy-BVP', 'size': '2098'}