<jupyter_start><jupyter_text>Imports<jupyter_code>import numpy as np
from pysplinefit import data
from matplotlib import pyplot as plt
%matplotlib inline<jupyter_output><empty_output><jupyter_text>Generate a Test Case - Fit Sine  Create the data<jupyter_code>theta = np.linspace(0, 2 * np.pi, 100)
y = np.sin(theta)
z = np.zeros(len(theta))<jupyter_output><empty_output><jupyter_text>Plot data for illustraion<jupyter_code>fig = plt.figure(figsize=(8, 8))
plt.plot(theta, y)
plt.xlabel('Theta')
plt.ylabel('Sin(Theta)')
plt.title('Synthetic Boundary Fitting Example - Input Data');<jupyter_output><empty_output><jupyter_text>Shuffle synthetic data so it has to be parameterized before fitting<jupyter_code># Make 2D array
input_data = np.column_stack((theta, y, z))

# Shuffle
np.random.shuffle(input_data)<jupyter_output><empty_output><jupyter_text>Instantiate an instance of the Boundary Class<jupyter_code># Set degree and number of control points
synthetic_bound = data.Boundary()
synthetic_bound.degree = 2
synthetic_bound.num_ctrlpts = 10
# Set input data and start/end points
synthetic_bound.data = input_data
synthetic_bound.start = np.array([0.0, np.sin(0.0), 0.0])
synthetic_bound.end = np.array([2 * np.pi, np.sin(2 * np.pi), 0.0])<jupyter_output><empty_output><jupyter_text>Create the initial curve and plot it with the data<jupyter_code>synthetic_bound.set_init_curve()
init_curve_points = synthetic_bound.init_curve.points(np.linspace(0, 1))
init_curve_ctrlpts = synthetic_bound.init_curve.control_points
fig = plt.figure(figsize=(8, 8))
plt.scatter(theta, y, s=10, label='Input data');
plt.plot(init_curve_points[:, 0], init_curve_points[:, 1], color='r', label='Initial Curve');
plt.scatter(init_curve_ctrlpts[:, 0], init_curve_ctrlpts[:, 1], color='g', label='Initial Curve Control Points')
plt.xlabel('Theta');
plt.ylabel('Y');
plt.title('Synthetic Input Data and Initial Curve');
plt.legend();<jupyter_output><empty_output><jupyter_text>Call fit - normal log level<jupyter_code>synthetic_bound.fit()<jupyter_output>Filling R Matrix
Checking partition of unity
Conditioning number of RTR: 7.805045519767996
Performing least squares
Filling R Matrix
Checking partition of unity
Conditioning number of RTR: 7.796874494228831
Performing least squares<jupyter_text>Plot results<jupyter_code>fit_points = synthetic_bound.fit_curve.points(np.linspace(0, 1, 100))
fit_ctrlpts = synthetic_bound.fit_curve.control_points

fig = plt.figure(figsize=(10,10))
plt.scatter(theta, y, s=8, label='Input data')
plt.plot(fit_points[:, 0], fit_points[:, 1], color='r', label='Fit curve');
plt.plot(fit_ctrlpts[:, 0], fit_ctrlpts[:, 1], color='g', marker='o', label='Fit curve control points')
plt.xlabel('Theta')
plt.ylabel('Y');
plt.legend()
plt.title('Final Fit Curve to Synthetic Data - Normal Logging');<jupyter_output><empty_output><jupyter_text>Call fit - quiet log level<jupyter_code>synthetic_bound.fit(logging=-1)
fit_points = synthetic_bound.fit_curve.points(np.linspace(0, 1, 100))
fit_ctrlpts = synthetic_bound.fit_curve.control_points

fig = plt.figure(figsize=(10,10))
plt.scatter(theta, y, s=8, label='Input data')
plt.plot(fit_points[:, 0], fit_points[:, 1], color='r', label='Fit curve');
plt.plot(fit_ctrlpts[:, 0], fit_ctrlpts[:, 1], color='g', marker='o', label='Fit curve control points')
plt.xlabel('Theta')
plt.ylabel('Y');
plt.legend()
plt.title('Final Fit Curve to Synthetic Data - Quiet Logging');<jupyter_output><empty_output><jupyter_text>Call fit - debug log level<jupyter_code>synthetic_bound.fit(logging=4)
fit_points = synthetic_bound.fit_curve.points(np.linspace(0, 1, 100))
fit_ctrlpts = synthetic_bound.fit_curve.control_points

fig = plt.figure(figsize=(10,10))
plt.scatter(theta, y, s=8, label='Input data')
plt.plot(fit_points[:, 0], fit_points[:, 1], color='r', label='Fit curve');
plt.plot(fit_ctrlpts[:, 0], fit_ctrlpts[:, 1], color='g', marker='o', label='Fit curve control points')
plt.xlabel('Theta')
plt.ylabel('Y');
plt.legend()
plt.title('Final Fit Curve to Synthetic Data - Debug Logging');<jupyter_output><empty_output><jupyter_text>Print out parameterized data<jupyter_code>print(synthetic_bound.parameterized_data[:10, :])<jupyter_output>[[0.         0.         0.         0.        ]
 [0.06346652 0.06342392 0.         0.00572201]
 [0.12693304 0.12659245 0.         0.0116086 ]
 [0.19039955 0.18925124 0.         0.01766156]
 [0.25386607 0.25114799 0.         0.02388563]
 [0.31733259 0.31203345 0.         0.03028602]
 [0.38079911 0.37166246 0.         0.03687311]
 [0.44426563 0.42979491 0.         0.04364724]
 [0.50773215 0.48619674 0.         0.05064542]
 [0.57119866 0.54064082 0.         0.05786293]]
{'fraction_non_alphanumeric': 0.14448261056247316, 'fraction_numerical': 0.0781451266638042, 'mean_word_length': 6.178736517719568, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 43, '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': '11', 'dir': 'jupyter-structured-clean-dedup', 'id': '610038', 'license': 'MIT', 'n_tokens_mistral': 1997, 'n_tokens_neox': 1724, 'n_words': 357, 'path': 'examples/Boundary_Fitting_Example.ipynb', 'repo_name': 'stpotter16/PySplineFit', 'size': '4658'}