|
| 1 | +using Revise, Test |
| 2 | +using IntervalMDPAbstractions, LazySets |
| 3 | + |
| 4 | +τ = 0.1 |
| 5 | + |
| 6 | +region1 = Hyperrectangle(low = [-1.0, -1.0], high = [0.0, 1.0]) |
| 7 | +f(x, u) = [x[1] + x[2] * τ, x[2] + (-x[1] + (1 - x[1])^2 * x[2]) * τ] |
| 8 | +dyn_reg1 = NonlinearDynamicsRegion(f, region1) |
| 9 | + |
| 10 | +region2 = Hyperrectangle(low = [0.0, -1.0], high = [1.0, 1.0]) |
| 11 | +g(x, u) = [x[1] + x[2] * τ, x[2] + (-x[2] + (1 - x[2])^2 * x[1]) * τ] |
| 12 | +dyn_reg2 = NonlinearDynamicsRegion(g, region2) |
| 13 | + |
| 14 | +w_stddev = [0.1, 0.1] |
| 15 | +w = AdditiveDiagonalGaussianNoise(w_stddev) |
| 16 | + |
| 17 | +dyn = PiecewiseNonlinearAdditiveNoiseDynamics([dyn_reg1, dyn_reg2], 2, 0, w) |
| 18 | + |
| 19 | +prepare_nominal(dyn, InputDiscrete([0.0])) |
| 20 | + |
| 21 | +X = Hyperrectangle(low = [-1.0, 0.0], high = [1.0, 1.0]) |
| 22 | +U = Singleton([0.0]) |
| 23 | + |
| 24 | +Y = concretize(nominal(dyn, X, U)) |
| 25 | + |
| 26 | +# First piecewise region |
| 27 | +X1 = Hyperrectangle(low = [-1.0, 0.0], high = [0.0, 1.0]) |
| 28 | + |
| 29 | +# 1st-order Taylor expansion at [center(X1)] = [-0.5; 0.5]: |
| 30 | +# z = x - center(X1) |
| 31 | +# y₁ = z₁ + 0.1 * z₂ - 0.45 |
| 32 | +# y₂ = -0.25 * z₁ + 1.2245 * z₂ + 0.6625 + [-0.075, 0.1] |
| 33 | +X1centered = Translation(X1, -[-0.5, 0.5]) |
| 34 | +AXD1 = AffineMap([1.0 0.1; -0.25 1.225], X1centered, [-0.45, 0.6625]) |
| 35 | +Y1_expected = MinkowskiSum(AXD1, Hyperrectangle(low = [0.0, -0.075], high = [0.0, 0.1])) |
| 36 | + |
| 37 | +# First piecewise region |
| 38 | +X2 = Hyperrectangle(low = [0.0, 0.0], high = [1.0, 1.0]) |
| 39 | + |
| 40 | +# 1st-order Taylor expansion at [center(X2)] = [0.5; 0.5]: |
| 41 | +# z = x - center(X2) |
| 42 | +# y₁ = z₁ + 0.1 * z₂ + 0.55 |
| 43 | +# y₂ = 0.025 * z₁ + 0.85 * z₂ + 0.4625 + [-0.025, 0.05] |
| 44 | +X2centered = Translation(X2, -[0.5, 0.5]) |
| 45 | +AXD2 = AffineMap([1.0 0.1; 0.025 0.85], X2centered, [0.55, 0.4625]) |
| 46 | +Y2_expected = MinkowskiSum(AXD2, Hyperrectangle(low = [0.0, -0.025], high = [0.0, 0.05])) |
| 47 | + |
| 48 | +Y_expected = concretize(ConvexHull(Y1_expected, Y2_expected)) |
| 49 | +@test isequivalent(Y, Y_expected) |
| 50 | + |
| 51 | + |
| 52 | +#### Region-based actions |
| 53 | +region2 = Hyperrectangle(low = [0.0, -1.0], high = [1.0, 1.0]) |
| 54 | +h(x, u) = [x[1] + x[2] * τ, x[2] + (-x[2] + (1 - x[2])^2 * x[1] + u[1]) * τ] |
| 55 | +dyn_reg2 = NonlinearDynamicsRegion(h, region2) |
| 56 | + |
| 57 | +w_stddev = [0.1, 0.1] |
| 58 | +w = AdditiveDiagonalGaussianNoise(w_stddev) |
| 59 | + |
| 60 | +dyn = PiecewiseNonlinearAdditiveNoiseDynamics([dyn_reg1, dyn_reg2], 2, 1, w) |
| 61 | + |
| 62 | +input_abs = InputGridSplit(Hyperrectangle(low = [-1.0], high = [1.0]), (3,)) |
| 63 | +prepare_nominal(dyn, input_abs) |
| 64 | + |
| 65 | +X = Hyperrectangle(low = [-1.0, 0.0], high = [1.0, 1.0]) |
| 66 | +U = Hyperrectangle(low = [-1.0], high = [-1 / 3]) |
| 67 | + |
| 68 | +Y = concretize(nominal(dyn, X, U)) |
| 69 | + |
| 70 | +# First piecewise region |
| 71 | +X1 = Hyperrectangle(low = [-1.0, 0.0], high = [0.0, 1.0]) |
| 72 | + |
| 73 | +# 1st-order Taylor expansion at [center(X1)] = [-0.5; 0.5]: |
| 74 | +# z = x - center(X1) |
| 75 | +# y₁ = z₁ + 0.1 * z₂ |
| 76 | +# y₂ = -0.1 * z₁ + 1.1 * z₂ + 0.6625 + [-0.075, 0.1] |
| 77 | +X1centered = Translation(X1, -[-0.5, 0.5]) |
| 78 | +AXD1 = LinearMap([1.0 0.1; -0.1 1.1], X1centered) |
| 79 | +Y1_expected = |
| 80 | + MinkowskiSum(AXD1, Hyperrectangle(; low = [0.0, -0.0625], high = [0.0, 0.0625])) |
| 81 | + |
| 82 | +# First piecewise region |
| 83 | +X2 = Hyperrectangle(low = [0.0, 0.0], high = [1.0, 1.0]) |
| 84 | + |
| 85 | +# 1st-order Taylor expansion at [center(X2)] = [0.5; 0.5]: |
| 86 | +# z = x - center(X2) |
| 87 | +# y₁ = z₁ + 0.1 * z₂ |
| 88 | +# y₂ = 0.1 * z₁ + 0.9 * z₂ + 0.1 * u₁ - 1/15 + [-0.0625, 0.0625] |
| 89 | +X2centered = Translation(X2, -[0.5, 0.5]) |
| 90 | +AXD2 = AffineMap([1.0 0.1; 0.1 0.9], X2centered, [0.0, -1 / 15]) |
| 91 | +U = Hyperrectangle(low = [-1.0], high = [-1 / 3]) |
| 92 | +Ucentered = Translation(U, -center(U)) |
| 93 | +AXDBU2 = MinkowskiSum(AXD2, LinearMap([0.0; 0.1], Ucentered)) |
| 94 | +Y2_expected = |
| 95 | + MinkowskiSum(AXDBU2, Hyperrectangle(low = [0.0, -0.0625], high = [0.0, 0.0625])) |
| 96 | + |
| 97 | +Y_expected = concretize(ConvexHull(Y1_expected, Y2_expected)) |
| 98 | +@test isequivalent(Y, Y_expected) |
| 99 | + |
| 100 | +# Vector inputs |
| 101 | +x = [0.5, 0.5] |
| 102 | +u = [0.0] |
| 103 | + |
| 104 | +y = nominal(dyn, x, u) |
| 105 | +y_expected = g(x, u) |
| 106 | +@test y ≈ y_expected |
0 commit comments