.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_revalidation/full_pipeline/_01_pipeline_analysis.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. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_revalidation_full_pipeline__01_pipeline_analysis.py: .. _pipeline_val_results: Walking speed estimation ======================== The following provides an analysis and comparison of the Mobilise-D algorithm pipeline on the `Mobilise-D Technical Validation Study (TVS) dataset `_ for the estimation of walking speed (free-living). In this example, we look into the performance of the Python implementation of the pipeline compared to the reference data. We also compare the actual performance to that obtained by the original Matlab-based implementation [1]_. .. [1] Kirk, C., Küderle, A., Micó-Amigo, M.E. et al. Mobilise-D insights to estimate real-world walking speed in multiple conditions with a wearable device. Sci Rep 14, 1754 (2024). https://doi.org/10.1038/s41598-024-51766-5 .. note:: If you are interested in how these results are calculated, head over to the :ref:`processing page `. .. GENERATED FROM PYTHON SOURCE LINES 21-24 .. code-block:: Python from typing import Optional .. GENERATED FROM PYTHON SOURCE LINES 25-28 Below the list of pipelines that are compared is shown. Note, that we use "MobGap" to refer to the reimplemented python algorithms, and the "Original Implementation" to refer to the original Matlab-based implementation. .. GENERATED FROM PYTHON SOURCE LINES 28-36 .. code-block:: Python algorithms = { "Official_MobiliseD_Pipeline": ("Mobilise-D Pipeline", "MobGap"), "EScience_MobiliseD_Pipeline": ( "Mobilise-D Pipeline", "Original Implementation", ), } .. GENERATED FROM PYTHON SOURCE LINES 37-44 The code below loads the data and prepares it for the analysis. By default, the data will be downloaded from an online repository (and cached locally). If you want to use a local copy of the data, you can set the `MOBGAP_VALIDATION_DATA_PATH` environment variable. and the `MOBGAP_VALIDATION_USE_LOCA_DATA` to `1`. The file download will print a couple log information, which can usually be ignored. You can also change the `version` parameter to load a different version of the data. .. GENERATED FROM PYTHON SOURCE LINES 44-176 .. code-block:: Python from pathlib import Path import pandas as pd from mobgap.data.validation_results import ValidationResultLoader from mobgap.utils.misc import get_env_var def format_loaded_results( values: dict[tuple[str, str], pd.DataFrame], index_cols: list[str], col_prefix_filter: Optional[str], convert_rel_error: bool = False, ) -> pd.DataFrame: formatted = ( pd.concat(values, names=["algo", "version", *index_cols]) .pipe( lambda df: ( df.filter(like=col_prefix_filter) if col_prefix_filter else df ) ) .reset_index() .assign( algo_with_version=lambda df: ( df["algo"] + " (" + df["version"] + ")" ), _combined="combined", ) ) if col_prefix_filter: formatted.columns = formatted.columns.str.removeprefix( col_prefix_filter ) if convert_rel_error: rel_cols = [c for c in formatted.columns if "rel_error" in c] formatted[rel_cols] = formatted[rel_cols] * 100 return formatted local_data_path = ( Path(get_env_var("MOBGAP_VALIDATION_DATA_PATH")) / "results" if int(get_env_var("MOBGAP_VALIDATION_USE_LOCAL_DATA", 0)) else None ) __RESULT_VERSION = "v1.2.0" loader = ValidationResultLoader( "full_pipeline", result_path=local_data_path, version=__RESULT_VERSION ) # Loading free-living data free_living_index_cols = [ "cohort", "participant_id", "time_measure", "recording", "recording_name", "recording_name_pretty", ] _free_living_results = { # Matched and aggregate/combined per-recording results for the 2.5 h free-living recordings v: loader.load_single_results(k, "free_living") for k, v in algorithms.items() } _free_living_results_raw = { # Matched per-WB results for the 2.5 h free-living recordings v: loader.load_single_csv_file(k, "free_living", "raw_matched_errors.csv") for k, v in algorithms.items() } free_living_results_combined = format_loaded_results( _free_living_results, free_living_index_cols, "combined__", convert_rel_error=True, ) free_living_results_matched = format_loaded_results( _free_living_results, free_living_index_cols, "matched__", convert_rel_error=True, ) free_living_results_matched_raw = format_loaded_results( values=_free_living_results_raw, index_cols=free_living_index_cols, col_prefix_filter=None, convert_rel_error=True, ) del _free_living_results, _free_living_results_raw # Loading laboratory data laboratory_index_cols = [ "cohort", "participant_id", "time_measure", "test", "trial", "test_name", "test_name_pretty", ] _laboratory_results = { # Matched and aggregate/combined per-recording results for the laboratory recordings v: loader.load_single_results(k, "laboratory") for k, v in algorithms.items() } _laboratory_results_raw = { # Matched per-WB results for the laboratory recordings v: loader.load_single_csv_file(k, "laboratory", "raw_matched_errors.csv") for k, v in algorithms.items() } laboratory_results_combined = format_loaded_results( _laboratory_results, laboratory_index_cols, "combined__", convert_rel_error=True, ) laboratory_results_matched = format_loaded_results( _laboratory_results, laboratory_index_cols, "matched__", convert_rel_error=True, ) laboratory_results_matched_raw = format_loaded_results( values=_laboratory_results_raw, index_cols=laboratory_index_cols, col_prefix_filter=None, convert_rel_error=True, ) del _laboratory_results, _laboratory_results_raw cohort_order = ["HA", "CHF", "COPD", "MS", "PD", "PFF"] .. rst-class:: sphx-glr-script-out .. code-block:: none Downloading data from 'https://raw.githubusercontent.com/mobilise-d/mobgap_validation/v1.2.0/results_file_registry.txt' to file '/home/docs/.cache/pooch/78b1846966bf2ef4b4c045271f1da6d0-results_file_registry.txt'. 0%| | 0.00/7.72k [00:00 pd.DataFrame: return ( df.pipe(apply_transformations, format_transforms_combined) .rename(columns=final_names_combined) .loc[:, list(final_names_combined.values())] ) def format_tables_matched(df: pd.DataFrame) -> pd.DataFrame: return ( df.pipe(apply_transformations, format_transforms_matched) .rename(columns=final_names_matched) .loc[:, list(final_names_matched.values())] ) .. GENERATED FROM PYTHON SOURCE LINES 351-368 Free-living dataset ------------------- Combined/Aggregated Evaluation ****************************** To mimic actual use of wearable device where actual decisions are made on aggregated measures over a longer measurement period and not WB per WB, our primary comparison is based on the median gait metrics over the entire recording. We call this combined or aggregated evaluation. For this we combined all WBs for a datapoint by taking the median of the calculated walking speed. These combined values were then compared between the systems. .. note:: In the free-living dataset, each datapoint represents one 2.5h recording. All results across all cohorts ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The results below represent the average performance across all participants independent of the cohort in terms of error, relative error, absolute error, and absolute relative error. .. GENERATED FROM PYTHON SOURCE LINES 368-407 .. code-block:: Python import matplotlib.pyplot as plt import seaborn as sns sns.set_context("talk") metrics = { "abs_rel_error": "Abs. Rel. Error (%)", "error": "Error (m/s)", "rel_error": "Rel. Error (%)", "abs_error": "Abs. Error (m/s)", } def multi_metric_plot(data, metrics, nrows, ncols): fig, axs = plt.subplots( nrows, ncols, sharex=True, figsize=(ncols * 6, nrows * 4 + 2) ) for ax, (metric, metric_label) in zip(axs.flatten(), metrics.items()): overall_df = data[["version", f"walking_speed_mps__{metric}"]].rename( columns={f"walking_speed_mps__{metric}": metric_label} ) sns.boxplot( data=overall_df, x="version", hue="version", y=metric_label, ax=ax ) ax.set_title(metric_label) ax.set_ylabel(metric_label) ax.tick_params(axis="both", which="major") ax.tick_params(axis="both", which="minor") ax.grid(True) plt.tight_layout() plt.show() free_living_results_combined.pipe(multi_metric_plot, metrics, 2, 2) .. image-sg:: /auto_revalidation/full_pipeline/images/sphx_glr__01_pipeline_analysis_001.png :alt: Abs. Rel. Error (%), Error (m/s), Rel. Error (%), Abs. Error (m/s) :srcset: /auto_revalidation/full_pipeline/images/sphx_glr__01_pipeline_analysis_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 408-429 .. code-block:: Python from mobgap.utils.df_operations import multilevel_groupby_apply_merge free_living_combined_perf_metrics_all = free_living_results_combined.pipe( multilevel_groupby_apply_merge, [ ( ["algo", "version"], partial(apply_aggregations, aggregations=custom_aggs_combined), ), ( ["algo"], partial(apply_transformations, transformations=stats_transform), ), ], ).pipe(format_tables_combined) free_living_combined_perf_metrics_all.style.pipe( revalidation_table_styles, validation_thresholds, ["algo"], ) .. raw:: html
    # participants WD mean and CI [m/s] INDIP mean and CI [m/s] Bias and LoA [m/s] Abs. Error [m/s] Rel. Error [%] Abs. Rel. Error [%] ICC
algo version                
Mobilise-D Pipeline MobGap 101 0.60 [0.57, 0.62] 0.57 [0.54, 0.60] 0.03 [-0.19, 0.26] 0.10 [0.08, 0.11]** 12.08 [6.27, 17.89] 21.20 [16.50, 25.90]* 0.62 [0.47, 0.73]
Original Implementation 101 0.68 [0.66, 0.71] 0.57 [0.54, 0.60] 0.12 [-0.10, 0.34] 0.13 [0.12, 0.15] 28.18 [21.77, 34.60] 30.11 [24.03, 36.18] 0.51 [-0.03, 0.76]


.. GENERATED FROM PYTHON SOURCE LINES 430-431 Residual plots .. GENERATED FROM PYTHON SOURCE LINES 431-462 .. code-block:: Python from mobgap.plotting import move_legend_outside, residual_plot def combo_residual_plot(data, name=None): name = name or data.name fig, axs = plt.subplots( ncols=2, sharey=True, sharex=True, figsize=(12, 9), constrained_layout=True, ) fig.suptitle(name) for (version, subdata), ax in zip(data.groupby("version"), axs): residual_plot( subdata, "walking_speed_mps__reference", "walking_speed_mps__detected", "cohort", "m", ax=ax, legend=ax == axs[-1], ) ax.set_title(version) move_legend_outside(fig, axs[-1]) plt.show() free_living_results_combined.query('algo == "Mobilise-D Pipeline"').pipe( combo_residual_plot, name="Aggregated Analysis - Walking Speed" ) .. image-sg:: /auto_revalidation/full_pipeline/images/sphx_glr__01_pipeline_analysis_002.png :alt: Aggregated Analysis - Walking Speed, MobGap, Original Implementation :srcset: /auto_revalidation/full_pipeline/images/sphx_glr__01_pipeline_analysis_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 463-468 Per-cohort analysis ~~~~~~~~~~~~~~~~~~~ The results below represent the average absolute error on walking speed estimation across all participants within a cohort. .. GENERATED FROM PYTHON SOURCE LINES 468-481 .. code-block:: Python fig, ax = plt.subplots(figsize=(12, 6)) sns.boxplot( data=free_living_results_combined, x="cohort", y="walking_speed_mps__abs_error", hue="version", order=cohort_order, showmeans=True, ax=ax, ).legend().set_title(None) ax.set_ylabel("Absolute Error [m/s]") ax.set_title("Absolute Error - Combined Analysis") fig.show() .. image-sg:: /auto_revalidation/full_pipeline/images/sphx_glr__01_pipeline_analysis_003.png :alt: Absolute Error - Combined Analysis :srcset: /auto_revalidation/full_pipeline/images/sphx_glr__01_pipeline_analysis_003.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 482-504 .. code-block:: Python free_living_combined_perf_metrics_cohort = ( free_living_results_combined.pipe( multilevel_groupby_apply_merge, [ ( ["cohort", "algo", "version"], partial(apply_aggregations, aggregations=custom_aggs_combined), ), ( ["cohort", "algo"], partial(apply_transformations, transformations=stats_transform), ), ], ) .pipe(format_tables_combined) .loc[cohort_order] ) free_living_combined_perf_metrics_cohort.style.pipe( revalidation_table_styles, validation_thresholds, ["cohort", "algo"], ) .. raw:: html
      # participants WD mean and CI [m/s] INDIP mean and CI [m/s] Bias and LoA [m/s] Abs. Error [m/s] Rel. Error [%] Abs. Rel. Error [%] ICC
cohort algo version                
HA Mobilise-D Pipeline MobGap 20 0.55 [0.52, 0.58] 0.57 [0.53, 0.62] -0.02 [-0.17, 0.12] 0.06 [0.04, 0.08] -2.48 [-7.89, 2.93] 10.36 [7.39, 13.33]* 0.65 [0.32, 0.85]
Original Implementation 20 0.63 [0.59, 0.66] 0.57 [0.53, 0.62] 0.05 [-0.13, 0.23] 0.09 [0.07, 0.11] 11.58 [4.19, 18.97] 16.87 [11.95, 21.79] 0.45 [0.04, 0.73]
CHF Mobilise-D Pipeline MobGap 10 0.56 [0.50, 0.63] 0.64 [0.54, 0.74] -0.08 [-0.30, 0.14] 0.11 [0.06, 0.16] -9.20 [-19.96, 1.56] 16.46 [10.44, 22.49] 0.61 [0.05, 0.88]
Original Implementation 10 0.82 [0.73, 0.91] 0.64 [0.54, 0.74] 0.18 [-0.01, 0.36] 0.18 [0.12, 0.24] 32.04 [18.50, 45.59] 32.15 [18.71, 45.59] 0.52 [-0.10, 0.88]
COPD Mobilise-D Pipeline MobGap 17 0.59 [0.55, 0.63] 0.57 [0.51, 0.63] 0.02 [-0.16, 0.20] 0.08 [0.05, 0.10] 7.68 [-4.26, 19.62] 15.92 [6.13, 25.71] 0.63 [0.23, 0.85]
Original Implementation 17 0.66 [0.62, 0.69] 0.57 [0.51, 0.63] 0.08 [-0.09, 0.25] 0.09 [0.06, 0.13] 19.71 [4.98, 34.44] 21.12 [6.87, 35.37] 0.49 [-0.04, 0.79]
MS Mobilise-D Pipeline MobGap 18 0.66 [0.61, 0.71] 0.61 [0.55, 0.67] 0.06 [-0.19, 0.30] 0.11 [0.07, 0.15] 13.04 [1.81, 24.28] 20.83 [12.66, 28.99] 0.42 [-0.00, 0.72]
Original Implementation 18 0.74 [0.69, 0.79] 0.61 [0.55, 0.67] 0.13 [-0.11, 0.38] 0.15 [0.10, 0.19] 25.77 [13.34, 38.20] 27.98 [16.68, 39.28] 0.27 [-0.11, 0.62]
PD Mobilise-D Pipeline MobGap 19 0.66 [0.60, 0.72] 0.58 [0.49, 0.67] 0.08 [-0.17, 0.33] 0.13 [0.09, 0.16] 23.06 [7.01, 39.10] 29.32 [15.63, 43.01] 0.63 [0.21, 0.84]
Original Implementation 19 0.73 [0.68, 0.79] 0.58 [0.49, 0.67] 0.15 [-0.09, 0.40] 0.16 [0.11, 0.21] 37.31 [18.56, 56.06] 38.34 [20.05, 56.64] 0.49 [-0.09, 0.80]
PFF Mobilise-D Pipeline MobGap 17 0.53 [0.48, 0.58] 0.44 [0.37, 0.51] 0.11 [-0.05, 0.26] 0.11 [0.07, 0.14] 34.11 [16.74, 51.48] 34.11 [16.74, 51.48] 0.62 [-0.08, 0.88]
Original Implementation 17 0.59 [0.54, 0.64] 0.44 [0.37, 0.51] 0.16 [0.00, 0.32] 0.16 [0.12, 0.20] 47.65 [28.94, 66.37] 47.65 [28.94, 66.37] 0.47 [-0.09, 0.82]


.. GENERATED FROM PYTHON SOURCE LINES 505-509 Scatter plot The results below represent the detected and reference values of walking speed scattered across all participants within a cohort. Correlation factor, p-value and confidence intervals of the regression line are shown in the plot. Each datapoint represents one participant. .. GENERATED FROM PYTHON SOURCE LINES 509-569 .. code-block:: Python from mobgap.plotting import calc_min_max_with_margin, make_square, plot_regline def combo_scatter_plot(data, name=None): name = name or data.name fig, axs = plt.subplots( ncols=2, sharey=True, sharex=True, figsize=(12, 8), constrained_layout=True, ) fig.suptitle(name) min_max = calc_min_max_with_margin( data["walking_speed_mps__reference"], data["walking_speed_mps__detected"], ) for (version, subdata), ax in zip(data.groupby("version"), axs): subdata = subdata[ [ "walking_speed_mps__reference", "walking_speed_mps__detected", "cohort", ] ].dropna(how="any") sns.scatterplot( subdata, x="walking_speed_mps__reference", y="walking_speed_mps__detected", hue="cohort", ax=ax, legend=ax == axs[-1], ) plot_regline( subdata["walking_speed_mps__reference"], subdata["walking_speed_mps__detected"], ax=ax, ) make_square(ax, min_max, draw_diagonal=True) ax.set_title(version) ax.set_xlabel("Reference [m]") ax.set_ylabel("Detected [m]") ax.tick_params(axis="both", labelsize=20) move_legend_outside(fig, axs[-1]) plt.show() free_living_results_combined.query('algo == "Mobilise-D Pipeline"').pipe( combo_scatter_plot, name="Mobilise-D Pipeline - Walking Speed" ) .. image-sg:: /auto_revalidation/full_pipeline/images/sphx_glr__01_pipeline_analysis_004.png :alt: Mobilise-D Pipeline - Walking Speed, MobGap, Original Implementation :srcset: /auto_revalidation/full_pipeline/images/sphx_glr__01_pipeline_analysis_004.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 570-592 Matched/True Positive Evaluation ******************************** The "Matched" Evaluation directly compares the performance of walking speed estimation on only the WBs that were detected in both systems (true positives). WBs were included in the true positive analysis, if there was an overlap of more than 80% between WBs detected by the two systems (details about the selection of this threshold can be found in [1]_). The threshold of 80% was selected as a trade-off to allow us: (i) to consider as much as possible a like-for-like comparison between selected WBs (INDIP vs. wearable device), and at the same time (ii) to include the minimum number of WBs to ensure sufficient statistical power for the analyses (i.e., at least 101 walking bouts for each cohort). This target was based upon the number of WBs rather than a percentage of total walking bouts that would allow us to meet criteria established by statistical experts for robust statistical analysis after sample-size re-evaluation (total WB number > 101 corresponding to ICC > 0.7 and a CI = 0.2). .. note:: compared to the results published in [1]_, the primary analysis on the matched results is performed on the average performance metrics across all matched WBs **per recording/per participant**. The original publication considered the average performance metrics across all matched WBs without additional aggregation. Results across all cohorts ~~~~~~~~~~~~~~~~~~~~~~~~~~ The results below represent the average performance across all participants independent of the cohort in terms of error, relative error, absolute error, and absolute relative error. .. GENERATED FROM PYTHON SOURCE LINES 592-594 .. code-block:: Python free_living_results_matched.pipe(multi_metric_plot, metrics, 2, 2) .. image-sg:: /auto_revalidation/full_pipeline/images/sphx_glr__01_pipeline_analysis_005.png :alt: Abs. Rel. Error (%), Error (m/s), Rel. Error (%), Abs. Error (m/s) :srcset: /auto_revalidation/full_pipeline/images/sphx_glr__01_pipeline_analysis_005.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 595-597 As each pipeline version produces different WB's, it is important to compare the number of matched WBs to put all other metrics into perspective. .. GENERATED FROM PYTHON SOURCE LINES 597-607 .. code-block:: Python fig, ax = plt.subplots(figsize=(12, 6)) sns.barplot( data=free_living_results_matched.groupby(["version"])["n_matched_wbs"] .sum() .reset_index(), x="version", y="n_matched_wbs", ax=ax, ) fig.show() .. image-sg:: /auto_revalidation/full_pipeline/images/sphx_glr__01_pipeline_analysis_006.png :alt: 01 pipeline analysis :srcset: /auto_revalidation/full_pipeline/images/sphx_glr__01_pipeline_analysis_006.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 608-626 .. code-block:: Python free_living_matched_perf_metrics_all = free_living_results_matched.pipe( multilevel_groupby_apply_merge, [ ( ["algo", "version"], partial(apply_aggregations, aggregations=custom_aggs_matched), ), ( ["algo"], partial(apply_transformations, transformations=stats_transform), ), ], ).pipe(format_tables_matched) free_living_matched_perf_metrics_all.style.pipe( revalidation_table_styles, validation_thresholds, ["algo"], ) .. raw:: html
    # participants WD mean and CI [m/s] INDIP mean and CI [m/s] Bias and LoA [m/s] Abs. Error [m/s] Rel. Error [%] Abs. Rel. Error [%] ICC # Matched WBs
algo version                  
Mobilise-D Pipeline MobGap 101 0.71 [0.68, 0.73] 0.67 [0.64, 0.70] 0.04 [-0.13, 0.21] 0.10 [0.09, 0.11]* 11.84 [8.31, 15.37] 19.63 [16.94, 22.32] 0.81 [0.67, 0.88] 1984
Original Implementation 101 0.77 [0.75, 0.80] 0.71 [0.68, 0.74] 0.07 [-0.13, 0.26] 0.12 [0.11, 0.13] 17.11 [12.22, 22.01] 22.89 [18.62, 27.17] 0.69 [0.37, 0.83] 1697


.. GENERATED FROM PYTHON SOURCE LINES 627-628 Residual plot .. GENERATED FROM PYTHON SOURCE LINES 628-631 .. code-block:: Python free_living_results_matched.query('algo == "Mobilise-D Pipeline"').pipe( combo_residual_plot, name="Matched WBs - Walking Speed" ) .. image-sg:: /auto_revalidation/full_pipeline/images/sphx_glr__01_pipeline_analysis_007.png :alt: Matched WBs - Walking Speed, MobGap, Original Implementation :srcset: /auto_revalidation/full_pipeline/images/sphx_glr__01_pipeline_analysis_007.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 632-637 Per-cohort analysis ~~~~~~~~~~~~~~~~~~~ Barplot The results below represent the average absolute error on walking speed estimation across all participants within a cohort. .. GENERATED FROM PYTHON SOURCE LINES 637-651 .. code-block:: Python fig, ax = plt.subplots(figsize=(12, 6)) sns.barplot( data=free_living_results_matched.groupby(["version", "cohort"])[ "n_matched_wbs" ] .sum() .reset_index(), hue="version", y="n_matched_wbs", x="cohort", order=cohort_order, ax=ax, ) fig.show() .. image-sg:: /auto_revalidation/full_pipeline/images/sphx_glr__01_pipeline_analysis_008.png :alt: 01 pipeline analysis :srcset: /auto_revalidation/full_pipeline/images/sphx_glr__01_pipeline_analysis_008.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 652-653 Boxplot .. GENERATED FROM PYTHON SOURCE LINES 653-665 .. code-block:: Python fig, ax = plt.subplots(figsize=(12, 6)) sns.boxplot( data=free_living_results_matched, x="cohort", y="walking_speed_mps__abs_error", hue="algo_with_version", order=cohort_order, ax=ax, ).legend().set_title(None) ax.set_ylabel("Absolute Error [m/s]") ax.set_title("Absolute Error - Matched Analysis") fig.show() .. image-sg:: /auto_revalidation/full_pipeline/images/sphx_glr__01_pipeline_analysis_009.png :alt: Absolute Error - Matched Analysis :srcset: /auto_revalidation/full_pipeline/images/sphx_glr__01_pipeline_analysis_009.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 666-667 Processing the per-cohort performance table .. GENERATED FROM PYTHON SOURCE LINES 667-690 .. code-block:: Python free_living_matched_perf_metrics_cohort = ( free_living_results_matched.pipe( multilevel_groupby_apply_merge, [ ( ["cohort", "algo", "version"], partial(apply_aggregations, aggregations=custom_aggs_matched), ), ( ["cohort", "algo"], partial(apply_transformations, transformations=stats_transform), ), ], ) .pipe(format_tables_matched) .loc[cohort_order] ) free_living_matched_perf_metrics_cohort.style.pipe( revalidation_table_styles, validation_thresholds, ["cohort", "algo"], ) .. raw:: html
      # participants WD mean and CI [m/s] INDIP mean and CI [m/s] Bias and LoA [m/s] Abs. Error [m/s] Rel. Error [%] Abs. Rel. Error [%] ICC # Matched WBs
cohort algo version                  
HA Mobilise-D Pipeline MobGap 20 0.72 [0.65, 0.78] 0.69 [0.62, 0.76] 0.02 [-0.08, 0.12] 0.08 [0.06, 0.09] 7.22 [3.70, 10.74] 13.72 [11.51, 15.93] 0.93 [0.82, 0.97] 524
Original Implementation 20 0.79 [0.74, 0.84] 0.75 [0.69, 0.81] 0.04 [-0.09, 0.17] 0.09 [0.08, 0.11] 9.45 [4.82, 14.08] 15.36 [12.39, 18.33] 0.85 [0.59, 0.94] 410
CHF Mobilise-D Pipeline MobGap 10 0.75 [0.67, 0.84] 0.78 [0.67, 0.89] -0.02 [-0.16, 0.12] 0.10 [0.07, 0.13] 2.72 [-4.40, 9.85] 15.32 [10.60, 20.03] 0.90 [0.67, 0.97] 220
Original Implementation 10 0.83 [0.72, 0.93] 0.83 [0.70, 0.96] -0.00 [-0.19, 0.18] 0.10 [0.06, 0.14] 5.39 [-6.37, 17.15] 15.19 [5.79, 24.60] 0.89 [0.60, 0.98] 176
COPD Mobilise-D Pipeline MobGap 17 0.69 [0.66, 0.73] 0.62 [0.57, 0.66] 0.07 [-0.05, 0.20] 0.10 [0.09, 0.12] 16.51 [10.46, 22.56] 20.74 [16.55, 24.92] 0.53 [-0.08, 0.83] 410
Original Implementation 17 0.75 [0.71, 0.79] 0.65 [0.60, 0.69] 0.10 [-0.03, 0.23] 0.13 [0.10, 0.15] 21.58 [15.75, 27.41] 24.30 [19.58, 29.02] 0.40 [-0.11, 0.77] 323
MS Mobilise-D Pipeline MobGap 18 0.77 [0.70, 0.83] 0.69 [0.63, 0.75] 0.08 [-0.10, 0.25] 0.12 [0.09, 0.15] 17.47 [9.38, 25.56] 22.69 [15.91, 29.48] 0.67 [0.12, 0.88] 327
Original Implementation 18 0.82 [0.76, 0.88] 0.71 [0.64, 0.78] 0.11 [-0.10, 0.32] 0.15 [0.11, 0.18] 27.78 [11.34, 44.22] 31.46 [16.01, 46.90] 0.59 [-0.02, 0.85] 355
PD Mobilise-D Pipeline MobGap 19 0.73 [0.67, 0.79] 0.71 [0.64, 0.78] 0.02 [-0.20, 0.24] 0.11 [0.09, 0.14] 8.92 [-2.59, 20.44] 20.70 [12.08, 29.33] 0.72 [0.41, 0.88] 267
Original Implementation 19 0.79 [0.74, 0.85] 0.73 [0.66, 0.81] 0.06 [-0.20, 0.32] 0.13 [0.09, 0.16] 17.07 [1.50, 32.64] 24.82 [11.17, 38.48] 0.53 [0.13, 0.78] 256
PFF Mobilise-D Pipeline MobGap 17 0.58 [0.52, 0.63] 0.53 [0.46, 0.60] 0.04 [-0.12, 0.20] 0.10 [0.08, 0.12] 15.71 [4.68, 26.74] 24.07 [15.37, 32.77] 0.79 [0.46, 0.92] 236
Original Implementation 17 0.66 [0.61, 0.70] 0.59 [0.54, 0.65] 0.06 [-0.11, 0.23] 0.11 [0.09, 0.14] 16.48 [7.25, 25.71] 23.29 [16.30, 30.29] 0.61 [0.09, 0.86] 177


.. GENERATED FROM PYTHON SOURCE LINES 691-699 Deep dive investigation: Do errors depend on WB duration or walking speed? ************************************************************************** Effect of WB duration ~~~~~~~~~~~~~~~~~~~~~ We investigate the dependency of the absolute walking speed error of all true-positive WBs from the real-world recording on the WB duration reported by the reference system. In the top, WB errors are grouped by various duration bouts. In the bottom the number of bouts within each duration group is visualized. .. GENERATED FROM PYTHON SOURCE LINES 699-757 .. code-block:: Python import numpy as np from mobgap.utils.df_operations import cut_into_overlapping_bins def plot_wb_duration_analysis(df): """Generates a single figure with: - First row: Two side-by-side boxplot for "new" and "old" cases. - Second row: A grouped bar chart comparing WB counts for "new" and "old" cases. df: DataFrame containing 'version' column with values 'new' or 'old' to distinguish data """ fig, axs = plt.subplot_mosaic( [["v"], ["v"], ["v"], ["n"]], sharex=True, figsize=(12, 9) ) # Compute WB durations in seconds df_with_durations = df.assign( duration_s=lambda df_: ( (df_["end__reference"] - df_["start__reference"]) / 100 ) ) bins = { "All": (-np.inf, np.inf), "> 10 s": (10, np.inf), "<= 10 s": (0, 10), "10 - 30 s": (10, 30), "30 - 60 s": (30, 60), "60 - 120 s": (60, 120), "> 120 s": (120, np.inf), } binned_df = cut_into_overlapping_bins( df_with_durations, "duration_s", bins ).reset_index() n = sns.countplot( data=binned_df, x="bin", hue="version", ax=axs["n"], legend=False ) for container in n.containers: n.bar_label(container, size=10) sns.boxplot( data=binned_df, x="bin", y="walking_speed_mps__abs_error", hue="version", ax=axs["v"], ) sns.despine(fig) axs["v"].set_ylabel("Absolute Walking Speed Error (m/s)") axs["n"].set_ylabel("WB Count") axs["n"].set_xlabel("Ref. WB Duration") fig.show() free_living_results_matched_raw.query("algo == 'Mobilise-D Pipeline'").pipe( plot_wb_duration_analysis ) .. image-sg:: /auto_revalidation/full_pipeline/images/sphx_glr__01_pipeline_analysis_010.png :alt: 01 pipeline analysis :srcset: /auto_revalidation/full_pipeline/images/sphx_glr__01_pipeline_analysis_010.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 758-765 Effect of walking speed on error ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ One important aspect of the algorithm performance is the dependency on the walking speed. Aka, how well do the algorithms perform at different walking speeds. For this we plot the absolute error against the walking speed of the reference data. For better granularity, we use the values per WB, instead of the aggregates per participant. The overlayed dots represent the trend-line calculated by taking the median of the absolute error within bins of 0.05 m/s. .. GENERATED FROM PYTHON SOURCE LINES 765-865 .. code-block:: Python # For plotting all participants at the end free_living_combined = free_living_results_matched_raw.copy() free_living_combined["cohort"] = "Combined" free_living_combined_ws_level_results = pd.concat( [free_living_results_matched_raw, free_living_combined] ).reset_index(drop=True) algo_names = free_living_combined_ws_level_results["algo_with_version"].unique() cohort_names = free_living_combined_ws_level_results["cohort"].unique() free_living_combined_ws_level_results["cohort"] = pd.Categorical( free_living_combined_ws_level_results["cohort"], categories=cohort_names, ordered=True, ) free_living_combined_ws_level_results["algo_with_version"] = pd.Categorical( free_living_combined_ws_level_results["algo_with_version"], categories=algo_names, ordered=True, ) # Create the figure with subplots fig = plt.figure(constrained_layout=True, figsize=(24, 5 * len(algo_names))) subfigs = fig.subfigures(len(algo_names), 1, wspace=0.1, hspace=0.1) # Define the min and max limits for x and y axes min_max_x = calc_min_max_with_margin( free_living_combined_ws_level_results["walking_speed_mps__reference"] ) min_max_y = calc_min_max_with_margin( free_living_combined_ws_level_results["walking_speed_mps__abs_error"] ) # Plotting each algorithm version for subfig, (algo, data) in zip( subfigs, free_living_combined_ws_level_results.groupby( "algo_with_version", observed=True ), ): subfig.suptitle(algo) subfig.supxlabel("Walking Speed (m/s)") subfig.supylabel("Absolute Error (m/s)") # Create subplots for each cohort axs = subfig.subplots(1, len(cohort_names), sharex=True, sharey=True) for ax, (cohort, cohort_data) in zip( axs, data.groupby("cohort", observed=True) ): # Scatter plot for the cohort data sns.scatterplot( data=cohort_data, x="walking_speed_mps__reference", # Reference walking speed y="walking_speed_mps__abs_error", # Absolute error ax=ax, alpha=0.3, ) # Define bins for walking speed bins = np.arange( 0, cohort_data["walking_speed_mps__reference"].max() + 0.05, 0.05 ) cohort_data["speed_bin"] = pd.cut( cohort_data["walking_speed_mps__reference"], bins=bins ) # Calculate bin centers cohort_data["bin_center"] = cohort_data["speed_bin"].apply( lambda x: x.mid ) # Calculate median error per bin and cohort binned_data = ( cohort_data.groupby("bin_center", observed=True)[ "walking_speed_mps__abs_error" ] .median() .reset_index() ) # Plot the median lines for each bin sns.scatterplot( data=binned_data, x="bin_center", y="walking_speed_mps__abs_error", # Median error ax=ax, ) ax.set_title(cohort) ax.set_xlabel(None) ax.set_ylabel(None) # Set axis limits ax.set_xlim(*min_max_x) ax.set_ylim(*min_max_y) fig.show() .. image-sg:: /auto_revalidation/full_pipeline/images/sphx_glr__01_pipeline_analysis_011.png :alt: CHF, COPD, HA, MS, PD, PFF, Combined, CHF, COPD, HA, MS, PD, PFF, Combined :srcset: /auto_revalidation/full_pipeline/images/sphx_glr__01_pipeline_analysis_011.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 866-883 Laboratory dataset ------------------ Combined/Aggregated Evaluation ****************************** To mimic actual use of wearable device where actual decisions are made on aggregated measures over a longer measurement period and not WB per WB, our primary comparison is based on the median gait metrics over the entire recording. We call this combined or aggregated evaluation. For this we combined all WBs for a datapoint by taking the median of the calculated walking speed. These combined values were then compared between the systems. .. note:: In the laboratory dataset, each datapoint represents one trial. All results across all cohorts ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The results below represent the average performance across all participants independent of the cohort in terms of error, relative error, absolute error, and absolute relative error. .. GENERATED FROM PYTHON SOURCE LINES 883-922 .. code-block:: Python import matplotlib.pyplot as plt import seaborn as sns sns.set_context("talk") metrics = { "abs_rel_error": "Abs. Rel. Error (%)", "error": "Error (m/s)", "rel_error": "Rel. Error (%)", "abs_error": "Abs. Error (m/s)", } def multi_metric_plot(data, metrics, nrows, ncols): fig, axs = plt.subplots( nrows, ncols, sharex=True, figsize=(ncols * 6, nrows * 4 + 2) ) for ax, (metric, metric_label) in zip(axs.flatten(), metrics.items()): overall_df = data[["version", f"walking_speed_mps__{metric}"]].rename( columns={f"walking_speed_mps__{metric}": metric_label} ) sns.boxplot( data=overall_df, x="version", hue="version", y=metric_label, ax=ax ) ax.set_title(metric_label) ax.set_ylabel(metric_label) ax.tick_params(axis="both", which="major") ax.tick_params(axis="both", which="minor") ax.grid(True) plt.tight_layout() plt.show() laboratory_results_combined.pipe(multi_metric_plot, metrics, 2, 2) .. image-sg:: /auto_revalidation/full_pipeline/images/sphx_glr__01_pipeline_analysis_012.png :alt: Abs. Rel. Error (%), Error (m/s), Rel. Error (%), Abs. Error (m/s) :srcset: /auto_revalidation/full_pipeline/images/sphx_glr__01_pipeline_analysis_012.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 923-941 .. code-block:: Python laboratory_combined_perf_metrics_all = laboratory_results_combined.pipe( multilevel_groupby_apply_merge, [ ( ["algo", "version"], partial(apply_aggregations, aggregations=custom_aggs_combined), ), ( ["algo"], partial(apply_transformations, transformations=stats_transform), ), ], ).pipe(format_tables_combined) laboratory_combined_perf_metrics_all.style.pipe( revalidation_table_styles, validation_thresholds, ["algo"], ) .. raw:: html
    # participants WD mean and CI [m/s] INDIP mean and CI [m/s] Bias and LoA [m/s] Abs. Error [m/s] Rel. Error [%] Abs. Rel. Error [%] ICC
algo version                
Mobilise-D Pipeline MobGap 1168 0.82 [0.80, 0.83] 0.83 [0.82, 0.85] -0.04 [-0.34, 0.27] 0.11 [0.10, 0.12] -0.40 [-1.64, 0.85] 14.70 [13.78, 15.62]* 0.83 [0.80, 0.85]
Original Implementation 1168 0.84 [0.82, 0.85] 0.83 [0.82, 0.85] -0.00 [-0.31, 0.30] 0.11 [0.11, 0.12] 5.28 [3.78, 6.78] 16.71 [15.52, 17.91] 0.82 [0.80, 0.84]


.. GENERATED FROM PYTHON SOURCE LINES 942-943 Residual plots .. GENERATED FROM PYTHON SOURCE LINES 943-973 .. code-block:: Python def combo_residual_plot(data, name=None): name = name or data.name fig, axs = plt.subplots( ncols=2, sharey=True, sharex=True, figsize=(12, 9), constrained_layout=True, ) fig.suptitle(name) for (version, subdata), ax in zip(data.groupby("version"), axs): residual_plot( subdata, "walking_speed_mps__reference", "walking_speed_mps__detected", "cohort", "m", ax=ax, legend=ax == axs[-1], ) ax.set_title(version) move_legend_outside(fig, axs[-1]) plt.show() laboratory_results_combined.query('algo == "Mobilise-D Pipeline"').pipe( combo_residual_plot, name="Aggregated Analysis - Walking Speed" ) .. image-sg:: /auto_revalidation/full_pipeline/images/sphx_glr__01_pipeline_analysis_013.png :alt: Aggregated Analysis - Walking Speed, MobGap, Original Implementation :srcset: /auto_revalidation/full_pipeline/images/sphx_glr__01_pipeline_analysis_013.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 974-979 Per-cohort analysis ~~~~~~~~~~~~~~~~~~~ The results below represent the average absolute error on walking speed estimation across all participants within a cohort. .. GENERATED FROM PYTHON SOURCE LINES 979-992 .. code-block:: Python fig, ax = plt.subplots(figsize=(12, 6)) sns.boxplot( data=laboratory_results_combined, x="cohort", y="walking_speed_mps__abs_error", hue="version", order=cohort_order, showmeans=True, ax=ax, ).legend().set_title(None) ax.set_ylabel("Absolute Error [m/s]") ax.set_title("Absolute Error - Combined Analysis") fig.show() .. image-sg:: /auto_revalidation/full_pipeline/images/sphx_glr__01_pipeline_analysis_014.png :alt: Absolute Error - Combined Analysis :srcset: /auto_revalidation/full_pipeline/images/sphx_glr__01_pipeline_analysis_014.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 993-1015 .. code-block:: Python laboratory_combined_perf_metrics_cohort = ( laboratory_results_combined.pipe( multilevel_groupby_apply_merge, [ ( ["cohort", "algo", "version"], partial(apply_aggregations, aggregations=custom_aggs_combined), ), ( ["cohort", "algo"], partial(apply_transformations, transformations=stats_transform), ), ], ) .pipe(format_tables_combined) .loc[cohort_order] ) laboratory_combined_perf_metrics_cohort.style.pipe( revalidation_table_styles, validation_thresholds, ["cohort", "algo"], ) .. raw:: html
      # participants WD mean and CI [m/s] INDIP mean and CI [m/s] Bias and LoA [m/s] Abs. Error [m/s] Rel. Error [%] Abs. Rel. Error [%] ICC
cohort algo version                
HA Mobilise-D Pipeline MobGap 227 0.85 [0.82, 0.88] 0.92 [0.89, 0.96] -0.08 [-0.37, 0.20] 0.12 [0.11, 0.14] -7.70 [-9.76, -5.65] 13.56 [12.11, 15.01] 0.76 [0.56, 0.86]
Original Implementation 227 0.84 [0.81, 0.86] 0.92 [0.89, 0.96] -0.07 [-0.36, 0.23] 0.12 [0.10, 0.13] -5.20 [-7.23, -3.18] 12.88 [11.56, 14.19] 0.74 [0.60, 0.82]
CHF Mobilise-D Pipeline MobGap 106 0.83 [0.78, 0.88] 0.90 [0.84, 0.96] -0.11 [-0.47, 0.24] 0.14 [0.11, 0.17] -9.42 [-12.28, -6.56] 13.52 [11.33, 15.70] 0.74 [0.47, 0.86]
Original Implementation 106 0.93 [0.87, 0.98] 0.90 [0.84, 0.96] -0.06 [-0.38, 0.26] 0.13 [0.10, 0.15] -2.40 [-5.85, 1.04] 13.77 [11.51, 16.04] 0.83 [0.72, 0.89]
COPD Mobilise-D Pipeline MobGap 214 0.84 [0.82, 0.87] 0.90 [0.87, 0.94] -0.07 [-0.42, 0.29] 0.11 [0.09, 0.13] -5.70 [-8.05, -3.34] 12.70 [10.90, 14.50] 0.63 [0.49, 0.73]
Original Implementation 214 0.86 [0.84, 0.89] 0.90 [0.87, 0.94] -0.02 [-0.32, 0.28] 0.09 [0.08, 0.11] 0.21 [-1.95, 2.36] 10.92 [9.33, 12.50] 0.74 [0.66, 0.80]
MS Mobilise-D Pipeline MobGap 228 0.86 [0.82, 0.89] 0.84 [0.80, 0.88] 0.00 [-0.26, 0.26] 0.10 [0.08, 0.11] 2.32 [0.07, 4.57] 12.46 [10.87, 14.05] 0.88 [0.85, 0.91]
Original Implementation 228 0.86 [0.83, 0.89] 0.84 [0.80, 0.88] 0.01 [-0.27, 0.30] 0.11 [0.10, 0.12] 4.99 [2.31, 7.68] 14.71 [12.71, 16.70] 0.84 [0.80, 0.88]
PD Mobilise-D Pipeline MobGap 224 0.81 [0.78, 0.85] 0.79 [0.75, 0.83] -0.01 [-0.26, 0.24] 0.10 [0.09, 0.11] 1.56 [-0.83, 3.96] 13.78 [12.20, 15.37] 0.88 [0.85, 0.91]
Original Implementation 224 0.84 [0.81, 0.87] 0.79 [0.75, 0.83] 0.02 [-0.26, 0.30] 0.11 [0.10, 0.12] 7.01 [4.07, 9.95] 16.25 [14.03, 18.47] 0.83 [0.79, 0.87]
PFF Mobilise-D Pipeline MobGap 169 0.68 [0.65, 0.72] 0.67 [0.62, 0.72] 0.01 [-0.26, 0.29] 0.11 [0.10, 0.12]** 12.64 [7.60, 17.67] 22.74 [18.60, 26.88]* 0.89 [0.85, 0.91]
Original Implementation 169 0.72 [0.69, 0.76] 0.67 [0.62, 0.72] 0.05 [-0.27, 0.37] 0.14 [0.12, 0.15] 22.36 [15.97, 28.75] 30.38 [24.80, 35.96] 0.83 [0.76, 0.88]


.. GENERATED FROM PYTHON SOURCE LINES 1016-1020 Scatter plot The results below represent the detected and reference values of walking speed scattered across all participants within a cohort. Correlation factor, p-value and confidence intervals of the regression line are shown in the plot. Each datapoint represents one participant. .. GENERATED FROM PYTHON SOURCE LINES 1020-1079 .. code-block:: Python from mobgap.plotting import calc_min_max_with_margin def combo_scatter_plot(data, name=None): name = name or data.name fig, axs = plt.subplots( ncols=2, sharey=True, sharex=True, figsize=(12, 8), constrained_layout=True, ) fig.suptitle(name) min_max = calc_min_max_with_margin( data["walking_speed_mps__reference"], data["walking_speed_mps__detected"], ) for (version, subdata), ax in zip(data.groupby("version"), axs): subdata = subdata[ [ "walking_speed_mps__reference", "walking_speed_mps__detected", "cohort", ] ].dropna(how="any") sns.scatterplot( subdata, x="walking_speed_mps__reference", y="walking_speed_mps__detected", hue="cohort", ax=ax, legend=ax == axs[-1], ) plot_regline( subdata["walking_speed_mps__reference"], subdata["walking_speed_mps__detected"], ax=ax, ) make_square(ax, min_max, draw_diagonal=True) ax.set_title(version) ax.set_xlabel("Reference [m]") ax.set_ylabel("Detected [m]") ax.tick_params(axis="both", labelsize=20) move_legend_outside(fig, axs[-1]) plt.show() laboratory_results_combined.query('algo == "Mobilise-D Pipeline"').pipe( combo_scatter_plot, name="Mobilise-D Pipeline - Walking Speed" ) .. image-sg:: /auto_revalidation/full_pipeline/images/sphx_glr__01_pipeline_analysis_015.png :alt: Mobilise-D Pipeline - Walking Speed, MobGap, Original Implementation :srcset: /auto_revalidation/full_pipeline/images/sphx_glr__01_pipeline_analysis_015.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 1080-1102 Matched/True Positive Evaluation ******************************** The "Matched" Evaluation directly compares the performance of walking speed estimation on only the WBs that were detected in both systems (true positives). WBs were included in the true positive analysis, if there was an overlap of more than 80% between WBs detected by the two systems (details about the selection of this threshold can be found in [1]_). The threshold of 80% was selected as a trade-off to allow us: (i) to consider as much as possible a like-for-like comparison between selected WBs (INDIP vs. wearable device), and at the same time (ii) to include the minimum number of WBs to ensure sufficient statistical power for the analyses (i.e., at least 101 walking bouts for each cohort). This target was based upon the number of WBs rather than a percentage of total walking bouts that would allow us to meet criteria established by statistical experts for robust statistical analysis after sample-size re-evaluation (total WB number > 101 corresponding to ICC > 0.7 and a CI = 0.2). .. note:: compared to the results published in [1]_, the primary analysis on the matched results is performed on the average performance metrics across all matched WBs **per trial**. The original publication considered the average performance metrics across all matched WBs without additional aggregation. Results across all cohorts ~~~~~~~~~~~~~~~~~~~~~~~~~~ The results below represent the average performance across all participants independent of the cohort in terms of error, relative error, absolute error, and absolute relative error. .. GENERATED FROM PYTHON SOURCE LINES 1102-1104 .. code-block:: Python laboratory_results_matched.pipe(multi_metric_plot, metrics, 2, 2) .. image-sg:: /auto_revalidation/full_pipeline/images/sphx_glr__01_pipeline_analysis_016.png :alt: Abs. Rel. Error (%), Error (m/s), Rel. Error (%), Abs. Error (m/s) :srcset: /auto_revalidation/full_pipeline/images/sphx_glr__01_pipeline_analysis_016.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 1105-1107 As each pipeline version produces different WB's, it is important to compare the number of matched WBs to put all other metrics into perspective. .. GENERATED FROM PYTHON SOURCE LINES 1107-1117 .. code-block:: Python fig, ax = plt.subplots(figsize=(12, 6)) sns.barplot( data=laboratory_results_matched.groupby(["version"])["n_matched_wbs"] .sum() .reset_index(), x="version", y="n_matched_wbs", ax=ax, ) fig.show() .. image-sg:: /auto_revalidation/full_pipeline/images/sphx_glr__01_pipeline_analysis_017.png :alt: 01 pipeline analysis :srcset: /auto_revalidation/full_pipeline/images/sphx_glr__01_pipeline_analysis_017.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 1118-1137 .. code-block:: Python laboratory_matched_perf_metrics_all = laboratory_results_matched.pipe( multilevel_groupby_apply_merge, [ ( ["algo", "version"], partial(apply_aggregations, aggregations=custom_aggs_matched), ), ( ["algo"], partial(apply_transformations, transformations=stats_transform), ), ], ).pipe(format_tables_matched) laboratory_matched_perf_metrics_all.style.pipe( revalidation_table_styles, validation_thresholds, ["algo"], ) .. raw:: html
    # participants WD mean and CI [m/s] INDIP mean and CI [m/s] Bias and LoA [m/s] Abs. Error [m/s] Rel. Error [%] Abs. Rel. Error [%] ICC # Matched WBs
algo version                  
Mobilise-D Pipeline MobGap 1168 0.79 [0.78, 0.80] 0.79 [0.78, 0.81] -0.00 [-0.21, 0.21] 0.08 [0.08, 0.09]** 2.34 [1.36, 3.33] 11.86 [11.12, 12.59] 0.90 [0.88, 0.91] 674
Original Implementation 1168 0.84 [0.83, 0.86] 0.84 [0.82, 0.85] 0.00 [-0.24, 0.25] 0.10 [0.09, 0.10] 4.05 [2.92, 5.19] 13.31 [12.44, 14.18] 0.86 [0.83, 0.87] 714


.. GENERATED FROM PYTHON SOURCE LINES 1138-1139 Residual plot .. GENERATED FROM PYTHON SOURCE LINES 1139-1142 .. code-block:: Python laboratory_results_matched.query('algo == "Mobilise-D Pipeline"').pipe( combo_residual_plot, name="Matched WBs - Walking Speed" ) .. image-sg:: /auto_revalidation/full_pipeline/images/sphx_glr__01_pipeline_analysis_018.png :alt: Matched WBs - Walking Speed, MobGap, Original Implementation :srcset: /auto_revalidation/full_pipeline/images/sphx_glr__01_pipeline_analysis_018.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 1143-1148 Per-cohort analysis ~~~~~~~~~~~~~~~~~~~ Barplot The results below represent the average absolute error on walking speed estimation across all participants within a cohort. .. GENERATED FROM PYTHON SOURCE LINES 1148-1162 .. code-block:: Python fig, ax = plt.subplots(figsize=(12, 6)) sns.barplot( data=laboratory_results_matched.groupby(["version", "cohort"])[ "n_matched_wbs" ] .sum() .reset_index(), hue="version", y="n_matched_wbs", x="cohort", order=cohort_order, ax=ax, ) fig.show() .. image-sg:: /auto_revalidation/full_pipeline/images/sphx_glr__01_pipeline_analysis_019.png :alt: 01 pipeline analysis :srcset: /auto_revalidation/full_pipeline/images/sphx_glr__01_pipeline_analysis_019.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 1163-1164 Boxplot .. GENERATED FROM PYTHON SOURCE LINES 1164-1176 .. code-block:: Python fig, ax = plt.subplots(figsize=(12, 6)) sns.boxplot( data=laboratory_results_matched, x="cohort", y="walking_speed_mps__abs_error", hue="algo_with_version", order=cohort_order, ax=ax, ).legend().set_title(None) ax.set_ylabel("Absolute Error [m/s]") ax.set_title("Absolute Error - Matched Analysis") fig.show() .. image-sg:: /auto_revalidation/full_pipeline/images/sphx_glr__01_pipeline_analysis_020.png :alt: Absolute Error - Matched Analysis :srcset: /auto_revalidation/full_pipeline/images/sphx_glr__01_pipeline_analysis_020.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 1177-1178 Processing the per-cohort performance table .. GENERATED FROM PYTHON SOURCE LINES 1178-1202 .. code-block:: Python laboratory_matched_perf_metrics_cohort = ( laboratory_results_matched.pipe( multilevel_groupby_apply_merge, [ ( ["cohort", "algo", "version"], partial(apply_aggregations, aggregations=custom_aggs_matched), ), ( ["cohort", "algo"], partial(apply_transformations, transformations=stats_transform), ), ], ) .pipe(format_tables_matched) .loc[cohort_order] ) laboratory_matched_perf_metrics_cohort.style.pipe( revalidation_table_styles, validation_thresholds, ["cohort", "algo"], ) .. raw:: html
      # participants WD mean and CI [m/s] INDIP mean and CI [m/s] Bias and LoA [m/s] Abs. Error [m/s] Rel. Error [%] Abs. Rel. Error [%] ICC # Matched WBs
cohort algo version                  
HA Mobilise-D Pipeline MobGap 227 0.84 [0.81, 0.86] 0.83 [0.80, 0.87] 0.00 [-0.19, 0.20] 0.08 [0.07, 0.09] 3.45 [1.02, 5.88] 11.44 [9.47, 13.42] 0.90 [0.84, 0.93] 80
Original Implementation 227 0.86 [0.84, 0.89] 0.87 [0.85, 0.90] -0.01 [-0.20, 0.18] 0.08 [0.07, 0.09] -0.46 [-2.08, 1.17] 9.61 [8.57, 10.65] 0.87 [0.81, 0.91] 102
CHF Mobilise-D Pipeline MobGap 106 0.75 [0.71, 0.79] 0.78 [0.73, 0.83] -0.04 [-0.22, 0.14] 0.07 [0.06, 0.09]* -3.98 [-6.18, -1.77] 9.28 [7.74, 10.82] 0.91 [0.81, 0.95] 53
Original Implementation 106 0.89 [0.84, 0.93] 0.95 [0.89, 1.02] -0.07 [-0.37, 0.24] 0.12 [0.10, 0.14] -3.44 [-7.01, 0.13] 13.16 [10.54, 15.77] 0.83 [0.69, 0.90] 60
COPD Mobilise-D Pipeline MobGap 214 0.87 [0.84, 0.89] 0.88 [0.85, 0.90] -0.01 [-0.15, 0.14] 0.06 [0.05, 0.07] 0.27 [-1.10, 1.63] 7.47 [6.54, 8.40] 0.92 [0.89, 0.95] 93
Original Implementation 214 0.90 [0.88, 0.93] 0.89 [0.86, 0.92] 0.01 [-0.14, 0.17] 0.06 [0.06, 0.07] 2.38 [0.82, 3.94] 7.76 [6.56, 8.96] 0.91 [0.87, 0.94] 106
MS Mobilise-D Pipeline MobGap 228 0.83 [0.80, 0.86] 0.82 [0.79, 0.85] 0.01 [-0.22, 0.24] 0.09 [0.08, 0.10] 3.37 [0.94, 5.80] 12.73 [10.87, 14.60] 0.88 [0.84, 0.91] 176
Original Implementation 228 0.86 [0.83, 0.89] 0.85 [0.81, 0.88] 0.01 [-0.25, 0.28] 0.10 [0.09, 0.12] 4.54 [1.98, 7.10] 14.03 [12.14, 15.93] 0.84 [0.79, 0.88] 182
PD Mobilise-D Pipeline MobGap 224 0.77 [0.75, 0.80] 0.79 [0.76, 0.82] -0.01 [-0.23, 0.20] 0.09 [0.08, 0.10] 0.66 [-1.32, 2.65] 12.16 [10.97, 13.36] 0.87 [0.83, 0.91] 150
Original Implementation 224 0.83 [0.80, 0.85] 0.82 [0.79, 0.85] 0.01 [-0.24, 0.26] 0.10 [0.09, 0.11] 4.74 [2.30, 7.18] 13.92 [12.16, 15.67] 0.84 [0.78, 0.88] 141
PFF Mobilise-D Pipeline MobGap 169 0.69 [0.66, 0.72] 0.68 [0.64, 0.72] 0.01 [-0.21, 0.23] 0.09 [0.08, 0.10]** 6.55 [3.34, 9.77] 15.07 [12.59, 17.55] 0.89 [0.85, 0.93] 122
Original Implementation 169 0.74 [0.71, 0.78] 0.72 [0.67, 0.76] 0.03 [-0.25, 0.31] 0.12 [0.10, 0.13] 11.65 [7.40, 15.90] 19.86 [16.38, 23.34] 0.84 [0.77, 0.89] 123


.. GENERATED FROM PYTHON SOURCE LINES 1203-1211 Deep dive investigation: Do errors depend on WB duration or walking speed? ************************************************************************** Effect of WB duration ~~~~~~~~~~~~~~~~~~~~~ We investigate the dependency of the absolute walking speed error of all true-positive WBs from the real-world recording on the WB duration reported by the reference system. In the top, WB errors are grouped by various duration bouts. In the bottom the number of bouts within each duration group is visualized. .. GENERATED FROM PYTHON SOURCE LINES 1211-1268 .. code-block:: Python import numpy as np def plot_wb_duration_analysis(df): """Generates a single figure with: - First row: Two side-by-side boxplot for "new" and "old" cases. - Second row: A grouped bar chart comparing WB counts for "new" and "old" cases. df: DataFrame containing 'version' column with values 'new' or 'old' to distinguish data """ fig, axs = plt.subplot_mosaic( [["v"], ["v"], ["v"], ["n"]], sharex=True, figsize=(12, 9) ) # Compute WB durations in seconds df_with_durations = df.assign( duration_s=lambda df_: ( (df_["end__reference"] - df_["start__reference"]) / 100 ) ) bins = { "All": (-np.inf, np.inf), "> 10 s": (10, np.inf), "<= 10 s": (0, 10), "10 - 30 s": (10, 30), "30 - 60 s": (30, 60), "60 - 120 s": (60, 120), "> 120 s": (120, np.inf), } binned_df = cut_into_overlapping_bins( df_with_durations, "duration_s", bins ).reset_index() n = sns.countplot( data=binned_df, x="bin", hue="version", ax=axs["n"], legend=False ) for container in n.containers: n.bar_label(container, size=10) sns.boxplot( data=binned_df, x="bin", y="walking_speed_mps__abs_error", hue="version", ax=axs["v"], ) sns.despine(fig) axs["v"].set_ylabel("Absolute Walking Speed Error (m/s)") axs["n"].set_ylabel("WB Count") axs["n"].set_xlabel("Ref. WB Duration") fig.show() laboratory_results_matched_raw.query("algo == 'Mobilise-D Pipeline'").pipe( plot_wb_duration_analysis ) .. image-sg:: /auto_revalidation/full_pipeline/images/sphx_glr__01_pipeline_analysis_021.png :alt: 01 pipeline analysis :srcset: /auto_revalidation/full_pipeline/images/sphx_glr__01_pipeline_analysis_021.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 1269-1276 Effect of walking speed on error ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ One important aspect of the algorithm performance is the dependency on the walking speed. Aka, how well do the algorithms perform at different walking speeds. For this we plot the absolute error against the walking speed of the reference data. For better granularity, we use the values per WB, instead of the aggregates per participant. The overlayed dots represent the trend-line calculated by taking the median of the absolute error within bins of 0.05 m/s. .. GENERATED FROM PYTHON SOURCE LINES 1276-1375 .. code-block:: Python # For plotting all participants at the end laboratory_combined = laboratory_results_matched_raw.copy() laboratory_combined["cohort"] = "Combined" laboratory_combined_ws_level_results = pd.concat( [laboratory_results_matched_raw, laboratory_combined] ).reset_index(drop=True) algo_names = laboratory_combined_ws_level_results["algo_with_version"].unique() cohort_names = laboratory_combined_ws_level_results["cohort"].unique() laboratory_combined_ws_level_results["cohort"] = pd.Categorical( laboratory_combined_ws_level_results["cohort"], categories=cohort_names, ordered=True, ) laboratory_combined_ws_level_results["algo_with_version"] = pd.Categorical( laboratory_combined_ws_level_results["algo_with_version"], categories=algo_names, ordered=True, ) # Create the figure with subplots fig = plt.figure(constrained_layout=True, figsize=(24, 5 * len(algo_names))) subfigs = fig.subfigures(len(algo_names), 1, wspace=0.1, hspace=0.1) # Define the min and max limits for x and y axes min_max_x = calc_min_max_with_margin( laboratory_combined_ws_level_results["walking_speed_mps__reference"] ) min_max_y = calc_min_max_with_margin( laboratory_combined_ws_level_results["walking_speed_mps__abs_error"] ) # Plotting each algorithm version for subfig, (algo, data) in zip( subfigs, laboratory_combined_ws_level_results.groupby( "algo_with_version", observed=True ), ): subfig.suptitle(algo) subfig.supxlabel("Walking Speed (m/s)") subfig.supylabel("Absolute Error (m/s)") # Create subplots for each cohort axs = subfig.subplots(1, len(cohort_names), sharex=True, sharey=True) for ax, (cohort, cohort_data) in zip( axs, data.groupby("cohort", observed=True) ): # Scatter plot for the cohort data sns.scatterplot( data=cohort_data, x="walking_speed_mps__reference", # Reference walking speed y="walking_speed_mps__abs_error", # Absolute error ax=ax, alpha=0.3, ) # Define bins for walking speed bins = np.arange( 0, cohort_data["walking_speed_mps__reference"].max() + 0.05, 0.05 ) cohort_data["speed_bin"] = pd.cut( cohort_data["walking_speed_mps__reference"], bins=bins ) # Calculate bin centers cohort_data["bin_center"] = cohort_data["speed_bin"].apply( lambda x: x.mid ) # Calculate median error per bin and cohort binned_data = ( cohort_data.groupby("bin_center", observed=True)[ "walking_speed_mps__abs_error" ] .median() .reset_index() ) # Plot the median lines for each bin sns.scatterplot( data=binned_data, x="bin_center", y="walking_speed_mps__abs_error", # Median error ax=ax, ) ax.set_title(cohort) ax.set_xlabel(None) ax.set_ylabel(None) # Set axis limits ax.set_xlim(*min_max_x) ax.set_ylim(*min_max_y) fig.show() .. image-sg:: /auto_revalidation/full_pipeline/images/sphx_glr__01_pipeline_analysis_022.png :alt: CHF, COPD, HA, MS, PD, PFF, Combined, CHF, COPD, HA, MS, PD, PFF, Combined :srcset: /auto_revalidation/full_pipeline/images/sphx_glr__01_pipeline_analysis_022.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 23.820 seconds) **Estimated memory usage:** 162 MB .. _sphx_glr_download_auto_revalidation_full_pipeline__01_pipeline_analysis.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: _01_pipeline_analysis.ipynb <_01_pipeline_analysis.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: _01_pipeline_analysis.py <_01_pipeline_analysis.py>` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: _01_pipeline_analysis.zip <_01_pipeline_analysis.zip>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_