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_truesolutionFunction
plot_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; 1 plots sol_group1, otherwise sol_group2
  • data::simdata: simulated dataset with groups group1/group2, xs, and tvals
  • t_range: dense time grid (e.g., 0:0.1:10)
  • sol_group1, sol_group2: matrices of shape (2, length(t_range)) with true latent trajectories
  • showdata::Bool=true: overlay each subject’s observed variables as scatter

Returns

  • curplot: a Plots.Plot with the chosen true solution (and optionally data scatter).
source

Individual trajectories

LatentDynamics.createindividualplotMethod
createindividualplot(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 model
  • data::simdata: simulated dataset with xs, x_baseline, and tvals
  • idx::Int: subject index in data
  • sol::Matrix: true latent solution for this subject’s group (2, length(trange))
  • trange: dense time grid for plotting the smooth ODE trajectory
  • args::LossArgs: controls smoothing (firstonly vs. averaged multi-IC)
  • title::String="": subplot title
  • showtruesol::Bool=true: overlay the supplied true solution
  • axislabs::Bool=false: add axis labels
  • showOLS::Bool=true: overlay global OLS in latent space
  • colors_truesol: two hex colors used for the true solution lines

Returns

  • curplot: a Plots.Plot object combining true solution (optional), ODE-smoothed latent means, encoder means (scatter), and optional OLS fit.
source
LatentDynamics.createindividualplot_piecewiseMethod
createindividualplot_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 model
  • data::simdata: simulated dataset with xs, x_baseline, and tvals
  • ind::Int: subject index in data
  • sol::Matrix: true solution (2, length(t_range)) for the subject’s group
  • t_range: dense time grid for plotting the true solution
  • title::String="": subplot title
  • axislabs::Bool=false: add axis labels
  • showtruesol::Bool=true: overlay true solution
  • showOLS::Bool=true: overlay OLS per segment aligned to each segment start
  • showglobalOLS::Bool=false: overlay an OLS fit over the full observed window
  • colors_truesol: two hex colors for the true solution lines

Returns

  • curplot: a Plots.Plot object with piecewise ODE curves, uncertainty ribbons, and optional OLS overlays.
source
LatentDynamics.eval_z_trajectoriesFunction
eval_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 model
  • data::simdata: simulated dataset with group1, group2, xs, and tvals
  • inds::Array{Int}: subject indices to visualize
  • sol_group1, sol_group2: true solutions (2, length(t_range)) for each group
  • t_range: dense time grid for smooth curves
  • args::LossArgs: smoothing controls (firstonly, etc.)
  • title::String="": panel title
  • showtruesol::Bool=true: overlay true solutions
  • axislabs::Bool=false: add axis labels in subplots
  • showOLS::Bool=true: overlay global OLS per subject
  • swapcolorcoding::Bool=false: swap the two colors used for the true solution

Returns

Nothing. Displays a Plots.Plot panel to the current display.

source

Panels of trajectories

Missing docstring.

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.createindividualplotMethod
createindividualplot(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 model
  • testdata::SMATestData: dataset holding time series, baselines, ids, and time points
  • args::LossArgs: controls the smoothing strategy (e.g., firstonly)
  • patient_id: identifier present in testdata.ids
  • axislabs::Bool=false: add axis labels (“time in months”, “value of latent representation”)
  • title::String="": subplot title
  • showOLS::Bool=true: overlay a (global) piecewise-aligned linear regression in latent space

Returns

  • curplot: a Plots.Plot object with:
    • smooth ODE latent means over a dense time grid,
    • encoder latent means as scatter,
    • optional OLS line(s).
source
LatentDynamics.createindividualplot_piecewiseMethod
createindividualplot_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 model
  • testdata::SMATestData: dataset holding time series, baselines, ids, and time points
  • patient_id: identifier present in testdata.ids
  • title::String="": subplot title
  • showOLS::Bool=true: overlay per-segment linear regressions aligned at each segment start
  • axislabs::Bool=false: add axis labels

Returns

  • curplot: a Plots.Plot object with segment-wise ODE rolls, encoder means (scatter), and optional OLS fits.
source

Panels of trajectories

LatentDynamics.plot_selected_idsFunction
plot_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 model
  • testdata::SMATestData: dataset with time series, baselines, ids, and time points
  • args::LossArgs: controls smoothing (e.g., firstonly)
  • selected_ids::Array: collection of patient IDs to plot
  • showOLS::Bool=true: show global OLS overlays
  • layout=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 disk
  • save_path::String="": path passed to savefig if save_plot == true

Returns

  • panelplot: a Plots.Plot panel with the requested subplots.

Notes

Saves the panel to save_path when save_plot=true.

source
LatentDynamics.plot_selected_ids_piecewiseMethod
plot_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 model
  • testdata::SMATestData: dataset with time series, baselines, ids, and time points
  • selected_ids::Array: collection of patient IDs to plot (order preserved)
  • showOLS::Bool=true: show per-segment OLS overlays in each subplot
  • layout=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 disk
  • save_path::String="": path passed to savefig if save_plot == true

Returns

  • panelplot: a Plots.Plot panel with the requested subplots.

Notes

Saves the panel to save_path when save_plot=true.

source