summaryrefslogtreecommitdiff
path: root/day1
diff options
context:
space:
mode:
Diffstat (limited to 'day1')
-rw-r--r--day1/session3.tex31
-rw-r--r--day1/session4.tex124
2 files changed, 101 insertions, 54 deletions
diff --git a/day1/session3.tex b/day1/session3.tex
index ae0eea2..69f28d5 100644
--- a/day1/session3.tex
+++ b/day1/session3.tex
@@ -126,6 +126,7 @@
%% % You might wish to add the option [pausesections]
%% \end{frame}
+\section{Statistics}
\begin{frame}
\frametitle{More on data processing}
\begin{block}{}
@@ -178,8 +179,10 @@
\item Pass/Fail (P/F)
\item Withdrawn (W)
\end{itemize}
+ \inctime{5}
\end{frame}
+\subsection{Data processing}
\begin{frame}[fragile]
\frametitle{File reading and parsing \ldots}
\begin{lstlisting}
@@ -188,22 +191,23 @@ for record in open('sslc1.txt'):
\end{lstlisting}
\end{frame}
+\subsection{Dictionary}
\begin{frame}[fragile]
\frametitle{Dictionary: Introduction}
\begin{itemize}
\item lists index: 0 \ldots n
\item dictionaries index using strings
\end{itemize}
-\begin{block}{Example}
+ \begin{block}{Example}
d = \{ ``Hitchhiker's guide'' : 42,
``Terminator'' : ``I'll be back''\}\\
d[``Terminator''] => ``I'll be back''
-\end{block}
+ \end{block}
\end{frame}
\begin{frame}[fragile]
\frametitle{Dictionary: Introduction}
-\begin{lstlisting}
+ \begin{lstlisting}
In [1]: d = {"Hitchhiker's guide" : 42,
"Terminator" : "I'll be back"}
@@ -215,24 +219,24 @@ Out[3]: True
In [4]: "Guido" in d
Out[4]: False
-\end{lstlisting}
+ \end{lstlisting}
\end{frame}
\begin{frame}[fragile]
\frametitle{Dictionary: Introduction}
-\begin{lstlisting}
+ \begin{lstlisting}
In [5]: d.keys()
Out[5]: ['Terminator', "Hitchhiker's
guide"]
In [6]: d.values()
Out[6]: ["I'll be back", 42]
-\end{lstlisting}
+ \end{lstlisting}
\end{frame}
\begin{frame}[fragile]
\frametitle{enumerate: Iterating through list indices}
-\begin{lstlisting}
+ \begin{lstlisting}
In [1]: names = ["Guido","Alex", "Tim"]
In [2]: for i, name in enumerate(names):
@@ -241,15 +245,16 @@ In [2]: for i, name in enumerate(names):
0 Guido
1 Alex
2 Tim
-\end{lstlisting}
+ \end{lstlisting}
+ \inctime{5}
\end{frame}
\begin{frame}[fragile]
\frametitle{Dictionary: Building parsed data}
- Let our dictionary be:
- \begin{lstlisting}
+ Let our dictionary be:
+ \begin{lstlisting}
science = {} # is an empty dictionary
- \end{lstlisting}
+ \end{lstlisting}
\end{frame}
\begin{frame}[fragile]
@@ -291,6 +296,7 @@ if score > 90:
\end{lstlisting}
\end{frame}
+\subsection{Visualizing the data}
\begin{frame}[fragile]
\frametitle{Pie charts}
\small
@@ -308,6 +314,7 @@ savefig('/tmp/science.png')
\includegraphics[height=2in, interpolate=true]{data/science}
\column{0.8\textwidth}
\end{columns}
+ \inctime{5}
\end{frame}
\begin{frame}[fragile]
@@ -381,6 +388,7 @@ savefig('/tmp/all_regions.png')
\includegraphics[height=3in, interpolate=true]{data/all_regions}
\end{frame}
+\subsection{Obtaining stastics}
\begin{frame}[fragile]
\frametitle{Obtaining statistics}
\begin{lstlisting}
@@ -395,6 +403,7 @@ print "Mode: ", stats.mode(math_scores)
print "Standard Deviation: ",
std(math_scores)
\end{lstlisting}
+ \inctime{15}
\end{frame}
\begin{frame}[fragile]
diff --git a/day1/session4.tex b/day1/session4.tex
index f6351a6..1a38a2d 100644
--- a/day1/session4.tex
+++ b/day1/session4.tex
@@ -136,14 +136,16 @@ let us now look at matrices in a little more detail.
\begin{frame}[fragile]
\frametitle{Matrices: Initializing}
\begin{lstlisting}
-In []: A = ([[5, 2, 4],
- [-3, 6, 2],
- [3, -3, 1]])
-
+In []: A = matrix([[ 1, 1, 2, -1],
+ [ 2, 5, -1, -9],
+ [ 2, 1, -1, 3],
+ [ 1, -3, 2, 7]])
In []: A
-Out[]: [[5, 2, 4],
- [-3, 6, 2],
- [3, -3, 1]]
+Out[]:
+matrix([[ 1, 1, 2, -1],
+ [ 2, 5, -1, -9],
+ [ 2, 1, -1, 3],
+ [ 1, -3, 2, 7]])
\end{lstlisting}
\end{frame}
@@ -153,10 +155,11 @@ Out[]: [[5, 2, 4],
\frametitle{Transpose of a Matrix}
\begin{lstlisting}
In []: linalg.transpose(A)
-Out[]:
-matrix([[ 5, -3, 3],
- [ 2, 6, -3],
- [ 4, 2, 1]])
+Out[]:
+matrix([[ 1, 2, 2, 1],
+ [ 1, 5, 1, -3],
+ [ 2, -1, -1, 2],
+ [-1, -9, 3, 7]])
\end{lstlisting}
\end{frame}
@@ -164,22 +167,23 @@ matrix([[ 5, -3, 3],
\frametitle{Sum of all elements}
\begin{lstlisting}
In []: linalg.sum(A)
-Out[]: 17
+Out[]: 12
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]
\frametitle{Matrix Addition}
\begin{lstlisting}
-In []: B = matrix([[3,2,-1],
- [2,-2,4],
- [-1, 0.5, -1]])
-
-In []: linalg.add(A, B)
+In []: B = matrix([[3,2,-1,5],
+ [2,-2,4,9],
+ [-1,0.5,-1,-7],
+ [9,-5,7,3]])
+In []: linalg.add(A,B)
Out[]:
-matrix([[ 8. , 4. , 3. ],
- [-1. , 4. , 6. ],
- [ 2. , -2.5, 0. ]])
+matrix([[ 4. , 3. , 1. , 4. ],
+ [ 4. , 3. , 3. , 0. ],
+ [ 1. , 1.5, -2. , -4. ],
+ [ 10. , -8. , 9. , 10. ]])
\end{lstlisting}
\end{frame}
@@ -188,9 +192,10 @@ matrix([[ 8. , 4. , 3. ],
\begin{lstlisting}
In []: linalg.multiply(A, B)
Out[]:
-matrix([[ 15. , 4. , -4. ],
- [ -6. , -12. , 8. ],
- [ -3. , -1.5, -1. ]])
+matrix([[ 3. , 2. , -2. , -5. ],
+ [ 4. , -10. , -4. , -81. ],
+ [ -2. , 0.5, 1. , -21. ],
+ [ 9. , 15. , 14. , 21. ]])
\end{lstlisting}
\end{frame}
@@ -200,9 +205,10 @@ matrix([[ 15. , 4. , -4. ],
\begin{lstlisting}
In []: linalg.inv(A)
Out[]:
-array([[ 0.28571429, -0.33333333, -0.47619048],
- [ 0.21428571, -0.16666667, -0.52380952],
- [-0.21428571, 0.5 , 0.85714286]])
+matrix([[-0.5 , 0.55, -0.15, 0.7 ],
+ [ 0.75, -0.5 , 0.5 , -0.75],
+ [ 0.5 , -0.15, -0.05, -0.1 ],
+ [ 0.25, -0.25, 0.25, -0.25]])
\end{lstlisting}
\end{small}
\end{frame}
@@ -211,7 +217,7 @@ array([[ 0.28571429, -0.33333333, -0.47619048],
\frametitle{Determinant}
\begin{lstlisting}
In []: det(A)
-Out[]: 42.0
+Out[66]: 80.0
\end{lstlisting}
\end{frame}
@@ -221,10 +227,11 @@ Out[]: 42.0
\begin{lstlisting}
In []: linalg.eig(A)
Out[]:
-(array([ 7., 2., 3.]),
- matrix([[-0.57735027, 0.42640143, 0.37139068],
- [ 0.57735027, 0.63960215, 0.74278135],
- [-0.57735027, -0.63960215, -0.55708601]]))
+(array([ 11.41026155, 3.71581643, -0.81723144, -2.30884654]),
+ matrix([[ 0.12300187, -0.53899627, 0.63269982, 0.56024583],
+ [ 0.8225266 , -0.67562403, -0.63919634, -0.20747251],
+ [-0.04763219, -0.47575453, -0.3709497 , -0.80066041],
+ [-0.55321941, -0.16331814, -0.23133374, 0.04497415]]))
\end{lstlisting}
\end{small}
\end{frame}
@@ -232,8 +239,8 @@ Out[]:
\begin{frame}[fragile]
\frametitle{Computing Norms}
\begin{lstlisting}
- In []: linalg.norm(A)
- Out[]: 10.63014581273465
+In []: linalg.norm(A)
+Out[]: 14.0
\end{lstlisting}
\end{frame}
@@ -243,14 +250,16 @@ Out[]:
\begin{lstlisting}
In []: linalg.svd(A)
Out[]:
-(matrix([[-0.13391246, -0.94558684, -0.29653495],
- [ 0.84641267, -0.26476432, 0.46204486],
- [-0.51541542, -0.18911737, 0.83581192]]),
- array([ 7.96445022, 7. , 0.75334767]),
- matrix([[-0.59703387, 0.79815896, 0.08057807],
- [-0.64299905, -0.41605821, -0.64299905],
- [-0.47969029, -0.43570384, 0.7616163 ]]))
- \end{lstlisting}
+(matrix([[-0.08588113, 0.29164297, -0.74892678, 0.58879325],
+ [-0.79093255, 0.39530483, -0.11188116, -0.45347812],
+ [ 0.1523891 , 0.78799358, 0.51966138, 0.29290907],
+ [ 0.58636823, 0.37113957, -0.39565558, -0.60156827]]),
+ array([ 13.17656506, 3.76954116, 2.79959047, 0.57531379]),
+ matrix([[-0.05893795, -0.42858358, 0.12442679, 0.89295039],
+ [ 0.80364672, 0.51537891, 0.03774111, 0.29514767],
+ [-0.11752501, 0.14226922, -0.96333552, 0.19476145],
+ [-0.58040171, 0.72832696, 0.23468759, 0.27855956]]))
+\end{lstlisting}
\end{small}
\end{frame}
@@ -282,8 +291,6 @@ Let us now look at how to solve this using \kwrd{matrices}
In []: b = matrix([[1], [-2], [0]])
In []: x = linalg.solve(A, b)
In []: Ax = dot(A, x)
- In []: allclose(Ax, b)
- Out[]: True
\end{lstlisting}
\end{frame}
@@ -295,13 +302,44 @@ Out[]:
array([[ 1.],
[-2.],
[-2.]])
+\end{lstlisting}
+\end{frame}
+\begin{frame}[fragile]
+\frametitle{Let's check!}
+\begin{lstlisting}
In []: Ax
Out[]:
matrix([[ 1.00000000e+00],
[ -2.00000000e+00],
[ 2.22044605e-16]])
\end{lstlisting}
+\begin{block}{}
+The last term in the matrix is actually \alert{0}!\\
+We can use \kwrd{allclose()} to check.
+\end{block}
+\begin{lstlisting}
+In []: allclose(Ax, b)
+Out[]: True
+\end{lstlisting}
+\end{frame}
+
+\subsection{Exercises}
+
+\begin{frame}[fragile]
+\frametitle{Problem}
+
+\end{frame}
+
+\begin{frame}[fragile]
+\frametitle{Problem}
+Solve the set of equations:
+\begin{align*}
+ x + y + 2z -w & = 3\\
+ 2x + 5y - z - 9w & = -3\\
+ 2x + y -z + 3w & = -11 \\
+ x - 3y + 2z + 7w & = -5\\
+\end{align*}
\end{frame}
\section{Summary}