.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/tracking/plotFilterFWGMouseTrajectoryManualVsLearnedParams.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. or to run this example in your browser via Binder .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_tracking_plotFilterFWGMouseTrajectoryManualVsLearnedParams.py: Filtering of a foraging mouse trajectory with manual vs learned parameters ========================================================================== The code below performs Kalman filtering and smoothing of a trajectory of the mouse shown on the left image below, as it forages in the arena shown on the right image below, with manual and learned parameters. Click on the images to see their larger versions. .. image:: /_static/mouseOnWheel.png :width: 300 :alt: image of mouse on wheel .. image:: /_static/foragingMouse.png :width: 300 :alt: image of foraging mouse .. GENERATED FROM PYTHON SOURCE LINES 21-23 Import packages --------------- .. GENERATED FROM PYTHON SOURCE LINES 23-38 .. code-block:: Python import sys import os import random import pickle import configparser import numpy as np import pandas as pd import torch import plotly.graph_objects as go import lds.tracking.utils import lds.inference import lds.learning .. GENERATED FROM PYTHON SOURCE LINES 39-41 Setup configuration variables ----------------------------- .. GENERATED FROM PYTHON SOURCE LINES 41-49 .. code-block:: Python start_position = 0 number_positions = 10000 color_measures = "black" color_pattern_filtered = "rgba(255,0,0,{:f})" cb_alpha = 0.3 data_filename = "http://www.gatsby.ucl.ac.uk/~rapela/svGPFA/data/positions_session003_start0.00_end15548.27.csv" .. GENERATED FROM PYTHON SOURCE LINES 50-52 Get the mouse position measurements ----------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 52-57 .. code-block:: Python data = pd.read_csv(data_filename) data = data.iloc[start_position:start_position+number_positions,:] y = np.transpose(data[["x", "y"]].to_numpy()) .. GENERATED FROM PYTHON SOURCE LINES 58-60 Kalman filter matrices for tracking ----------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 60-66 .. code-block:: Python date_times = pd.to_datetime(data["time"]) dt = (date_times.iloc[1]-date_times.iloc[0]).total_seconds() B, _, Z, _, Qe = lds.tracking.utils.getLDSmatricesForTracking( dt=dt, sigma_a=np.nan, sigma_x=np.nan, sigma_y=np.nan) .. GENERATED FROM PYTHON SOURCE LINES 67-69 Filtering with manual parameters -------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 69-95 .. code-block:: Python pos_x0_manual = y[0, 0] pos_y0_manual = y[1, 0] vel_x0_manual = 0.0 vel_y0_manual = 0.0 acc_x0_manual = 0.0 acc_y0_manual = 0.0 sigma_a_manual = 1e4 sigma_x_manual = 1e2 sigma_y_manual = 1e2 sqrt_diag_V0_value_manual = 1e-3 m0_manual = np.array([pos_x0_manual, vel_x0_manual, acc_x0_manual, pos_y0_manual, vel_y0_manual, acc_y0_manual], dtype=np.double) R_manual = np.diag([sigma_x_manual**2, sigma_y_manual**2]) V0_manual = np.diag(np.ones(len(m0_manual))*sqrt_diag_V0_value_manual**2) Q_manual = Qe*sigma_a_manual filterRes_manual = lds.inference.filterLDS_SS_withMissingValues_np( y=y, B=B, Q=Q_manual, m0=m0_manual, V0=V0_manual, Z=Z, R=R_manual) smoothRes_manual = lds.inference.smoothLDS_SS( B=B, xnn=filterRes_manual["xnn"], Vnn=filterRes_manual["Vnn"], xnn1=filterRes_manual["xnn1"], Vnn1=filterRes_manual["Vnn1"], m0=m0_manual, V0=V0_manual) .. GENERATED FROM PYTHON SOURCE LINES 96-98 Filtering with learned parameters --------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 100-102 Learn parameters ~~~~~~~~~~~~~~~~ .. GENERATED FROM PYTHON SOURCE LINES 102-161 .. code-block:: Python skip_estimation_sigma_a = False skip_estimation_R = False skip_estimation_m0 = False skip_estimation_V0 = False lbfgs_max_iter = 2 lbfgs_tolerance_grad = -1 lbfgs_tolerance_change = 1e-3 lbfgs_lr = 0.01 lbfgs_n_epochs = 75 lbfgs_tol = 1e-3 Qe_reg_param_learned = 1e-2 sqrt_diag_R_torch = torch.DoubleTensor([sigma_x_manual, sigma_y_manual]) m0_torch = torch.from_numpy(m0_manual.copy()) sqrt_diag_V0_torch = torch.DoubleTensor([sqrt_diag_V0_value_manual for i in range(len(m0_manual))]) if Qe_reg_param_learned is not None: Qe_regularized_learned = Qe + Qe_reg_param_learned * np.eye(Qe.shape[0]) else: Qe_regularized_learned = Qe y_torch = torch.from_numpy(y.astype(np.double)) B_torch = torch.from_numpy(B.astype(np.double)) Qe_regularized_learned_torch = torch.from_numpy(Qe_regularized_learned.astype(np.double)) Z_torch = torch.from_numpy(Z.astype(np.double)) vars_to_estimate = {} if skip_estimation_sigma_a: vars_to_estimate["sigma_a"] = False else: vars_to_estimate["sigma_a"] = True if skip_estimation_R: vars_to_estimate["sqrt_diag_R"] = False vars_to_estimate["R"] = False else: vars_to_estimate["sqrt_diag_R"] = True vars_to_estimate["R"] = True if skip_estimation_m0: vars_to_estimate["m0"] = False else: vars_to_estimate["m0"] = True if skip_estimation_V0: vars_to_estimate["sqrt_diag_V0"] = False vars_to_estimate["V0"] = False else: vars_to_estimate["sqrt_diag_V0"] = True vars_to_estimate["V0"] = True optim_res_learned = lds.learning.torch_lbfgs_optimize_SS_tracking_diagV0( y=y_torch, B=B_torch, sigma_a0=sigma_a_manual, Qe=Qe_regularized_learned_torch, Z=Z_torch, sqrt_diag_R_0=sqrt_diag_R_torch, m0_0=m0_torch, sqrt_diag_V0_0=sqrt_diag_V0_torch, max_iter=lbfgs_max_iter, lr=lbfgs_lr, vars_to_estimate=vars_to_estimate, tolerance_grad=lbfgs_tolerance_grad, tolerance_change=lbfgs_tolerance_change, n_epochs=lbfgs_n_epochs, tol=lbfgs_tol) .. rst-class:: sphx-glr-script-out .. code-block:: none in closure, ll=-157750.21970555978 .. GENERATED FROM PYTHON SOURCE LINES 162-164 Filter ~~~~~~ .. GENERATED FROM PYTHON SOURCE LINES 164-177 .. code-block:: Python Q_learned = optim_res_learned["estimates"]["sigma_a"].item()**2*Qe m0_learned = optim_res_learned["estimates"]["m0"].numpy() V0_learned = np.diag(optim_res_learned["estimates"]["sqrt_diag_V0"].numpy()**2) R_learned = np.diag(optim_res_learned["estimates"]["sqrt_diag_R"].numpy()**2) filterRes_learned = lds.inference.filterLDS_SS_withMissingValues_np( y=y, B=B, Q=Q_learned, m0=m0_learned, V0=V0_learned, Z=Z, R=R_learned) smoothRes_learned = lds.inference.smoothLDS_SS( B=B, xnn=filterRes_learned["xnn"], Vnn=filterRes_learned["Vnn"], xnn1=filterRes_learned["xnn1"], Vnn1=filterRes_learned["Vnn1"], m0=m0_learned, V0=V0_learned) .. rst-class:: sphx-glr-script-out .. code-block:: none /opt/hostedtoolcache/Python/3.12.5/x64/lib/python3.12/site-packages/numpy/linalg/_linalg.py:2371: RuntimeWarning: divide by zero encountered in slogdet .. GENERATED FROM PYTHON SOURCE LINES 178-180 Plots ----- .. GENERATED FROM PYTHON SOURCE LINES 180-320 .. code-block:: Python def get_fig_kinematics_vs_time( time, measured_x, measured_y, finite_diff_x, finite_diff_y, manual_mean_x, manual_mean_y, manual_ci_x_upper, manual_ci_y_upper, manual_ci_x_lower, manual_ci_y_lower, learned_mean_x, learned_mean_y, learned_ci_x_upper, learned_ci_y_upper, learned_ci_x_lower, learned_ci_y_lower, cb_alpha, color_true, color_measured, color_finite_diff, color_manual_pattern, color_learned_pattern, xlabel, ylabel): fig = go.Figure() if measured_x is not None: trace_mes_x = go.Scatter( x=time, y=measured_x, mode="markers", marker={"color": color_measured}, name="measured x", showlegend=True, ) fig.add_trace(trace_mes_x) if measured_y is not None: trace_mes_y = go.Scatter( x=time, y=measured_y, mode="markers", marker={"color": color_measured}, name="measured y", showlegend=True, ) fig.add_trace(trace_mes_y) if finite_diff_x is not None: trace_fd_x = go.Scatter( x=time, y=finite_diff_x, mode="markers", marker={"color": color_finite_diff}, name="finite difference x", showlegend=True, ) fig.add_trace(trace_fd_x) if finite_diff_y is not None: trace_fd_y = go.Scatter( x=time, y=finite_diff_y, mode="markers", marker={"color": color_finite_diff}, name="finite difference y", showlegend=True, ) fig.add_trace(trace_fd_y) trace_manual_x = go.Scatter( x=time, y=manual_mean_x, mode="markers", marker={"color": color_manual_pattern.format(1.0)}, name="manual x", showlegend=True, legendgroup="manual_x", ) fig.add_trace(trace_manual_x) trace_manual_x_cb = go.Scatter( x=np.concatenate([time, time[::-1]]), y=np.concatenate([manual_ci_x_upper, manual_ci_x_lower[::-1]]), fill="toself", fillcolor=color_manual_pattern.format(cb_alpha), line=dict(color=color_manual_pattern.format(0.0)), showlegend=False, legendgroup="manual_x", ) fig.add_trace(trace_manual_x_cb) trace_manual_y = go.Scatter( x=time, y=manual_mean_y, mode="markers", marker={"color": color_manual_pattern.format(1.0)}, name="manual y", showlegend=True, legendgroup="manual_y", ) fig.add_trace(trace_manual_y) trace_manual_y_cb = go.Scatter( x=np.concatenate([time, time[::-1]]), y=np.concatenate([manual_ci_y_upper, manual_ci_y_lower[::-1]]), fill="toself", fillcolor=color_manual_pattern.format(cb_alpha), line=dict(color=color_manual_pattern.format(0.0)), showlegend=False, legendgroup="manual_y", ) fig.add_trace(trace_manual_y_cb) trace_learned_x = go.Scatter( x=time, y=learned_mean_x, mode="markers", marker={"color": color_learned_pattern.format(1.0)}, name="learned x", showlegend=True, legendgroup="learned_x", ) fig.add_trace(trace_learned_x) trace_learned_x_cb = go.Scatter( x=np.concatenate([time, time[::-1]]), y=np.concatenate([learned_ci_x_upper, learned_ci_x_lower[::-1]]), fill="toself", fillcolor=color_learned_pattern.format(cb_alpha), line=dict(color=color_learned_pattern.format(0.0)), showlegend=False, legendgroup="learned_x", ) fig.add_trace(trace_learned_x_cb) trace_learned_y = go.Scatter( x=time, y=learned_mean_y, mode="markers", marker={"color": color_learned_pattern.format(1.0)}, name="learned y", showlegend=True, legendgroup="learned_y", ) fig.add_trace(trace_learned_y) trace_learned_y_cb = go.Scatter( x=np.concatenate([time, time[::-1]]), y=np.concatenate([learned_ci_y_upper, learned_ci_y_lower[::-1]]), fill="toself", fillcolor=color_learned_pattern.format(cb_alpha), line=dict(color=color_learned_pattern.format(0.0)), showlegend=False, legendgroup="learned_y", ) fig.add_trace(trace_learned_y_cb) fig.update_layout(xaxis_title=xlabel, yaxis_title=ylabel, paper_bgcolor='rgba(0,0,0,0)', plot_bgcolor='rgba(0,0,0,0)', ) return fig .. GENERATED FROM PYTHON SOURCE LINES 321-323 Set variables for plotting ~~~~~~~~~~~~~~~~~~~~~~~~~~ .. GENERATED FROM PYTHON SOURCE LINES 323-348 .. code-block:: Python N = y.shape[1] time = np.arange(0, N*dt, dt) filtered_means_manual = filterRes_manual["xnn"] filtered_covs_manual = filterRes_manual["Vnn"] filtered_std_x_y_manual = np.sqrt(np.diagonal(a=filtered_covs_manual, axis1=0, axis2=1)) filtered_means_learned = filterRes_learned["xnn"] filtered_covs_learned = filterRes_learned["Vnn"] filtered_std_x_y_learned = np.sqrt(np.diagonal(a=filtered_covs_learned, axis1=0, axis2=1)) smoothed_means_manual = smoothRes_manual["xnN"] smoothed_covs_manual = smoothRes_manual["VnN"] smoothed_std_x_y_manual = np.sqrt(np.diagonal(a=smoothed_covs_manual, axis1=0, axis2=1)) smoothed_means_learned = smoothRes_learned["xnN"] smoothed_covs_learned = smoothRes_learned["VnN"] smoothed_std_x_y_learned = np.sqrt(np.diagonal(a=smoothed_covs_learned, axis1=0, axis2=1)) color_true = "blue" color_measured = "black" color_finite_diff = "blue" color_manual_pattern = "rgba(255,165,0,{:f})" color_learned_pattern = "rgba(255,0,0,{:f})" cb_alpha = 0.3 .. GENERATED FROM PYTHON SOURCE LINES 349-351 Positions filtered ~~~~~~~~~~~~~~~~~~ .. GENERATED FROM PYTHON SOURCE LINES 351-394 .. code-block:: Python measured_x = y[0, :] measured_y = y[1, :] finite_diff_x = None finite_diff_y = None filtered_mean_x_manual = filtered_means_manual[0, 0, :] filtered_mean_y_manual = filtered_means_manual[3, 0, :] filtered_mean_x_learned = filtered_means_learned[0, 0, :] filtered_mean_y_learned = filtered_means_learned[3, 0, :] filtered_ci_x_upper_manual = filtered_mean_x_manual + 1.96*filtered_std_x_y_manual[:, 0] filtered_ci_x_lower_manual = filtered_mean_x_manual - 1.96*filtered_std_x_y_manual[:, 0] filtered_ci_y_upper_manual = filtered_mean_y_manual + 1.96*filtered_std_x_y_manual[:, 3] filtered_ci_y_lower_manual = filtered_mean_y_manual - 1.96*filtered_std_x_y_manual[:, 3] filtered_ci_x_upper_learned = filtered_mean_x_learned + 1.96*filtered_std_x_y_learned[:, 0] filtered_ci_x_lower_learned = filtered_mean_x_learned - 1.96*filtered_std_x_y_learned[:, 0] filtered_ci_y_upper_learned = filtered_mean_y_learned + 1.96*filtered_std_x_y_learned[:, 3] filtered_ci_y_lower_learned = filtered_mean_y_learned - 1.96*filtered_std_x_y_learned[:, 3] fig = get_fig_kinematics_vs_time( time=time, measured_x=measured_x, measured_y=measured_y, finite_diff_x=finite_diff_x, finite_diff_y=finite_diff_y, manual_mean_x=filtered_mean_x_manual, manual_mean_y=filtered_mean_y_manual, manual_ci_x_upper=filtered_ci_x_upper_manual, manual_ci_y_upper=filtered_ci_y_upper_manual, manual_ci_x_lower=filtered_ci_x_lower_manual, manual_ci_y_lower=filtered_ci_y_lower_manual, learned_mean_x=filtered_mean_x_learned, learned_mean_y=filtered_mean_y_learned, learned_ci_x_upper=filtered_ci_x_upper_learned, learned_ci_y_upper=filtered_ci_y_upper_learned, learned_ci_x_lower=filtered_ci_x_lower_learned, learned_ci_y_lower=filtered_ci_y_lower_learned, cb_alpha=cb_alpha, color_true=color_true, color_measured=color_measured, color_finite_diff=color_finite_diff, color_learned_pattern=color_learned_pattern, color_manual_pattern=color_manual_pattern, xlabel="Time (sec)", ylabel="Position (pixels)") fig .. raw:: html


.. GENERATED FROM PYTHON SOURCE LINES 395-397 Positions smoothed ~~~~~~~~~~~~~~~~~~ .. GENERATED FROM PYTHON SOURCE LINES 397-441 .. code-block:: Python measured_x = y[0, :] measured_y = y[1, :] finite_diff_x = None finite_diff_y = None smoothed_mean_x_manual = smoothed_means_manual[0, 0, :] smoothed_mean_y_manual = smoothed_means_manual[3, 0, :] smoothed_mean_x_learned = smoothed_means_learned[0, 0, :] smoothed_mean_y_learned = smoothed_means_learned[3, 0, :] smoothed_ci_x_upper_manual = smoothed_mean_x_manual + 1.96*smoothed_std_x_y_manual[:, 0] smoothed_ci_x_lower_manual = smoothed_mean_x_manual - 1.96*smoothed_std_x_y_manual[:, 0] smoothed_ci_y_upper_manual = smoothed_mean_y_manual + 1.96*smoothed_std_x_y_manual[:, 3] smoothed_ci_y_lower_manual = smoothed_mean_y_manual - 1.96*smoothed_std_x_y_manual[:, 3] smoothed_ci_x_upper_learned = smoothed_mean_x_learned + 1.96*smoothed_std_x_y_learned[:, 0] smoothed_ci_x_lower_learned = smoothed_mean_x_learned - 1.96*smoothed_std_x_y_learned[:, 0] smoothed_ci_y_upper_learned = smoothed_mean_y_learned + 1.96*smoothed_std_x_y_learned[:, 3] smoothed_ci_y_lower_learned = smoothed_mean_y_learned - 1.96*smoothed_std_x_y_learned[:, 3] fig = get_fig_kinematics_vs_time( time=time, measured_x=measured_x, measured_y=measured_y, finite_diff_x=finite_diff_x, finite_diff_y=finite_diff_y, manual_mean_x=smoothed_mean_x_manual, manual_mean_y=smoothed_mean_y_manual, manual_ci_x_upper=smoothed_ci_x_upper_manual, manual_ci_y_upper=smoothed_ci_y_upper_manual, manual_ci_x_lower=smoothed_ci_x_lower_manual, manual_ci_y_lower=smoothed_ci_y_lower_manual, learned_mean_x=smoothed_mean_x_learned, learned_mean_y=smoothed_mean_y_learned, learned_ci_x_upper=smoothed_ci_x_upper_learned, learned_ci_y_upper=smoothed_ci_y_upper_learned, learned_ci_x_lower=smoothed_ci_x_lower_learned, learned_ci_y_lower=smoothed_ci_y_lower_learned, cb_alpha=cb_alpha, color_true=color_true, color_measured=color_measured, color_finite_diff=color_finite_diff, color_learned_pattern=color_learned_pattern, color_manual_pattern=color_manual_pattern, xlabel="Time (sec)", ylabel="Position (pixels)") fig .. raw:: html


.. GENERATED FROM PYTHON SOURCE LINES 442-444 Velocities filtered ~~~~~~~~~~~~~~~~~~~ .. GENERATED FROM PYTHON SOURCE LINES 444-486 .. code-block:: Python measured_x = None measured_y = None finite_diff_x = np.diff(y[0, :])/dt finite_diff_y = np.diff(y[1, :])/dt filtered_mean_x_manual = filtered_means_manual[1, 0, :] filtered_mean_y_manual = filtered_means_manual[4, 0, :] filtered_mean_x_learned = filtered_means_learned[1, 0, :] filtered_mean_y_learned = filtered_means_learned[4, 0, :] filtered_ci_x_upper_manual = filtered_mean_x_manual + 1.96*filtered_std_x_y_manual[:, 1] filtered_ci_x_lower_manual = filtered_mean_x_manual - 1.96*filtered_std_x_y_manual[:, 1] filtered_ci_y_upper_manual= filtered_mean_y_manual + 1.96*filtered_std_x_y_manual[:, 4] filtered_ci_y_lower_manual = filtered_mean_y_manual - 1.96*filtered_std_x_y_manual[:, 4] filtered_ci_x_upper_learned = filtered_mean_x_learned + 1.96*filtered_std_x_y_learned[:, 1] filtered_ci_x_lower_learned = filtered_mean_x_learned - 1.96*filtered_std_x_y_learned[:, 1] filtered_ci_y_upper_learned= filtered_mean_y_learned + 1.96*filtered_std_x_y_learned[:, 4] filtered_ci_y_lower_learned = filtered_mean_y_learned - 1.96*filtered_std_x_y_learned[:, 4] fig = get_fig_kinematics_vs_time( time=time, measured_x=measured_x, measured_y=measured_y, finite_diff_x=finite_diff_x, finite_diff_y=finite_diff_y, manual_mean_x=filtered_mean_x_manual, manual_mean_y=filtered_mean_y_manual, manual_ci_x_upper=filtered_ci_x_upper_manual, manual_ci_y_upper=filtered_ci_y_upper_manual, manual_ci_x_lower=filtered_ci_x_lower_manual, manual_ci_y_lower=filtered_ci_y_lower_manual, learned_mean_x=filtered_mean_x_learned, learned_mean_y=filtered_mean_y_learned, learned_ci_x_upper=filtered_ci_x_upper_learned, learned_ci_y_upper=filtered_ci_y_upper_learned, learned_ci_x_lower=filtered_ci_x_lower_learned, learned_ci_y_lower=filtered_ci_y_lower_learned, cb_alpha=cb_alpha, color_true=color_true, color_measured=color_measured, color_finite_diff=color_finite_diff, color_manual_pattern=color_manual_pattern, color_learned_pattern=color_learned_pattern, xlabel="Time (sec)", ylabel="Velocity (pixels/sec)") fig .. raw:: html


.. GENERATED FROM PYTHON SOURCE LINES 487-489 Velocities smoothed ~~~~~~~~~~~~~~~~~~~ .. GENERATED FROM PYTHON SOURCE LINES 489-532 .. code-block:: Python measured_x = None measured_y = None finite_diff_x = np.diff(y[0, :])/dt finite_diff_y = np.diff(y[1, :])/dt smoothed_mean_x_manual = smoothed_means_manual[1, 0, :] smoothed_mean_y_manual = smoothed_means_manual[4, 0, :] smoothed_mean_x_learned = smoothed_means_learned[1, 0, :] smoothed_mean_y_learned = smoothed_means_learned[4, 0, :] smoothed_ci_x_upper_manual = smoothed_mean_x_manual + 1.96*smoothed_std_x_y_manual[:, 1] smoothed_ci_x_lower_manual = smoothed_mean_x_manual - 1.96*smoothed_std_x_y_manual[:, 1] smoothed_ci_y_upper_manual= smoothed_mean_y_manual + 1.96*smoothed_std_x_y_manual[:, 4] smoothed_ci_y_lower_manual = smoothed_mean_y_manual - 1.96*smoothed_std_x_y_manual[:, 4] smoothed_ci_x_upper_learned = smoothed_mean_x_learned + 1.96*smoothed_std_x_y_learned[:, 1] smoothed_ci_x_lower_learned = smoothed_mean_x_learned - 1.96*smoothed_std_x_y_learned[:, 1] smoothed_ci_y_upper_learned= smoothed_mean_y_learned + 1.96*smoothed_std_x_y_learned[:, 4] smoothed_ci_y_lower_learned = smoothed_mean_y_learned - 1.96*smoothed_std_x_y_learned[:, 4] fig = get_fig_kinematics_vs_time( time=time, measured_x=measured_x, measured_y=measured_y, finite_diff_x=finite_diff_x, finite_diff_y=finite_diff_y, manual_mean_x=smoothed_mean_x_manual, manual_mean_y=smoothed_mean_y_manual, manual_ci_x_upper=smoothed_ci_x_upper_manual, manual_ci_y_upper=smoothed_ci_y_upper_manual, manual_ci_x_lower=smoothed_ci_x_lower_manual, manual_ci_y_lower=smoothed_ci_y_lower_manual, learned_mean_x=smoothed_mean_x_learned, learned_mean_y=smoothed_mean_y_learned, learned_ci_x_upper=smoothed_ci_x_upper_learned, learned_ci_y_upper=smoothed_ci_y_upper_learned, learned_ci_x_lower=smoothed_ci_x_lower_learned, learned_ci_y_lower=smoothed_ci_y_lower_learned, cb_alpha=cb_alpha, color_true=color_true, color_measured=color_measured, color_finite_diff=color_finite_diff, color_manual_pattern=color_manual_pattern, color_learned_pattern=color_learned_pattern, xlabel="Time (sec)", ylabel="Velocity (pixels/sec)") fig .. raw:: html


.. GENERATED FROM PYTHON SOURCE LINES 533-535 Accelerations filtered ~~~~~~~~~~~~~~~~~~~~~~ .. GENERATED FROM PYTHON SOURCE LINES 535-578 .. code-block:: Python measured_x = None measured_y = None finite_diff_x = np.diff(np.diff(y[0, :]))/dt**2 finite_diff_y = np.diff(np.diff(y[1, :]))/dt**2 filtered_mean_x_manual = filtered_means_manual[2, 0, :] filtered_mean_y_manual = filtered_means_manual[5, 0, :] filtered_mean_x_learned = filtered_means_learned[2, 0, :] filtered_mean_y_learned = filtered_means_learned[5, 0, :] filtered_ci_x_upper_manual = filtered_mean_x_manual + 1.96*filtered_std_x_y_manual[:, 2] filtered_ci_x_lower_manual = filtered_mean_x_manual - 1.96*filtered_std_x_y_manual[:, 2] filtered_ci_y_upper_manual = filtered_mean_y_manual + 1.96*filtered_std_x_y_manual[:, 5] filtered_ci_y_lower_manual = filtered_mean_y_manual - 1.96*filtered_std_x_y_manual[:, 5] filtered_ci_x_upper_learned = filtered_mean_x_learned + 1.96*filtered_std_x_y_learned[:, 2] filtered_ci_x_lower_learned = filtered_mean_x_learned - 1.96*filtered_std_x_y_learned[:, 2] filtered_ci_y_upper_learned = filtered_mean_y_learned + 1.96*filtered_std_x_y_learned[:, 5] filtered_ci_y_lower_learned = filtered_mean_y_learned - 1.96*filtered_std_x_y_learned[:, 5] fig = get_fig_kinematics_vs_time( time=time, measured_x=measured_x, measured_y=measured_y, finite_diff_x=finite_diff_x, finite_diff_y=finite_diff_y, manual_mean_x=filtered_mean_x_manual, manual_mean_y=filtered_mean_y_manual, manual_ci_x_upper=filtered_ci_x_upper_manual, manual_ci_y_upper=filtered_ci_y_upper_manual, manual_ci_x_lower=filtered_ci_x_lower_manual, manual_ci_y_lower=filtered_ci_y_lower_manual, learned_mean_x=filtered_mean_x_learned, learned_mean_y=filtered_mean_y_learned, learned_ci_x_upper=filtered_ci_x_upper_learned, learned_ci_y_upper=filtered_ci_y_upper_learned, learned_ci_x_lower=filtered_ci_x_lower_learned, learned_ci_y_lower=filtered_ci_y_lower_learned, cb_alpha=cb_alpha, color_true=color_true, color_measured=color_measured, color_finite_diff=color_finite_diff, color_manual_pattern=color_manual_pattern, color_learned_pattern=color_learned_pattern, xlabel="Time (sec)", ylabel="Acceleration (pixels/sec^2)") fig .. raw:: html


.. GENERATED FROM PYTHON SOURCE LINES 579-581 Accelerations smoothed ~~~~~~~~~~~~~~~~~~~~~~ .. GENERATED FROM PYTHON SOURCE LINES 581-624 .. code-block:: Python measured_x = None measured_y = None finite_diff_x = np.diff(np.diff(y[0, :]))/dt**2 finite_diff_y = np.diff(np.diff(y[1, :]))/dt**2 smoothed_mean_x_manual = smoothed_means_manual[2, 0, :] smoothed_mean_y_manual = smoothed_means_manual[5, 0, :] smoothed_mean_x_learned = smoothed_means_learned[2, 0, :] smoothed_mean_y_learned = smoothed_means_learned[5, 0, :] smoothed_ci_x_upper_manual = smoothed_mean_x_manual + 1.96*smoothed_std_x_y_manual[:, 2] smoothed_ci_x_lower_manual = smoothed_mean_x_manual - 1.96*smoothed_std_x_y_manual[:, 2] smoothed_ci_y_upper_manual = smoothed_mean_y_manual + 1.96*smoothed_std_x_y_manual[:, 5] smoothed_ci_y_lower_manual = smoothed_mean_y_manual - 1.96*smoothed_std_x_y_manual[:, 5] smoothed_ci_x_upper_learned = smoothed_mean_x_learned + 1.96*smoothed_std_x_y_learned[:, 2] smoothed_ci_x_lower_learned = smoothed_mean_x_learned - 1.96*smoothed_std_x_y_learned[:, 2] smoothed_ci_y_upper_learned = smoothed_mean_y_learned + 1.96*smoothed_std_x_y_learned[:, 5] smoothed_ci_y_lower_learned = smoothed_mean_y_learned - 1.96*smoothed_std_x_y_learned[:, 5] fig = get_fig_kinematics_vs_time( time=time, measured_x=measured_x, measured_y=measured_y, finite_diff_x=finite_diff_x, finite_diff_y=finite_diff_y, manual_mean_x=smoothed_mean_x_manual, manual_mean_y=smoothed_mean_y_manual, manual_ci_x_upper=smoothed_ci_x_upper_manual, manual_ci_y_upper=smoothed_ci_y_upper_manual, manual_ci_x_lower=smoothed_ci_x_lower_manual, manual_ci_y_lower=smoothed_ci_y_lower_manual, learned_mean_x=smoothed_mean_x_learned, learned_mean_y=smoothed_mean_y_learned, learned_ci_x_upper=smoothed_ci_x_upper_learned, learned_ci_y_upper=smoothed_ci_y_upper_learned, learned_ci_x_lower=smoothed_ci_x_lower_learned, learned_ci_y_lower=smoothed_ci_y_lower_learned, cb_alpha=cb_alpha, color_true=color_true, color_measured=color_measured, color_finite_diff=color_finite_diff, color_manual_pattern=color_manual_pattern, color_learned_pattern=color_learned_pattern, xlabel="Time (sec)", ylabel="Acceleration (pixels/sec^2)") fig .. raw:: html


.. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 14.562 seconds) .. _sphx_glr_download_auto_examples_tracking_plotFilterFWGMouseTrajectoryManualVsLearnedParams.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: binder-badge .. image:: images/binder_badge_logo.svg :target: https://mybinder.org/v2/gh/joacorapela/lds_python/gh-pages?filepath=notebooks/auto_examples/tracking/plotFilterFWGMouseTrajectoryManualVsLearnedParams.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plotFilterFWGMouseTrajectoryManualVsLearnedParams.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plotFilterFWGMouseTrajectoryManualVsLearnedParams.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plotFilterFWGMouseTrajectoryManualVsLearnedParams.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_