def _computePartialLikelihoods(self):
for n in range(self.ntips, self.nnodes):<EOL><INDENT>ni = n - self.ntips <EOL>nright = self.rdescend[ni]<EOL>nleft = self.ldescend[ni]<EOL>if nright < self.ntips:<EOL><INDENT>istipr = True<EOL><DEDENT>else:<EOL><INDENT>istipr = False<EOL><DEDENT>if nleft < self.ntips:<EOL><INDENT>istipl = True<EOL><DEDENT>else:<EOL><INDENT>istipl = False<EOL><DEDENT>tright = self.t[nright]<EOL>tleft = self.t[nleft]<EOL>self.L[n] = scipy.ndarray(self._Lshape, dtype='<STR_LIT:float>')<EOL>if self.dparamscurrent:<EOL><INDENT>for param in self._paramlist_PartialLikelihoods:<EOL><INDENT>self.dL[param][n] = scipy.ndarray(self._dLshape[param],<EOL>dtype='<STR_LIT:float>')<EOL><DEDENT><DEDENT>if self.dtcurrent:<EOL><INDENT>for n2 in self.dL_dt.keys():<EOL><INDENT>self.dL_dt[n2][n] = scipy.zeros(self._Lshape, dtype='<STR_LIT:float>')<EOL><DEDENT><DEDENT>for k in self._catindices:<EOL><INDENT>if istipr:<EOL><INDENT>Mright = MLright = self._M(k, tright,<EOL>self.tips[nright], self.gaps[nright])<EOL><DEDENT>else:<EOL><INDENT>Mright = self._M(k, tright)<EOL>MLright = broadcastMatrixVectorMultiply(Mright,<EOL>self.L[nright][k])<EOL><DEDENT>if istipl:<EOL><INDENT>Mleft = MLleft = self._M(k, tleft,<EOL>self.tips[nleft], self.gaps[nleft])<EOL><DEDENT>else:<EOL><INDENT>Mleft = self._M(k, tleft)<EOL>MLleft = broadcastMatrixVectorMultiply(Mleft,<EOL>self.L[nleft][k])<EOL><DEDENT>self.L[n][k] = MLright * MLleft<EOL>if self.dtcurrent:<EOL><INDENT>for (tx, Mx, nx, MLxother, istipx) in [<EOL>(tright, Mright, nright, MLleft, istipr),<EOL>(tleft, Mleft, nleft, MLright, istipl)]:<EOL><INDENT>if istipx:<EOL><INDENT>tipsx = self.tips[nx]<EOL>gapsx = self.gaps[nx]<EOL><DEDENT>else:<EOL><INDENT>tipsx = gapsx = None<EOL><DEDENT>dM_dt = self._dM(k, tx, '<STR_LIT:t>', Mx, tipsx, gapsx)<EOL>if istipx:<EOL><INDENT>LdM_dt = dM_dt<EOL><DEDENT>else:<EOL><INDENT>LdM_dt = broadcastMatrixVectorMultiply(<EOL>dM_dt, self.L[nx][k])<EOL><DEDENT>self.dL_dt[nx][n][k] = LdM_dt * MLxother<EOL>for ndx in self.descendants[nx]:<EOL><INDENT>self.dL_dt[ndx][n][k] = broadcastMatrixVectorMultiply(<EOL>Mx, self.dL_dt[ndx][nx][k]) * MLxother<EOL><DEDENT><DEDENT><DEDENT>if self.dparamscurrent:<EOL><INDENT>for param in self._paramlist_PartialLikelihoods:<EOL><INDENT>if istipr:<EOL><INDENT>dMright = self._dM(k, tright, param, Mright,<EOL>self.tips[nright], self.gaps[nright])<EOL><DEDENT>else:<EOL><INDENT>dMright = self._dM(k, tright, param, Mright)<EOL><DEDENT>if istipl:<EOL><INDENT>dMleft = self._dM(k, tleft, param, Mleft,<EOL>self.tips[nleft], self.gaps[nleft])<EOL><DEDENT>else:<EOL><INDENT>dMleft = self._dM(k, tleft, param, Mleft)<EOL><DEDENT>for j in self._sub_index_param(param):<EOL><INDENT>if istipr:<EOL><INDENT>dMLright = dMright[j]<EOL>MdLright = <NUM_LIT:0><EOL><DEDENT>else:<EOL><INDENT>dMLright = broadcastMatrixVectorMultiply(<EOL>dMright[j], self.L[nright][k])<EOL>MdLright = broadcastMatrixVectorMultiply(<EOL>Mright, self.dL[param][nright][k][j])<EOL><DEDENT>if istipl:<EOL><INDENT>dMLleft = dMleft[j]<EOL>MdLleft = <NUM_LIT:0><EOL><DEDENT>else:<EOL><INDENT>dMLleft = broadcastMatrixVectorMultiply(<EOL>dMleft[j], self.L[nleft][k])<EOL>MdLleft = broadcastMatrixVectorMultiply(<EOL>Mleft, self.dL[param][nleft][k][j])<EOL><DEDENT>self.dL[param][n][k][j] = ((dMLright + MdLright)<EOL>* MLleft + MLright * (dMLleft + MdLleft))<EOL><DEDENT><DEDENT><DEDENT><DEDENT>if ni > <NUM_LIT:0> and ni % self.underflowfreq == <NUM_LIT:0>:<EOL><INDENT>scale = scipy.amax(scipy.array([scipy.amax(self.L[n][k],<EOL>axis=<NUM_LIT:1>) for k in self._catindices]), axis=<NUM_LIT:0>)<EOL>assert scale.shape == (self.nsites,)<EOL>self.underflowlogscale += scipy.log(scale)<EOL>for k in self._catindices:<EOL><INDENT>self.L[n][k] /= scale[:, scipy.newaxis]<EOL>if self.dtcurrent:<EOL><INDENT>for n2 in self.dL_dt.keys():<EOL><INDENT>self.dL_dt[n2][n][k] /= scale[:, scipy.newaxis]<EOL><DEDENT><DEDENT>if self.dparamscurrent:<EOL><INDENT>for param in self._paramlist_PartialLikelihoods:<EOL><INDENT>for j in self._sub_index_param(param):<EOL><INDENT>self.dL[param][n][k][j] /= scale[:, scipy.newaxis]<EOL><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT>for ntodel in [nright, nleft]:<EOL><INDENT>if ntodel in self.L:<EOL><INDENT>del self.L[ntodel]<EOL><DEDENT>if self.dparamscurrent:<EOL><INDENT>for param in self._paramlist_PartialLikelihoods:<EOL><INDENT>if ntodel in self.dL[param]:<EOL><INDENT>del self.dL[param][ntodel]<EOL><DEDENT><DEDENT><DEDENT>if self.dtcurrent:<EOL><INDENT>for n2 in self.dL_dt.keys():<EOL><INDENT>if ntodel in self.dL_dt[n2]:<EOL><INDENT>del self.dL_dt[n2][ntodel]<EOL><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT>
Update `L`, `dL`, `dL_dt`.