Commit 6b974123 authored by vincentvigon's avatar vincentvigon
Browse files

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 diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -11,147 +11,10 @@
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"%matplotlib inline\n",
"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",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"%matplotlib inline\n",
"np.set_printoptions(precision=3,suppress=True)"
]
......
This diff is collapsed.
......@@ -211,11 +211,11 @@
"\n",
"plt.figure(figsize=(12,12))\n",
"mini,maxi=np.min(y),np.max(y)\n",
"xx=np.linspace(0,2)\n",
"x_1, x_2 = np.meshgrid(xx, xx)\n",
"hat_Y= hat_w[0]+hat_w[1]*x_1+hat_w[2]*x_2\n",
"hat_Y= hat_w[0]+hat_w[1]*x_1+hat_w[2]*x_2\n",
"plt.imshow(hat_Y,\n",
" origin='lower',\n",
" extent=[0,2,0,2],\n",
" norm=plt.Normalize(vmin=mini, vmax=maxi))\n",
"\n",
......
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,
% 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 *))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment