📄 demo_svmpout.html
字号:
<html><head> <meta HTTP-EQUIV="Content-Type" CONTENT="text/html;charset=ISO-8859-1"> <title>demo_svmpout.m</title><link rel="stylesheet" type="text/css" href="../../m-syntax.css"></head><body><code><span class=h1>% DEMO_SVMPOUT Fitting a posteriory probability to SVM output.</span><br><span class=help>%</span><br><span class=help>% A posteriory probability p(y==1|f(x)) of the first class</span><br><span class=help>% given SVM output f(x) is assumed to be sigmoid function. </span><br><span class=help>% Parameters A(1) and A(2) of the sigmoid function </span><br><span class=help>% p(y==1|f(x)) = 1/(1+exp(A(1)*f(x)+A(2)) </span><br><span class=help>% are estimated using Maximum-Likelihood [Platt99a]. </span><br><span class=help>%</span><br><span class=help>% The Gaussian mixture model (GMM) is fitted to the SVM output</span><br><span class=help>% and the a posteriory probability are computed for </span><br><span class=help>% comparison to the ML estimate.</span><br><span class=help>% </span><br><span class=help>% The ML estimation of the sigmoid function is imlemented </span><br><span class=help>% in 'mlsigmoid' (see 'help mlsigmoid' for more info).</span><br><span class=help>%</span><br><hr><span class=help1>% <span class=help1_field>About:</span> Statistical Pattern Recognition Toolbox</span><br><span class=help1>% (C) 1999-2003, Written by Vojtech Franc and Vaclav Hlavac</span><br><span class=help1>% <a href="http://www.cvut.cz">Czech Technical University Prague</a></span><br><span class=help1>% <a href="http://www.feld.cvut.cz">Faculty of Electrical Engineering</a></span><br><span class=help1>% <a href="http://cmp.felk.cvut.cz">Center for Machine Perception</a></span><br><br><span class=help1>% <span class=help1_field>Modifications:</span></span><br><span class=help1>% 03-jun-2004, VF</span><br><span class=help1>% 6-May-2003, VF</span><br><br><hr>help demo_svmpout;<br>echo on;<br><br><span class=comment>% load training data</span><br>data = load(<span class=quotes>'riply_trn'</span>);<br><br><span class=comment>% train SVM model</span><br>svm_model = smo(data,struct(<span class=quotes>'ker'</span>,<span class=quotes>'rbf'</span>,<span class=quotes>'arg'</span>,1,<span class=quotes>'C'</span>,10));<br><br><span class=comment>% plot SVM decision boundary </span><br><span class=graph>figure</span>; ppatterns(data); psvm(svm_model);<br><br><span class=comment>% compute SVM output</span><br>[dummy,svm_output.X] = svmclass(data.X,svm_model);<br>svm_output.y = data.y;<br><br><span class=comment>% ML fitting of sigmod to SVM ouput</span><br><span class=comment>%-------------------------------------------------------</span><br>sigmoid_model = mlsigmoid(svm_output);<br><br><span class=comment>% plot fitted probability</span><br>fx = linspace(min(svm_output.X), max(svm_output.X), 200);<br>sigmoid_apost = sigmoid(fx,sigmoid_model);<br><br><span class=graph>figure</span>; hold on; <br>xlabel(<span class=quotes>'svm output f(x)'</span>); ylabel(<span class=quotes>'p(y=1|f(x))'</span>);<br>hsigmoid = <span class=graph>plot</span>(fx,sigmoid_apost,<span class=quotes>'k'</span>);<br>ppatterns(svm_output);<br><br><span class=comment>% ML estimation of GMM model of SVM output</span><br><span class=comment>%-------------------------------------------------------</span><br>gmm_model = mlcgmm( svm_output );<br><br><span class=comment>% compute a posteriory probability</span><br>pcond = pdfgauss( fx, gmm_model);<br>gmm_apost = (pcond(1,:)*gmm_model.Prior(1))./...<br> (pcond(1,:)*gmm_model.Prior(1)+(pcond(2,:)*gmm_model.Prior(2)));<br><br>hgmm = <span class=graph>plot</span>(fx,gmm_apost,<span class=quotes>'g'</span>);<br>hcomp = pgauss(gmm_model); <br><br>legend([hsigmoid,hgmm,hcomp],<span class=quotes>'P(y=1|f(x)) ML-Sigmoid'</span>,...<br> <span class=quotes>'P(y=1|f(x)) ML-GMM'</span>,<span class=quotes>'P(f(x)|y=1) ML-GMM'</span>,<span class=quotes>'P(f(x)|y=2) ML-GMM'</span>);<br><br>echo off;<br><br><span class=comment>% EOF</span><br></code>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -