该用户从未签到
新手上路
![Rank: 1](static/image/common/star_level1.gif)
- 积分
- 25
- 极客币
- 85
- 主题
- 24
- 帖子
- 40
- 注册时间
- 2018-10-22
- 在线时间
- 3 小时
- 性别
- 保密
|
![](static/image/common/ico_lz.png)
楼主 |
发表于 2018-11-20 10:40:29
|
显示全部楼层
您好,前辈!
我最主要的问题集中在polynomial核与sigmoid核上,
poly核:y_poly = (a0*<x,x'> + c0)^n = (a0*x^T*x' + c0)^n;
sigmoid核:y_sig = tanh(a1*<x,x'> + c1) = tanh(a1*x^T*x' + c1);
像高斯核,我们都知道,y = exp(-c*||x - x'||^2),令x'=0时我们可以画出来y关于x的变化曲线,是一个钟形。
但是像上面两个poly核与sigmoid核,我也想画出y关于x的变化曲线,但就是不知道如何来画?
非常希望您能指导我一下!
- clc;clear;clf;
- x = -10:0.1:10;
- N = size(x,2);
- %% 1 polynomial kernel
- n = 2;
- a2 = 1;
- c2 = 0;
- for i = 1:N
- y_poly1(i) = (a2*x(i) + c2)^n;
- end
- for i = 1:N
- y_poly2(i) = (a2*x(i) + c2)^3;
- end
- %% 2 sigmoid kernel
- % for i = 1:N
- % y_sig2(i) = 1/(1+exp(-distance(i)));
- % end
- a1 =1;
- c1 = 0; %control the center
- for i = 1:N
- y_sig(i) = tanh(a1*x(i) + c1);
- end
- %% 3 Gaussian kernel
- sigma1 = 2;
- for i = 1:N
- y_gau(i) = exp(-norm(x(i))^2/(2*sigma1^2));
- end
- figure(1);
- plot(x,y_poly1,'c','linewidth',1.5);
- hold on
- plot(x,y_poly2,'c--','linewidth',1.5);
- hold on
- plot(x,y_sig,'g','linewidth',1.5);
- hold on
- plot(x,y_gau,'b','linewidth',1.5);
- hold off
- h=legend('Polynomial,n=2','Polynomial,n=3','Sigmoid','Gaussian');
- set(h,'FontName','Times New Roman','FontSize',16);
- set(gca,'YLim',[-3 3]);
- set(gca,'linewidth',1.5,'FontName','Times New Roman','FontSize',20);
- xlabel('x','FontName','Times New Roman','FontSize',20);
- ylabel('','FontName','Times New Roman','FontSize',16);
[color=rgb(51, 102, 153) !important]复制代码
|
|