Concepts / Online Learning

Online Learning

An online learner can be converted into a PAC learner by running it on T independently sampled examples.

  • Programming

A Decision Before the Answer

Imagine a learner that must decide whether a current instance belongs to one class or another before it knows the correct answer. After making the prediction, the learner receives the true label and can use that information to improve later predictions. This timing pattern is the central idea of online learning: prediction and learning are interwoven instead of being separated into two large phases.

Four Events in Every Round

An online learning run consists of consecutive rounds. In round t, the algorithm has a current hypothesis h_t. It receives an instance, uses h_t to make a prediction, observes the correct label, and then uses that label to support future predictions. These four events occur in order: receive the instance, predict, reveal the label, and update the learner's later behavior.

use current hypothesisthen reveallearn from outcomeInstance x_tcurrent examplePredictionh_t(x_t)True labelrevealed after predictionFuture hypothesissupports later predictions
What happens first, next, and last when the learner receives an example, predicts, observes its label, and updates future predictions?
  • The learner receives the current instance.
  • The learner predicts before seeing the correct label.
  • The correct label is revealed.
  • The learner uses the revealed label to support future predictions.

From Test to Training

An example has two roles at different moments of the same round. Before its label is revealed, it tests the learner's current hypothesis because the learner must predict its label without knowing the answer. After the correct label is revealed, that same example can contribute to future learning. This is why online learning repeatedly combines prediction and training within each round.

predict before revealuse label afterwardExample x_tlabel hiddenExample x_ttrue label knownPredictiontest current h_tFuture learningsupports later h
How can the same example test the current hypothesis before its label is known and then train the learner afterward?

Tracing one generated round

Follow a single online round in which the learner receives an instance, predicts, and then receives the correct label.

Receive: The learner receives the current instance x_t while its correct label is not yet available.

Predict: The current hypothesis h_t maps the instance to a prediction, such as 0 or 1.

Reveal: The correct label is supplied only after the prediction has been made.

Learn: The revealed label becomes information that can support predictions in later rounds.

The example first tests h_t and then becomes available for future learning.

Building a PAC Learner from the Run

The online-to-PAC conversion runs the online algorithm on T independently sampled examples. Suppose examples come from a distribution D over an instance domain X, and their labels are supplied by a true hypothesis h⋆ in H. At round t, the online algorithm uses h_t to predict the label of the tth example. After all T rounds, the run has produced the sequence h_1 through h_T. The converted PAC learner chooses a uniformly random member h_r of that sequence as its output.

feed sequentiallyproducechoose random index rT examplesindependently sampledOnline roundspredict, reveal, learnh_1 through h_Thypotheses producedh_runiformly chosen output
How do T independently sampled examples pass through consecutive online rounds to produce a final PAC hypothesis?
  1. Draw T examples independently from D.
  2. Process them in order through the online learner.
  3. Record the current hypothesis h_t associated with each round.
  4. Choose an index r uniformly from the T rounds.
  5. Return h_r as the PAC learner's hypothesis.

Why the Mistake Bound Matters

Assume the online algorithm has a finite mistake bound M_A(H). This bound limits the total number of prediction mistakes the algorithm can make across the online sequence. Because the selected hypothesis h_r comes from that sequence, the total mistakes constrain the average error represented across the hypotheses. The resulting expected risk of the uniformly selected hypothesis is bounded by M_A(H) divided by T.

limitsspreads mistakes acrosscontrolsM_A(H)finite total mistakesT roundsonline examplesSequence mistakeslimited by the boundExpected riskbounded by M_A(H) / T
How does the mistake bound limit errors across T rounds and influence the expected risk of the selected hypothesis?

How T changes the bound

Suppose an online algorithm has a finite mistake bound M_A(H), and it is run for T rounds. What does the conversion guarantee about the selected hypothesis?

Count mistakes: Across the online sequence, the total number of mistakes is limited by M_A(H).

Select a round: Choose one index r uniformly, so every hypothesis h_1 through h_T has the same chance to become the output.

Relate errors to rounds: The expected risk of the selected hypothesis is bounded by the mistake bound divided by the number of rounds.

Increase T: With the mistake bound held fixed, increasing the number of online examples makes the bound M_A(H) / T smaller.

The online learner supplies the numerator through its mistake bound, while the amount of online data supplies the denominator through T.

Choosing a Hypothesis from the Sequence

The converted learner does not invent a separate hypothesis by applying a new selection rule outside the online process. The online run itself creates h_1, h_2, and so on through h_T. A random index r identifies which member is returned. The expected guarantee accounts for both sources of randomness: the independently sampled examples and the random choice of r.

next roundcontinuescontinueschoose index rh_1round 1h_2round 2h_tround th_Tround Th_runiformly selected
Where do the candidate hypotheses come from, and why can selecting one of them yield bounded expected risk?

The selection works because the online mistakes are distributed over the sequence of rounds. If the sequence contains only a bounded total number of mistakes, then choosing a member of the sequence uniformly cannot have an uncontrolled expected risk under the conversion's assumptions. The guarantee is therefore an average expected guarantee over the sampled examples and the random index.

Online and PAC Learning Compared

FeatureOnline learningPAC learning
OrganizationConsecutive rounds that combine prediction and learningA batch training phase followed by prediction on new examples
Current exampleThe learner predicts before receiving its correct labelThe learner first receives training examples before producing the hypothesis used for later evaluation
Hypothesis behaviorThe current hypothesis can change across roundsThe learner produces a hypothesis from the training batch
Conversion connectionProduces h_1 through h_T during the online runCan use a uniformly selected h_r from that run as the output hypothesis
thensupportsproducesused onPredictbefore labelTraining batchlearn firstReveal labelsame roundHypothesisafter trainingSupport futurelearningnext roundsNew examplesevaluate afterward
What changes between the online model's consecutive prediction-and-update rounds and the PAC model's training phase followed by evaluation?

In the source's papaya analogy, PAC learning means tasting a group of papayas before predicting the taste of new papayas. Online learning instead requires a prediction about each current papaya before its correct taste is known; after the answer is obtained, that papaya can help with later predictions.

Common Reasoning Mistakes

  • Treating online learning as a batch training phase followed by a separate prediction phase.

    Online learning interweaves prediction and learning across consecutive rounds.

    Fix: Remember the order within each round: instance, prediction, revealed label, and support for future predictions.

  • Assuming the label is available before the online prediction.

    The defining timing pattern is that the prediction occurs before the correct label is revealed.

    Fix: Treat the current example as a test example first and as a training example afterward.

  • Selecting a hypothesis that was not produced during the online run.

    The described conversion selects a uniformly random h_r from h_1 through h_T.

    Fix: Track the hypotheses created at the rounds and choose one of those members.

  • Ignoring the mistake bound.

    The conversion assumes a finite mistake bound M_A(H), which limits total mistakes.

    Fix: Connect the guarantee to both quantities: the mistake bound M_A(H) and the number of rounds T.

  • Thinking that increasing T changes the algorithm's mistake bound.

    The source describes M_A(H) as the algorithm's contribution and T as the amount of online data in the bound.

    Fix: Keep the roles separate: M_A(H) limits total mistakes, while T determines how those mistakes affect the expected-risk bound.

Check Your Understanding

MEDIUM

Explain the online-to-PAC conversion in your own words. Your explanation should name the source of the T examples, identify the sequence h_1 through h_T, state how h_r is selected, and describe the role of M_A(H) in the expected-risk bound.

Hints
  • Start with the order of events in one online round.
  • Then explain what the complete run produces.
  • Finally connect the finite mistake bound and T to the expected risk.
EASY

A learner receives an example, predicts its label, sees the correct label, and uses that information on later examples. Is this schedule closer to online learning or PAC learning? Explain which event establishes your answer.

Hints
  • Focus on whether prediction happens before or after the label is known.
  • PAC learning separates its batch training phase from later prediction.

Key Takeaways

  1. Online learning is a sequence of rounds in which the learner receives an instance, predicts, observes the correct label, and uses that label for future predictions.
  2. The same example is first a test of the current hypothesis and then a source of training information.
  3. Running an online learner on T independently sampled examples creates hypotheses h_1 through h_T.
  4. The converted PAC learner chooses a uniformly random h_r from that sequence.
  5. A finite mistake bound M_A(H) limits total online mistakes, producing an expected-risk bound of M_A(H) divided by T.

Key Takeaways

  • Online learning combines prediction and learning within consecutive rounds rather than separating them into batch training and later prediction.
  • Each round follows the order: receive an instance, predict, reveal the label, and use the result for future predictions.
  • An online run on T independently sampled examples produces h_1 through h_T, from which a uniformly selected h_r becomes the PAC output.
  • The finite mistake bound M_A(H) limits total online mistakes and gives the selected hypothesis expected risk bounded by M_A(H) / T.
  • The conversion connects the online and PAC views without creating a hypothesis outside the online learner's sequence.