Simplify some probability calculations a bit
authorMartin C. Frith
Mon Apr 01 07:48:24 2019 +0900 (5 months ago)
changeset 9779eeaeea88f2c
parent 976 f3f69ccff967
child 978 d429589d040e
Simplify some probability calculations a bit
src/Alignment.cc
src/Centroid.cc
src/Centroid.hh
     1.1 --- a/src/Alignment.cc	Fri Mar 29 14:46:20 2019 +0900
     1.2 +++ b/src/Alignment.cc	Mon Apr 01 07:48:24 2019 +0900
     1.3 @@ -34,7 +34,7 @@
     1.4    const int numEmissionCounts = alph.size * alph.size;
     1.5    double* transitionCounts = &expectedCounts[ numEmissionCounts ];
     1.6  
     1.7 -  transitionCounts[0] += ec.MM + ec.DM + ec.IM + ec.PM;  // match count
     1.8 +  transitionCounts[0] += ec.toMatch;
     1.9    transitionCounts[1] += ec.DD + ec.MD + ec.PD;  // deleted letter count
    1.10    transitionCounts[2] += ec.II + ec.MI + ec.DI + ec.PI;  // ins. letter count
    1.11    transitionCounts[3] += ec.MD + ec.PD;  // deletion open/close count
     2.1 --- a/src/Centroid.cc	Fri Mar 29 14:46:20 2019 +0900
     2.2 +++ b/src/Centroid.cc	Mon Apr 01 07:48:24 2019 +0900
     2.3 @@ -28,10 +28,11 @@
     2.4    ExpectedCount::ExpectedCount ()
     2.5    {
     2.6      double d0 = 0;
     2.7 -    MM = d0; MD = d0; MP = d0; MI = d0;
     2.8 -    DD = d0; DM = d0; DI = d0;
     2.9 -    PP = d0; PM = d0; PD = d0; PI = d0;
    2.10 -    II = d0; IM = d0;
    2.11 +    toMatch = d0;
    2.12 +    MD = d0; MP = d0; MI = d0;
    2.13 +    DD = d0; DI = d0;
    2.14 +    PP = d0; PD = d0; PI = d0;
    2.15 +    II = d0;
    2.16  
    2.17      for (int n=0; n<scoreMatrixRowSize; n++)
    2.18        for (int m=0; m<scoreMatrixRowSize; m++) emit[n][m] = d0;
    2.19 @@ -795,9 +796,7 @@
    2.20  
    2.21  	    const double alignProb = xSum * yM;
    2.22  	    c.emit[letter1][letter2] += alignProb;
    2.23 -	    c.MM += xM * yM;
    2.24 -	    c.DM += xD * yM;
    2.25 -	    c.IM += xI * yM;
    2.26 +	    c.toMatch += alignProb;
    2.27  	    c.MD += xM * yD * eF;
    2.28  	    c.DD += xD * yD;
    2.29  	    c.MI += xM * yI * eFI;
    2.30 @@ -829,10 +828,7 @@
    2.31  
    2.32  	    const double alignProb = xSum * yM;
    2.33  	    c.emit[letter1][letter2] += alignProb;
    2.34 -	    c.MM += xM * yM;
    2.35 -	    c.DM += xD * yM;
    2.36 -	    c.IM += xI * yM;
    2.37 -	    c.PM += xP * yM;
    2.38 +	    c.toMatch += alignProb;
    2.39  	    c.MD += xM * yD * eF;
    2.40  	    c.DD += xD * yD;
    2.41  	    c.PD += xP * yD;
    2.42 @@ -872,9 +868,7 @@
    2.43  	    const double alignProb = xSum * yM;
    2.44  	    countUncertainLetters(c.emit[letter1], alignProb,
    2.45  				  alphabetSize, match_score[letter1], lp2);
    2.46 -	    c.MM += xM * yM;
    2.47 -	    c.DM += xD * yM;
    2.48 -	    c.IM += xI * yM;
    2.49 +	    c.toMatch += alignProb;
    2.50  	    c.MD += xM * yD * eF;
    2.51  	    c.DD += xD * yD;
    2.52  	    c.MI += xM * yI * eFI;
    2.53 @@ -907,10 +901,7 @@
    2.54  	    const double alignProb = xSum * yM;
    2.55  	    countUncertainLetters(c.emit[letter1], alignProb,
    2.56  				  alphabetSize, match_score[letter1], lp2);
    2.57 -	    c.MM += xM * yM;
    2.58 -	    c.DM += xD * yM;
    2.59 -	    c.IM += xI * yM;
    2.60 -	    c.PM += xP * yM;
    2.61 +	    c.toMatch += alignProb;
    2.62  	    c.MD += xM * yD * eF;
    2.63  	    c.DD += xD * yD;
    2.64  	    c.PD += xP * yD;
     3.1 --- a/src/Centroid.hh	Fri Mar 29 14:46:20 2019 +0900
     3.2 +++ b/src/Centroid.hh	Mon Apr 01 07:48:24 2019 +0900
     3.3 @@ -16,10 +16,11 @@
     3.4    struct ExpectedCount{
     3.5    public:
     3.6      double emit[scoreMatrixRowSize][scoreMatrixRowSize];
     3.7 -    double MM, MD, MP, MI;
     3.8 -    double DD, DM, DI;
     3.9 -    double PP, PM, PD, PI;
    3.10 -    double II, IM;
    3.11 +    double toMatch;
    3.12 +    double MD, MP, MI;
    3.13 +    double DD, DI;
    3.14 +    double PP, PD, PI;
    3.15 +    double II;
    3.16    public:
    3.17      ExpectedCount ();
    3.18    };