Commit 6b974123 authored by vincentvigon's avatar vincentvigon

3 premier chap de 'alea'

parent a005fb67
Pipeline #2564 failed with stage
in 2 minutes and 59 seconds
......@@ -3,4 +3,4 @@
**/__pycache__
**/.ipynb_checkpoints/
**/.DS_Store
**/build
\ No newline at end of file
......@@ -5,8 +5,10 @@
<inspection_tool class="PyCompatibilityInspection" enabled="true" level="WARNING" enabled_by_default="true">
<option name="ourVersions">
<value>
<list size="1">
<list size="3">
<item index="0" class="java.lang.String" itemvalue="3.5" />
<item index="1" class="java.lang.String" itemvalue="3.6" />
<item index="2" class="java.lang.String" itemvalue="3.7" />
</list>
</value>
</option>
......
......@@ -4,4 +4,7 @@
<option name="languageLevel" value="ES6" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.6" project-jdk-type="Python SDK" />
<component name="PythonCompatibilityInspectionAdvertiser">
<option name="version" value="3" />
</component>
</project>
\ No newline at end of file
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
......@@ -19,302 +19,6 @@
"np.set_printoptions(precision=3,suppress=True)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Préliminaires d'algèbre linéaire\n",
"\n",
"Attention, en numpy les vecteurs, les matrices lignes et les matrices colonnes sont des objets différents:\n",
"\n",
"* vecteur.shape = (?)\n",
"* matrice_ligne.shape = (1,?)\n",
"* matrice_colonne.shape = (?,1)\n",
"* matrice_quelconque.shape = (?,?)\n",
"\n",
"Observez bien les sorties consoles: les vecteurs s'écrivent avec 1 crochet, les matrices avec 2 crochets.\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Multiplication matricielle\n",
"\n",
"`np.matmul()` s'applique uniquement entre matrices."
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"mat_col\n",
" [[1.]\n",
" [1.]\n",
" [1.]]\n",
"\n",
"mat_lin\n",
" [[1. 1. 1.]]\n",
"\n",
"mat_square\n",
" [[1. 1. 1.]\n",
" [1. 1. 1.]\n",
" [1. 1. 1.]]\n",
"\n",
"mat_square × mat_col\n",
" [[3.]\n",
" [3.]\n",
" [3.]]\n",
"\n",
"mat_lin × mat_square\n",
" [[3. 3. 3.]]\n",
"\n",
"mat_lin × mat_square × mat_col\n",
" [[9.]]\n"
]
}
],
"source": [
"size=3\n",
"mat_col=np.ones(shape=[size,1])\n",
"mat_lin=np.ones(shape=[1,size])\n",
"mat_square=np.ones(shape=[size,size])\n",
"\n",
"print(\"\\nmat_col\\n\",mat_col)\n",
"print(\"\\nmat_lin\\n\",mat_lin)\n",
"print(\"\\nmat_square\\n\",mat_square)\n",
"\n",
"print(\"\\nmat_square × mat_col\\n\",np.matmul(mat_square,mat_col) )\n",
"print(\"\\nmat_lin × mat_square\\n\",np.matmul(mat_lin,mat_square))\n",
"print(\"\\nmat_lin × mat_square × mat_col\\n\", np.matmul(np.matmul(mat_lin,mat_square),mat_col))\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"sinon on peut utiliser `np.dot()` qui permet les multiplications matrice × vecteur, matrice × matrice, vecteur × vecteur (=produit scalaire)"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"vec0 × vec1\n",
" 6.0\n",
"\n",
"vec0 × mat_square\n",
" [3. 3. 3.]\n",
"\n",
"mat_square × vec0\n",
" [3. 3. 3.]\n",
"\n",
"mat_square × mat_square\n",
" [[3. 3. 3.]\n",
" [3. 3. 3.]\n",
" [3. 3. 3.]]\n"
]
}
],
"source": [
"size=3\n",
"vec0=np.ones(shape=[size])\n",
"vec1=2*np.ones(shape=[size])\n",
"mat_square=np.ones(shape=[size,size])\n",
"\n",
"print(\"\\nvec0 × vec1\\n\",np.dot(vec0,vec1))\n",
"print(\"\\nvec0 × mat_square\\n\",np.dot(vec0,mat_square))\n",
"print(\"\\nmat_square × vec0\\n\",np.dot(mat_square,vec0))\n",
"print(\"\\nmat_square × mat_square\\n\",np.dot(mat_square,mat_square))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"et si vous avez python 3.5+, vous pouver utilisez l'opérateur @ qui rend les codes plus lisibles"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"vec0 × vec1\n",
" 6.0\n",
"\n",
"vec0 × mat_square\n",
" [3. 3. 3.]\n",
"\n",
"mat_square × vec0\n",
" [3. 3. 3.]\n",
"\n",
"mat_square × mat_square\n",
" [[3. 3. 3.]\n",
" [3. 3. 3.]\n",
" [3. 3. 3.]]\n"
]
}
],
"source": [
"print(\"\\nvec0 × vec1\\n\",vec0 @ vec1)\n",
"print(\"\\nvec0 × mat_square\\n\",vec0 @ mat_square)\n",
"print(\"\\nmat_square × vec0\\n\",mat_square @ vec0)\n",
"print(\"\\nmat_square × mat_square\\n\",mat_square @ mat_square)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"***Exo:*** Multipliez matriciellement des matrices de taille non-compatible.\n",
"Extrayez la partie intéressante du message d'erreur."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### inverse et transposée \n",
"\n",
"Notez que le pseudo-inverse permet d'inverser les matrices non-inversibles (testez). "
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"mat\n",
" [[1. 0. 2.]\n",
" [0. 1. 0.]\n",
" [0. 0. 1.]]\n",
"\n",
"mat^T\n",
" [[1. 0. 0.]\n",
" [0. 1. 0.]\n",
" [2. 0. 1.]]\n",
"\n",
"mat^(-1)\n",
" [[ 1. 0. -2.]\n",
" [ 0. 1. 0.]\n",
" [ 0. 0. 1.]]\n",
"\n",
"mat^(-1)-pseudo-inverse\n",
" [[ 1. 0. -2.]\n",
" [ 0. 1. 0.]\n",
" [ 0. 0. 1.]]\n"
]
}
],
"source": [
"size=3\n",
"mat=np.zeros(shape=[size,size])\n",
"for i in range(size):\n",
" mat[i,i]=1\n",
"mat[0,size-1]=2\n",
"\n",
"\n",
"print(\"\\nmat\\n\",mat )\n",
"print(\"\\nmat^T\\n\",mat.T)\n",
"print(\"\\nmat^(-1)\\n\",np.linalg.inv(mat))\n",
"print(\"\\nmat^(-1)-pseudo-inverse\\n\",np.linalg.pinv(mat))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### vecteur propre et valeur propre\n",
"\n",
"Souvenez-vous qu'en anglais valeur/vecteur 'propre' c'est 'eigen' value/vector"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"mat\n",
" [[0.085 0.287 0.206 0.422]\n",
" [0.191 0.262 0.253 0.295]\n",
" [0.244 0.07 0.06 0.626]\n",
" [0.383 0.001 0.161 0.454]]\n",
"\n",
"eigVal\n",
" [ 1. 0.122 -0.195 -0.066]\n",
"\n",
"eigVec\n",
" [[-0.5 -0.416 -0.418 0.39 ]\n",
" [-0.5 -0.763 0.307 0.432]\n",
" [-0.5 0.402 -0.739 -0.813]\n",
" [-0.5 0.287 0.43 -0.036]]\n"
]
}
],
"source": [
"size=4\n",
"\"\"\"une matrice aléatoire auquel on fait subir une opération de normalisation (laquelle?)\"\"\"\n",
"mat=np.random.uniform(low=0,high=10,size=[size,size])\n",
"rowSum=np.sum(mat,axis=1)\n",
"\"\"\" mat[i,j]=mat[i,j]/rowSum(i) \"\"\"\n",
"for i in range(size): mat[i,:]/=rowSum[i]\n",
"\n",
"eigVal,eigVec=np.linalg.eig(mat)\n",
"print(\"\\nmat\\n\", mat )\n",
"print(\"\\neigVal\\n\",np.real(eigVal))\n",
"print(\"\\neigVec\\n\", np.real(eigVec))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"***A vous:*** \n",
"\n",
"* Pourquoi 1 est-il valeur propre ? Quel est le vecteur propre associé? `np.linalg.eig` donne-t-il les vecteurs propres à droite ou à gauche? Sont-ils disposés en ligne ou bien en colonne?\n",
"\n",
"* Toutes les matrices sont-elles diagonalisables? A quoi servent les np.real()? \n",
"\n",
"* laquelle de ces deux formules est la bonne ?\n",
"\n",
" Diag = P^-1 @ mat @ P \n",
"\n",
"ou\n",
"\n",
" Diag = P @ mat @ P^-1\n",
" \n",
"Vérifiez avec python. Aide: Pour transformez un vecteur en matrice diagonale, utilisez `np.diag(vecteur)`"
]
},
{
"cell_type": "markdown",
"metadata": {},
......
This diff is collapsed.
......@@ -273,7 +273,7 @@
"\n",
"Réponse: on peut faire des stats maintenant! \n",
"* estimer la variance du bruit\n",
"* estimre la variances des estimateurs $\\hat w_i$\n",
"* estimer la variances des estimateurs $\\hat w_i$\n",
"* faire un test pour savoir si l'un des $w_i$ est nul. Ce qui revient à dire que le i-ième input n'a aucune influence sur l'output. Ce genre de considération est importante, car on cherche à expliquer l'output de la manière la plus simple possible. \n",
"\n",
"Au travail:"
......@@ -460,9 +460,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.0"
"version": "3.6.5"
}
},
"nbformat": 4,
"nbformat_minor": 1
"nbformat_minor": 2
}
This diff is collapsed.
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Permutation aléatoire"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.5"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
% Default to the notebook output style
((* if not cell_style is defined *))
((* set cell_style = 'style_ipython.tplx' *))
((* endif *))
% Inherit from the specified cell style.
((* extends cell_style *))
%===============================================================================
% Latex Book
%===============================================================================
((* block predoc *))
((( super() )))
((* block tableofcontents *))\tableofcontents((* endblock tableofcontents *))
((* endblock predoc *))
((* block docclass *))
\documentclass[9pt, twocolumn, landscape,A4,reprint, floatfix, groupaddress, prb]{book}
\usepackage{placeins}
\AtBeginDocument{
\heavyrulewidth=.08em
\lightrulewidth=.05em
\cmidrulewidth=.03em
\belowrulesep=.65ex
\belowbottomsep=0pt
\aboverulesep=.4ex
\abovetopsep=0pt
\cmidrulesep=\doublerulesep
\cmidrulekern=.5em
\defaultaddspace=.5em
\addtolength{\voffset}{-0.5in}
\addtolength{\hoffset}{-0.5in}
\addtolength{\textheight}{1in}
\addtolength{\textwidth}{1in}
}
%\addtolength{\voffset}{-0.5in}
%\addtolength{\hoffset}{-0.5in}
\usepackage[francais]{babel} % Pour la langue française
\setlength{\itemsep}{0pt}
\setlength{\columnsep}{0.5in}
% Force floating figures to be [H]
\usepackage{float}
\floatplacement{figure}{H}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{mathrsfs}
\usepackage{makeidx}
\usepackage{listings}
\usepackage[svgnames]{xcolor} % Required for colour specification
\definecolor{dkgreen}{rgb}{0,0.6,0}
\definecolor{gray}{rgb}{0.5,0.5,0.5}
\definecolor{mauve}{rgb}{0.58,0,0.82}
\definecolor{verylightgray}{rgb}{0.9,0.9,0.9}
\lstset{frame=tb,
language=Python,
aboveskip=3mm,
belowskip=3mm,
showstringspaces=false,
columns=flexible,
basicstyle={\small\ttfamily},
numbers=none,
numberstyle=\tiny\color{gray},
keywordstyle=\color{blue},
commentstyle=\color{dkgreen},
stringstyle=\color{mauve},
breaklines=true,
breakatwhitespace=false,
tabsize=3,
otherkeywords={self},
backgroundcolor=\color{verylightgray},
}
%\usepackage{showframe}
\definecolor{pythonblue}{rgb}{0.21,0.45,0.65}
\definecolor{pythonyellow}{rgb}{1.,0.77,0.18}
\parindent=0pt
\setlength{\parskip}{1.5ex plus 1.0ex minus 0.5ex}
%\renewcommand{\labelitemi}{$\bullet$}
((* endblock docclass *))
((* block markdowncell scoped *))
((( cell.source | citation2latex | strip_files_prefix | convert_pandoc('markdown', 'json',extra_args=[]) | resolve_references | convert_pandoc('json','latex', extra_args=["--top-level-division=chapter"]) )))
((* endblock markdowncell *))
((* block maketitle *))
\begin{titlepage}
%\vspace*{\baselineskip}
\centering
{\Large Vincent Vigon}
%\vspace*{0.167\textheight}
\raggedleft
\textbf{\fontsize{30}{36}\selectfont Python}\\[\baselineskip]
% \textbf{\textcolor{pythonblue}{\fontsize{50}{60}\selectfont Python}}\\[\baselineskip]
\textcolor{pythonyellow}{\fontsize{30}{36}\selectfont \textit{pour les proba-stats}}
%\vspace*{0.1\textheight}
\centering
\includegraphics{img/champi.jpg}
\vfill
{\large Université de Strasbourg}
\end{titlepage}
((* endblock maketitle *))
((*- block any_cell -*))
((*- if not 'hide' in cell['metadata'].get('tags', {}) -*))
((( super() )))
((*- endif -*))
((*- endblock any_cell -*))
((* block input scoped *))
\begin{lstlisting}[breaklines]
(((cell.source)))
\end{lstlisting}
((* endblock input *))
......@@ -11779,11 +11779,11 @@ div#notebook {
<h3 id="Master-2-DUAS-Unistra,--2017-2018">Master 2 DUAS Unistra, 2017-2018<a class="anchor-link" href="#Master-2-DUAS-Unistra,--2017-2018">&#182;</a></h3><hr>
<h1 id="Programmer-en-Python">Programmer en Python<a class="anchor-link" href="#Programmer-en-Python">&#182;</a></h1><hr>
<h2 id="Contenu">Contenu<a class="anchor-link" href="#Contenu">&#182;</a></h2><ul>
<li><strong>Le langage (1)</strong> - <a href="02-histogramme_densite.html">html</a> - <a href="02-histogramme_densite.slides.html">diaporama</a></li>
<li><strong>Les généralités</strong> - <a href="04-plusDeLois.html">html</a> - <a href="04-plusDeLois.slides.html">diaporama</a></li>
<li><strong>histogramme</strong> - <a href="02-histogramme_densite.html">html</a> - <a href="02-histogramme_densite.slides.html">diaporama</a></li>
<li><strong>plus de loi</strong> - <a href="04-plusDeLois.html">html</a> - <a href="04-plusDeLois.slides.html">diaporama</a></li>
</ul>
<p><strong>Exécuter en ligne</strong>
<a href="https://mybinder.org/v2/gh/boileaum/cours-python/master"><img style="display: inline" src="https://mybinder.org/badge.svg"></a></p>
<p><strong>Exécuter en ligne</strong></p>
<p><a href="https://mybinder.org/v2/gh/vincentvigon/aleaDataSignal.git/master"><img style="display: inline" src="https://mybinder.org/badge.svg"></a></p>
<p><strong>Télécharger le</strong> <a href="cours-python.pdf"><strong>pdf</strong></a></p>
<p><strong>Sources sur </strong><a href="https://gitlab.math.unistra.fr/mm2act/cours-python"><strong>GitLab</strong></a></p>
<hr>
......
This diff is collapsed.
This diff is collapsed.
"""
Convert notebooks listed in `chapters` into latex and then a PDF.
Note:
- The notebooks are first copied into the build_pdf directory (with a chapter
number prepended).
"""
import re
import subprocess
import os
chapters = ['02-histogramme_densite',
'04-plusDeLois']
# To test a subset, adjust the list of chapters and
# remove the build_pdf directory before running this script.
build_dir = 'build_pdf/'
if not os.path.exists(build_dir):
os.makedirs(build_dir)
# os.system('cp -r exact_solvers '+build_dir)
# os.system('cp -r utils '+build_dir)
# os.system('cp *.html '+build_dir)
# os.system('cp -r figures '+build_dir)
# os.system('cp riemann.tplx '+build_dir)
# os.system('cp *.cls '+build_dir)
# os.system('cp *.css '+build_dir)
# os.system('cp riemann.bib '+build_dir)