> For the complete documentation index, see [llms.txt](https://zedive.gitbook.io/project-l/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://zedive.gitbook.io/project-l/part-3/advanced_topics/machine_learning/learning-theory/pac_examples.md).

# PAC Examples

Hopefully these examples can clear up some confusions after reading these formal definitions. Pay attention not just to the algorithm itself but more importantly to the proof that states why it is PAC.

## Positive Half-lines

The domain $$X = \mathbb{R}$$, $$C = H = {positive;half; lines}$$. // C = H why? by the def of this problem hypothesis is the mapping A positive half line is a threshold (a real number) such that all pts to the left are labeled - and all pts to the right are labels +.

## Learning Algorithm

Sort the training data in ascending order Find greatest - labeled pt and smallest + labeled pt Set the threshold anywhere in this interval

## Prove PAC

![](https://3556266963-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LtpqP4Bii7DT_BTd4fN%2F-LtpqQ7GPCPppH_fyCKt%2F-LtpqayaTW-f22ognGQI%2FScreen%20Shot%202016-11-28%20at%2012.05.55%20AM.png?generation=1573935286881358\&alt=media)

The generalization error of h will be the region b/w h and c. Points in this region is labeled differently by the concept and the hypothesis. We need to show the generalization error is low with high probability. Equivalently (for the convenience of computation?), we need to show $$Pr\[err\_D(h) > \epsilon] \leq \delta$$.

Two cases for $$err\_D(h) > \epsilon$$: 1. $$B\_+$$ $$h$$ is more than $$\epsilon$$ away from $$c$$ (to the right) 2. $$B\_-$$ $$h$$ is more than $$\epsilon$$ away from $$c$$ (to the left)

$$R\_+$$ as the interval $$\[c, r\_+]$$ where $$r\_+$$ is a pt to the right of c such that Pr$$\[c, r\_+]$$ is $$\epsilon$$. Now we want to find $$Pr(B\_+)$$. $$B\_+$$ only occurs when $$h$$ is to the right of $$r\_+$$. This only happens when all $$x\_i \notin R\_+$$. (i.e. not training data in that interval so the algorithm cannot learn a threshold exists in that interval.)

Since $$P(R\_+) = \epsilon$$, $$Pr\[x\_i \notin R\_+] \leq 1 - \epsilon$$. Then

$$
Pr\[B\_+] = Pr\[x\_1 \notin R\_+ \land x\_2 \notin R\_+ \land ... \land x\_m \notin R\_+] \leq (1 - \epsilon)^m
$$

$$x\_i$$ are all random and independent.

By symmetry, $$Pr\[B\_-] \leq (1 - \epsilon)^m$$.

Now we can bound $$\begin{aligned} Pr\[err\_D > \epsilon] & \leq Pr\[B\_+ \lor B\_-] \ & \leq Pr\[B\_+] + Pr\[B\_-]\quad (union bound) \ & \leq 2(1 - \epsilon)^m \ & \leq 2\mathrm{e}^{-\epsilon m} \quad\quad\quad (1 - x \leq \mathrm{e}^{-x}) \end{aligned}$$

So we want to set it less than delta, $$Pr\[err\_D > \epsilon] \leq 2\mathrm{e}^{-\epsilon m} \leq \delta$$. Take ln on both sides and solve for m, we get $$m \geq \frac{1}{\epsilon} \ln(\frac{2}{\delta})$$. This shows $$C$$ is PAC-learnable (because as m gets larger $$\epsilon$$ and $$\delta$$ are getting smaller). $$QED$$

## Review

* We want to bound Pr\[err\_D > epsilon] first.
* Identify the error region then union bound&#x20;
* Set the bound less than delta
* Solve for m (m should bound epsilon and delta).

## Positive Intervals

Again, the domain $$X = \mathbb{R}$$. The concept class is also the hypothesis space $$C = H$$. Each $$c \in C$$ specifies an interval that will be labeled +. All pts outside of the interval will be labeled -.

## Learning Algorithm

Pick a consistent $$h \in H$$.

## Prove PAC

Again, we want to prove $$C$$ is PAC-learnable by $$H$$. In order to bound $$Pr\[err\_D > \epsilon]$$, we need to break down all cases where $$err\_D > \epsilon$$.

Let $$c\_l$$ be the left boundary of c and $$c\_r$$ be the right boundary of c. Define: 1. $$L\_-$$ h is more than $$\frac{\epsilon}{2}$$ away from $$c\_l$$ (to the left) 2. $$L\_+$$ h is more than $$\frac{\epsilon}{2}$$ away from $$c\_l$$ (to the right) 3. $$R\_-$$ h is more than $$\frac{\epsilon}{2}$$ away from $$c\_r$$ (to the left) 4. $$R\_+$$ h is more than $$\frac{\epsilon}{2}$$ away from $$c\_r$$ (to the right)

There are 2 x 2 = 4 combinations: $${L\_-, R\_-}$$, $${L\_-, R\_+}$$, $${L\_+, R\_-}$$, $${L\_+, R\_+}$$

We want to have this bound, $$Pr\[err\_D > \epsilon] \leq Pr\[L\_-, R\_- \lor L\_-, R\_+ \lor L\_+, R\_- \lor L\_+, R\_+]$$ $$\leq Pr\[L\_-, R\_-] + Pr\[L\_-, R\_+] + Pr\[L\_+, R\_-] + Pr\[L\_+, R\_+]$$ (Union Bound) $$\leq 4(1 - \frac{\epsilon}{2})^m$$ $$\leq 4(\mathbb{e}^{-\frac{\epsilon}{2}})^m = 4\mathbb{e}^{-\frac{\epsilon m}{2}}$$ (again $$1 - x \leq \mathrm{e}^{-x}$$)

We good. Now set it less than $$\delta$$ and solve for m Take ln then solve we get $$m \geq \frac{2}{\epsilon} \ln(\frac{4}{\delta})$$. $$QED$$

## Learning Axis-aligned Rectangles

![](https://3556266963-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LtpqP4Bii7DT_BTd4fN%2F-LtpqQ7GPCPppH_fyCKt%2F-Ltpqayt5DqZjvS8W0Hf%2FScreen%20Shot%202016-11-29%20at%2011.18.19%20AM.png?generation=1573935286921396\&alt=media)

## Learning Algorithm

c is the target concept. The algorithm finds h which is the *smallest* consistent rectangle.

## Prove PAC

Figure out the cases where $$err\_D > \epsilon$$. Since h is the smallest rectangle, we grow each edge outward by probability mass $$\frac{\epsilon}{4}$$. Why it has to be inside c? Cause every pt inside h is labeled + and every pt outside h is labeled -. Outside of c is -, not an error. So we have to identify the error region first. In this problem, err = c - h.

$$\begin{aligned} Pr\[err\_D > \epsilon] & \leq Pr\[B\_1 \lor B\_2 \lor B\_3 \lor B\_4] \ & \leq Pr\[B\_1] + Pr\[B\_2] + Pr\[B\_3] + Pr\[B\_4] \quad (union ; bound) \ & \leq 4(1 - \frac{\epsilon}{4})^m \ & \leq 4\mathrm{e}^{-\frac{\epsilon m}{4}} \quad\quad\quad (1 - x \leq \mathrm{e}^{-x}) \end{aligned}$$

Solve for m.

Ending note: The proofs above are all tailored to each problem. There is a more general theorem for proving PAC.
