TT Lab
Blog

한국어 English 日本語 中文

Get started
Blog

Blog

The Framework of Reinforcement Learning: MDP, State, Action, Reward, Discount, Policy, and Value Function Read Through a Table Tennis Arm

Status: Draft (2026-10-18), Measured. Numbers are simulation values calculated directly in Python 3.9.6 and numpy 2.0.2 on a notebook (Apple M1 Max, macOS 26.5). Raw data and code: Working directory measure/robot-arm-basics/rl/'s ttenv.py(environment), baselines.py, thr.py, result out/rl/baselines.json, out/rl/throughput.json. The toy problem is intentionally kept small to demonstrate principles, and there are no actual robot experiments (hardware not measured). The initial ball states are from the DeepMind dataset (CC-BY 4.0). References were accessed on 2026-10-18. Writing rules: Measured data is the default, unmeasurable items are marked as "Not measured", and unverified items are marked as "Unverified".

Table of Contents

1. Intuition: Results Arrive Late

The methods in parts 1 to 10 calculated "what is correct" in advance. Reinforcement learning (RL) does not do that calculation. It tries, observes the outcome, and shifts actions slightly toward the direction that yielded better results. This is identical to how a child learns to throw a ball.

In table tennis, this "result" arrives late. At the exact moment you pull the racket back, you cannot know whether it was a good move; 0.5 seconds later, when the ball lands on the opponent's table, the signal of success finally arrives. In the meantime, the arm has made dozens of decisions. Attributing which decision contributed to the success(credit assignment) is the core difficulty of reinforcement learning, and the discount factor and value function in this post, along with the advantage function in part 12, are mechanisms designed to handle this problem.

Part 10 asked, "What should be left to learning?" Parts 11 to 15 revisit the learning side of that question from first principles. Part 11 establishes the framework, part 12 directly implements PPO, part 13 covers rewards and action spaces, part 14 addresses the transition from simulation to reality, and part 15 covers evaluation methods.

2. Illustration: The Toy Problem of This Series

장난감 문제: 옆에서 본 1자유도 진자 라켓 탁구대 끝 y = −1.37 네트 회전축 준비 φ = −0.5 타격 φ > 0 공(상대가 친 실제 타구) 상태: φ, φ̇, 공 y·z·v_y·v_z(지연·잡음 가능), 시각, 바운스 여부 행동: 10 ms 마다 관절 가속도(직접) 또는 첫 걸음에 타격 파라미터 2개 보상: 상대 탁구대에 넣으면 1(희소) 또는 형태를 준 보상
Figure: 1-DOF pendulum racket and ball from a side view, showing state, action, and reward

To finish learning within a few minutes and run multiple seeds to take the median, the problem must be small. Therefore, it was constructed as follows.

Because it is 1-DOF, the racket angle and racket velocity cannot be chosen independently. The timing of when you hit determines the racket face angle. Consequently, some balls cannot be returned no matter how you hit them, and this limitation is measured as the "upper bound" in section 4.

3. Framework: Markov Decision Process

Reinforcement learning problems are usually formulated as a Markov decision process (MDP). Mapping the five elements to the table tennis arm yields the following.

Element Meaning Toy Problem Actual Table Tennis Robot
State s All information necessary to determine the future φ, φ̇, ball y·z·v_y·v_z, time, bounce status (8 variables) Joint angles and velocities, recent history of ball position and velocity, opponent information
Action a Chosen at every step 1 joint acceleration every 10 ms (direct), or 2 striking parameters (part 13) Joint velocity/torque commands, or choice of hitting technique
Transition P(s′|s, a) Rules determining the next state Physics from parts 6 and 7 (unknown to the learner) Reality
Reward r Numerical value received at each step 1 upon scoring (sparse) or shaped reward (part 13) Defined by the designer
Discount γ How much to reduce future rewards 0.99 Depends on the problem

Markov Property. This is the assumption that "knowing only the current state makes the past unnecessary." If only the ball position is given and velocity is omitted, this assumption breaks down, because even at the same position, it is impossible to know whether the ball is approaching or receding. It also breaks down when there is a delay. If you are looking at the ball from 20 ms ago, you also need to know the commands you sent in the meantime to understand the present. Therefore, real systems include multiple recent observations in the state. The low-level policy in D'Ambrosio et al. 2024 takes the last 8 steps of ball position/velocity and joint states as inputs (arXiv:2408.03906 Section II-C).

Policy and Value. A policy π(a|s) is a rule for choosing actions given a state. The policy in this series is a Gaussian policy where a neural network outputs the mean and samples actions from a normal distribution. The value function is "what the expected discounted sum of future rewards will be if this policy is followed from this state onwards."

되돌림(return):     G_t = r_t + γ r_{t+1} + γ² r_{t+2} + …
상태 가치:          V(s)    = E[ G_t | s_t = s ]
행동 가치:          Q(s, a) = E[ G_t | s_t = s, a_t = a ]
이점(advantage):    A(s, a) = Q(s, a) − V(s)        「평소보다 얼마나 나은 행동이었나」

The advantage is used by PPO in part 12 to determine the direction to modify actions. You must reward **"better results than usual"** rather than just "good results" to distinguish whether the ball was easy or the action was good.

Discount Factor and Horizon. γ scales down future rewards by a factor of γ at each step. One can think that the future is "visible" for approximately 1/(1 − γ) steps ahead.

γ 0.9 0.95 0.99 0.999
Effective horizon 1/(1 − γ) 10 steps (0.1 s) 20 steps 100 steps (1.0 s) 1,000 steps

The episode lengths in the toy problem measured using a random policy had 5th, 50th, and 95th percentiles of 62, 105, and 137 steps (at 10 ms per step). Because the success reward arrives only once at the end of the episode, with γ = 0.9, that reward dwindles to 0.9⁸⁰ ≈ 0.0002 for a swing that started 80 steps prior. Therefore, γ = 0.99 is used. However, a longer horizon increases the variance of the returns, and dealing with this is the GAE of part 12.

4. Measurement: How Far Can We Go Without Learning?

Before starting learning, a baseline is measured. As will be reiterated in part 15, a learning curve without a baseline tells you nothing. These are the results for 1,000 evaluation balls.

Method Success (Returned) Hit Racket
Random policy (uniformly random acceleration at every step) 1.5% 27.4%
Standing still (maintaining ready posture) 0% 9.6%
Best constant action in hybrid action space (same strike parameters for all balls) 45.9% -
Classical planner: Tested 119 grid points with a spin-agnostic model, choosing per ball 40.0% -
Upper bound of hybrid action space: Chose per ball on the grid using true outcomes 85.4% -

4.1 Running Environments in Bulk

Reinforcement learning consumes many samples. A single training run in part 12 uses about 1.4 million environment steps. Therefore, vectorizing multiple environments and running them simultaneously is fundamental. Throughput was measured by running N environments with the same array operations in numpy (excluding other computations, discarding the first of 5 runs, and taking the median).

환경을 한꺼번에 굴리면: 병렬 수와 처리량 1 16 256 4,096 1,000 10,000 100,000 1,000,000 한꺼번에 굴린 환경 수(로그) 환경 걸음/초(로그) 1,103 15,742 82,200 180,870 389,283 numpy 벡터 연산, CPU 코어 하나. 걸음 = 10 ms 제어 한 번(물리 10번).
Figure: Throughput according to the number of concurrently run environments
Number of concurrent environments 1 16 256 1,024 4,096
Environment steps/second (median) 1,103 15,742 82,200 180,870 389,283
Ratio compared to a single environment 1x 14x 75x 164x 353x

When running a single environment, the cost of a single Python step dominates; as arrays grow larger, that cost is distributed across multiple environments. Rudin et al. 2021 pushed the same idea using a GPU physics engine, simulating thousands of robots in parallel and reporting that a flat-terrain walking policy was trained in under 4 minutes on a single workstation GPU (arXiv:2109.11978 abstract). D'Ambrosio et al. 2024 trained a base policy for about 2.4 billion steps using 6,000 parallel simulation workers (Section II-C). This is revisited in part 14.

5. Limitations

6. Conclusion

TT Briefing. You only know if you did well after the ball lands. That's why we set a large discount factor of 0.99, so praise reaches back to the swing made 1 second ago!

References

All materials were accessed on 2026-10-18.

Sign in to like

Comments

No comments yet.

Sign in to leave a comment