Skip to content

Commit

Permalink
optimize calculation speed
Browse files Browse the repository at this point in the history
  • Loading branch information
solaoi committed Mar 28, 2022
1 parent ccb1241 commit 1a41807
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion colc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ if (binSize === null) {
}
bash.push("| sort -n | awk");
bash.push(
`'BEGIN{OFMT="%.6f"}NR==1{min=$1}{sum+=$1;d[NR]=$1}END{avg=sum/NR;for(i in d)s+=(d[i]-avg)^2;stddev=sqrt(s/(NR-1));q1=(3*d[int((NR-1)/4)+1]+d[int((NR-1)/4)+2])/4;q3=(d[int(3*(NR-1)/4)+1]+3*d[int(3*(NR-1)/4)+2])/4;iqr=q3-q1;stur=1+log(NR)/log(2);sturi=int(stur);sturges=stur>sturi?sturi+1:sturi;max=d[NR];print stddev,avg,sum,NR,max,min,sqrt(s/(NR-1))/sqrt(NR),s/(NR-1),(NR%2)?d[(NR+1)/2]:(d[NR/2]+d[NR/2+1])/2,avg+stddev,avg-stddev,avg+2*stddev,avg-2*stddev,avg+3*stddev,avg-3*stddev,(max-min)/sturges,(3.5*stddev)/(exp(log(NR)/3)),q1,q3,iqr,q1-1.5*iqr,q3+1.5*iqr,(max-min)/sqrt(NR),2*iqr/(exp(log(NR)/3))}'`,
`'BEGIN{OFMT="%.6f"}NR==1{min=$1}{sum+=$1;d[NR]=$1}END{avg=sum/NR;for(i in d)s+=(d[i]-avg)^2;stddev=sqrt(s/(NR-1));q1=(3*d[int((NR-1)/4)+1]+d[int((NR-1)/4)+2])/4;q3=(d[int(3*(NR-1)/4)+1]+3*d[int(3*(NR-1)/4)+2])/4;iqr=q3-q1;stur=1+log(NR)/log(2);sturi=int(stur);sturges=stur>sturi?sturi+1:sturi;max=d[NR];range=max-min;sqrtnr=sqrt(NR);threerootnr=exp(log(NR)/3);print stddev,avg,sum,NR,max,min,sqrt(s/(NR-1))/sqrtnr,s/(NR-1),(NR%2)?d[(NR+1)/2]:(d[NR/2]+d[NR/2+1])/2,avg+stddev,avg-stddev,avg+2*stddev,avg-2*stddev,avg+3*stddev,avg-3*stddev,range/sturges,(3.5*stddev)/threerootnr,q1,q3,iqr,q1-1.5*iqr,q3+1.5*iqr,range/sqrtnr,2*iqr/threerootnr}'`,
);
return bash.join(" ");
})();
Expand Down

0 comments on commit 1a41807

Please sign in to comment.