Commit 9757f72e authored by Ulmer Louis's avatar Ulmer Louis
Browse files

ajout tim

parent 56a9cb44
No preview for this file type
No preview for this file type
%% TP7
% Ensemble de points aleatoires
randn('state', 1200)
% G?n?ration des donn?es
vmu1 = [0; 0];
vmu2 = [5; 5];
vSIGMA1 = [1 0.5; 0.5 4];
vSIGMA2 = [1 0.5; 0.5 4];
n1 = 100; % nombre de points classe 1
n2 = 150; % nombre de points classe 2
% generation de donnees aleatoires suivant lois gaussiennes
% classe 0
X1 = mvnrnd(vmu1, vSIGMA1,n1);
Y1 = -ones(n1, 1); %on met _1
% classe 1
X2 = mvnrnd(vmu2, vSIGMA2,n2);
Y2 = ones(n2, 1);
figure, plot(X1(:,1), X1(:,2), 'ro', 'markersize', 8, 'markerfacecolor', 'r')
hold on
plot(X2(:,1), X2(:,2), 'bv', 'markersize', 8, 'markerfacecolor', 'b')
% Dans la suite on ne travaillera qu'avec X et Y
% matrice des donn?es
X = [X1; X2]; clear X1 X2
% vecteur des labels
Y = [Y1; Y2]; clear Y1 Y2
%%
%%n=length(Y);
%%C=ones(n,1);
%----------------
% ratio = 1/3;
% [xapp, yapp, xtest, ytest] = splitdata(X, Y, ratio);
% ratio = 1/2;
% [xapp, yapp, xval, yval] = splitdata(xapp, yapp, ratio);
%-----------------
C=200
[w,b]=monsvmclass(X,Y,C);
ypred=monsvmval(X,w,b);
%%
% bout de code pour tracer la fronti?re de d?cision d'un SVM lin?aire
% f(x) = w'*x = B
% W est le vecteur de param?tres du mod?le et b le terme de biais
figure(1)
N = 200;
[aux1,aux2]=meshgrid(linspace(-5,5,N));
aux=[reshape(aux1,N*N,1) reshape(aux2,N*N,1)];
fx = aux*w + b;
figure(1), hold on
% trace la frontiere de d?cision f(x) = 0 et la marge f(x)=1 et f(x)=-1
[c,h]=contour(aux1,aux2,reshape(fx, N,N), [-1 0 1], 'g', 'Linewidth',2);
clabel(c,h);
%%
vectC=logspace(-2,2,9)
N = 200;
[aux1,aux2]=meshgrid(linspace(-5,5,N));
aux=[reshape(aux1,N*N,1) reshape(aux2,N*N,1)];
for i=1:1:length(vectC)
[w,b]=monsvmclass(X,Y,vectC(i));
fx = aux*w + b;
figure(1), subplot(3,3,i)
%trace pt apprentissage
plot(X(Y==-1,1),X(Y==-1,2),'sb','markersize',8,'markerfacecolor','b')
hold on
plot(X(Y==1,1),X(Y==1,2),'sb','markersize',8,'markerfacecolor','r')
% trace la frontiere de d?cision f(x) = 0 et la marge f(x)=1 et f(x)=-1
[c,h]=contour(aux1,aux2,reshape(fx, N,N), [-1 0 1], 'g', 'Linewidth',2);
clabel(c,h);
end
%% 2 Reconnaissance de Chiffres Manuscrits
load("uspsasi.mat")
% classe 1
ch1=2;
ind1=find(y==ch1);
n1=length(ind1);
X1=x(ind1,:);
Y1=ones(n1,1);
% classe 2
ch2=8;
ind2=find(y==ch2);
n2=length(ind2);
X2=x(ind2,:);
Y2=ones(n2,1);
%on met tout de bout en bout
X=[X1;X2];
Y=[Y1;Y2];
% %solution cvx du dual
% K=X*X';
% H=K.*(Y*Y');
% n=size(H,1);
% e=ones(n,1);
% C=10;
% verbose=0;
% chouia= 1e-8;
% [petitalpha, bqp, pos]=monqp(H,e,Y,0,C,chouia,verbose);
% alphaqp=zeros(n,1);
% alphaqp(pos)=petitalpha;
%
% %calcul de w a partir des alphas
%
% d=size(X,2);
% wqp=zeros(d,1);
%
%
C=200
[w,b]=monsvmclass(X,Y,C);
ypred=monsvmval(X,w,b);
function [xapp, yapp, xtest, ytest, indices] = SepareDataNfoldCV(x, y, Nfold, NumFold);
%% Generer les donnees app et test pour Nfold-CV
%% Valable pour N classes
%% x : donnees
%% y : labels
%% Nfold : nombre de decoupage
%% NumFold : num�ro de la portion � prendre pour les donn�es de test
%% G2 - F�vrier 2006
if NumFold > Nfold
error('Num Portion sup � Nfold')
end
classcode = unique(y);
Nbclasse = length(classcode);
IndApp = [];
IndTest = [];
for i=1:Nbclasse
Indclass_i = find(y==classcode(i));
N_i = length(Indclass_i);
LongPortion_i = round(N_i/Nfold); %% longueur de chaque portion
IndTestClass_i = Indclass_i( LongPortion_i*(NumFold-1) + 1 : min(LongPortion_i*NumFold, N_i) );
IndTest = [IndTest; IndTestClass_i];
IndAppClass_i = setdiff(Indclass_i, IndTestClass_i);
IndApp = [IndApp; IndAppClass_i];
end
xapp = x(IndApp, :); yapp = y(IndApp);
xtest = x(IndTest, :); ytest = y(IndTest);
indices.app = IndApp;
indices.test = IndTest;
......@@ -11,7 +11,7 @@ y1=-ones(n1,1);
x1=data_letter(ind1,:);
%cluster 2
lettre2=find(alphabet=='g');; %lettre g
lettre2=find(alphabet=='g'); %lettre g
ind2=find(label_letter==lettre2);
n2=length(ind2);
y2=ones(n2,1);
......@@ -21,7 +21,7 @@ X=[x1;x2];
Y=[y1;y2];
%% validation croise
[xapp, yapp, xtest, ytest] = splitdata(X, Y, 3/4);
[xapp,xtest,meanxapp,stdxapp] = normalizemeanstd(xapp,xtest);
[xapp,xtest,meanxapp,stdxapp] = normalizemeanstd(xapp,xtest);%a mettre dans la boucle car on utilise des bouts de stats qu'on ne devrait pas
%[xapp, yapp, xval, yval] = splitdata(xapp, yapp, 2/3);
K=3 %nombre d'ensembles
meilleur_C=zeros(K,1)
......@@ -80,4 +80,12 @@ FN=numel(find(ypred(ind_moins1)~=ytest(ind_moins1)))
confusionmat(ytest,ypred)
%% Courbe d'intervale de confiance
load('letter_test.mat');
%%
%[xapp, yapp, xtest, ytest] = splitdata(X, Y, 3/4);
xapp=X;
yapp=Y;
......@@ -20,8 +20,15 @@ x2=data_letter(ind2,:);
X=[x1;x2];
Y=[y1;y2];
%% validation croise
[xapp, yapp, xtest, ytest] = splitdata(X, Y, 3/4);
[xapp,xtest,meanxapp,stdxapp] = normalizemeanstd(xapp,xtest);
load('letter_test.mat');
%%
%[xapp, yapp, xtest, ytest] = splitdata(X, Y, 3/4);
xapp=X;
yapp=Y;
[xapp,xtest,meanxapp,stdxapp] = normalizemeanstd(xapp,xtest);%a mettre dans la boucle car on utilise des bouts de stats qu'on ne devrait pas
%[xapp, yapp, xval, yval] = splitdata(xapp, yapp, 2/3);
K=3 %nombre d'ensembles
meilleur_C=zeros(K,1)
......@@ -80,4 +87,6 @@ FN=numel(find(ypred(ind_moins1)~=ytest(ind_moins1)))
confusionmat(ytest,ypred)
%% Courbe d'intervale de confiance
No preview for this file type
This diff is collapsed.
from django.test import TestCase
from django.test import Client
from django.urls import reverse
from django.contrib.auth.models import User
from django.core import mail
class URLAnonymeTest(TestCase):
def test_index(self):
response=self.client.get('/')
self.assertEqual(response.status_code,200)
def test_login(self):
response=self.client.get(reverse('login'))
self.assertEqual(response.status_code,200)
uri=reverse('garage:vehicule-list')
response=self.client.get(uri)
self.assertRedirects(response,'/accounts/login/?next=/vehicule/')
def test_logout(self):
response=self.client.get(reverse('logout'))
self.assertEqual(response.status_code,200)
uri=reverse('garage:vehicule-list')
response=self.client.get(uri)
self.assertRedirects(response,'/')
# Create your tests here.
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