|
767 | 767 | 0.0 |
768 | 768 | (reverse (map vector deltas dones truncates))))))) |
769 | 769 |
|
770 | | -;; For example when all rewards are 1.0 and if using an discount factor of 0.5, the advantages approach 2.0 assymptotically when going backwards in time. |
| 770 | +;; For example when all deltas are 1.0 and if using an discount factor of 0.5, the advantages approach 2.0 assymptotically when going backwards in time. |
771 | 771 | (advantages {:dones [false false false] :truncates [false false false]} |
772 | 772 | [1.0 1.0 1.0] |
773 | 773 | 0.5 |
|
1059 | 1059 | (def actor (Actor 3 64 1)) |
1060 | 1060 | (py. actor load_state_dict (torch/load "src/ppo/actor.pt")) |
1061 | 1061 |
|
1062 | | -(let [angle-values (torch/linspace (- PI) PI 854) |
1063 | | - speed-values (torch/linspace 1.0 -1.0 480) |
1064 | | - grid (torch/meshgrid speed-values angle-values :indexing "ij") |
1065 | | - cos-angle (torch/cos (last grid)) |
1066 | | - sin-angle (torch/sin (last grid)) |
1067 | | - observations (torch/stack [(py. cos-angle ravel) |
1068 | | - (py. sin-angle ravel) |
1069 | | - (py. (first grid) ravel)] |
1070 | | - :axis 1) |
1071 | | - actions (without-gradient |
1072 | | - (py. (py. (py. actor deterministic_act observations) |
1073 | | - reshape 480 854) numpy)) |
1074 | | - actions-tensor (dtype/elemwise-cast (dtt/ensure-tensor (py/->jvm actions)) |
1075 | | - :float32)] |
| 1062 | +(let [angle-values (torch/linspace (- PI) PI 854) |
| 1063 | + speed-values (torch/linspace 1.0 -1.0 480) |
| 1064 | + grid (torch/meshgrid speed-values angle-values :indexing "ij") |
| 1065 | + cos-angle (torch/cos (last grid)) |
| 1066 | + sin-angle (torch/sin (last grid)) |
| 1067 | + observations (torch/stack [(py. cos-angle ravel) |
| 1068 | + (py. sin-angle ravel) |
| 1069 | + (py. (first grid) ravel)] |
| 1070 | + :axis 1) |
| 1071 | + actions (without-gradient |
| 1072 | + (py. (py. (py. actor deterministic_act observations) |
| 1073 | + reshape 480 854) numpy)) |
| 1074 | + actions-tensor (dtt/clone |
| 1075 | + (dtype/elemwise-cast (dtt/ensure-tensor (py/->jvm actions)) |
| 1076 | + :float32)) |
| 1077 | + actions-trsps (dtt/transpose actions-tensor [1 0])] |
| 1078 | + (dtt/mset! actions-tensor 240 (dfn/- 1.0 (actions-tensor 240))) |
| 1079 | + (dtt/mset! actions-trsps 427 (dfn/- 1.0 (actions-trsps 427))) |
1076 | 1080 | (bufimg/tensor->image (dfn/* actions-tensor 255))) |
1077 | 1081 | ;; This image shows the motor control input as a function of pendulum angle and angular velocity. |
1078 | 1082 | ;; As one can see, the pendulum is decelerated when the speed is high (dark values at the top of the image). |
1079 | 1083 | ;; Near the centre of the image (speed zero and angle zero) one can see how the pendulum is accelerated when the angle is negative and the speed small and decelerated when the angle is positive and the speed is small. |
1080 | | -;; Also the image is not symmetrical because otherwise the pendulum would not start swinging up when pointing downwards. |
| 1084 | +;; Also the image is not symmetrical because otherwise the pendulum would not start swinging up when pointing downwards (left and right boundary of the image). |
1081 | 1085 |
|
1082 | 1086 | ;; ## Automated Pendulum |
1083 | 1087 | ;; |
|
0 commit comments