Documente Academic
Documente Profesional
Documente Cultură
t = 0:0.1:10;
%t = 0:0.1:20;
x = 2*sin(10*t)+0.5*t.^2+4;
x = 2*sin(10*t)+0.5*t+4;
%x = 2*rand(size(t))+0.5*t+4;
x = (x - min(x)) / (max(x) - min(x));
x = x';
data = x(1:end-1);
dataLabels = x(2:end);
trainDataLength = round(length(data)*70/100);
TrainingSet = data(1:trainDataLength);
TrainingSetLabels = dataLabels(1:trainDataLength);
TestSet = data(trainDataLength+1:end);
TestSetLabels = dataLabels(trainDataLength+1:end);
figure('color','w');
plot(t(1:length(TrainingSetLabels)), TrainingSetLabels,
'-b');
f2=figure('color','w');
plot(t(1:length(TrainingSetLabels)), TrainingSetLabels,
'-b');
hold on;
plot(t(1:length(TrainingSetLabels)), predicted_label, '-
r');
hold on;
f3=figure('color','w');
plot(TrainingSet,TrainingSetLabels,'b.')
hold on;plot(TrainingSet,predicted_label,'r.')
[predicted_label, accuracy, decision_values] =
svmpredict(TestSetLabels, TestSet, model);
figure(f2)
plot(t(length(TrainingSetLabels)+1:end-1), TestSetLabels,
'-k');
hold on;
plot(t(length(TrainingSetLabels)+1:end-1),
predicted_label, '-m');
hold off;
xlim([min(t),max(t)])
figure(f3)
hold on;
plot(TestSet,TestSetLabels,'k.')
hold on;plot(TestSet,predicted_label,'m.')
%%
%% 2-D
t = 0:0.1:10;
%t = 0:0.1:20;
x = 2*sin(10*t)+0.5*t.^2+4;
x = 2*sin(10*t)+0.5*t+4;
figure('color','w');
plot(t(1:length(TrainingSetLabels)), TrainingSetLabels,
'-b');
f2=figure('color','w');
plot(t(1:length(TrainingSetLabels)), TrainingSetLabels,
'-b');
hold on;
plot(t(1:length(TrainingSetLabels)), predicted_label, '-
r');
hold on;
f3=figure('color','w');
plot(TrainingSet,TrainingSetLabels,'b.')
hold on;plot(TrainingSet,predicted_label,'r.')
figure(f3)
hold on;
plot(TestSet,TestSetLabels,'k.')
hold on;plot(TestSet,predicted_label,'m.')
return;
N = 1000;
M = 1;
t = randn(N,1);
clear r
m = 1:10:100;
for M = m
x = [t];
for ii=1:M-1
x = [x t+ii*randn(N,1)/2];
end
x = normalize(x);
% t1 = randn(N,1);
% t2 = randn(N,1);
% x = [t1 t2];
% y = 3*t1 - 5*t2;
y = 2*t + randn(N,1)/2 + 7;
% corrcoef([x y]);
%
% b= glmfit(x,y);
for ii = 1
for jj=1
tic;model = svmtrain(y(1:N/2),x(1:N/2,:),['-s 4 -
t 2 -n ' num2str(ii/2) ' -c ' num2str(1)]);toc
tic;zz=svmpredict(y(N/2+1:end),x(N/2+1:end,:),model);toc
tmp = corrcoef(zz, y(N/2+1:end));
r(1+(M-1)/10) = tmp(2);
end
end
end
w = model.SVs' * model.sv_coef
b = -model.rho