Plotting
We provide various functions to visualize the learnt latent trajectories, both for individual patients and panels of multiple patients, for both simulated data and SMArtCARE data. We provide functions to plot the trajectories of the overall estimator of the solution and functions to plot the prediction from the model starting at the current time point until the next time point (the _piecewise functions).
Simulated data
LatentDynamics.plot_truesolution — Functionplot_truesolution(group, data::simdata, t_range, sol_group1, sol_group2; showdata=true)Plot the ground-truth latent solution for a simulated cohort, optionally overlaying observed (simulated) measurements.
Arguments
group: integer group selector;1plotssol_group1, otherwisesol_group2data::simdata: simulated dataset with groupsgroup1/group2,xs, andtvalst_range: dense time grid (e.g.,0:0.1:10)sol_group1,sol_group2: matrices of shape(2, length(t_range))with true latent trajectoriesshowdata::Bool=true: overlay each subject’s observed variables as scatter
Returns
curplot: aPlots.Plotwith the chosen true solution (and optionally data scatter).
Individual trajectories
LatentDynamics.createindividualplot — Methodcreateindividualplot(m::odevae, data::simdata, idx::Int, sol::Matrix, trange, args::LossArgs;
title::String="", showtruesol::Bool=true, axislabs::Bool=false,
showOLS::Bool=true, colors_truesol::Array{String}=["#ff7f0e" "#1f77b4"])Plot the learned latent trajectory for one simulated subject, optionally showing the true latent solution and an OLS overlay.
Arguments
m::odevae: trained ODE-VAE modeldata::simdata: simulated dataset withxs,x_baseline, andtvalsidx::Int: subject index indatasol::Matrix: true latent solution for this subject’s group(2, length(trange))trange: dense time grid for plotting the smooth ODE trajectoryargs::LossArgs: controls smoothing (firstonlyvs. averaged multi-IC)title::String="": subplot titleshowtruesol::Bool=true: overlay the supplied true solutionaxislabs::Bool=false: add axis labelsshowOLS::Bool=true: overlay global OLS in latent spacecolors_truesol: two hex colors used for the true solution lines
Returns
curplot: aPlots.Plotobject combining true solution (optional), ODE-smoothed latent means, encoder means (scatter), and optional OLS fit.
LatentDynamics.createindividualplot_piecewise — Methodcreateindividualplot_piecewise(m::odevae, data::simdata, ind::Int, sol::Matrix, t_range;
title::String="", axislabs::Bool=false, showtruesol::Bool=true,
showOLS::Bool=true, showglobalOLS::Bool=false,
colors_truesol::Array{String}=["#ff7f0e" "#1f77b4"])Plot piecewise local ODE solutions between observed time points for one simulated subject, optionally overlaying the group’s true solution, per-segment OLS, and a global OLS fit.
Arguments
m::odevae: trained ODE-VAE modeldata::simdata: simulated dataset withxs,x_baseline, andtvalsind::Int: subject index indatasol::Matrix: true solution(2, length(t_range))for the subject’s groupt_range: dense time grid for plotting the true solutiontitle::String="": subplot titleaxislabs::Bool=false: add axis labelsshowtruesol::Bool=true: overlay true solutionshowOLS::Bool=true: overlay OLS per segment aligned to each segment startshowglobalOLS::Bool=false: overlay an OLS fit over the full observed windowcolors_truesol: two hex colors for the true solution lines
Returns
curplot: aPlots.Plotobject with piecewise ODE curves, uncertainty ribbons, and optional OLS overlays.
LatentDynamics.eval_z_trajectories — Functioneval_z_trajectories(m::odevae, data::simdata, inds::Array{Int},
sol_group1::Matrix, sol_group2::Matrix, t_range, args::LossArgs;
title::String="", showtruesol::Bool=true, axislabs::Bool=false,
showOLS::Bool=true, swapcolorcoding::Bool=false)Display a panel of per-subject latent trajectory plots for simulated data, selecting the appropriate ground-truth solution by group membership.
Arguments
m::odevae: trained ODE-VAE modeldata::simdata: simulated dataset withgroup1,group2,xs, andtvalsinds::Array{Int}: subject indices to visualizesol_group1,sol_group2: true solutions(2, length(t_range))for each groupt_range: dense time grid for smooth curvesargs::LossArgs: smoothing controls (firstonly, etc.)title::String="": panel titleshowtruesol::Bool=true: overlay true solutionsaxislabs::Bool=false: add axis labels in subplotsshowOLS::Bool=true: overlay global OLS per subjectswapcolorcoding::Bool=false: swap the two colors used for the true solution
Returns
Nothing. Displays a Plots.Plot panel to the current display.
Panels of trajectories
Missing docstring for plot_seleced_ids_piecewise(m::odevae, data::simdata, inds::Array{Int}, sol_group1::Matrix, sol_group2::Matrix, t_range; axislabs::Bool=false, showtruesol::Bool=true, showtitle::Bool=true, showOLS::Bool=true, showglobalOLS::Bool=false, swapcolorcoding::Bool=false, sort_inds::Bool=true ). Check Documenter's build log for details.
SMArtCARE data
Individual trajectories
LatentDynamics.createindividualplot — Methodcreateindividualplot(m::odevae, testdata::SMATestData, args::LossArgs, patient_id;
axislabs::Bool=false, title::String="", showOLS::Bool=true)Plot the learned latent trajectory for a single SMArtCARE patient, comparing the ODE-smoothed latent mean to encoder means (and optionally an OLS fit).
The smooth trajectory is obtained either from a single-IC rollout (args.firstonly == true) or by averaging predictions from all time points as initial conditions.
Arguments
m::odevae: trained ODE-VAE modeltestdata::SMATestData: dataset holding time series, baselines, ids, and time pointsargs::LossArgs: controls the smoothing strategy (e.g.,firstonly)patient_id: identifier present intestdata.idsaxislabs::Bool=false: add axis labels (“time in months”, “value of latent representation”)title::String="": subplot titleshowOLS::Bool=true: overlay a (global) piecewise-aligned linear regression in latent space
Returns
curplot: aPlots.Plotobject with:- smooth ODE latent means over a dense time grid,
- encoder latent means as scatter,
- optional OLS line(s).
LatentDynamics.createindividualplot_piecewise — Methodcreateindividualplot_piecewise(m::odevae, testdata::SMATestData, patient_id;
title::String="", showOLS::Bool=true, axislabs::Bool=false)Plot local, piecewise ODE solutions between consecutive observed time points for one SMArtCARE patient, with uncertainty ribbons from the encoder’s log-variance and optional OLS overlays.
Arguments
m::odevae: trained ODE-VAE modeltestdata::SMATestData: dataset holding time series, baselines, ids, and time pointspatient_id: identifier present intestdata.idstitle::String="": subplot titleshowOLS::Bool=true: overlay per-segment linear regressions aligned at each segment startaxislabs::Bool=false: add axis labels
Returns
curplot: aPlots.Plotobject with segment-wise ODE rolls, encoder means (scatter), and optional OLS fits.
Panels of trajectories
LatentDynamics.plot_selected_ids — Functionplot_selected_ids(m::odevae, testdata::SMATestData, args::LossArgs, selected_ids::Array;
showOLS::Bool=true, layout=nothing, size=nothing,
save_plot::Bool=false, save_path::String="")Create a panel of global ODE-smoothed latent trajectories for multiple SMArtCARE patients. Uses the same smoothing strategy as createindividualplot.
Arguments
m::odevae: trained ODE-VAE modeltestdata::SMATestData: dataset with time series, baselines, ids, and time pointsargs::LossArgs: controls smoothing (e.g.,firstonly)selected_ids::Array: collection of patient IDs to plotshowOLS::Bool=true: show global OLS overlayslayout=nothing: layout tuple(rows, cols); defaults to(length(selected_ids)÷4, 4)size=nothing:(width, height)in pixels; defaults to(1200, round(200/3)*length(selected_ids))save_plot::Bool=false: save figure to disksave_path::String="": path passed tosavefigifsave_plot == true
Returns
panelplot: aPlots.Plotpanel with the requested subplots.
Notes
Saves the panel to save_path when save_plot=true.
LatentDynamics.plot_selected_ids_piecewise — Methodplot_selected_ids_piecewise(m::odevae, testdata::SMATestData, selected_ids::Array;
showOLS::Bool=true, layout=nothing, size=nothing,
save_plot::Bool=false, save_path::String="")Create a panel of piecewise ODE plots for multiple SMArtCARE patients.
Arguments
m::odevae: trained ODE-VAE modeltestdata::SMATestData: dataset with time series, baselines, ids, and time pointsselected_ids::Array: collection of patient IDs to plot (order preserved)showOLS::Bool=true: show per-segment OLS overlays in each subplotlayout=nothing: layout tuple(rows, cols); defaults to(length(selected_ids)÷4, 4)size=nothing:(width, height)in pixels; defaults to(1200, round(200/3)*length(selected_ids))save_plot::Bool=false: save figure to disksave_path::String="": path passed tosavefigifsave_plot == true
Returns
panelplot: aPlots.Plotpanel with the requested subplots.
Notes
Saves the panel to save_path when save_plot=true.