|
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). |
|
0 commit comments