0

How do I properly constrain this minimizing function? Mincvf(cvf1) should minimize cvf1 with respect to h and I want to set so that h>=0.4

proc iml;

EDIT kirjasto.basfraaka var "open";

read all var "open" into cp;
p=cp[1:150];

conh={0.4 . .,. . .,. . .};

m=nrow(p);
m2=38;
pi=constant("pi");
e=constant("e");


start Kmod(x,h,pi,e);
k=1/(h#(2#pi)##(1/2))#e##(-x##2/(2#h##2));
return (k);
finish;


start mhatx2 (m2,newp,h,pi,e);
t5=j(m2,1);                   /*mhatx omit x=t*/
do x=1 to m2;
i=T(1:m2);
temp1=x-i;
ue=Kmod(temp1,h,pi,e)#newp[i];
le=Kmod(temp1,h,pi,e);
t5[x]=(sum(ue)-ue[x])/(sum(le)-le[x]);
end;
return (t5);
finish;

Start CVF1(h) global (newp,pi,e,m2);
cv3=j(m2,1);                                            
cv3=1/m2#sum((newp-mhatx2(m2,newp,h,pi,e))##2);
return(cv3);
finish;


start mincvf(CVF1);
optn={0,0};
init=1;
call nlpqn(rc, res,"CVF1",init) blc="conh";
return (res);
finish;


start outer(p,m) global(newp);
wl=38;    /*window length*/
m1=m-wl;    /*last window begins at m-wl*/
newp=j(wl,1);
hyi=j(m1,1);
do x=1 to m1;
we=x+wl-1;             /*window end*/
w=T(x:we);            /*window*/
newp=p[w];
hyi[x]=mincvf(CVF1);
end;
return (hyi);
finish;


wl=38;    /*window length*/
m1=m-wl;    /*last window begins at m-wl*/

time=T(1:m1);

ttt=j(m1,1);
ttt=outer(p,m);
print time ttt p;

However I get lots of:

WARNING: Division by zero, result set to missing value.

 count     : number of occurrences is 2
 operation : / at line 1622 column 22
 operands  : _TEM1003, _TEM1006

_TEM1003      1 row       1 col     (numeric)

         .

_TEM1006      1 row       1 col     (numeric)

         0

 statement : ASSIGN at line 1622 column 1
 traceback : module MHATX2 at line 1622 column 1
             module CVF1 at line 1629 column 1
             module MINCVF at line 1634 column 1
             module OUTER at line 1651 column 1

Which happens because losing of precision when h approaches 0 and "le" in "mhatx2" approaches 0. At value h=0.4, le is ~0.08 so I just artificially picked that as a lower bound which is still precise enough.

Also this output of "outer" subroutine, ttt which is vector of h fitted for the rolling windows, still provides values below the constraint 0.4. Why?

4

2 回答 2

0

通过这种方式工作,必须将该选项和约束向量都放入输入括号中:

现在我没有得到除以 0 的警告。先前未指定的由于精度损失点现在根本没有指定,该值由 0.14 代替,但误差不大。

启动 mincvf(CVF1);

康={0.14 . .,. . .,. . .};

选择={0,0};

初始化=1;

调用 nlpqn(rc, res,"CVF1",init,optn,con);

返回(资源);

结束;

于 2014-07-27T12:45:14.947 回答
0

我以前通过简单地对输入应用乘法变换来解决精度损失问题......将其乘以 10,000 或任何必要的值,然后在最后恢复变换。

不确定它是否适用于您的情况,但可能值得一试。

于 2014-07-25T15:07:16.307 回答