I'm trying to create a code to run Newton Raphson optimization. I'm using proc iml, but when I need to evaluate the error (e) I need to sum up all the square differences and don't know how to tell SAS that in that case I need the sum of the components of the vector and not the vector. The code is the following:
proc iml; use chap0; read all var{X} into X;
read all var{t} into t;
W=1;
s= exp(X*w)/(1+ exp(X*w)); print s;
e = (s - t) ** 2; /*here I need the result of the sum for that and not the matrix*/
g=2*(s-t)*s*(1-s);
h=2 * s * (1 - s) * (s * (1 - s) + (s - t) * (1 - 2 * s));
count=0;/*init count number*/
do until (e<1e-8);
count=count+1;
w=w0-g/h; /*here I also need the sum of g and h*/
s= exp(X*w)/(1+ exp(X*w));
e = (s - t) ** 2;
wo=w;
end;
Thanks!