| Literature DB >> 31622352 |
Antoine Falisse1, Gil Serrancolí2, Christopher L Dembia3, Joris Gillis4,5, Friedl De Groote1.
Abstract
Algorithmic differentiation (AD) is an alternative to finite differences (FD) for evaluating function derivatives. The primary aim of this study was to demonstrate the computational benefits of using AD instead of FD in OpenSim-based trajectory optimization of human movement. The secondary aim was to evaluate computational choices including different AD tools, different linear solvers, and the use of first- or second-order derivatives. First, we enabled the use of AD in OpenSim through a custom source code transformation tool and through the operator overloading tool ADOL-C. Second, we developed an interface between OpenSim and CasADi to solve trajectory optimization problems. Third, we evaluated computational choices through simulations of perturbed balance, two-dimensional predictive simulations of walking, and three-dimensional tracking simulations of walking. We performed all simulations using direct collocation and implicit differential equations. Using AD through our custom tool was between 1.8 ± 0.1 and 17.8 ± 4.9 times faster than using FD, and between 3.6 ± 0.3 and 12.3 ± 1.3 times faster than using AD through ADOL-C. The linear solver efficiency was problem-dependent and no solver was consistently more efficient. Using second-order derivatives was more efficient for balance simulations but less efficient for walking simulations. The walking simulations were physiologically realistic. These results highlight how the use of AD drastically decreases computational time of trajectory optimization problems as compared to more common FD. Overall, combining AD with direct collocation and implicit differential equations decreases the computational burden of trajectory optimization of human movement, which will facilitate their use for biomechanical applications requiring the use of detailed models of the musculoskeletal system.Entities:
Mesh:
Year: 2019 PMID: 31622352 PMCID: PMC6797126 DOI: 10.1371/journal.pone.0217730
Source DB: PubMed Journal: PLoS One ISSN: 1932-6203 Impact factor: 3.240
Fig 1Example of AD forward and reverse modes.
A function y = f(x1,x2) = cos x2−x2x1 is broken down into a sequence of elementary operations, forming an expression graph. In the forward mode, the forward seeds and are propagated from the inputs to the output, and the Jacobian J = ∂f/∂ relates and to the forward sensitivity . In the reverse mode, the reverse seed is propagated from the output to the inputs, and the transposed Jacobian J relates to the reverse sensitivities and .
Fig 2Flowchart depicting the optimal control framework.
We developed two approaches (AD-ADOLC and AD-Recorder) to make an OpenSim function F and its forward (F fwd) and reverse (F rev) directional derivatives available within the CasADi environment for use by the NLP solver during the optimization. In the AD-ADOLC approach (top), ADOL-C’s algorithms are used in a C++ code to provide F fwd and F rev. In the AD-Recorder approach (bottom), Recorder provides the expression graph of F as MATLAB source code from which CasADi’s C-code generator generates C-code containing F, F fwd, and F rev. The AD-Recorder approach combines operator overloading, when generating the expression graph, and source code transformation, when processing the expression graph to generate C-code for F, F fwd, and F rev. In both approaches, the code comprising F, F fwd, and F rev is compiled as a Dynamic-link Library (DLL), which is imported as an external function within the CasADi environment. In our application, F represents the multi-body dynamics and is called when formulating the optimal control problem. The latter is then composed into a differentiable optimal control transcription using CasADi. During the optimization, CasADi provides the NLP solver with evaluations of the NLP objective function (nlp f), constraints (nlp g), objective function gradient (nlp grad f), constraint Jacobian (nlp jac g), and Hessian of the Lagrangian (nlp hess l). CasADi efficiently queries F fwd and F rev to construct the full derivative matrices.
Formulation of example 1.
| Pendulum simulations | |||
|---|---|---|---|
| 2 degree of freedom pendulum: 504 | 2 degree of freedom pendulum: 458 | ||
| Joint positions | Derivatives of | ||
Controls: we introduced accelerations (time derivative of velocities) as controls (implicit formulations) in addition to joint torques. Bounds: lb and ub are for lower and upper bounds, respectively. Scaling: we used time scaling for the joint states and controls. Objective function: to avoid singular arcs, situations for which controls are not uniquely defined by the optimality conditions [37], we appended a penalty function L with the remaining controls to the objective function L. Dynamic constraints are scaled using the same scale factors as used for the states [37]. We used implicit formulations. Path constraints: f(∙) computes net joint torques T according to the skeleton dynamics.
Formulation of example 3.
| 3D tracking simulations of walking | |||
|---|---|---|---|
| 61318 | 56050 equality constraints, 9200 inequality constraints | ||
| Muscle activations | Derivatives of | ||
| Contact sphere transversal plane locations | |||
Controls are introduced for the state derivatives in addition to arm excitations. Bounds of joint states and controls are based on measured data (); min and max are for minimum and maximum values, respectively; r is range of motion; lb and ub are for lower and upper bounds, respectively; bounds of contact parameters (p, p) are based on [4]. Scaling: joint states and controls, and tendon forces are scaled such that the lower and upper bounds are between -1 and 1; contact parameters are scaled such that their lower and upper bounds are -0.5 and 0.5, respectively. Objective function L tracks measured joint positions (), ground reaction forces () and torques (), and joint torques of the lower limbs, trunk, and arms (). A penalty function L is appended to L. Dynamic constraints are scaled using scale factors used for the states [37]. Path constraints: f(∙) computes net joint torques T according to the skeleton dynamics, f(∙) describes the Hill-type muscle contraction dynamics [10], MA is moment arm of muscle m, and T are passive torques [5].
Numerical tools.
| NLP solver | Linear solvers | AD approaches | |
|---|---|---|---|
| IPOPT | Mumps | Operator overloading | |
| HSL collection | ma27 | ||
| Source code transformation | |||
Fig 3Comparison of computational time (top) and number of iterations (bottom) between FD, AD-ADOLC, and AD-Recorder. The comparisons are expressed as ratios and averaged over results from different initial guesses (error bars represent ± one standard deviation). The horizontal lines indicate 1:1 ratios. Ratios larger than one indicate slower convergence (top) and more iterations (bottom) with FD or AD-ADOLC as compared to AD-Recorder. Pend indicates pendulum simulations with the number being the number of degrees of freedom; Pred and Track indicate predictive and tracking simulations, respectively. The results were obtained using mumps and an approximated Hessian.
Comparison of computational time, number of iterations, and computational time per iteration between linear solvers.
| Solver | Pendulum simulations | 2D predictive simulations | 3D tracking simulations | ||||||
|---|---|---|---|---|---|---|---|---|---|
| CPU time | Iteration Number | CPU time per Iteration | CPU time | Iteration Number | CPU time per Iteration | CPU time | Iteration Number | CPU time per Iteration | |
| 0.6 ± | 1.0 ± 0.0 | 0.6 ± 0.1 | 1.0 ± 0.3 | 1.4 ± 0.3 | 0.7 ± 0.1 | 0.7 ± 0.2 | 0.9 ± 0.3 | 0.7 ± 0.0 | |
| 0.6 ± 0.0 | 1.0 ± 0.0 | 0.6 ± 0.0 | 2.4 ± 2.5 | 2.8 ± 2.8 | 0.8 ± 0.0 | / | / | / | |
| 0.9 ± 0.1 | 1.0 ± 0.0 | 0.9 ± 0.0 | 1.3 ± 0.0 | 1.2 ± 0.0 | 1.1 ± 0.0 | 0.5 ± 0.2 | 0.7 ± 0.3 | 0.7 ± 0.0 | |
| 1.1 ± 0.1 | 1.0 ± 0.0 | 1.1 ± 0.1 | 2.1 ± 0.5 | 1.1 ± 0.1 | 1.8 ± 0.3 | 2.3 ± 0.0 | 1.9 ± 0.0 | 1.2 ± 0.0 | |
| 0.7 ± 0.0 | 1.0 ± 0.0 | 0.7 ± 0.0 | 1.2 ± 0.3 | 1.2 ± 0.1 | 1.0 ± 0.2 | / | / | / | |
The comparisons are expressed as ratios (mean ± one standard deviation; results obtained with solver from the HSL collection over results obtained with mumps
* indicates ma27, ma57, ma77, ma86, or ma97).
The ratios are averaged over results from different initial guesses. Ratios larger than one indicate faster convergence, fewer iterations, or less time per iteration with mumps. The use of the solvers ma57 and ma97 led to memory issues for the 3D tracking simulations and these cases were therefore excluded from the analysis. The simulations were run using AD-Recorder and an approximated Hessian.
Fig 4Comparison of computational time (top) and number of iterations (bottom) between exact and approximated Hessian. The comparisons are expressed as ratios and averaged over results from different initial guesses (error bars represent ± one standard deviation). The horizontal lines indicate 1:1 ratios. Ratios larger than one indicate slower convergence (top) and more iterations (bottom) with an exact versus an approximated Hessian. Pend indicates pendulum simulations with the number being the number of degrees of freedom; Pred and Track indicate predictive and tracking simulations, respectively. The results were obtained using all solvers and AD-Recorder.
Fig 5Results from trajectory optimization of walking.
(Top) Results from 2D predictive simulations of walking (joint angles: flex is flexion, GC is gait cycle; muscle activations: bic is biceps, fem is femoris, sh is short head, max is maximus, gastroc is gastrocnemius, ant is anterior; ground reaction forces: BW is body weight). Experimental data are shown as mean ± two standard deviations. (Bottom) Results from 3D tracking simulations of walking (joint angles: R is right, L is left, add is adduction, rot is rotation; muscle activations: med is medialis, long is longus, lat is lateralis). The vertical lines indicate right heel strike (solid) and left toe-off (dashed); only part of the gait cycle, when experimental ground reaction forces are available, is tracked. The experimental electromyography data is normalized to peak muscle activations. The foot diagrams depict a down-up view of the configuration of the contact spheres of the right foot pre-calibration (left: generic) and post-calibration (right: optimized). The coefficient of determination R is given for the tracked variables.
Formulation of example 2.
| 2D predictive simulations of walking | |||
|---|---|---|---|
| 13807 | 12857 equality constraints, 1800 inequality constraints | ||
| Muscle activations | Derivatives of | ||
| Half gait cycle duration | |||
Controls are introduced for the time derivative of the states (implicit formulations) in addition to trunk excitations. Bounds are manually (man) set for the joint states and controls; lb and ub are for lower and upper bounds, respectively. Scaling: joint states and controls, and tendon forces are scaled such that the lower and upper bounds are between -1 and 1. Objective function L is normalized by distance traveled d. To avoid singular arcs [37], a penalty function L (with low weight) with the remaining controls is appended to L. Dynamic constraints are scaled using the scale factors used for the states [37]. Path constraints: f(∙) computes net joint torques T according to the skeleton dynamics, f(∙) describes the Hill-type muscle contraction dynamics [10], MA is moment arm of muscle contains all states except the pelvis forward position qpelvis,for (symmetry), and 1.33 m s-1 is the prescribed gait speed.