1. clear
  2. % http://www.peteryu.ca/tutorials/matlab/visualize_decision_boundaries
  3.  
  4. % load RankData
  5. % NumTrain =200;
  6.  
  7. load RankData2
  8.  
  9. % X = [X, -ones(size(X,1),1)];
  10.  
  11. lambda = 20;
  12. rho = 2;
  13. c1 =10;
  14. c2 =10;
  15. epsilon = 0.2;
  16. result=[];
  17. ker = 'linear';
  18. ker = 'rbf';
  19. sigma = 1/200;
  20.  
  21. method=4
  22. contour_level1 = [-epsilon,0, epsilon];
  23. contour_level2 = [-epsilon,0, epsilon];
  24. xrange = [-5 5];
  25. yrange = [-5 5];
  26. % step size for how finely you want to visualize the decision boundary.
  27. inc = 0.1;
  28. % generate grid coordinates. this will be the basis of the decision
  29. % boundary visualization.
  30. [x1, x2] = meshgrid(xrange(1):inc:xrange(2), yrange(1):inc:yrange(2));
  31. % size of the (x, y) image, which will also be the size of the
  32. % decision boundary image that is used as the plot background.
  33. image_size = size(x1)
  34.  
  35. xy = [x1(:) x2(:)]; % make (x,y) pairs as a bunch of row vectors.
  36. %xy = [reshape(x, image_size(1)*image_size(2),1) reshape(y, image_size(1)*image_size(2),1)]
  37.  
  38. % loop through each class and calculate distance measure for each (x,y)
  39. % from the class prototype.
  40.  
  41. % calculate the city block distance between every (x,y) pair and
  42. % the sample mean of the class.
  43. % the sum is over the columns to produce a distance for each (x,y)
  44. % pair.
  45.  
  46. switch method
  47. case 1
  48. par = NonLinearDualSVORIM(X, y, c1, c2, epsilon, rho, ker, sigma);
  49. f = TestPrecisionNonLinear(par,X, y,X, y, ker,epsilon,sigma);
  50. % set up the domain over which you want to visualize the decision
  51. % boundary
  52. d = [];
  53. for k=1:max(y)
  54. d(:,k) = decisionfun(xy, par, X,y,k,epsilon, ker,sigma)';
  55. end
  56. [~,idx] = min(abs(d)/par.normw{k},[],2);
  57. case 2
  58. par = NonLinearDualBoundSVORIM(X, y, c1, c2, epsilon, rho, ker, sigma);
  59. f = TestPrecisionNonLinear(par,X, y,X, y, ker,epsilon,sigma);
  60. % set up the domain over which you want to visualize the decision
  61. % boundary
  62. d = [];
  63. for k=1:max(y)
  64. d(:,k) = decisionfun(xy, par, X,y,k,epsilon, ker,sigma)';
  65. end
  66. [~,idx] = min(abs(d)/par.normw{k},[],2);
  67. contour_level=contour_level1;
  68. case 3
  69. % par = NewSVORIM(X, y, c1, c2, epsilon, rho);
  70. par = LinearDualSVORIM(X,y, c1, c2, epsilon, rho); % ADMM for linear dual model
  71. d = [];
  72. for k=1:max(y)
  73. w= par.w(:,k)';
  74. d(:,k) = w*xy'-par.b(k);
  75. end
  76. [~,idx] = min(abs(d)/norm(par.w),[],2);
  77. contour_level=contour_level1;
  78. case 4
  79. path='C:\Users\hd\Desktop\svorim\svorim\';
  80. name='RankData2';
  81. k=0;
  82. fname1 = strcat(path, name,'_train.', num2str(k));
  83. fname2 = strcat(path, name,'_targets.', num2str(k));
  84. fname2 = strcat(path, name,'_test.', num2str(k));
  85. Data=[X y];
  86. save(fname1,'Data','-ascii');
  87. save(fname2,'y','-ascii');
  88. save(fname2,'X','-ascii');
  89. command= strcat(path,'svorim -F 1 -Z 0 -Co 10 -p 0 -Ko 1 C:\Users\hd\Desktop\svorim\svorim\', name, '_train.', num2str(k));
  90. % command= 'C:\Users\hd\Desktop\svorim\svorim\svorim -F 1 -Z 0 -Co 10 C:\Users\hd\Desktop\svorim\svorim\RankData2_train.0';
  91. % 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'
  92. dos(command);
  93. fname2 = strcat(fname1, '.svm.alpha');
  94. alpha_bais = textread(fname2);
  95. r=length(unique(y));
  96. model.alpha=alpha_bais(1:end-r+1);
  97. model.b=alpha_bais(end-r+2:end);
  98. for k=1:r-1
  99. d(:,k)=model.alpha'*Kernel(ker,X',xy',sigma)- model.b(k);
  100. end
  101. pretarget=[];idx=[];
  102. for i=1:size(X,1)
  103. idx(i) = min([find(d(i,:)<0,1,'first'),length(model.b)+1]);
  104. end
  105. contour_level=contour_level2;
  106. end
  107.  
  108. % % reshape the idx (which contains the class label) into an image.
  109. % decisionmap = reshape(idx, image_size);
  110. %
  111. % figure(7);
  112.  
  113. % %show the image
  114. % imagesc(xrange,yrange,decisionmap);
  115. % hold on;
  116. % set(gca,'ydir','normal');
  117. %
  118. % % colormap for the classes:
  119. % % class 1 = light red, 2 = light green, 3 = light blue
  120. % cmap = [1 0.8 0.8; 0.95 1 0.95; 0.9 0.9 1];
  121. % colormap(cmap);
  122. %
  123. % imagesc(xrange,yrange,decisionmap);
  124.  
  125. % plot the class training data.
  126.  
  127. color = {'r.','go','b*','r.','go','b*'};
  128.  
  129. for i=1:max(y)
  130. plot(X(y==i,1),X(y==i,2), color{i});
  131. hold on
  132. end
  133. % include legend
  134. % legend('Class 1', 'Class 2', 'Class 3','Location','NorthOutside', ...
  135. % 'Orientation', 'horizontal');
  136. legend('Class 1', 'Class 2', 'Class 3');
  137. set(gca,'ydir','normal');
  138. hold on
  139. for k = 1:max(y)-1
  140. decisionmapk = reshape(d(:,k), image_size);
  141. contour(x1,x2, decisionmapk, [contour_level(1) contour_level(1) ], color{k},'Fill','off');
  142. contour(x1,x2, decisionmapk, [contour_level(2) contour_level(2) ], color{k},'Fill','off','LineWidth',2);
  143. contour(x1,x2, decisionmapk, [contour_level(3) contour_level(3) ], color{k},'Fill','off');
  144. % if k<max(y)
  145. % contour(x1,x2, decisionmap, [k+1 k+1], color{k},'Fill','off');
  146. % end
  147. end
  148.  
  149. hold off
  150. %
  151. % label the axes.
  152. xlabel('x1');
  153. 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. 10.Properties

    The common language runtime (CLR) offers two kinds of properties: 1.parameterless properties, which ...

  2. 用iconv指令解决utf8和gb18030编码间转换

    Linux显示在Windows编辑过的中文就会显示乱码是由于两个操作系统使用的编码不同所致.Linux下使用的编码是utf8,而Windows使用的是gb18030.  解决方案:  在终端中,进入到 ...

  3. C/C++内存泄漏及检测 转

    C/C++内存泄漏及检测 2011-02-20 17:51 by 吴秦, 30189 阅读, 13 评论, 收藏, 编辑 “该死系统存在内存泄漏问题”,项目中由于各方面因素,总是有人抱怨存在内存泄漏, ...

  4. SQL笔记(1)索引/触发器

    --创建聚集索引 create clustered index ix_tbl_test_DocDate on tbl_test(DocDate) GO --创建非聚集索引 create nonclus ...

  5. MYSQL中的SELECT查询时进行运算

    SELECT在mysql中是查询表中的数据的作用,但也可以在查询的时候直接进行运算,然后返回查询后的结果 比如 )) FROM username2 其中的IFNULL函数是对adven数据进行判断,若 ...

  6. bootstrap学习笔记<八>(bootstrap核心布局风格——栅格系统)

    栅格系统(bootstrap的核心之一,也是bootstrap的主要布局风格) 栅格系统是对原有div布局的升级版.打破了传统div模式只能纵向垂直排列的弊端,大大提高了页面布局的速度和效果,也很好的 ...

  7. (五)Super VLAN

  8. Gas Station

    Description: There are N gas stations along a circular route, where the amount of gas at station i i ...

  9. centos JDK安装

    第一步:查看Linux自带的JDK是否已安装 (卸载centOS已安装的1.4) 安装好的CentOS会自带OpenJdk,用命令 java -version ,会有下面的信息: java versi ...

  10. 教你开启红米的USB大容量存储选项,全网首发哦

    教你开启红米的USB大容量存储选项,全网首发哦 http://bbs.7to.cn/thread-10732-1-1.html 发表于 2014-4-29 110643 红米note入手也有两天了.各 ...