이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
Hi,
Is the a way to do parameter estimation using Least Absolute deviation with constraints in matlab.
If so, please let me know of a place to read about it.
thanks.
채택된 답변
Matt J
2013년 7월 2일
If you are talking about the problem
min_x sum( abs(r(x)))
it is equivalent to
min_{x,d} sum(d)
s.t.
r(x) <=d
-r(x)<=d
The above formulation is differentiable if r(x) is differentiable, so FMINCON can handle it. You can obviously add any additional constraints you wish, so long as they too are differentiable.
댓글 수: 14
Hi,
Thanks for your answer.
I have a dataset yt (all positive - size (100,1)). I need to fit a straight line to this data with the constraints that intercept parameter is greater than zero and slope parameter is between 0 1nd 1.
Could you please help me with this code? It is a little difficult to figure it out using your answer.
Thanks much!
So, the problem is as follows?
min.
f(m,b) = sum( abs(yi-m*xi-b))
s.t.
b>=0
0<=m<=1
yes, but
b > 0
0<= m < 1
Thanks.
You cannot impose strict inequality constraints. The minimum can be ill-defined, for example in the minimization of f(a)=a^2 over a>0. If a=0 is not allowed, then what do you consider the minimizing point?
Thanks. can I have something like a >0.00000001. Would you please help me with the code ?
dav
2013년 7월 2일
I can provide the code which generates the data. but I dont know how to estimate it?
dav
2013년 7월 2일
The data set is yt.
clc;
clear;
T = 300;
a0 = 0.1; a1 = 0.4;
ra = zeros(T+2000,1);
seed=123;
rng(seed);
ra = trnd(5,T+2000,1);
ytn = [];
epsi=zeros(T+2000,1);
simsig=zeros(T+2000,1);
unvar = a0/(1-a1);
for i = 1:T+2000
if (i==1)
simsig(i) = unvar;
s=(simsig(i))^0.5;
epsi(i) = ra(i) * s;
else
simsig(i) = a0+ a1*(epsi(i-1))^2;
s=(simsig(i))^0.5;
epsi(i) = ra(i)* s;
end
end
epsi2 = epsi.^2;
yt = epsi2(2001:T+2000);
I don't understand your code, but here's an example for you to study
%%Fake data
xi=0:10;
yi=2*xi+bt+randn(size(xi))/2;
%%Linprog parameters
N=length(xi);
e=ones(N,1);
f=[0,0,e.'];
A=[xi(:),e,-speye(N);-xi(:), -e, -speye(N)];
b=[yi(:);-yi(:)];
lb=zeros(N+2,1);
ub=inf(N+2,1); ub(1)=1;
%%Perform fit and test
p=linprog(f,A,b,[],[],lb,ub);
slope=p(1),
intercept=p(2),
yf=slope*xi+intercept;
plot(xi,yi,xi,yf)
Thank you very much
Could you please explain the following codes
f=[0,0,e.'];
A=[xi(:),e,-speye(N);-xi(:), -e, -speye(N)];
b=[yi(:);-yi(:)];
and also bt in yi=2*xi+bt+randn(size(xi))/2;
thanks
Recall that the reformulation of the problem requires additional constraints
r(x) <=d
-r(x)<=d
where r(x) is your residual. The A,b pair that you've cited is the implementation of these additional constraints. bt is the true intercept of the simulated line data, yi. You can choose any value for it that you want, for simulation purposes, and see if the p(2) returned by linprog ends up being a good estimate of it.
dav
2013년 7월 18일
is it possible to add the constraint that the parameter estimates should be positive here?
Matt J
2013년 7월 18일
Not sure what you mean by "add". I already put positivity constraints in my example using the lb input argument to linprog. Similarly, I used ub to impose the upper bounds you originally mentioned.
thank you.
I used your code to test the data set I have. BOTH parameter estimates should be 0.1. However, the estimates I get using your code are very different. is there a way to fix it. From a standard theory I know that when you regress the y vector I have mentioned on the x vector I should get parameters, both equal to 0.1
clc;
clear;
p=1;
T = 300;
a0 = 0.1; a1 = 0.1;
seed=123;
ra = randn(T+2000,1);
epsi=zeros(T+2000,1);
simsig=zeros(T+2000,1);
unvar = a0/(1-a1);
for i = 1:T+2000
if (i==1)
simsig(i) = unvar;
s=(simsig(i))^0.5;
epsi(i) = ra(i) * s;
else
simsig(i) = a0+ a1*(epsi(i-1))^2;
s=(simsig(i))^0.5;
epsi(i) = ra(i)* s;
end
end
epsi2 = epsi.^2;
y = epsi2(2001:T+2000); % THIS IS THE DATA SET I WANT TO TEST.
len = length(y);
x = zeros(len,p);
for i = 1:p
x(1+i:len,i) = y(1:len-i,1); % THIS IS THE x VECTOR
end
N=length(x);
e=ones(N,1);
f=[0,0,e.'];
A=[x(:),e,-speye(N);-x(:), -e, -speye(N)];
b=[y(:);-y(:)];
lb=zeros(N+2,1);
ub=inf(N+2,1); ub(1)=1;
%%Perform fit and test
p=linprog(f,A,b,[],[],lb,ub);
slope=p(1),
intercept=p(2),
All I can say is that I tested the example code I gave you. It worked fine for me and produced accurate estimates.
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Linear Programming and Mixed-Integer Linear Programming에 대해 자세히 알아보기
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
