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/200; method=4
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.1;
% 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 = NonLinearDualSVORIM(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);
case 2
par = NonLinearDualBoundSVORIM(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 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);
for k=1:r-1
d(:,k)=model.alpha'*Kernel(ker,X',xy',sigma)- model.b(k);
end
pretarget=[];idx=[];
for i=1:size(X,1)
idx(i) = min([find(d(i,:)<0,1,'first'),length(model.b)+1]);
end
contour_level=contour_level2;
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(cmap);
%
% 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');
% end
end hold off
%
% label the axes.
xlabel('x1');
ylabel('x2');

  这里执行的是chu wei的支持向量顺序回归机模型SVORIM

在matlab中执行dos环境中命令,并其读取结果画图的更多相关文章

  1. appium自动化测试框架——在python脚本中执行dos命令

    一般我们运行dos命令,会有两种需求,一种是需要收集执行结果,如ip.device等:一种是不需要收集结果,如杀死或开启某个服务. 对应的在python中就要封装两种方法,来分别实现这两种需求. 1. ...

  2. C#中执行Dos命令

    //dosCommand Dos命令语句 public string Execute(string dosCommand) { ); } /// <summary> /// 执行DOS命令 ...

  3. 【Windows】Windows中解析DOS的for命令使用

    目录结构: contents structure [+] 简介 for /d ... in ... 案例 案例:打印C://根目录下所有的文件夹名称 案例:打印当前路径下,只有1-3个字母的文件夹名 ...

  4. pycharm中在andconda环境中配置pyqt环境

    一般在andconda环境中,自带pyqt5 在pip install pyqt5之后,需要安装pyqt5_tools. 对于pycharm需要配置pyqt Designer和pyqt UIC. De ...

  5. 在airflow的BashOperator中执行docker容器中的脚本容易忽略的问题

    dag模板 from airflow import DAG from airflow.operators.bash_operator import BashOperator from airflow. ...

  6. 在c++程序中执行DOS命令

    转自博客:http://blog.csdn.net/ypist/article/details/8485049 #1,system()方式 在C盘根目录下新建文件夹,名称为12: system(&qu ...

  7. 【Windows】Windows中解析DOS的DIR命令使用

    总结一下cmd中的dir命令的用法 64位win10系统上,打印帮助文档. D:\test>dir /? 显示目录中的文件和子目录列表. DIR [drive:][path][filename] ...

  8. linux中执行java或者mvn命令提示没有权限解决办法

    $ chmod a+x /var/jenkins_home/jdk1.8.0_191/bin/java $ chmod a+x /var/jenkins_home/apache-maven-3.3.9 ...

  9. 在vim中执行外部命令

    11.7.5  在Vim编辑器中执行Shell命令 有时需要在Vim编辑器中执行Shell命令,例如需要验证一个Shell命令是否正确,以便写入脚本中:需要在文件中引用某个Shell命令的输入等.本小 ...

随机推荐

  1. Servlet&jsp基础:第二部分

    声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...

  2. CUBRID学习笔记 24 数据类型1

    ---恢复内容开始--- 一 数字类型  注意小数的四舍五入问题 1数字型 Type Bytes Mix Max Exact/approx. SHORTSMALLINT 2 -32,768 32,76 ...

  3. jQuery的domReady

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  4. c point

    a[i] 与 *(a+i) 是等价的. 事实上在计算a[i]的值时,c语言首先将前者转换为后者形式, 而且,通常而言,用指针编写的程序要比用数组下标编写的程序执行速度快,(为什么?) 因此,应该尽量用 ...

  5. [转载] 每个 Python 程序员都要知道的日志实践

    原文: http://python.jobbole.com/81666/ 在现实生活中,记录日志非常重要.银行转账时会有转账记录:飞机飞行过程中,会有黑盒子(飞行数据记录器)记录飞行过程中的一切.如果 ...

  6. ecnu1624求交集多边形面积

    链接 本来在刷hdu的一道题..一直没过,看到谈论区发现有凹的,我这种方法只能过凸多边形的相交面积.. 就找来这道题试下水. 两个凸多边形相交的部分要么没有 要么也是凸多边形,那就可以把这部分单独拿出 ...

  7. mysql 特殊字符

    1.倒引号,比如表中有一个字段为desc,在mysql中desc是关键字,如何表明desc是字段呢? 有两种办法:desc使用倒引号引起来,或者在desc前面加上表名,如下:mysql> sel ...

  8. numpy库的常用知识

    为什么有numpy这个库呢?准安装的Python中用列表(list)保存一组值,可以用来当作数组使用,不过由于列表的元素可以是任何对象,因此列表中所保存的是对象的指针.这样为了保存一个简单的[1,2, ...

  9. 【Todo】OSGi学习

    经常听到.见到OSGi这个名字.那么就单开一篇文章记录一下对OSGi的学习吧. 主要是做一些概念上面的学习.暂时不打算深入实践. 主要参考:http://www.osgi.com.cn/article ...

  10. eclipse_中的注释_快捷键

    eclipse 中的注释 快捷键   把要注释的代码选中,按Ctrl+Shift+/ /* */ 形式的 ctrl+/ //形式的 取消代码注释: 把要注释的代码选中,按Ctrl+Shift+\ /* ...