386 lines
51 KiB
HTML
386 lines
51 KiB
HTML
|
<!DOCTYPE html>
|
|||
|
<html>
|
|||
|
<head>
|
|||
|
<meta charset="UTF-8">
|
|||
|
<title>Fonctions auxilliaires</title>
|
|||
|
<style>
|
|||
|
/* From extension vscode.github */
|
|||
|
.vscode-dark img[src$=\#gh-light-mode-only],
|
|||
|
.vscode-light img[src$=\#gh-dark-mode-only] {
|
|||
|
display: none;
|
|||
|
}
|
|||
|
|
|||
|
/* From extension vscode.markdown-math */
|
|||
|
@font-face{font-family:KaTeX_AMS;src:url(fonts/KaTeX_AMS-Regular.woff2) format("woff2"),url(fonts/KaTeX_AMS-Regular.woff) format("woff"),url(fonts/KaTeX_AMS-Regular.ttf) format("truetype");font-weight:400;font-style:normal}@font-face{font-family:KaTeX_Caligraphic;src:url(fonts/KaTeX_Caligraphic-Bold.woff2) format("woff2"),url(fonts/KaTeX_Caligraphic-Bold.woff) format("woff"),url(fonts/KaTeX_Caligraphic-Bold.ttf) format("truetype");font-weight:700;font-style:normal}@font-face{font-family:KaTeX_Caligraphic;src:url(fonts/KaTeX_Caligraphic-Regular.woff2) format("woff2"),url(fonts/KaTeX_Caligraphic-Regular.woff) format("woff"),url(fonts/KaTeX_Caligraphic-Regular.ttf) format("truetype");font-weight:400;font-style:normal}@font-face{font-family:KaTeX_Fraktur;src:url(fonts/KaTeX_Fraktur-Bold.woff2) format("woff2"),url(fonts/KaTeX_Fraktur-Bold.woff) format("woff"),url(fonts/KaTeX_Fraktur-Bold.ttf) format("truetype");font-weight:700;font-style:normal}@font-face{font-family:KaTeX_Fraktur;src:url(fonts/KaTeX_Fraktur-Regular.woff2) format("woff2"),url(fonts/KaTeX_Fraktur-Regular.woff) format("woff"),url(fonts/KaTeX_Fraktur-Regular.ttf) format("truetype");font-weight:400;font-style:normal}@font-face{font-family:KaTeX_Main;src:url(fonts/KaTeX_Main-Bold.woff2) format("woff2"),url(fonts/KaTeX_Main-Bold.woff) format("woff"),url(fonts/KaTeX_Main-Bold.ttf) format("truetype");font-weight:700;font-style:normal}@font-face{font-family:KaTeX_Main;src:url(fonts/KaTeX_Main-BoldItalic.woff2) format("woff2"),url(fonts/KaTeX_Main-BoldItalic.woff) format("woff"),url(fonts/KaTeX_Main-BoldItalic.ttf) format("truetype");font-weight:700;font-style:italic}@font-face{font-family:KaTeX_Main;src:url(fonts/KaTeX_Main-Italic.woff2) format("woff2"),url(fonts/KaTeX_Main-Italic.woff) format("woff"),url(fonts/KaTeX_Main-Italic.ttf) format("truetype");font-weight:400;font-style:italic}@font-face{font-family:KaTeX_Main;src:url(fonts/KaTeX_Main-Regular.woff2) format("woff2"),url(fonts/KaTeX_Main-Regular.woff) format("woff"),url(fonts/KaTeX_Main-Regular.ttf) format("truetype");font-weight:400;font-style:normal}@font-face{font-family:KaTeX_Math;src:url(fonts/KaTeX_Math-BoldItalic.woff2) format("woff2"),url(fonts/KaTeX_Math-BoldItalic.woff) format("woff"),url(fonts/KaTeX_Math-BoldItalic.ttf) format("truetype");font-weight:700;font-style:italic}@font-face{font-family:KaTeX_Math;src:url(fonts/KaTeX_Math-Italic.woff2) format("woff2"),url(fonts/KaTeX_Math-Italic.woff) format("woff"),url(fonts/KaTeX_Math-Italic.ttf) format("truetype");font-weight:400;font-style:italic}@font-face{font-family:"KaTeX_SansSerif";src:url(fonts/KaTeX_SansSerif-Bold.woff2) format("woff2"),url(fonts/KaTeX_SansSerif-Bold.woff) format("woff"),url(fonts/KaTeX_SansSerif-Bold.ttf) format("truetype");font-weight:700;font-style:normal}@font-face{font-family:"KaTeX_SansSerif";src:url(fonts/KaTeX_SansSerif-Italic.woff2) format("woff2"),url(fonts/KaTeX_SansSerif-Italic.woff) format("woff"),url(fonts/KaTeX_SansSerif-Italic.ttf) format("truetype");font-weight:400;font-style:italic}@font-face{font-family:"KaTeX_SansSerif";src:url(fonts/KaTeX_SansSerif-Regular.woff2) format("woff2"),url(fonts/KaTeX_SansSerif-Regular.woff) format("woff"),url(fonts/KaTeX_SansSerif-Regular.ttf) format("truetype");font-weight:400;font-style:normal}@font-face{font-family:KaTeX_Script;src:url(fonts/KaTeX_Script-Regular.woff2) format("woff2"),url(fonts/KaTeX_Script-Regular.woff) format("woff"),url(fonts/KaTeX_Script-Regular.ttf) format("truetype");font-weight:400;font-style:normal}@font-face{font-family:KaTeX_Size1;src:url(fonts/KaTeX_Size1-Regular.woff2) format("woff2"),url(fonts/KaTeX_Size1-Regular.woff) format("woff"),url(fonts/KaTeX_Size1-Regular.ttf) format("truetype");font-weight:400;font-style:normal}@font-face{font-family:KaTeX_Size2;src:url(fonts/KaTeX_Size2-Regular.woff2) format("woff2"),url(fonts/KaTeX_Size2-Regular.woff) format("woff"),url(fonts/KaTeX_Size2-Regular.ttf) format("truetype");font-weight:400;font-style:normal}@font-face{font-family:KaTeX_Size3;src:url(fonts/KaTeX_Size3-Regular.woff2) format("woff2"),url(fonts/KaT
|
|||
|
|
|||
|
/*---------------------------------------------------------------------------------------------
|
|||
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|||
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|||
|
*--------------------------------------------------------------------------------------------*/
|
|||
|
|
|||
|
.katex-error {
|
|||
|
color: var(--vscode-editorError-foreground);
|
|||
|
}
|
|||
|
|
|||
|
/* From extension marp-team.marp-vscode */
|
|||
|
#marp-vscode {
|
|||
|
all: initial;
|
|||
|
}
|
|||
|
|
|||
|
/* Override VS Code default CSS rules reverting to initial
|
|||
|
https://github.com/microsoft/vscode/blob/master/src/vs/workbench/contrib/webview/browser/pre/main.js#L53 */
|
|||
|
body.marp-vscode {
|
|||
|
padding: 0;
|
|||
|
}
|
|||
|
|
|||
|
body.marp-vscode img {
|
|||
|
max-width: unset;
|
|||
|
max-height: unset;
|
|||
|
}
|
|||
|
|
|||
|
body.marp-vscode a,
|
|||
|
body.marp-vscode a:hover,
|
|||
|
body.marp-vscode code {
|
|||
|
color: unset;
|
|||
|
}
|
|||
|
|
|||
|
body.marp-vscode blockquote {
|
|||
|
background: unset;
|
|||
|
border-color: unset;
|
|||
|
}
|
|||
|
|
|||
|
@media screen {
|
|||
|
body.marp-vscode {
|
|||
|
overflow-y: scroll;
|
|||
|
}
|
|||
|
|
|||
|
#marp-vscode [data-marp-vscode-slide-wrapper] {
|
|||
|
margin: 20px;
|
|||
|
}
|
|||
|
|
|||
|
#marp-vscode svg[data-marpit-svg] {
|
|||
|
box-shadow: 0 5px 10px rgb(0 0 0 / 25%);
|
|||
|
display: block;
|
|||
|
margin: 0;
|
|||
|
}
|
|||
|
|
|||
|
/* Based on https://github.com/microsoft/vscode/blob/master/extensions/markdown-language-features/media/markdown.css */
|
|||
|
#code-csp-warning {
|
|||
|
background-color: #444;
|
|||
|
box-shadow: 1px 1px 1px rgb(0 0 0 / 25%);
|
|||
|
color: white;
|
|||
|
cursor: pointer;
|
|||
|
font-family: sans-serif;
|
|||
|
font-size: 12px;
|
|||
|
line-height: 22px;
|
|||
|
margin: 16px;
|
|||
|
padding: 6px;
|
|||
|
position: fixed;
|
|||
|
right: 0;
|
|||
|
text-align: center;
|
|||
|
top: 0;
|
|||
|
word-wrap: break-word;
|
|||
|
}
|
|||
|
|
|||
|
#code-csp-warning:hover {
|
|||
|
text-decoration: none;
|
|||
|
background-color: #007acc;
|
|||
|
box-shadow: 2px 2px 2px rgb(0 0 0 / 25%);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
@media print {
|
|||
|
body.marp-vscode #code-csp-warning {
|
|||
|
display: none;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
</style>
|
|||
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.10.2/dist/katex.min.css" integrity="sha384-yFRtMMDnQtDRO8rLpMIKrtPCD5jdktao2TV19YiZYWMDkUR5GQZR/NOVTdquEx1j" crossorigin="anonymous">
|
|||
|
<link href="https://cdn.jsdelivr.net/npm/katex-copytex@latest/dist/katex-copytex.min.css" rel="stylesheet" type="text/css">
|
|||
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/Microsoft/vscode/extensions/markdown-language-features/media/markdown.css">
|
|||
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/Microsoft/vscode/extensions/markdown-language-features/media/highlight.css">
|
|||
|
<style>
|
|||
|
body {
|
|||
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe WPC', 'Segoe UI', system-ui, 'Ubuntu', 'Droid Sans', sans-serif;
|
|||
|
font-size: 14px;
|
|||
|
line-height: 1.6;
|
|||
|
}
|
|||
|
</style>
|
|||
|
<style>
|
|||
|
.task-list-item { list-style-type: none; } .task-list-item-checkbox { margin-left: -20px; vertical-align: middle; }
|
|||
|
</style>
|
|||
|
|
|||
|
<script src="https://cdn.jsdelivr.net/npm/katex-copytex@latest/dist/katex-copytex.min.js"></script>
|
|||
|
<script type="text/javascript">
|
|||
|
/* From extension marp-team.marp-vscode */
|
|||
|
var O=Object.defineProperty;var n=(V,S)=>O(V,"name",{value:S,configurable:!0});(()=>{var V={676:(v,y,s)=>{v.exports=s(185)},185:(v,y)=>{"use strict";var s;s={value:!0};const A="marpitSVGPolyfill:setZoomFactor,",i=Symbol();let a,e;function g(o){const l=typeof o=="object"&&o.target||document,p=typeof o=="object"?o.zoom:o;window[i]||(Object.defineProperty(window,i,{configurable:!0,value:!0}),window.addEventListener("message",({data:t,origin:f})=>{if(f===window.origin)try{if(t&&typeof t=="string"&&t.startsWith(A)){const[,r]=t.split(","),c=Number.parseFloat(r);Number.isNaN(c)||(e=c)}}catch(r){console.error(r)}}));let b=!1;Array.from(l.querySelectorAll("svg[data-marpit-svg]"),t=>{var f,r,c,w;t.style.transform||(t.style.transform="translateZ(0)");const h=p||e||t.currentScale||1;a!==h&&(a=h,b=h);const $=t.getBoundingClientRect(),{length:M}=t.children;for(let m=0;m<M;m+=1){const _=t.children[m],d=_.getScreenCTM();if(d){const k=(r=(f=_.x)===null||f===void 0?void 0:f.baseVal.value)!==null&&r!==void 0?r:0,q=(w=(c=_.y)===null||c===void 0?void 0:c.baseVal.value)!==null&&w!==void 0?w:0,E=_.firstElementChild,{style:x}=E;x.transformOrigin||(x.transformOrigin=`${-k}px ${-q}px`),x.transform=`scale(${h}) matrix(${d.a}, ${d.b}, ${d.c}, ${d.d}, ${d.e-$.left}, ${d.f-$.top}) translateZ(0.0001px)`}}}),b!==!1&&Array.from(l.querySelectorAll("iframe"),({contentWindow:t})=>{t==null||t.postMessage(`${A}${b}`,window.origin==="null"?"*":window.origin)})}n(g,"n"),a=1,e=void 0;const u=n((o,l,p)=>{if(o.getAttribute(l)!==p)return o.setAttribute(l,p),!0},"i");function L({once:o=!1,target:l=document}={}){const p=navigator.vendor==="Apple Computer, Inc."?[g]:[];let b=!o;const t=n(()=>{for(const f of p)f({target:l});(function(f=document){Array.from(f.querySelectorAll('svg[data-marp-fitting="svg"]'),r=>{var c;const w=r.firstChild,h=w.firstChild,{scrollWidth:$,scrollHeight:M}=h;let m,_=1;if(r.hasAttribute("data-marp-fitting-code")&&(m=(c=r.parentElement)===null||c===void 0?void 0:c.parentElement),r.hasAttribute("data-marp-fitting-math")&&(m=r.parentElement),m){const E=getComputedStyle(m),x=Math.ceil(m.clientWidth-parseFloat(E.paddingLeft||"0")-parseFloat(E.paddingRight||"0"));x&&(_=x)}const d=Math.max($,_),k=Math.max(M,1),q=`0 0 ${d} ${k}`;u(w,"width",`${d}`),u(w,"height",`${k}`),u(r,"preserveAspectRatio",getComputedStyle(r).getPropertyValue("--preserve-aspect-ratio")||"xMinYMin meet"),u(r,"viewBox",q)&&r.classList.toggle("__reflow__")})})(l),b&&window.requestAnimationFrame(t)},"a");return t(),()=>{b=!1}}n(L,"a");const C=Symbol(),F=n((o=document)=>{if(typeof window=="undefined")throw new Error("Marp Core's browser script is valid only in browser context.");if(o[C])return o[C];const l=L({target:o}),p=n(()=>{l(),delete o[C]},"r");return Object.defineProperty(o,C,{configurable:!0,value:p}),p},"s");s=F,s=F,y.observer=L}},S={};function B(v){var y=S[v];if(y!==void 0)return y.exports;var s=S[v]={exports:{}};return V[v](s,s.exports,B),s.exports}n(B,"__webpack_require__");var j={};(()=>{"use strict";var v=B(676);function y(){let i,a;const e=n(()=>{const u=!!document.getElementById("marp-vscode");i!==u&&(document.body.classList.toggle("marp-vscode",u),u?a=(0,v.observer)():(a==null||a(),a=void 0),i=u),i?s():A()},"updateCallback");window.addEventListener("load",()=>window.setTimeout(e,100)),window.addEventListener("vscode.markdown.updateContent",e),e()}n(y,"preview");const s=n(()=>{const i=document.querySelectorAll("style:not(#marp-vscode-style):not(#_defaultStyles):not([data-marp-vscode-body])"),a=document.querySelectorAll('link[rel="stylesheet"][href]:not([href*="marp-vscode"])');i.forEach(e=>{var g;e.closest("#marp-vscode")||(e.dataset.marpVscodeBody=(g=e.textContent)!=null?g:"",e.textContent="")}),a.forEach(e=>{if(e.closest("#marp-vscode"))return;const{href:g}=e;e.dataset.marpVscodeHref=g,e.removeAttribute("href")})},"removeStyles"),A=n(()=>{const i=document.querySelectorAll("style[data-marp-vscode-body]"),a=document.querySelectorAll("link[data-marp-vscode-href]");i.forEach(e=>{e.textContent=e.dataset.marpVscodeBody||"",delete e.dataset.marpVscodeBody}),a.forEach(e=>{e
|
|||
|
|
|||
|
</script>
|
|||
|
|
|||
|
</head>
|
|||
|
<body class="vscode-body vscode-light">
|
|||
|
<hr>
|
|||
|
<h2 id="author-laurent-fainsintitle-tav-tp1-lfdescription-rapport-de-traitement-des-données-audio-visuelles-travail-pratique-1-laurent-fainsin">author: Laurent Fainsin
|
|||
|
title: TAV, TP1, LF
|
|||
|
description: Rapport de Traitement des données audio-visuelles, Travail Pratique 1, Laurent Fainsin</h2>
|
|||
|
<h1 id="fonctions-auxilliaires">Fonctions auxilliaires</h1>
|
|||
|
<pre><code class="language-matlab"><div><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">y</span> = <span class="hljs-title">bezier</span><span class="hljs-params">(beta_0,beta,beta_d,x)</span></span>
|
|||
|
d = <span class="hljs-built_in">length</span>(<span class="hljs-built_in">beta</span>)+<span class="hljs-number">1</span>;
|
|||
|
y = beta_0 * (<span class="hljs-number">1</span>-x).^d + beta_d * x.^d;
|
|||
|
<span class="hljs-keyword">for</span> <span class="hljs-built_in">i</span> = <span class="hljs-number">1</span>:d<span class="hljs-number">-1</span>
|
|||
|
y = y + <span class="hljs-built_in">beta</span>(<span class="hljs-built_in">i</span>) * <span class="hljs-built_in">nchoosek</span>(d,<span class="hljs-built_in">i</span>) * x.^<span class="hljs-built_in">i</span> .* (<span class="hljs-number">1</span>-x).^(d-<span class="hljs-built_in">i</span>);
|
|||
|
<span class="hljs-keyword">end</span>
|
|||
|
<span class="hljs-keyword">end</span>
|
|||
|
</div></code></pre>
|
|||
|
<pre><code class="language-matlab"><div><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">y</span> = <span class="hljs-title">bezier_bruitee</span><span class="hljs-params">(beta_0,beta,beta_d,x,sigma)</span></span>
|
|||
|
y = bezier(beta_0,<span class="hljs-built_in">beta</span>,beta_d,x)+sigma*<span class="hljs-built_in">randn</span>(<span class="hljs-built_in">size</span>(x));
|
|||
|
<span class="hljs-keyword">end</span>
|
|||
|
</div></code></pre>
|
|||
|
<h1 id="exercice-1">Exercice 1</h1>
|
|||
|
<pre><code class="language-matlab"><div><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">estimation</span> = <span class="hljs-title">moindres_carres</span><span class="hljs-params">(D_app, beta_0, beta_d, d)</span></span>
|
|||
|
X = D_app(<span class="hljs-number">1</span>,:)';
|
|||
|
Y = D_app(<span class="hljs-number">2</span>,:)';
|
|||
|
|
|||
|
B = Y - beta_0*(<span class="hljs-number">1</span>-X).^d - beta_d*(X.^d);
|
|||
|
|
|||
|
A = <span class="hljs-built_in">zeros</span>(<span class="hljs-built_in">length</span>(X), d<span class="hljs-number">-1</span>);
|
|||
|
<span class="hljs-keyword">for</span> <span class="hljs-built_in">i</span>=<span class="hljs-number">1</span>:(d<span class="hljs-number">-1</span>)
|
|||
|
A(:,<span class="hljs-built_in">i</span>) = <span class="hljs-built_in">nchoosek</span>(d, <span class="hljs-built_in">i</span>) .* X.^<span class="hljs-built_in">i</span> .* (<span class="hljs-number">1</span>-X).^(d-<span class="hljs-built_in">i</span>);
|
|||
|
<span class="hljs-keyword">end</span>
|
|||
|
|
|||
|
estimation = A \ B;
|
|||
|
<span class="hljs-keyword">end</span>
|
|||
|
</div></code></pre>
|
|||
|
<pre><code class="language-matlab"><div>donnees_apprentissage;
|
|||
|
close all;
|
|||
|
|
|||
|
<span class="hljs-comment">% Degré de la courbe de Bezier </span>
|
|||
|
d = <span class="hljs-number">8</span>;
|
|||
|
|
|||
|
<span class="hljs-comment">% Estimation des paramètres de la courbe de Bezier (sauf beta_0 et beta_d) :</span>
|
|||
|
beta_estime = moindres_carres(D_app,beta_0,beta_d,d);
|
|||
|
|
|||
|
<span class="hljs-comment">% Trac de la courbe de Bezier estime, de degré d (trait rouge) :</span>
|
|||
|
y_estime = bezier(beta_0,beta_estime,beta_d,x);
|
|||
|
<span class="hljs-built_in">plot</span>(x,y_estime,<span class="hljs-string">'-r'</span>,<span class="hljs-string">'MarkerSize'</span>,<span class="hljs-number">10</span>,<span class="hljs-string">'LineWidth'</span>,<span class="hljs-number">3</span>);
|
|||
|
lg = <span class="hljs-built_in">legend</span>(<span class="hljs-string">' Modele exact'</span>,<span class="hljs-string">' Donnees d''apprentissage'</span>,[<span class="hljs-string">' Modele estime ($d='</span> num2str(d) <span class="hljs-string">'$)'</span>],<span class="hljs-string">'Location'</span>,<span class="hljs-string">'Best'</span>);
|
|||
|
set(lg,<span class="hljs-string">'Interpreter'</span>,<span class="hljs-string">'Latex'</span>);
|
|||
|
</div></code></pre>
|
|||
|
<img src="file:////home/lfainsin/2A/TDAV/TP1/rapport/exercice_1.svg">
|
|||
|
<h1 id="exercice-2">Exercice 2</h1>
|
|||
|
<pre><code class="language-matlab"><div><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">erreur</span> = <span class="hljs-title">erreur_apprentissage</span><span class="hljs-params">(D_app,beta_0,beta_d,d)</span></span>
|
|||
|
X = D_app(<span class="hljs-number">1</span>,:)';
|
|||
|
Y = D_app(<span class="hljs-number">2</span>,:)';
|
|||
|
|
|||
|
<span class="hljs-built_in">beta</span> = moindres_carres(D_app, beta_0, beta_d, d);
|
|||
|
estimation = bezier(beta_0, <span class="hljs-built_in">beta</span>, beta_d, X);
|
|||
|
|
|||
|
erreur = <span class="hljs-built_in">mean</span>((estimation - Y).^<span class="hljs-number">2</span>);
|
|||
|
<span class="hljs-keyword">end</span>
|
|||
|
</div></code></pre>
|
|||
|
<pre><code class="language-matlab"><div>donnees_apprentissage;
|
|||
|
close all;
|
|||
|
|
|||
|
<span class="hljs-comment">% Calcul de l'erreur d'apprentissage en fonction de d :</span>
|
|||
|
liste_d = <span class="hljs-number">2</span>:<span class="hljs-built_in">length</span>(D_app);
|
|||
|
liste_erreurs_apprentissage = [];
|
|||
|
<span class="hljs-keyword">for</span> d = liste_d
|
|||
|
erreur = erreur_apprentissage(D_app,beta_0,beta_d,d);
|
|||
|
liste_erreurs_apprentissage = [liste_erreurs_apprentissage erreur];
|
|||
|
<span class="hljs-keyword">end</span>
|
|||
|
|
|||
|
<span class="hljs-comment">% Trac de l'erreur d'apprentissage en fonction de d :</span>
|
|||
|
<span class="hljs-built_in">figure</span>(<span class="hljs-string">'Name'</span>,<span class="hljs-string">'Erreur d''apprentissage'</span>,<span class="hljs-string">'Position'</span>,[<span class="hljs-number">0.4</span>*L,<span class="hljs-number">0.05</span>*H,<span class="hljs-number">0.6</span>*L,<span class="hljs-number">0.7</span>*H]);
|
|||
|
<span class="hljs-built_in">plot</span>(liste_d,liste_erreurs_apprentissage,<span class="hljs-string">'sb-'</span>,<span class="hljs-string">'LineWidth'</span>,<span class="hljs-number">2</span>);
|
|||
|
set(gca,<span class="hljs-string">'FontSize'</span>,<span class="hljs-number">20</span>);
|
|||
|
xlabel(<span class="hljs-string">'$d$'</span>,<span class="hljs-string">'Interpreter'</span>,<span class="hljs-string">'Latex'</span>,<span class="hljs-string">'FontSize'</span>,<span class="hljs-number">30</span>);
|
|||
|
ylabel(<span class="hljs-string">'Erreur'</span>,<span class="hljs-string">'FontSize'</span>,<span class="hljs-number">30</span>);
|
|||
|
<span class="hljs-built_in">legend</span>(<span class="hljs-string">' Erreur d''apprentissage'</span>,<span class="hljs-string">'Location'</span>,<span class="hljs-string">'Best'</span>);
|
|||
|
</div></code></pre>
|
|||
|
<img src="file:////home/lfainsin/2A/TDAV/TP1/rapport/exercice_2.svg">
|
|||
|
<h1 id="données-de-test">Données de test</h1>
|
|||
|
<h2 id="exercice-1-1">Exercice 1</h2>
|
|||
|
<pre><code class="language-matlab"><div>donnees_test;
|
|||
|
|
|||
|
<span class="hljs-comment">% % Degr de la courbe de Bzier utilise comme modle (testez plusieurs valeurs de d entre 2 et 20) :</span>
|
|||
|
degres = <span class="hljs-number">2</span>:<span class="hljs-number">5</span>:<span class="hljs-number">20</span>;
|
|||
|
|
|||
|
<span class="hljs-keyword">for</span> d=degres
|
|||
|
beta_estime = moindres_carres(D_test,beta_0,beta_d,d);
|
|||
|
y_estime = bezier(beta_0,beta_estime,beta_d,x);
|
|||
|
<span class="hljs-built_in">plot</span>(x,y_estime,<span class="hljs-string">'MarkerSize'</span>,<span class="hljs-number">10</span>,<span class="hljs-string">'LineWidth'</span>,<span class="hljs-number">3</span>, <span class="hljs-string">'DisplayName'</span>, [<span class="hljs-string">'d='</span>,num2str(d)]);
|
|||
|
<span class="hljs-keyword">end</span>
|
|||
|
</div></code></pre>
|
|||
|
<img src="file:////home/lfainsin/2A/TDAV/TP1/rapport/exercice_1_test.svg">
|
|||
|
<h2 id="exercice-2-1">Exercice 2</h2>
|
|||
|
<pre><code class="language-matlab"><div>donnees_test;
|
|||
|
close all;
|
|||
|
|
|||
|
liste_d = <span class="hljs-number">2</span>:<span class="hljs-number">10</span>:<span class="hljs-built_in">length</span>(D_test);
|
|||
|
liste_erreurs_apprentissage = [];
|
|||
|
<span class="hljs-keyword">for</span> d = liste_d
|
|||
|
erreur = erreur_apprentissage(D_test,beta_0,beta_d,d);
|
|||
|
liste_erreurs_apprentissage = [liste_erreurs_apprentissage erreur];
|
|||
|
<span class="hljs-keyword">end</span>
|
|||
|
|
|||
|
<span class="hljs-comment">% Trac de l'erreur d'apprentissage en fonction de d :</span>
|
|||
|
<span class="hljs-built_in">figure</span>(<span class="hljs-string">'Name'</span>,<span class="hljs-string">'Erreur d''apprentissage'</span>,<span class="hljs-string">'Position'</span>,[<span class="hljs-number">0.4</span>*L,<span class="hljs-number">0.05</span>*H,<span class="hljs-number">0.6</span>*L,<span class="hljs-number">0.7</span>*H]);
|
|||
|
<span class="hljs-built_in">plot</span>(liste_d,liste_erreurs_apprentissage,<span class="hljs-string">'sb-'</span>,<span class="hljs-string">'LineWidth'</span>,<span class="hljs-number">2</span>);
|
|||
|
set(gca,<span class="hljs-string">'FontSize'</span>,<span class="hljs-number">20</span>);
|
|||
|
xlabel(<span class="hljs-string">'$d$'</span>,<span class="hljs-string">'Interpreter'</span>,<span class="hljs-string">'Latex'</span>,<span class="hljs-string">'FontSize'</span>,<span class="hljs-number">30</span>);
|
|||
|
ylabel(<span class="hljs-string">'Erreur'</span>,<span class="hljs-string">'FontSize'</span>,<span class="hljs-number">30</span>);
|
|||
|
<span class="hljs-built_in">legend</span>(<span class="hljs-string">' Erreur d''apprentissage'</span>,<span class="hljs-string">'Location'</span>,<span class="hljs-string">'Best'</span>);
|
|||
|
</div></code></pre>
|
|||
|
<img src="file:////home/lfainsin/2A/TDAV/TP1/rapport/exercice_2_test.svg">
|
|||
|
<h1 id="exercice-3">Exercice 3</h1>
|
|||
|
<pre><code class="language-matlab"><div><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">erreur</span> = <span class="hljs-title">erreur_generalisation</span><span class="hljs-params">(D_test,D_app,beta_0,beta_d,d)</span></span>
|
|||
|
X = D_test(<span class="hljs-number">1</span>,:)';
|
|||
|
Y = D_test(<span class="hljs-number">2</span>,:)';
|
|||
|
|
|||
|
<span class="hljs-built_in">beta</span> = moindres_carres(D_app, beta_0, beta_d, d);
|
|||
|
estimation = bezier(beta_0, <span class="hljs-built_in">beta</span>, beta_d, X);
|
|||
|
|
|||
|
erreur = <span class="hljs-built_in">mean</span>((estimation - Y).^<span class="hljs-number">2</span>);
|
|||
|
<span class="hljs-keyword">end</span>
|
|||
|
</div></code></pre>
|
|||
|
<pre><code class="language-matlab"><div><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-params">[d_estime, sigma_estime]</span> = <span class="hljs-title">estimation_d_sigma</span><span class="hljs-params">(liste_d, liste_erreurs_generalisation)</span></span>
|
|||
|
[~, index] = <span class="hljs-built_in">min</span>(liste_erreurs_generalisation);
|
|||
|
d_estime = liste_d(index);
|
|||
|
|
|||
|
sigma_estime = std(liste_erreurs_generalisation);
|
|||
|
<span class="hljs-keyword">end</span>
|
|||
|
</div></code></pre>
|
|||
|
<pre><code class="language-matlab"><div>donnees_test;
|
|||
|
close all;
|
|||
|
|
|||
|
<span class="hljs-comment">% Calcul de l'erreur d'apprentissage (risque empirique) :</span>
|
|||
|
liste_d = <span class="hljs-number">2</span>:<span class="hljs-number">20</span>;
|
|||
|
liste_erreurs_apprentissage = [];
|
|||
|
<span class="hljs-keyword">for</span> d = liste_d
|
|||
|
erreur = erreur_apprentissage(D_app,beta_0,beta_d,d);
|
|||
|
liste_erreurs_apprentissage = [liste_erreurs_apprentissage erreur];
|
|||
|
<span class="hljs-keyword">end</span>
|
|||
|
|
|||
|
<span class="hljs-comment">% Tracé de l'erreur d'apprentissage en fonction de d :</span>
|
|||
|
<span class="hljs-built_in">figure</span>(<span class="hljs-string">'Name'</span>,<span class="hljs-string">'Erreur d''apprentissage et erreur de generalisation'</span>,<span class="hljs-string">'Position'</span>,[<span class="hljs-number">0.4</span>*L,<span class="hljs-number">0.05</span>*H,<span class="hljs-number">0.6</span>*L,<span class="hljs-number">0.7</span>*H]);
|
|||
|
<span class="hljs-built_in">plot</span>(liste_d,liste_erreurs_apprentissage,<span class="hljs-string">'sb-'</span>,<span class="hljs-string">'LineWidth'</span>,<span class="hljs-number">2</span>);
|
|||
|
set(gca,<span class="hljs-string">'FontSize'</span>,<span class="hljs-number">20</span>);
|
|||
|
xlabel(<span class="hljs-string">'$d$'</span>,<span class="hljs-string">'Interpreter'</span>,<span class="hljs-string">'Latex'</span>,<span class="hljs-string">'FontSize'</span>,<span class="hljs-number">30</span>);
|
|||
|
ylabel(<span class="hljs-string">'Erreur'</span>,<span class="hljs-string">'FontSize'</span>,<span class="hljs-number">30</span>);
|
|||
|
<span class="hljs-built_in">hold</span> on;
|
|||
|
|
|||
|
<span class="hljs-comment">% Calcul de l'erreur de généralisation (risque espéré) :</span>
|
|||
|
liste_erreurs_generalisation = [];
|
|||
|
<span class="hljs-keyword">for</span> d = liste_d
|
|||
|
erreur = erreur_generalisation(D_test,D_app,beta_0,beta_d,d);
|
|||
|
liste_erreurs_generalisation = [liste_erreurs_generalisation erreur];
|
|||
|
<span class="hljs-keyword">end</span>
|
|||
|
|
|||
|
<span class="hljs-comment">% Tracé de l'erreur de généralisation en fonction de d :</span>
|
|||
|
<span class="hljs-built_in">plot</span>(liste_d,liste_erreurs_generalisation,<span class="hljs-string">'sg-'</span>,<span class="hljs-string">'LineWidth'</span>,<span class="hljs-number">2</span>);
|
|||
|
<span class="hljs-built_in">legend</span>(<span class="hljs-string">' Erreur d''apprentissage'</span>,<span class="hljs-string">' Erreur de generalisation'</span>,<span class="hljs-string">'Location'</span>,<span class="hljs-string">'Best'</span>);
|
|||
|
|
|||
|
<span class="hljs-comment">% Estimation du degré d et de l'écart-type sigma :</span>
|
|||
|
[d_estime,sigma_estime] = estimation_d_sigma(liste_d,liste_erreurs_generalisation);
|
|||
|
fprintf(<span class="hljs-string">'Estimation du degre : d = %d\n'</span>,d_estime);
|
|||
|
fprintf(<span class="hljs-string">'Estimation de l''ecart-type du bruit sur les donnees : %.3f\n'</span>,sigma_estime);
|
|||
|
</div></code></pre>
|
|||
|
<pre><code><code><div>Estimation du degre : d = 5
|
|||
|
Estimation de l'ecart-type du bruit sur les donnees : 0.477
|
|||
|
</div></code></code></pre>
|
|||
|
<img src="file:////home/lfainsin/2A/TDAV/TP1/rapport/exercice_3.svg">
|
|||
|
<h1 id="exercice-4">Exercice 4</h1>
|
|||
|
<pre><code class="language-matlab"><div><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">VC</span> = <span class="hljs-title">calcul_VC</span><span class="hljs-params">(D_app, beta_0, beta_d, d)</span></span>
|
|||
|
X = D_app(<span class="hljs-number">1</span>,:)';
|
|||
|
Y = D_app(<span class="hljs-number">2</span>,:)';
|
|||
|
n = <span class="hljs-built_in">length</span>(X);
|
|||
|
|
|||
|
VC = <span class="hljs-number">0</span>;
|
|||
|
<span class="hljs-keyword">for</span> <span class="hljs-built_in">j</span>=<span class="hljs-number">1</span>:n
|
|||
|
D_app_loo = [D_app(:,<span class="hljs-number">1</span>:<span class="hljs-built_in">j</span><span class="hljs-number">-1</span>) , D_app(:,<span class="hljs-built_in">j</span>+<span class="hljs-number">1</span>:n)];
|
|||
|
<span class="hljs-built_in">beta</span> = moindres_carres(D_app_loo, beta_0, beta_d, d);
|
|||
|
|
|||
|
estimation = bezier(beta_0, <span class="hljs-built_in">beta</span>, beta_d, X(<span class="hljs-built_in">j</span>));
|
|||
|
VC = VC + (Y(<span class="hljs-built_in">j</span>) - estimation).^<span class="hljs-number">2</span>;
|
|||
|
<span class="hljs-keyword">end</span>
|
|||
|
|
|||
|
VC = VC/n;
|
|||
|
<span class="hljs-keyword">end</span>
|
|||
|
</div></code></pre>
|
|||
|
<pre><code class="language-matlab"><div><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-params">[d_estime,sigma_estime]</span> = <span class="hljs-title">estimation_d_sigma_bis</span><span class="hljs-params">(liste_d,liste_VC)</span></span>
|
|||
|
[~, index] = <span class="hljs-built_in">min</span>(liste_VC);
|
|||
|
d_estime = liste_d(index);
|
|||
|
|
|||
|
sigma_estime = std(liste_VC);
|
|||
|
<span class="hljs-keyword">end</span>
|
|||
|
</div></code></pre>
|
|||
|
<pre><code class="language-matlab"><div>donnees_test;
|
|||
|
close all;
|
|||
|
|
|||
|
<span class="hljs-comment">% Calcul de la validation croisée Leave-one-out :</span>
|
|||
|
liste_d = <span class="hljs-number">2</span>:<span class="hljs-number">20</span>;
|
|||
|
liste_VC = [];
|
|||
|
tic;
|
|||
|
<span class="hljs-keyword">for</span> d = liste_d
|
|||
|
VC = calcul_VC(D_app,beta_0,beta_d,d);
|
|||
|
liste_VC = [liste_VC VC];
|
|||
|
<span class="hljs-keyword">end</span>
|
|||
|
toc;
|
|||
|
|
|||
|
<span class="hljs-comment">% Tracé de la validation croisée Leave-one-out en fonction de d :</span>
|
|||
|
<span class="hljs-built_in">figure</span>(<span class="hljs-string">'Name'</span>,<span class="hljs-string">'Validation croisee'</span>,<span class="hljs-string">'Position'</span>,[<span class="hljs-number">0.4</span>*L,<span class="hljs-number">0.05</span>*H,<span class="hljs-number">0.6</span>*L,<span class="hljs-number">0.7</span>*H]);
|
|||
|
<span class="hljs-built_in">plot</span>(liste_d,liste_VC,<span class="hljs-string">'sr-'</span>,<span class="hljs-string">'LineWidth'</span>,<span class="hljs-number">2</span>);
|
|||
|
set(gca,<span class="hljs-string">'FontSize'</span>,<span class="hljs-number">20</span>);
|
|||
|
xlabel(<span class="hljs-string">'$d$'</span>,<span class="hljs-string">'Interpreter'</span>,<span class="hljs-string">'Latex'</span>,<span class="hljs-string">'FontSize'</span>,<span class="hljs-number">30</span>);
|
|||
|
ylabel(<span class="hljs-string">'$VC$'</span>,<span class="hljs-string">'Interpreter'</span>,<span class="hljs-string">'Latex'</span>,<span class="hljs-string">'FontSize'</span>,<span class="hljs-number">30</span>);
|
|||
|
|
|||
|
<span class="hljs-comment">% Estimation du degré d et de l'écart-type sigma :</span>
|
|||
|
[d_estime,sigma_estime] = estimation_d_sigma_bis(liste_d,liste_VC);
|
|||
|
fprintf(<span class="hljs-string">'Estimation du degre : d = %d\n'</span>,d_estime);
|
|||
|
fprintf(<span class="hljs-string">'Estimation de l''ecart-type du bruit sur les donnees : %.3f\n'</span>,sigma_estime);
|
|||
|
</div></code></pre>
|
|||
|
<pre><code><code><div>Estimation du degre : d = 5
|
|||
|
Estimation de l'ecart-type du bruit sur les donnees : 0.563
|
|||
|
</div></code></code></pre>
|
|||
|
<img src="file:////home/lfainsin/2A/TDAV/TP1/rapport/exercice_4.svg">
|
|||
|
<h1 id="exercice-5-optionnel">Exercice 5 (Optionnel)</h1>
|
|||
|
<pre><code class="language-matlab"><div>clear;
|
|||
|
close all;
|
|||
|
|
|||
|
<span class="hljs-comment">% constantes</span>
|
|||
|
beta_0 = <span class="hljs-number">115</span>;
|
|||
|
beta_d = <span class="hljs-number">123</span>;
|
|||
|
<span class="hljs-built_in">beta</span> = [<span class="hljs-number">133</span>,<span class="hljs-number">96</span>,<span class="hljs-number">139</span>,<span class="hljs-number">118</span>];
|
|||
|
n_app = <span class="hljs-number">100</span>;
|
|||
|
pas_app = <span class="hljs-number">1</span>/(n_app<span class="hljs-number">-1</span>);
|
|||
|
x_j = <span class="hljs-number">0</span>:pas_app:<span class="hljs-number">1</span>;
|
|||
|
sigma = <span class="hljs-number">0.5</span>;
|
|||
|
d = <span class="hljs-number">5</span>;
|
|||
|
n = <span class="hljs-number">10000</span>;
|
|||
|
|
|||
|
beta_moyen = <span class="hljs-built_in">zeros</span>(<span class="hljs-number">1</span>, d<span class="hljs-number">-1</span>)';
|
|||
|
sigma_moyen = <span class="hljs-number">0</span>;
|
|||
|
<span class="hljs-keyword">for</span> <span class="hljs-built_in">i</span>=<span class="hljs-number">1</span>:n
|
|||
|
<span class="hljs-comment">% génération de nouveaux points d'apprentissage</span>
|
|||
|
y_j = bezier_bruitee(beta_0,<span class="hljs-built_in">beta</span>,beta_d,x_j,sigma);
|
|||
|
D_app = [x_j ; y_j];
|
|||
|
|
|||
|
beta_estime = moindres_carres(D_app,beta_0,beta_d,d);
|
|||
|
beta_moyen = beta_moyen + beta_estime/n;
|
|||
|
<span class="hljs-keyword">end</span>
|
|||
|
|
|||
|
[beta' , beta_moyen]
|
|||
|
</div></code></pre>
|
|||
|
<pre><code class="language-matlab"><div>>> exercice_5
|
|||
|
|
|||
|
<span class="hljs-built_in">ans</span> =
|
|||
|
|
|||
|
<span class="hljs-number">133.0000</span> <span class="hljs-number">133.0007</span>
|
|||
|
<span class="hljs-number">96.0000</span> <span class="hljs-number">96.0013</span>
|
|||
|
<span class="hljs-number">139.0000</span> <span class="hljs-number">138.9989</span>
|
|||
|
<span class="hljs-number">118.0000</span> <span class="hljs-number">118.0024</span>
|
|||
|
</div></code></pre>
|
|||
|
|
|||
|
</body>
|
|||
|
</html>
|