<jupyter_start><jupyter_text>Setup---Load trajectory data<jupyter_code>from grama.data import df_trajectory_windowed

(
    pt.ggplot(df_trajectory_windowed, pt.aes("x", "y"))
    + pt.geom_point()
)<jupyter_output><empty_output><jupyter_text>Load a trajectory model to fit<jupyter_code>from grama.models import make_trajectory_linear
md_trajectory = make_trajectory_linear()
md_trajectory.printpretty()<jupyter_output>model: Trajectory Model

  inputs:
    var_det:
      tau: [0.05, inf]
      u0: [0.1, inf]
      v0: [0.1, inf]
      t: [0, 600]
    var_rand:
    copula:
        None
  functions:
    x_trajectory: ['u0', 'v0', 'tau', 't'] -> ['x']
    y_trajectory: ['u0', 'v0', 'tau', 't'] -> ['y']<jupyter_text>Fit trajectory model to data<jupyter_code>md_fit = (
    df_trajectory_windowed
    >> gr.ft_nls(
        md=md_trajectory,
        method="SLSQP",
        uq_method="linpool",
    )
)

md_fit.printpretty()<jupyter_output>... fit_nls setting out = ['y', 'x']
... eval_nls setting out = ['y', 'x']
... eval_nls setting var_fix = []
... eval_nls setting var_feat = ['t']<jupyter_text>Visualize estimated parameter distributions<jupyter_code>(
    md_fit
    >> gr.ev_monte_carlo(n=500, df_det="nom", skip=True)
    >> gr.pt_auto()
)<jupyter_output>Design runtime estimates unavailable; model has no timing data.
Calling plot_scattermat....<jupyter_text>Assess model<jupyter_code># Nominal curve
df_nom = (
    md_fit
    >> gr.ev_nominal(df_det=df_trajectory_windowed)
)

(
    pt.ggplot(mapping=pt.aes("x", "y"))
    + pt.geom_line(data=df_nom)
    + pt.geom_point(data=df_trajectory_windowed, color="salmon")
)<jupyter_output>... provided columns intersect model output.
eval_df() is dropping {'y', 'x'}<jupyter_text>Assess model with ensemble of trajectories<jupyter_code># Nominal curve
df_lines = (
    md_fit
    >> gr.ev_monte_carlo(n=200, df_det=df_trajectory_windowed)
)
# Visualize
plot = (
    pt.ggplot(mapping=pt.aes("x", "y"))
    + pt.geom_line(data=df_lines, mapping=pt.aes(group="u0"), alpha=1/5)
    + pt.geom_point(data=df_trajectory_windowed, color="salmon")
    + pt.theme_minimal()
)
plot
# Save the figure
plot.save("./trajectory-uncertainty-cone.png")<jupyter_output>Warning: Saving 6.4 x 4.8 in image.
Warning: Filename: ./trajectory-uncertainty-cone.png
{'fraction_non_alphanumeric': 0.15069686411149827, 'fraction_numerical': 0.013066202090592335, 'mean_word_length': 4.443127962085308, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 32, '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': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '197686', 'license': 'MIT', 'n_tokens_mistral': 947, 'n_tokens_neox': 914, 'n_words': 157, 'path': 'examples/trajectory_validation/trajectory_presentation.ipynb', 'repo_name': 'QingmuDeng/py_grama', 'size': '2296'}