Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New exercises/problems strucutre #3

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# ans/sol'ns temp files
99anssol/

## Core latex/pdflatex auxiliary files:
*.aux
*.lof
Expand Down
89 changes: 89 additions & 0 deletions 02_linear_algebra.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
%!TEX root = all_exercises.tex
\beforeFirstExercises{ch2}

exercises (if any) for each section would go here... see sample in ch3

\afterLastExercises{ch2}


\setcounter{section}{12}
\section{Linear Algebra Problem}

\begin{problems}{ch2}


\begin{problem}
The expression $\alpha \vu$ for $\alpha \in \R$ and
unit vector $\vu \in \R^n$ defines a line of points that may be obtained by varying the
value of $\alpha$.
Derive an expression for the point $\vy$ that lies on this line that is
as close as possible to an arbitrary point $\vx \in \R^n$.
This operation of replacing a point by its nearest member within some set
is called {\em projection}.

{\em Exercise contributed by Ian Goodfellow}

\begin{solution}
We begin by defining the distance from $\vy$ to $\vx$.
We would like to find the $\vy$ that minimizes this distance:
\begin{equation}
|| \vx - \vy||^2.
\end{equation}
Next, we need to enforce the constraint that $\vy$ lies on the line defined by $\alpha \vu$.
We can do this simply by defining $\vy$ to be $\alpha \vu$.
\begin{equation}
|| \vx - \alpha \vu ||^2.
\end{equation}
Next, we expand the expression:
\begin{align}
& || \vx - \alpha \vu ||^2 \\
=& ( \vx - \alpha \vu )^\top (\vx - \alpha \vu) \\
=& \vx^\top \vx - 2 \alpha \vx^\top \vu + \alpha^2 \vu^\top \vu \\
=& \vx^\top \vx - 2 \alpha \vx^\top \vu + \alpha^2.
\end{align}
In the last line,
we used the fact that $\vu$ is a unit vector to make the simplification $\vu^\top \vu = 1$.

We can minimize this distance by taking the derivative with respect to $\alpha$ and setting it to zero:
\begin{align}
& - 2 \vx^\top \vu + 2 \alpha = 0 \\
\Rightarrow & \alpha = \vx\top \vu.
\end{align}

Recalling that $\vy = \alpha \vu$, we can conclude that $\vy = \vx^\top \vu \vu$.

{\em Solution contributed by Ian Goodfellow}
\end{solution}
\end{problem}


\begin{problem}

\begin{hint}
\end{hint}

\begin{answer}\end{answer}

\begin{solution}
\end{solution}
\end{problem}



\begin{problem}

\begin{hint}
\end{hint}

\begin{answer}\end{answer}

\begin{solution}
\end{solution}
\end{problem}




\end{problems}


95 changes: 95 additions & 0 deletions 03_prob_and_info_theory.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
%!TEX root = all_exercises.tex

\beforeFirstExercises{ch3}
\section{Why Probability?}

add exercises here...

\section{Random Variables}

\begin{exercises}{ch3}

\begin{exercise}
EXRCIS QUESTION

\begin{eanswer}EXRCIS ANS\end{eanswer}
\begin{esolution}
EXRCIS SOLUTION.
\end{esolution}
\end{exercise}


\end{exercises}

\section{Probability Distributions}

\begin{exercises}{ch3}

\begin{exercise}
Do the following vectors represent probability distributions?
\begin{exparts*}
\partsitem $\left(\tfrac{1}{2}, \tfrac{1}{2}, \tfrac{1}{2} \right)^T$
\partsitem $\left(\tfrac{1}{4}, \tfrac{1}{4}, \tfrac{1}{4}, \tfrac{1}{4} \right)^T$
\partsitem $\left(0.3, 0.3, -0.1, 0.5 \right)^T$
\end{exparts*}

\begin{eanswer}\begin{ansparts*}
\partsitem No; weights don't add to one.
\partsitem Yes.
\partsitem No; contains a negative number.
\end{ansparts*}\end{eanswer}
\end{exercise}


\end{exercises}






\setcounter{section}{13}
\section{Structured Probabilistic Models}

add exercises here...


\afterLastExercises{ch3}



\setcounter{section}{14}
\section{Probability and Information Theory Problems}

\begin{problems}{ch3}


\begin{problem} \label{problem:geometric_distr_biased_coin_until_heads}
You have a biased coin which lands on \texttt{heads} with probability $p$,
and consequently lands on \texttt{tails} with probability $(1-p)$.
Suppose you want to flip the coin until you get \texttt{heads}.
Define the random variable $N$ as the number of tosses required until the first \texttt{heads} outcome.
What is the probability mass function $P_N(n)$ for success on the $n$\textsuperscript{th} toss?
Confirm that the formula is a valid probability distribution by showing $\sum_{n=1}^\infty P_N(n) = 1$.

\begin{hint}
Find the probabilities for cases $n=1,2,3,\ldots$ and look for a pattern.
\end{hint}

\begin{solution}
The biased coin flip is modelled by a random variable $Y$,
and different coin flips correspond to random variables $Y_1$, $Y_2$, $Y_3$, \ldots which are independent copies of $Y$.
The probability of getting \texttt{heads} on the first flip is $P_N(1)=\textrm{Pr}\!\left( \{ Y_1=\texttt{heads} \} \right)\! =p$.
The probability of getting \texttt{heads} on the second flip corresponds
to the event $\{Y_1=\texttt{tails}\} \ \texttt{AND} \ \{Y_2=\texttt{heads} \}$.
We assumed the coin flips are independent so % the probability of this event is the product
$P_N(2)=(1-p)p$.
Similarly $P_N(3) = (1-p)^2p$.
The general formula is $P_N(n) = (1-p)^{n-1}p$.
\end{solution}
\end{problem}


\end{problems}


Empty file added 99anssol/.keep
Empty file.
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,39 @@
# dlbook_exercises
Exercises for the Deep Learning textbook at www.deeplearningbook.org


Definitions
-----------
- Exercise = easy question with numbering contiguous throughout chapter e.g. E{chapter}.{counter}
- Problem = harder end-of-chapter problem


Exercise formatting
-------------------

- each exercise section starts an `{exercises}{CHNUM}` where CHNUM is some filename (e.g. ch2)
- each exercise envoronment contains
- question text
- one or more {hint} environments
- an {eanswer} environment (optional)
- an {esolution} environment (optional)


Problems formatting
-------------------

- each problems section starts an `{problems}{CHNUM}` where CHNUM is some filename (e.g. ch2)
- each problem environment contains
- question text
- one or more {hint} environments
- an {answer} environment (optional)
- an {solution} environment (optional)



Credits
-------
Ian Goodfellow -- author
Andrew D. Hwang -- tex macros, via http://www.gutenberg.org/ebooks/33283
Jim Hefferon -- tex macros, via http://joshua.smcvt.edu/linearalgebra/
Ivan Savov -- copy paste
101 changes: 101 additions & 0 deletions all_exercises.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
\documentclass[letterpaper,oneside]{book}
\title{Exercises for the Deep Learning Textbook}

\usepackage{bm}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amsthm}


\newif\ifMIT
%\MITtrue % uncomment to use MIT template
\MITfalse
\input{math_commands.tex}


\newif\ifSOLSINTHEBACK
%\SOLSINTHEBACKtrue % uncomment to for final version (include files in 99ans/ in Answers/Sol'ns Appendix)
\SOLSINTHEBACKfalse
\ifSOLSINTHEBACK
\usepackage{answers} % for solutions in the back
\else
\usepackage[nosolutionfiles]{answers} % use when proofreading
\fi
\input{exercises_commands.tex}




\begin{document}
\maketitle


\part{Applied Math and Machine Learning Basics}

\setcounter{chapter}{1}
\chapter{Linear Algebra}
\input{02_linear_algebra.tex}


\chapter{Probability and InformationTheory}
\input{03_prob_and_info_theory.tex}

% continue with other chapters here...




\appendix



\ifSOLSINTHEBACK

\chapter{Answers and solutions}

\section*{Chapter 2 solutions}
\label{sec:chapter2sols}
{ \footnotesize

% \subsection*{Answers to exercises}
% \showExerciseAnswers{ch2}
%
% \subsection*{Solutions to selected exercises}
% \showExerciseSolutions{ch2}

\subsection*{Answers to problems}
\showProblemAnswers{ch2}

\subsection*{Solutions to selected problems}
\showProblemSolutions{ch2}

}


\section*{Chapter 3 solutions}
\label{sec:chapter3sols}
{ \footnotesize

\subsection*{Answers to exercises}
\showExerciseAnswers{ch3}

\subsection*{Solutions to selected exercises}
\showExerciseSolutions{ch3}

\subsection*{Answers to problems}
\showProblemAnswers{ch3}

\subsection*{Solutions to selected problems}
\showProblemSolutions{ch3}

}



\else
% NO SOLUTIONS IN THE BACK (shown inline for proofreading)
\fi



\end{document}
Loading