AI Hero Club

Reasoning and Reinforcement Learning · Lesson 3

Marked Complete by You0 / 8

Saved in this browser only. Marking a lesson complete does not mean the project has passed verification.

Lesson Outline 9 subsections
Course Contents 8 lessons
Full course plan.
Reasoning and Reinforcement Learning / Learning Plan ↗

LESSON 03 / 8Suggested study 135 minutes

Within-group Comparisons and Valid Advantage Estimates

Why can subtracting a group’s mean reward change the expected gradient, and when is a leave-one-out baseline unbiased?

3 Questions for This Lesson
  • Impartial conditions for demonstrating an independent baseline and retaining a baseline
  • Accurates a change in the zoom bias and standard deviation with its own group average
  • Explanatory lapses in zero groups, associated sampling and different task difficulties
Course Project ZIP ↓

The Baseline as an Expectation Identity

Chapter II is estimated by the gradient of the incentive score, but the difference may be large. This chapter gives returns less baselines; the baseline is not real values, but reference numbers. b(x)b(x) Without relying on the current trajectories, it multiplys the baseline by zero, minus the expected gradient. The baseline is neutral even if the values are wrong; it affects the variance rather than the constant equation. Baselines are allowed to be estimated by other independent samples, provided that they are independent of the current sample after giving X and stop the gradient when calculating score losses.

The extreme example is that the baseline is equal to the current reward, with all advantages zero and the gradient always zero; it is clearly no longer equal to the general non-zero target gradient. Another common confusion is that “No prejudice.” should be understood as being in a better direction for each batch of updates. The average value of repeats samples when describing fixed parameters without bias may still be poor estimates for one batch; the parameter trajectory is not an unbiased copy of the exact gradient trajectory after changes in non-linear optimizers, tailoring and subsequent parameters.

E[(R−b(x))s∣x]=E[Rs∣x]−b(x)E[s∣x]=∇J(x)\mathbb E[(R-b(x))s\mid x]=\mathbb E[Rs\mid x]-b(x)\mathbb E[s\mid x]=\nabla J(x)
The baseline is independent of the current trajectory and score conditions are equal to zero.

Example 1: A Minimal Two-Action Control Variate

Makes the correct action half probability, rewards one, rewards zero. For the correct action logit score, half correct and half negative. Without baseline, the estimater takes half probability, half zero probability, average value E [G] = 1/2 × 1/2+1/2 × 0=1/4;second order E [G²] = 1/2 ×( 1/2) ²= 1/8 is defined as: Var(G) = E [(G−E[G] )²]= E [G²] − E [G] Two, so here's the... 1/8−(1/4) ²= 1/16. After reducing the constant baseline by half, when correct (1−1/2)(1/2)=1/4(1-1/2)(1/2)=1/4, when error (0−1/2)(−1/2)=1/4(0-1/2)(-1/2)=1/4, the variance is zero and the average is unchanged.

This example does not allow for the introduction of a baseline to expect the reward to always make all parameters the lowest gradient difference. Var(G) = E [G²] − E [G] The mean square in 2 is not related to b, so the minimum difference equals the minimum second order rule. E[(R−b)2s2]E[(R-b)^2s^2] , cross-referenced to b to guide b∗=E[Rs2]/E[s2]b^*=E[Rs^2]/E[s^2], the pre-determining denominator is positive and the rectangular is present. The vector score, if the target is the sum of the coordinates, also spreads squarely to obtain b*= E [R‖s‖²] / E [‖s‖²]; this does not guarantee that each of the coordinates is best. Only score square weights and incentives satisfy the appropriate relationship is equal to the average average reward. This project uses an interpretable set of averages and does not claim to be the best control variable for the difference in the gradient of the entire neural network.

Why Including the Sample in Its Group Mean Shrinks the Estimate

The same input independently draws a G trajectory, so that Article I is rewarded as RiR_i, score sis_i, the group mean value is the sum of all rewards and divided by G. Use Ri−RˉR_i-\bar R As an advantage, the baseline contains its own rewards and is therefore not independent. Roll out expectations: the 1/G item contributing to the original gradient of its own, and the other G−1 entry multiplys zero for independence. Less each expectation is the original gradient. 1−1/G1-1/G, the average number of groups is still this scale.

The conclusions are for estimates of standard deviations, separate distribution with input, fixed parameter sampling, and the same weight for each. G To reduce it to seven-eighths at 8 o'clock. 7/8 The positive constant scaling can sometimes adjust the absorption of learning rates, but it cannot be called a strict and unbiased estimate of the original target. If the Task Force is not small, different input will be scaled differently, and even the task weights will change, and it is no longer a simple global learning rate that can be modified.

E ⁣[1G∑i(Ri−Rˉ)si]=(1−1/G)∇J,AiLOO=Ri−∑j≠iRjG−1\mathbb E\!\left[\frac1G\sum_i(R_i-\bar R)s_i\right]=(1-1/G)\nabla J,\quad A_i^{\mathrm{LOO}}=R_i-\frac{\sum_{j\ne i}R_j}{G-1}
Fixed input, IID sampling, precise relationships when not excluding random standard deviations.

Leave-One-Out Group Means Restore Independence

Definition of a baseline remaining in Article i as other G−1 An average of the given input and the current parameter. Independent sampling guarantees the independence of the other tracks from article i, so the baseline is set by article i score to zero. For each article, it is averaged and the target gradient is estimated without bias. It is also equal to its own average advantage by G divided. G−1, so the code can be calculated efficiently at a time with its own aggregate reduction, without really recycling the G-list.

Project run. py 's loo_advantages group flat batches to reshape, requiring G at least two and total elements to be removed from G. It seeks each group first and the current value is reduced to G−1. All task groups must be placed continuously; if the different task samples are disrupted first, they are still in eight groups, which may occasionally constitute an independent baseline, but no longer the agreed input control variable, differences in difficulty will increase the variance and interpretations may not be consistent with the instructions. Sample numbers and input records are more useful than keeping only one average reward.

Example 2: Computing Advantages for Four Trajectories

Grouping rewards [1,0,0,0]. The average value of the group is 0 25, with its own advantages [0.75,-0.25,-0.25,-0.25]; leaving a baseline for [0,1/3,1/3,1/3], with its own advantages [1,-1/3,-1/3,-1/3], which is the same for 4/3. Both sets of advantages are zero, but “Advantages and Zeros” cannot prove the expected gradient itself, because it has to multiply the respective score. Zero and only describe the algebraic nature of the group 's centralization.

If the reward is converted to [0,0,0,0] or [1,1,1,1], the two central advantages are zero. They do not have relative information in the group and they do not equal to the entire strategic gradient: other groups that may be drawn can still contribute to non-zero. The project actually includes the probability of sampling logarithms in return for punishment, so the rewards are the same but with different probabilities, and there may still be signals in the positive parts; the training start strategy is fully consistent with the reference, with zero penalties, and without success, the first batch may indeed not be updated at all.

Standard-Deviation Normalization Is Not a Free Operation

Some of the relative methods of centralizing the incentives by removing the standard deviations from the group plus the small constant. The standard deviation is the current whole random variable, dependent on the current trajectory and associated with score, so that the previous independent baseline evidence cannot be directly applied. Even without its own baseline, a random denominator cannot be expected to be a constant. This may control the scale, but optimizing the weighting of objects and tasks changes; it must be studied as a different estimate, rather than using “Values are more stable” as proof of maintaining the original goal.

For example, both sets of the same input have only one success, but a set of incentive margins has been artificially scaled tenfold. The gradient is also magnified tenfold without a standard deviation; the standard deviations are almost offset by one. This is not necessarily correct, but they have different meanings for the reward scale. The GRPO proposed by DeepSeekMath also involves old tactics, cropping, KL, and specific advantage definitions, and this course uses its group comparative perspective alone, and the real project achieves a single REINFORCE without a full GRPO recovery name.

How Independence Assumptions in Sampling Can Fail

If the same group of beam searches obtains several powerful and relevant paths, or if they are copied eight times after a single trajectories have been drawn, other tracks are no longer independent and a baseline is left with current action information. Each reward is identical in the case of replication, with zero centralization, regardless of whether the true gradient is not zero. The conditions are also recalculated and cannot be demonstrated separately.

Fixed random seeds allow the experiment to be repeated, not the same random numbers to be repeated for all members. Torch. Generator controls successive random streams, and multiminormial produces separate samples of each row in the batch. Tests with the same initial seed should be reruned by the same track that allows drifting; not every member in the training will reset the same seed to produce a fully relevant sample.

BUILD THE MECHANISM

Keep a baseline with an exact enumeration.

Achieves three group score estimates with no baseline, own mean value and LOO. Downloads the full course items and runs them in the project root directory; edits only learner/starter.py, which already provides a tectonic framework.

Input and Output G > = 2; LOO baseline excludes the current reward; group output is subject to G.
The score is considered to be a given gradient vector and this function does not reverse the baseline to policy.

Run in the Project DirectoryStudy tasks to be completed
# estimate
def estimate(rewards,scores,mode='loo'):
    raise NotImplementedError('loo')
Hint 1

Write to G=2 four sequenced action groups, without a large sample approximation.

Hint 2

Baseline i = (total reward−ri)/(G−1)).

Hint 3

Each group multiplys its combined probability; the mean value should be reduced (G−1)/G).

Independent inspection .venv/bin/python -m learner.check --stage loo --output runs/learner-loo.json

Migration test Change p=.3, G=3 to compare the exact gradients in the list and in the first writing; copying the same member no longer meets the premise of independence without bias.

Reference Implementation and Explanation
Run in the Project DirectoryReference achieved
# estimate
def estimate(rewards,scores,mode='loo'):
 n=len(rewards)
 if n<2 or len(scores)!=n:raise ValueError('at least two paired samples')
 if mode not in ['none','self','loo']:raise ValueError('unknown baseline')
 total=sum(rewards);out=[0.]*len(scores[0])
 for i,(reward,score)in enumerate(zip(rewards,scores)):
  baseline=0 if mode=='none'else total/n if mode=='self'else (total-reward)/(n-1)
  for j,s in enumerate(score):out[j]+=(reward-baseline)*s/n
 return out

This Lesson's Deliverable: Enumerable Evidence of Deviation

Stdlib Lab.py lists all the lists of three action strategies and G equals two, three, and four, totalling nine, twenty-seven, and eighty-one groups, respectively. Each set of probability is a multiplier of action probabilities, adding each advantage to the average of score; leaving one estimate by coordinates is equal to the solvency gradient, with its own mean value equal to its fixed scaling. This is not a beautiful conclusion from a large number of Monte Carlo samples, but rather an exact weighting of limited space, influenced only by a floating point slippage error.

Readers should also take the initiative to remove the condition of independence: if a group is forced to copy, there will be a zero gradient. If a G is removed, leaving a zero denominator, the code must reject instead of adding a small psilon. For a zero reward, the correct action is to keep zero information rather than to surreptitiously replace a false success. The next chapter will add the reference strategy to the reward, maintaining all sampling, independence and stop gradient conditions in this chapter in order to induce mathematics to real training.

Run in the Project DirectoryDirectly Run Check
from lab import finite, group_expectation
z=[.3,-.2,.1];g=4
t=group_expectation(z,g);truth=finite(z)["gradient"]
assert max(abs(a-b) for a,b in zip(t["leave_one_out_gradient"],truth)) < 1e-12
print(t)

TRY IT YOURSELF

Practice I: One baseline for three awards

Incentive [1,1,0], calculates the advantage with its own mean advantage.

Hint 1
An average of the whole group is calculated, and then the other members are excluded from the average value on their own.
Hint 2
The two vectors of advantage are written separately and the ratio is compared; the advantages and zero are not checked equally with the expectations for the sample.
Compare with the Solution
Average 2/3, with its own advantages [1/3,1/3,−2/3]. The other incentives in Articles 1 and 2 are the same for Article 3 1/2, so the advantage [1/2,1/2,−1] is the former multiplied by 3/2. Zero is not an impartial certificate; it is the result of the independence of the other samples after the given input.

TRY IT YOURSELF

Practice II: Relevant sampling reverses

What happens when you take one and then you copy eight?

Hint 1
Are the other members of the copied sample also independent of the current sample? First, compare all the awards.
Hint 2
Each item excludes its own average, and questions whether the resulting gradient matches the normal non-zero true gradient and the independent premise for positioning it.
Compare with the Solution
All incentives are the same, with a flat value equal to its own reward and a zero advantage. Real strategy gradients are usually not zero, so they are estimated to be biased. The problem is not that G is not big enough, but that other members are fully relevant to the current sample and the independent baseline proves to be ineffective.

TRY IT YOURSELF

Practice III: Minimum margin baseline

Minimum E [(R−b)^2 s^2] for score s, decomposition constantb.

Hint 1
The target is rolled out into a secondary version of b, s2 being the weight.
Hint 2
Rs and ss do not change when b is guided; check E [s²] for positive and zero, without directly guessing the mean reward.
Compare with the Solution
Guidance for b by -2E [(R−b)s²] = 0 If E [s²] > 0, b=E [Rs²] / E [s²] 2E;second degree guide [s²] >0 guarantees only very small. [s²] = 0, score is almost zero everywhere, all b is the same. This weight does not normally equal E. [R] 。

CHECK YOUR UNDERSTANDING

Check Your Understanding

Answer first, then open the explanation to check your reasoning. These questions help reveal gaps in understanding; independent implementation and transfer require separate evaluation.

What is the average value of the 1. G=8 containing itself estimated to be scaled up under this chapter?

Show ExplanationYour own reward goes to the baseline, minus 1/G of the original gradient.
2. What do you need to keep a baseline?

Show ExplanationThe given input and the current parameters allow other members to be independent in order to deflate the baseline by score ' s expectations.
3. Can you directly follow the neutral proof after using the current random standard deviation?

Show ExplanationThe random denominator relies on the current sample and is not a constant to produce expectations.
4. How should the zero reward group be dealt with?

Show ExplanationZero information is already part of the problem of dilution.

Manual completion records your progress; it does not certify your project.