|
|
楼主

楼主 |
发表于 2010-10-22 13:39:49
|
只看该作者
Boost to tackle nonlinearity
From oloolo's blog on SasProgramming
<p><a href="http://feedads.g.doubleclick.net/~a/vxjN9NmrYX5QuayULzfxI_qWna8/0/da"><img src="http://feedads.g.doubleclick.net/~a/vxjN9NmrYX5QuayULzfxI_qWna8/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/vxjN9NmrYX5QuayULzfxI_qWna8/1/da"><img src="http://feedads.g.doubleclick.net/~a/vxjN9NmrYX5QuayULzfxI_qWna8/1/di" border="0" ismap="true"></img></a></p><pre style="background-color: #ebebeb; border-bottom: #999999 1px dashed; border-left: #999999 1px dashed; border-right: #999999 1px dashed; border-top: #999999 1px dashed; color: #000001; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; width: 100%;"><code>
data nonlinear;
do x=1 to 627;
p=(sin(x/100)+1)*0.45;
do j=1 to 100;
x1=x+(j-1)/100;
if ranuni(8655645)<=p then y=1; else y=0;
output; drop p j;
end;
end;
run;
proc rank data=nonlinear out=nonlinearrank groups=20;
var x1;
ranks rank1;
run;
proc means data=nonlinearrank noprint;
class rank1;
var y x1;
output out=_mean(where=(_type_=1)) mean(y)=y mean(x1)=x1;
run;
%inc "C:\Documents and Settings\lxie\Desktop\SAS Prog and Docs\Boost macro2 ver3.0.sas";
%inc "C:\Documents and Settings\lxie\Desktop\SAS Prog and Docs\predict macro.sas";
%boost2(nonlinear, 1, outputds, outwts, 100, 3);
%macro pred(niter);
%do i=1 %to &niter;
%predict(nonlinear, 1, outputds, outlogds, out_pred, sumpred&i, 3, &i);
%end;
data sumpred_all;
merge %do i=1 %to &niter;
sumpred&i.(rename=(sum_pred=sum_pred&i))
%end;;
run;
%mend;
%pred(100);
proc datasets library=work nolist;
delete sumpred1-sumpred100;
quit;
options nosource;
proc export data=sumpred_all outfile="c:\sumpred.csv" dbms=csv replace; run;
options source;
</code></pre><br />
In R, use this code piece to recover the animation:<br />
<pre style="background-color: #ebebeb; border-bottom: #999999 1px dashed; border-left: #999999 1px dashed; border-right: #999999 1px dashed; border-top: #999999 1px dashed; color: #000001; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; width: 100%;"><code>
library(caTools);
test<-read.csv('c:/sumpred.csv', header=T)
minmax<-quantile(as.matrix(test), c(0,1))
sz=314; p=100;
y<-sort(sample(1:62700, size=sz))
image=array(0, c(sz, p, 100))
for (i in (1:100)){
pic=matrix(0, ncol=p, nrow=sz)
trace=round((test[y,i]-minmax[1])/(minmax[2]-minmax[1])*p);
for(j in (1:sz)){
image[j, trace[j], i]=1
}
}
write.gif(image, "c:/boost.gif", col=gray(1:2/2))
im = read.gif("c:/boost.gif")
for(i in 1:100){
image(im$image[,,i], col=(im$col),
main=paste('Iter', i), y=1:100, x=1:314,
xlab="Index", ylab="Percentage of 1")
}
test2<-test[,-1]-test[-100]
test2<-cbind(test[,1], test2)
par(mfrow=c(2,1))
for (i in (1:100)){
plot(test2[,i], type='l', ylim=c(-0.5, 1),
main=paste('Iteration', i, 'Delta'),
ylab='Delta')
plot(test[,i], type='l', ylim=minmax,
main=paste('Iteration', i, 'Score'),
ylab='Score')
Sys.sleep(0.1)
}
</code></pre><br />
<br />
<div class="separator" style="border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; clear: both; text-align: center;"><a href="http://4.bp.blogspot.com/_slrAR0IXTL0/TAWGGMbs65I/AAAAAAAAATQ/LC_o7LTZT90/s1600/boost.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" gu="true" height="638" src="http://4.bp.blogspot.com/_slrAR0IXTL0/TAWGGMbs65I/AAAAAAAAATQ/LC_o7LTZT90/s640/boost.png" width="640" /></a></div><div class="blogger-post-footer"><img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/29815492-2897517425666845174?l=www.sas-programming.com' alt='' /></div><img src="http://feeds.feedburner.com/~r/SasProgramming/~4/YJDxnC5ICmQ" height="1" width="1"/> |
|