画图代码

clear
% http://www.peteryu.ca/tutorials/matlab/visualize_decision_boundaries % load RankData
% NumTrain =200; load RankData2 % X = [X, -ones(size(X,1),1)]; lambda = 20;
rho = 2;
c1 =10;
c2 =10;
epsilon = 0.2;
result=[];
ker = 'linear';
ker = 'rbf';
sigma = 1/1000;
method=5
contour_level1 = [-epsilon,0, epsilon];
contour_level2 = [-epsilon,0, epsilon];
xrange = [-5 5];
yrange = [-5 5];
% step size for how finely you want to visualize the decision boundary.
inc = 0.01;
% generate grid coordinates. this will be the basis of the decision
% boundary visualization.
[x1, x2] = meshgrid(xrange(1):inc:xrange(2), yrange(1):inc:yrange(2));
% size of the (x, y) image, which will also be the size of the
% decision boundary image that is used as the plot background.
image_size = size(x1) xy = [x1(:) x2(:)]; % make (x,y) pairs as a bunch of row vectors.
%xy = [reshape(x, image_size(1)*image_size(2),1) reshape(y, image_size(1)*image_size(2),1)] % loop through each class and calculate distance measure for each (x,y)
% from the class prototype. % calculate the city block distance between every (x,y) pair and
% the sample mean of the class.
% the sum is over the columns to produce a distance for each (x,y)
% pair. switch method
case 1
par = ParNonLinearDualSVORIM(X, y, c1, c2, epsilon, rho, ker, sigma);
f = TestPrecisionNonLinear(par,X, y,X, y, ker,epsilon,sigma);
% set up the domain over which you want to visualize the decision
% boundary
d = [];
for k=1:max(y)
d(:,k) = decisionfun(xy, par, X,y,k,epsilon, ker,sigma)';
end
[~,idx] = min(abs(d)/par.normw{k},[],2);
contour_level=contour_level1;
case 2
par = ParNonLinearDualBoundSVORIM(X, y, c1, c2, epsilon, rho, ker, sigma);
f = TestPrecisionNonLinear(par,X, y,X, y, ker,epsilon,sigma);
% set up the domain over which you want to visualize the decision
% boundary
d = [];
for k=1:max(y)
d(:,k) = decisionfun(xy, par, X,y,k,epsilon, ker,sigma)';
end
[~,idx] = min(abs(d)/par.normw{k},[],2);
contour_level=contour_level1;
case 3
% par = NewSVORIM(X, y, c1, c2, epsilon, rho);
par = LinearDualSVORIM(X,y, c1, c2, epsilon, rho); % ADMM for linear dual model
d = [];
for k=1:max(y)
w= par.w(:,k)';
d(:,k) = w*xy'-par.b(k);
end
[~,idx] = min(abs(d)/norm(par.w),[],2);
contour_level=contour_level1;
case 4
path='C:\Users\hd\Desktop\svorim\svorim\';
name='RankData2';
k=0;
fname1 = strcat(path, name,'_train.', num2str(k));
fname2 = strcat(path, name,'_targets.', num2str(k));
fname2 = strcat(path, name,'_test.', num2str(k));
Data=[X y];
save(fname1,'Data','-ascii');
save(fname2,'y','-ascii');
save(fname2,'X','-ascii');
command= strcat(path,'svorim -F 1 -Z 0 -Co 10 -p 0 -Ko 1/10 C:\Users\hd\Desktop\svorim\svorim\', name, '_train.', num2str(k));
% command= 'C:\Users\hd\Desktop\svorim\svorim\svorim -F 1 -Z 0 -Co 10 C:\Users\hd\Desktop\svorim\svorim\RankData2_train.0';
% command='C:\Users\hd\Desktop\svorim\svorim\svorim -F 1 -Z 0 -Co 10 G:\datasets-orreview\discretized-regression\5bins\X4058\matlab\mytask_train.0'
dos(command);
fname2 = strcat(fname1, '.svm.alpha');
alpha_bais = textread(fname2);
r=length(unique(y));
model.alpha=alpha_bais(1:end-r+1);
model.b=alpha_bais(end-r+2:end);
xnew=xy;
nT=size(xnew,1);
for k=1:r-1
% d(:,k)=model.alpha'*Kernel(ker,X',xy',sigma)- model.b(k);
if nT >1000
for j=1:nT/1000
xnewk=xnew(1000*(j-1)+1:1000*j,:);
f(1000*(j-1)+1:1000*j) = model.alpha'*Kernel(ker,X',xnewk',sigma)- model.b(k);
end
xnewk=xnew(1000*j+1:nT,:);
f(1000*j+1:nT)=model.alpha'*Kernel(ker,X',xnewk',sigma)- model.b(k);
else
f =model.alpha'*Kernel(ker,X',xnew',sigma)- model.b(k);
end
d(:,k)=f;
end pretarget=[];idx=[];
for i=1:size(xy,1)
idx(i) = min([find(d(i,:)<0,1,'first'),length(model.b)+1]);
end
contour_level=contour_level2;
case 5
train.patterns =X;
train.targets = y;
test.patterns =xy;
test.targets = ones(size(xy,1),1);
switch ker
case 'linear'
parameters=[c1];
Algorithm = SVOREXLin();
Title='SVORLin(c=10)';
case 'rbf'
parameters=[c1 sigma];
Algorithm = SVORIM();
Title='SVORIM(\gamma=1/1000)';
end
[model_information] = Algorithm.runAlgorithm(train, test, parameters); % r=length(unique(y));
% model.alpha=model_information.model.projection';
% model.b=model_information.model.thresholds;
% xnew=xy;
% nT=size(xnew,1);
% for k=1:r-1
% % d(:,k)=model.alpha'*Kernel(ker,X',xy',sigma)- model.b(k);
% if nT >1000
% for j=1:nT/1000
% xnewk=xnew(1000*(j-1)+1:1000*j,:);
% f(1000*(j-1)+1:1000*j) = model.alpha'*Kernel(ker,X',xnewk',sigma)- model.b(k);
% end
% xnewk=xnew(1000*j+1:nT,:);
% f(1000*j+1:nT)=model.alpha'*Kernel(ker,X',xnewk',sigma)- model.b(k);
% else
% f =model.alpha'*Kernel(ker,X',xnew',sigma)- model.b(k);
% end
% d(:,k)=f;
% end
%
% pretarget=[];idx=[];
% for i=1:size(xy,1)
% idx(i) = min([find(d(i,:)<0,1,'first'),length(model.b)+1]);
% end
idx=model_information.predictedTest;
contour_level=contour_level2;
MZE =1- mean(model_information.predictedTrain==y);
MAE= mean(abs(model_information.predictedTrain-y));
Title = [Title 'MZE=' num2str(MZE) 'MAE=' num2str(MAE)]; case 6
train.patterns =X;
train.targets = y;
test.patterns =xy;
test.targets = ones(size(xy,1),1);
switch ker
case 'linear'
parameters=[c1];
Algorithm = SVORLin();
Title='REDSVMLin(c=10)';
case 'rbf'
parameters=[c1 sigma];
Algorithm = REDSVM();
Title='REDSVM(\gamma=1/1000)';
end
[model_information] = Algorithm.runAlgorithm(train, test, parameters);
idx=model_information.predictedTest;
contour_level=contour_level2;
MZE =1- mean(model_information.predictedTrain==y);
MAE= mean(abs(model_information.predictedTrain-y));
Title = [Title 'MZE=' num2str(MZE) 'MAE=' num2str(MAE)];
end % reshape the idx (which contains the class label) into an image.
decisionmap = reshape(idx, image_size); % figure(7);
%
% %show the image
% imagesc(xrange,yrange,decisionmap);
% hold on;
% set(gca,'ydir','normal');
%
% % colormap for the classes:
% % class 1 = light red, 2 = light green, 3 = light blue
% cmap = [1 0.8 0.8; 0.95 1 0.95; 0.9 0.9 1];
% colormap cool;
%
% imagesc(xrange,yrange,decisionmap); % plot the class training data. color = {'r.','go','b*','r.','go','b*'}; for i=1:max(y)
plot(X(y==i,1),X(y==i,2), color{i});
hold on
end
% include legend
% legend('Class 1', 'Class 2', 'Class 3','Location','NorthOutside', ...
% 'Orientation', 'horizontal');
legend('Class 1', 'Class 2', 'Class 3');
set(gca,'ydir','normal');
hold on
for k = 1:max(y)-1
% decisionmapk = reshape(d(:,k), image_size);
% contour(x1,x2, decisionmapk, [contour_level(1) contour_level(1) ], color{k},'Fill','off');
% contour(x1,x2, decisionmapk, [contour_level(2) contour_level(2) ], color{k},'Fill','off','LineWidth',2);
% contour(x1,x2, decisionmapk, [contour_level(3) contour_level(3) ], color{k},'Fill','off');
if k<max(y)
contour(x1,x2, decisionmap, [k+1 k+1], color{k},'Fill','off','LineWidth',2);
end
end hold off
%
% label the axes.
xlabel('x1');
ylabel('x2');
title(Title)

MATLAB画图的更多相关文章

  1. Matlab画图,坐标轴范围设置和间隔设置

    在Matlab画图的时候,系统默认的坐标轴范围以及间隔有时候并不是很合适,如何根据自己的要求来显示呢,Set语句就可以帮忙咯!! 1. set(gca,'xtick',0:100:2500)      ...

  2. Matlab画图-非常具体,非常全面

    Matlab画图 强大的画图功能是Matlab的特点之中的一个,Matlab提供了一系列的画图函数,用户不须要过多的考虑画图的细节,仅仅须要给出一些基本參数就能得到所需图形,这类函数称为高层画图函数. ...

  3. 设置 matlab 画图格式

    1:设置 matlab 画图格式 clear;clc; % load("array.mat"); % Bestallarray=array; % rllofcircle(Besta ...

  4. 如何解决 Matlab 画图时中文显示乱码的问题?

    使用的是win10系统,从前几个月某一天,我的matlab的figure里的中文都变成了口口.很是郁闷,还以为是动到了什么配置引起的. 前几天更新了matlab 2018b,发现还有这个问题.就觉得不 ...

  5. matlab 画图进阶

    matlab 画图进阶 applications of matlab in engineering 图表类型的选择 first:advanced 2d plots special plots logl ...

  6. matlab 画图技巧

    基本画图工具:matlab 画图中线型及颜色设置 matlab中坐标轴设置技巧 **Matlab中的坐标轴设置技巧**    axisoff;      %去掉坐标轴  axistight;      ...

  7. 20140513 matlab画图

    1.matlab画图 x1=[1.00E-06,2.00E-06,4.00E-06,9.00E-06,2.00E-05,4.00E-05,8.00E-05,2.00E-04,4.00E-04,7.00 ...

  8. matlab画图函数plot()/set/legend

    简单plot()/legend/XY轴范围axis 除了坐标轴信息外还可以添加其它的信息,如所画曲线的信息等:测试代码如下 x=0:pi/20:2*pi; y1=sin(x); y2=cos(x); ...

  9. linux tomcat部署含有matlab画图打包的java web程序

    首先说下问题:matlab可以把相关算法代码打包成jar文件共java调用,本例使用的jar文件的作用是画图并保存,然后部署在linux的tomcat中进行发布.这里出现了一个问题,具体如下:linu ...

随机推荐

  1. 青岛理工大学第五届ACM交流赛 部分题解

    A:后缀维护si*pi的最小值,查询的时候二分,判断后缀和当前两个部分就行. #include <bits/stdc++.h> using namespace std; typedef l ...

  2. [HDOJ3308]LCIS(线段树,区间合并)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3308 题意:给定n个数,两个操作: U A B:将位置A的数值改成B Q A B:查询[A,B]内最长 ...

  3. 设置三思LED的IP地址跟端口号

    出厂设置是:202.11.11.01 初始端口号是:2929 设置虚拟机的ip跟LED的ip在一个网段上,在虚拟机上telnet命令,登陆到LED上面. 在/etc/init.d/rcS文件中, #! ...

  4. Intellij IDEA中使用Struts2

    据说struts2中有很多的漏洞, 不过作为学习我也就用了吧, 因为书上面是按着这个讲的呀. 难怪官网上也没有struts2.2.1的版本的下载. 1. 下载struts2.2.1 ga版本 2. 新 ...

  5. scala中如何编写自定义的流程控制结构

    scala是一种函数式编程风格的语言,除了常见的if......else  ,for ,while等传统的流程控制结构,也可以自定义流程控制的控制结构. 再了解scala如何实现编写新的流程结构,我们 ...

  6. NYOJ214

    单调递增子序列(二) 时间限制:1000 ms  |  内存限制:65535 KB 难度:4   描述 给定一整型数列{a1,a2...,an}(0<n<=100000),找出单调递增最长 ...

  7. SQL HAVING语句

    HAVING 子句 在 SQL 中增加 HAVING 子句原因是,WHERE 关键字无法与合计函数一起使用. SQL HAVING 语法 SELECT column_name, aggregate_f ...

  8. iOS - Sign up/in 注册/登录

    1.Sign up/in 1.1 用户登录安全原则 不能在网络上传输用户隐私数据的明文. 不能在本地和服务器上存储用户隐私数据的明文. 1.2 用户登录流程 登录成功之后,应该跳转视图控制器到主页. ...

  9. Linux下查看文件权限、修改文件权限的方法

    查看权限命令查看目录的相关权限可以采用命令ls -lD,或者直接用ls -la 如 ls -l www.jb51.net  //这里表示查看www.jb51.net目录 修改权限命令 chmod 77 ...

  10. Android提高篇之自定义dialog实现processDialog“正在加载”效果、使用Animation实现图片旋转

     知识点: 1.使用imageview.textview自定义dialog 2.使用Animation实现图片旋转动画效果 3.通过自定义theme去掉dialog的title 没有使用progres ...