tools/footprint/linear-regression.awk

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/tools/footprint/linear-regression.awk	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,58 @@
     1.4 +# This Source Code Form is subject to the terms of the Mozilla Public
     1.5 +# License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 +# file, You can obtain one at http://mozilla.org/MPL/2.0/.
     1.7 +
     1.8 +function regress(DATAPOINTS,SX,SY,SXY,SX2)
     1.9 +{
    1.10 +   b1 = (DATAPOINTS * SXY - SX * SY) / (DATAPOINTS * SX2 - SX * SX);
    1.11 +   b0 = (SY - b1 * SX ) / DATAPOINTS;
    1.12 +   return b1 " * x + " b0; 
    1.13 +}
    1.14 +
    1.15 +BEGIN {
    1.16 +        if (!Skip) Skip = 0;
    1.17 +        if (Interval) 
    1.18 +        {
    1.19 +           Count = 0;
    1.20 +           IntervalCount = 0;
    1.21 +        }
    1.22 +      }
    1.23 +
    1.24 +NR>Skip {
    1.25 +        sx += $1;
    1.26 +        sy += $2;
    1.27 +        sxy += $1 * $2;
    1.28 +        sx2 += $1 * $1;
    1.29 +        #print NR " " sx " " sy " " sxy " " sx2
    1.30 +
    1.31 +        if (Interval)
    1.32 +        {
    1.33 +           if(Count == Interval-1)
    1.34 +           {
    1.35 +              IntervalCount += 1;
    1.36 +
    1.37 +              print NR-Count, "-", NR, ":  ", regress(Count,isx,isy,isxy,isx2);
    1.38 +
    1.39 +              Count = 0;
    1.40 +              isx = 0;
    1.41 +              isy = 0;
    1.42 +              isxy = 0;
    1.43 +              isx2 = 0;
    1.44 +           }
    1.45 +           else
    1.46 +           {
    1.47 +              Count += 1;
    1.48 +              isx += $1;
    1.49 +              isy += $2;
    1.50 +              isxy += $1 * $2;
    1.51 +              isx2 += $1 * $1;
    1.52 +           }
    1.53 +        }
    1.54 +     }
    1.55 +
    1.56 +END {
    1.57 +       if(Interval) {
    1.58 +          print NR-Count, "-", NR, ":  ", regress(Count,isx,isy,isxy,isx2);
    1.59 +       }
    1.60 +       print regress(NR-Skip, sx, sy, sxy, sx2); 
    1.61 +    }

mercurial