Skip to content

Commit c8a006a

Browse files
committed
Add axes to action function image
1 parent 44e188d commit c8a006a

1 file changed

Lines changed: 18 additions & 14 deletions

File tree

src/ppo/main.clj

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,20 +1059,24 @@
10591059
(def actor (Actor 3 64 1))
10601060
(py. actor load_state_dict (torch/load "src/ppo/actor.pt"))
10611061

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)))
10761080
(bufimg/tensor->image (dfn/* actions-tensor 255)))
10771081
;; This image shows the motor control input as a function of pendulum angle and angular velocity.
10781082
;; As one can see, the pendulum is decelerated when the speed is high (dark values at the top of the image).

0 commit comments

Comments
 (0)