This is a follow up to my previous question posted here
I want to define an absolute error loss function of the following form
% Loss Function (absolute error loss)
%% input curves
scale = 1.5;
x1 = [0,4,6,10,15,20]*scale;
y1 = [18,17.5,13,12,8,10];
x2 = [0,10.5,28]*scale;
y2= [18.2,10.6,10.3];
%% y2 is the target function and y1 is the function to be shifted
f = y1;
g = interp1(x2,y2,x1);
%% linprog inputs
% x = linprog(f,A,b)
% i = 1:length(x1)
A = [fi - 1; -fi -1];
x = [a ui];
b = [gi -gi];
% obj = sum_i u_i (function to minimize)
%% solve system
I am not sure how to set this up and solve this sytem in MATLAB's linprog
Could someone please help?

 채택된 답변

Torsten
Torsten 2022년 7월 7일
편집: Torsten 2022년 7월 7일

1 개 추천

I think the whole procedure only makes sense if x1 is a subset of x2, but here we go:
scale = 1.5;
x1 = [0,4,6,10,15,20]*scale;
y1 = [18,17.5,13,12,8,10];
x2 = [0,10.5,28]*scale;
y2= [18.2,10.6,10.3];
%% y2 is the target function and y1 is the function to be shifted
f = y1;
g = interp1(x2,y2,x1);
ff = [0,ones(size(x1))];
A = [f.',-eye(numel(x1));-f.',-eye(numel(x1))];
b = [g.',-g.'];
sol = linprog(ff,A,b);
Optimal solution found.
a = sol(1)
a = 1.0111
% Compare with least-squares solution
a2 = sum(f.*g)/sum(f.^2)
a2 = 0.9895
And the next step is
min: max_i ( abs( a*f_i - g_i ) )
? :-)

댓글 수: 3

Deepa Maheshvare
Deepa Maheshvare 2022년 7월 7일
편집: Deepa Maheshvare 2022년 7월 7일
Thanks a lot, could you please explain a bit on ff = [0,ones(size(x1))]. I could understand how A is defined but the values defined for `ff` is not clear to me.
I think objective function is ff^Tx and x = [a u1 u2 u3 u4 u5 u6 u1 u2 u3 u4 u5 u6]. I also fail to understand why ff is [0, ones(size(x1))] and not [0 ones(2*size(x1))]. Is x just [a u1 u2 u3 u4 u5 u6] ?
Then ff^T*x yields sum_i ui.
min: max_i ( abs( a*f_i - g_i ) )
sorry, could not understand what you are pointing to.
Is x just [a u1 u2 u3 u4 u5 u6] ?
Yes.
Then ff^T*x yields sum_i ui.
Yes.
min: max_i ( abs( a*f_i - g_i ) )
sorry, could not understand what you are pointing to.
Besides the two norms you used until now, you can try as a third approach to find "a" that minimizes the maximal deviation of a*f from g:
min: max_i ( abs (a*f_i - g_i) )
Was just a joke :-)
Deepa Maheshvare
Deepa Maheshvare 2022년 7월 7일
:-)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

제품

릴리스

R2021a

질문:

2022년 7월 7일

댓글:

2022년 7월 7일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by