smooth function

函数:

f(x)=||x||1

平滑近似:
fμ(x)=g(||x||1)=(||x||1)22μ||x||1μ20||x||1μμ||x||1

%% plot smoothed function and its original function
times = 2;

mu = 0.5; %精度控制参数:accuracy control parameter
step = 0.05; % 粒度

% first part
[X,Y] = meshgrid(-mu:step:mu);

X1 =reshape(X,[numel(X) 1]);
Y1 = reshape(Y,[numel(Y) 1]);

M = [X1 Y1];

f = sum(abs(M),2).^2 /(2*mu);
f = reshape(f,[size(X,1),size(X,2)]);
% l1 norm
f0 = sum(abs(M),2);
f0 = reshape(f0,[size(X,1),size(X,2)]);
%  second part
[X0,Y0] = meshgrid(mu:step:times*mu);


X2 =reshape(X0,[numel(X0) 1]);
Y2 = reshape(Y0,[numel(Y0) 1]);

M2 = [X2 Y2];
f2 = bsxfun(@minus,sum(abs(M2),2) ,mu/2);

f2 = reshape(f2,[size(X0,1),size(X0,2)]);

% third part

[X3,Y3] = meshgrid(-times*mu:step:-mu);


X4 =reshape(X3,[numel(X3) 1]);
Y4 = reshape(Y3,[numel(Y3) 1]);

M3 = [X4 Y4];
f3 = bsxfun(@minus,sum(abs(M3),2) ,mu/2);

f3 = reshape(f3,[size(X3,1),size(X3,2)]);

% forth part
tim = 2;
[X5,Y5] = meshgrid(-tim*mu:step:tim*mu);


X6 =reshape(X5,[numel(X5) 1]);
Y6 = reshape(Y5,[numel(Y5) 1]);

M4 = [X6 Y6];
f4 = bsxfun(@minus,sum(abs(M4),2) ,mu/2);

f4 = reshape(f4,[size(X5,1),size(X5,2)]);

figure(1);
subplot(2,2,1);
surf(X,Y,f);
hold on;
surf(X,Y,f0);
title('smoothed and its original');
%hold on;
% surf(X0,Y0,f2);
% hold on ;
% surf(X3,Y3,f3);
% hold on;
subplot(2,2,2);
surf(X5,Y5,f4);
title('original');
subplot(2,2,3);
surf(X,Y,f);
hold on;
surf(X5,Y5,f4);

subplot(2,2,4);
surf(X,Y,f0);
hold on;
% for point: [-1 -2],[-1 2] => val: 3

plot3(-0.1,-0.2,0.3,'.r','markersize',30);
plot3(-0.1,0.2,0.3,'.k','markersize',30);

这里写图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值