help with the parameters

1 Ansicht (letzte 30 Tage)
dav
dav am 18 Jul. 2013
Hello,
Following is a code im using to estimate the parameters using the least absolute deviation using a program I found online.
However, my estimates are not accurate . they should both be equal to 0.1. Also is there a way to add a constraint that the parameters are positive?
Thanks.
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);
%{
Minimizing the sums of squares of errors is appropriate when
the noise in your model is normally distributed. Its not
uncommon to expect a normal error structure. But sometimes
we choose instead to minimize the sum of absolute errors.
How do we do this? Its a linear programming trick this time.
For each data point, we add a pair of unknowns called slack
variables. Thus
y(i) = a + b*x(i) + u(i) - v(i)
Here the scalars a and b, and the vectors u and v are all unknowns.
We will constrain both u(i) and v(i) to be non-negative. Solve
the linear programming system with equality constraints as
above, and the objective will be to minimize sum(u) + sum(v).
The total number of unknowns will be 2+2*n, where n is the
number of data points in our "regression" problem.
%}
len = length(y);
x = zeros(len,p);
for i = 1:p
x(1+i:len,i) = y(1:len-i,1);
end
% formulate the linear programming problem.
n = length(x);
% our objective sums both u and v, ignores the regression
% coefficients themselves.
f = [0 0 ones(1,2*n)]';
% a and b are unconstrained, u and v vectors must be positive.
LB = [-inf -inf , zeros(1,2*n)];
% no upper bounds at all.
UB = [];
% Build the regression problem as EQUALITY constraints, when
% the slack variables are included in the problem.
Aeq = [ones(n,1), x, eye(n,n), -eye(n,n)];
beq = y;
% estimation using linprog
params = linprog(f,[],[],Aeq,beq,LB,UB);
% we can now drop the slack variables
coef = params(1:2)

Antworten (0)

Kategorien

Mehr zu Linear Programming and Mixed-Integer Linear Programming finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by