You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Julia/README.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -54,20 +54,20 @@ For the results in Table II of the paper, this script is repeated with seeds 1:1
54
54
This script is similar to `PG_OCP_known_basis_functions_Altro.jl`, but the solver IPOPT is used instead of Altro. Due to the different solver, the results differ slightly from the ones presented in the paper.
55
55
56
56
### PG_OCP_generic_basis_functions_Altro.jl
57
-
This script reproduces the results of the optimal control approach with generic basis functions (Figure 3) given in Section V-C of the paper.
57
+
This script reproduces the results of the optimal control approach with generic basis functions (Figure 3) given in Section V-C of the paper. Due to small adjustments to the code (see Erratum in the [general README](../README.md)) and resulting numerical differences, the results from **v0.2.2** and later differ slightly from those presented in the paper. If you wish to reproduce the exact results from the paper, you can pull an earlier release of the code before version **v0.2.2**.
The method presented in the paper ["A flexible state–space model for learning nonlinear dynamical systems"](https://doi.org/10.1016/j.automatica.2017.02.030) is utilized to systematically derive basis functions and priors for the parameters based on a reduced-rank GP approximation. Afterward, by calling the function `particle_Gibbs()`, samples are drawn from the posterior distribution using particle Gibbs sampling. These samples are then passed to the function `solve_PG_OCP_Altro()`, which solves the scenario OCP using Altro.
63
+
In this example, the method presented in the paper ["A flexible state–space model for learning nonlinear dynamical systems"](https://doi.org/10.1016/j.automatica.2017.02.030) is utilized to systematically derive basis functions and priors for the parameters based on a reduced-rank GP approximation. Afterward, by calling the function `particle_Gibbs()`, samples are drawn from the posterior distribution using particle Gibbs sampling. These samples are then passed to the function `solve_PG_OCP_Altro()`, which solves the scenario OCP using Altro.
64
64
65
-
The runtime of the script is about 2 hours on a standard laptop. Using an improved phi function can reduce the runtime to about 50 minutes, but the results change slightly due to numerical reasons. Further explanations can be found in the source code.
65
+
The runtime of the script is about 1 hour on a standard laptop.
66
66
67
67
For the results in Table IV of the paper, this script is repeated with seeds 1:100.
68
68
69
69
### PG_OCP_generic_basis_functions_Ipopt.jl
70
-
This script is similar to `PG_OCP_generic_basis_functions_Altro.jl`, but the solver IPOPT is used instead of Altro. Due to the different solver, the results differ slightly from the ones presented in the paper.
70
+
This script is similar to `PG_OCP_generic_basis_functions_Altro.jl`, but the solver IPOPT is used instead of Altro.
71
71
72
72
## List of source code files
73
73
The following files in the folder [src](src) contain the PGopt source code.
Copy file name to clipboardExpand all lines: Julia/docs/src/examples/PG_OCP_generic_basis_functions.md
+57-58Lines changed: 57 additions & 58 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,12 +1,12 @@
1
1
# Optimal control with generic basis functions
2
2
3
-
This example reproduces the results of the optimal control approach with generic basis functions (Figure 3) given in Section V-C of the [paper](../reference.md).
3
+
This example reproduces the results of the optimal control approach with generic basis functions (Figure 3) given in Section V-C of the [paper](../reference.md). Due to small adjustments to the code (see Erratum in the [Introduction](../index.md)) and resulting numerical differences, the results from **v0.2.2** and later differ slightly from those presented in the paper. If you wish to reproduce the exact results from the paper, you can pull an earlier release of the code before version **v0.2.2**.
The method presented in the paper ["A flexible state–space model for learning nonlinear dynamical systems"](https://doi.org/10.1016/j.automatica.2017.02.030) is utilized to systematically derive basis functions and priors for the parameters based on a reduced-rank GP approximation. Afterward, by calling the function `particle_Gibbs()`, samples are drawn from the posterior distribution using particle Gibbs sampling. These samples are then passed to the function `solve_PG_OCP_Altro()` (or `solve_PG_OCP_Ipopt()` in case IPOPT is used), which solves the scenario OCP using the solver Altro.
8
8
9
-
A Julia script that contains all the steps described in the following and exactly reproduces Figure 2 of the paper can be found at `PGopt/Julia/examples/PG_OCP_generic_basis_functions_Altro.jl`. For the results in Table IV of the paper, this script is repeated with seeds 1:100. The runtime of the script is about 2 hours on a standard laptop. Using an improved function `phi()`, can reduce the runtime to about 50 minutes, but the results change slightly due to numerical reasons. Further explanations are given below.
9
+
A Julia script that contains all the steps described in the following and reproduces Figure 2 of the paper can be found at `PGopt/Julia/examples/PG_OCP_generic_basis_functions_Altro.jl`. For the results in Table IV of the paper, this script is repeated with seeds 1:100. The runtime of the script is about 2 hours on a standard laptop.
10
10
11
11
A similar example that utilizes the solver IPOPT can be found at `PGopt/Julia/examples/PG_OCP_generic_basis_functions_Ipopt.jl`. Due to the different solver, the results differ slightly from the ones presented in the paper.
12
12
@@ -43,6 +43,9 @@ n_y = 1 # number of outputs
43
43
Then, generate generic basis functions and priors based on a reduced-rank GP approximation.
44
44
The approach is described in the paper ["A flexible state–space model for learning nonlinear dynamical systems"](https://doi.org/10.1016/j.automatica.2017.02.030).
45
45
The equation numbers given in the following refer to this paper.
46
+
In this example, a GP with a squared exponential kernel
47
+
$k(z, z') = s_f \exp (-\frac{1}{2} (z - z')^\top \Lambda^{-1} (z - z'))$,
48
+
where $\Lambda = l^2 I$ and $I$ is the identity matrix, is approximated.
46
49
```julia
47
50
n_phi_x = [55] # number of basis functions for each state
48
51
n_phi_u =5# number of basis functions for the control input
@@ -54,10 +57,6 @@ L_u = 10 # interval length for u
54
57
L =zeros(1, 1, n_z) # array containing the interval lengths
55
58
L[1, 1, :] = [L_u L_x]
56
59
57
-
# Hyperparameters of the squared exponential kernel
58
-
l = [2] # length scale
59
-
sf =100# scale factor
60
-
61
60
# Initialize.
62
61
j_vec =zeros(n_phi, 1, n_z) # contains all possible vectors j; j_vec[i, 1, :] corresponds to the vector j in eq. (5) for basis function i
63
62
lambda =zeros(n_phi, n_z) # lambda[i, :] corresponds to the vector λ in eq. (9) (right-hand side) for basis function i
@@ -66,71 +65,65 @@ In the following, all possible vectors ``j`` are constructed (i.e., `j_vec`). Th
66
65
```julia
67
66
cart_prod_sets =Array{Any}(undef, n_z) # array of arrays; cart_prod_sets[i] corresponds to the i-th set to be considered for the Cartesian product, i.e., [1 : n_basis[i]].
68
67
for i =1:n_z
69
-
cart_prod_sets[i] =Array(1:n_phi_dims[i])
68
+
cart_prod_sets[i] =Array(1:n_phi_dims[i])
70
69
end
71
70
72
71
subscript_values =Array{Int64}(undef, n_z) # contains the equivalent subscript values corresponding to a given single index i
73
72
variants = [1; cumprod(n_phi_dims[1:end-1])] # required to convert the single index i to the equivalent subscript value
74
73
75
74
# Construct Cartesian product and calculate spectral densities.
76
75
for i in1:n_phi
77
-
# Convert the single index i to the equivalent subscript values.
After the paper's publication, a much more efficient implementation was found, which, for numerical reasons, produces slightly different results (differences in the range ``1\cdot 10^{-16}`` when called once).
118
-
However, these minimal deviations lead to noticeably different results since the function phi is called recursively ``T \cdot N \cdot K_{\mathrm{total}}`` times (= very often).
119
-
This is the improved implementation, which is significantly faster but yields slightly different results.
Since the optimization cannot deal with multithreading or in-place computations, a less efficient definition of phi is required for the subsequent optimization.
Determine the parameters of the matrix normal prior (with mean matrix ``0``, right covariance matrix ``Q`` (see above), and left covariance matrix ``V``) for ``A``.
143
-
``V`` is derived from the GP approximation according to eq. (8b), (11a), and (9).
136
+
``V`` is derived from the GP approximation according to eq. (8b), (9).
137
+
The spectral density of the anisotropic squared exponential kernel
138
+
$k(z, z') = s_f \exp (-\frac{1}{2} (z - z')^\top \Lambda^{-1} (z - z'))$
## Define and solve optimal control problem using Altro
215
214
In the following, the optimal control problem is defined and solved using the solver Altro. An example using the solver IPOPT is given in the next section.
216
215
With the Altro solver, problems of the following form can be solved
Solve the optimal control problem using the solver IPOPT. In this case, no formal guarantees for the constraint satisfaction can be derived since Assumption 1 is not satisfied as the employed basis functions cannot represent the actual dynamics with arbitrary precision.
389
388
Since the cost function depends only on the control inputs ``u_{0:H}``, the optional argument `J_u` is set to `true`.
Copy file name to clipboardExpand all lines: Julia/docs/src/index.md
+15-1Lines changed: 15 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
3
3
**PGopt** is a software for determining optimal input trajectories with probabilistic performance and constraint satisfaction guarantees for unknown systems with latent states based on input-output measurements. In order to quantify uncertainties, which is crucial for deriving formal guarantees, a Bayesian approach is employed and a prior over the unknown dynamics and the system trajectory is formulated in state-space representation. Since for practical applicability, the prior must be updated based on input-output measurements, but the corresponding posterior distribution is analytically intractable, particle Gibbs (PG) sampling is utilized to draw samples from this distribution. Based on these samples, a scenario optimal control problem (OCP) is formulated and probabilistic performance and constraint satisfaction guarantees are inferred via a greedy constraint removal.
4
4
5
-
The approach is explained in the paper "Learning-Based Optimal Control with Performance Guarantees for Unknown Systems with Latent States", available as a preprint on [arXiv](https://arxiv.org/abs/2303.17963).
5
+
The approach is explained in the paper "Learning-Based Optimal Control with Performance Guarantees for Unknown Systems with Latent States", available on [IEEExplore](https://doi.org/10.23919/ECC64448.2024.10590972) and as a preprint on [arXiv](https://arxiv.org/abs/2303.17963).
6
6
7
7
## Versions
8
8
This document describes the Julia implementation of `PGopt`. In this version, the solvers [Altro](https://github.com/RoboticExplorationLab/Altro.jl) and [IPOPT](https://coin-or.github.io/Ipopt/) can be employed to solve the optimal control problem (OCP).
@@ -13,6 +13,20 @@ The solver IPOPT is more general than Altro, and this implementation allows arbi
13
13
14
14
Besides the Julia implementation, there is also a MATLAB implementation that utilizes [CasADi](https://web.casadi.org/) and [IPOPT](https://coin-or.github.io/Ipopt/). Further information can be found [here](https://github.com/TUM-ITR/PGopt/tree/main/MATLAB).
15
15
16
+
## Erratum: Hyperparameters in Section V-C
17
+
It has come to our attention that the hyperparameters reported in the example with generic basis functions in Section V-C of the paper were unclear due to a notational inconsistency in the kernel representation. While the theoretical conclusions of the paper remain unaffected, the code for the example with generic basis functions has been updated for consistency with the general literature in version **v0.2.2** and later.
18
+
19
+
### Corrected Kernel Definition
20
+
The squared exponential kernel is now defined as
21
+
$k(z, z') = s_f \exp (-\frac{1}{2} (z - z')^\top \Lambda^{-1} (z - z'))$,
22
+
where $\Lambda = l^2 I$, and $I$ is the identity matrix.
23
+
24
+
This updated definition ensures consistency with the general literature. Using this definition, the hyperparameters for the example in Section V-C (Table III) of the paper are:
25
+
* $l = 2\pi \approx 6.28$
26
+
* $s_f = \frac{100^2}{8\pi^4} \approx 12.83$
27
+
28
+
The updated definition may result in small numerical differences (e.g., due to rounding or recalculation) compared to the original results presented in the paper. These differences are minor and do not impact the overall findings or conclusions.
29
+
16
30
## Installation
17
31
`PGopt` can be installed using the Julia package manager. Start a Pkg REPL (press `]` in a Julia REPL), and install `PGopt` via
0 commit comments