def _rmll_gradient(self, optSig02=True, optSig12=True, optSign2=True, optBeta=True): self._updateConstants() self._updateApproximation() K0 = self._K0 K1 = self._K1 m = self._mean ttau = self._ttau tnu = self._tnu Ssq = self._Ssq LnSsq = self._LnSsq LnSsqK = self._LnSsqK Smtnu = ttau * m - tnu b = Smtnu - dot(LnSsq.T, dot(LnSsqK, Smtnu)) ret = [] if optSig02: r = 0.5 * (dot(b, dot(K0, b)) - trace2(LnSsq.T, dot(LnSsq, K0))) ret.append(r) if optSig12: r = 0.5 * (dot(b, dot(K1, b)) - trace2(LnSsq.T, dot(LnSsq, K1))) ret.append(r) if optSign2: r = 0.5 * (dot(b, b) - trace2(LnSsq.T, LnSsq)) ret.append(r) if optBeta: r = -dot(b, self._X) ret += list(r) ret = NP.array(ret) assert NP.all(NP.isfinite( ret)), 'Not finite regular marginal loglikelihood gradient.' return ret
def _rmll_gradient(self, optSig02=True, optSig12=True, optSign2=True, optBeta=True): self._updateConstants() self._updateApproximation() m = self._mean H = self._H V = self._V ttau = self._ttau tnu = self._tnu G0 = self._G0 G1 = self._G1 Smtnu = ttau * m - tnu KSmtnu = self._rdotK(Smtnu) b = Smtnu - V * KSmtnu + dot(H.T, dot(H, KSmtnu)) ret = [] if optSig02: r = 0.5*(dot(b, dot(G0, dot(G0.T, b))) - trace2(ddot(V, G0, left=True), G0.T)\ + trace2(H.T, dot(dot(H, G0), G0.T))) ret.append(r) if optSig12: r = 0.5*(dot(b, dot(G1, dot(G1.T, b))) - trace2(ddot(V, G1, left=True), G1.T)\ + trace2(H.T, dot(dot(H, G1), G1.T))) ret.append(r) if optSign2: r = 0.5*(dot(b, b) - NP.sum(V)\ + trace2(H.T, H)) ret.append(r) if optBeta: ret += list(-dot(b, self._X)) return NP.array(ret)
def _rmll_gradient(self, optSig02=True, optSig12=True, optSign2=True, optBeta=True): self._updateConstants() self._updateApproximation() m = self._mean H = self._H V = self._V ttau = self._ttau tnu = self._tnu G0 = self._G0 G1 = self._G1 Smtnu = ttau*m - tnu KSmtnu = self._rdotK(Smtnu) b = Smtnu - V*KSmtnu + dot(H.T, dot(H, KSmtnu)) ret = [] if optSig02: r = 0.5*(dot(b, dot(G0, dot(G0.T, b))) - trace2(ddot(V, G0, left=True), G0.T)\ + trace2(H.T, dot(dot(H, G0), G0.T))) ret.append(r) if optSig12: r = 0.5*(dot(b, dot(G1, dot(G1.T, b))) - trace2(ddot(V, G1, left=True), G1.T)\ + trace2(H.T, dot(dot(H, G1), G1.T))) ret.append(r) if optSign2: r = 0.5*(dot(b, b) - NP.sum(V)\ + trace2(H.T, H)) ret.append(r) if optBeta: ret += list(-dot(b, self._X)) return NP.array(ret)
def _rmll_gradient(self, optSig02=True, optSig12=True, optSign2=True, optBeta=True): self._updateConstants() self._updateApproximation() K0 = self._K0 K1 = self._K1 m = self._mean ttau = self._ttau tnu = self._tnu Ssq = self._Ssq LnSsq = self._LnSsq LnSsqK = self._LnSsqK Smtnu = ttau*m - tnu b = Smtnu - dot(LnSsq.T, dot(LnSsqK, Smtnu) ) ret = [] if optSig02: r = 0.5*(dot(b,dot(K0,b)) - trace2(LnSsq.T, dot(LnSsq, K0))) ret.append(r) if optSig12: r = 0.5*(dot(b,dot(K1,b)) - trace2(LnSsq.T, dot(LnSsq, K1))) ret.append(r) if optSign2: r = 0.5*(dot(b,b) - trace2(LnSsq.T, LnSsq)) ret.append(r) if optBeta: r = -dot(b, self._X) ret += list(r) ret = NP.array(ret) assert NP.all(NP.isfinite(ret)), 'Not finite regular marginal loglikelihood gradient.' return ret
def _rmll_gradient(self, optSig02=True, optSig12=True, optSign2=True, optBeta=True): self._updateConstants() self._updateApproximation() W = self._W Wsq = self._Wsq f = self._f K = self._K K0 = self._K0 K1 = self._K1 m = self._mean a = self._a Ln = self._Ln X = self._X LnWsq = stl(Ln, NP.diag(Wsq)) LnWsqK = dot(LnWsq, K) d = self._dKn() h = self._likelihood.third_derivative_log(f) diags = (d - dotd(LnWsqK.T, LnWsqK)) * h ret = [] if optSig02: dK0a = dot(K0, a) dF0 = dK0a - dot(LnWsqK.T, dot(LnWsq, dK0a)) r = dot(a, dF0) - dot(a, dF0) + 0.5*dot(a, dK0a)\ + 0.5*NP.sum( diags*dF0 )\ - 0.5*trace2( LnWsq.T, dot(LnWsq,K0) ) ret.append(r) if optSig12: dK1a = dot(K1, a) dF1 = dK1a - dot(LnWsqK.T, dot(LnWsq, dK1a)) r = dot(a, dF1) - dot(a, dF1) + 0.5*dot(a, dK1a)\ + 0.5*NP.sum( diags*dF1 )\ - 0.5*trace2( LnWsq.T, dot(LnWsq,K1) ) ret.append(r) if optSign2: dFn = a - dot(LnWsqK.T, dot(LnWsq, a)) r = dot(a, dFn) - dot(a, dFn) + 0.5*dot(a, a)\ + 0.5*NP.sum( diags*dFn )\ - 0.5*trace2( LnWsq.T, LnWsq ) ret.append(r) if optBeta: dFmb = -dot(LnWsqK.T, dot(LnWsq, X)) dFb = dFmb+X r = dot(a, dFb) - dot(a, dFmb)\ + 0.5*NP.sum( diags*dFb.T, 1) ret += list(r) ret = NP.array(ret) assert NP.all(NP.isfinite(ret)), 'Not finite regular marginal loglikelihood gradient.' return ret
def _rmll_gradient(self, optSig02=True, optSig12=True, optSign2=True, optBeta=True): self._updateConstants() self._updateApproximation() (f,a)=(self._f,self._a) (W,Wsq) = (self._W,self._Wsq) Lk = self._Lk m = self._mean X = self._X G0 = self._G0 G1 = self._G1 sign2 = self._sign2 G01 = self._G01 #g = self._likelihood.gradient_log(f) #a==g h = self._likelihood.third_derivative_log(f) V = W/self._A d = self._dKn() G01tV = ddot(G01.T, V, left=False) H = stl(Lk, G01tV) dkH = self._ldotK(H) diags = (d - sign2**2 * V - dotd(G01, dot(dot(G01tV, G01), G01.T))\ - 2.0*sign2*dotd(G01, G01tV) + dotd(dkH.T, dkH)) * h ret = [] if optSig02: dK0a = dot(G0, dot(G0.T, a)) t = V*dK0a - dot(H.T, dot(H, dK0a)) dF0 = dK0a - self._rdotK(t) LkG01VG0 = dot(H, G0) VG0 = ddot(V, G0, left=True) ret0 = dot(a, dF0) - 0.5*dot(a, dK0a) + dot(f-m, t)\ + 0.5*NP.sum( diags*dF0 )\ + -0.5*trace2(VG0, G0.T) + 0.5*trace2( LkG01VG0.T, LkG01VG0 ) ret.append(ret0) if optSig12: dK1a = dot(G1, dot(G1.T, a)) t = V*dK1a - dot(H.T, dot(H, dK1a)) dF1 = dK1a - self._rdotK(t) LkG01VG1 = dot(H, G1) VG1 = ddot(V, G1, left=True) ret1 = dot(a, dF1)- 0.5*dot(a, dK1a) + dot(f-m, t)\ + 0.5*NP.sum( diags*dF1 )\ + -0.5*trace2(VG1, G1.T) + 0.5*trace2( LkG01VG1.T, LkG01VG1 ) ret.append(ret1) if optSign2: t = V*a - dot(H.T, dot(H, a)) dFn = a - self._rdotK(t) retn = dot(a, dFn)- 0.5*dot(a, a) + dot(f-m, t)\ + 0.5*NP.sum( diags*dFn )\ + -0.5*NP.sum(V) + 0.5*trace2( H.T, H ) ret.append(retn) if optBeta: t = ddot(V, X, left=True) - dot(H.T, dot(H, X)) dFbeta = X - self._rdotK(t) retbeta = dot(a, dFbeta) + dot(f-m, t) for i in range(dFbeta.shape[1]): retbeta[i] += 0.5*NP.sum( diags*dFbeta[:,i] ) ret.extend(retbeta) ret = NP.array(ret) assert NP.all(NP.isfinite(ret)), 'Not finite regular marginal loglikelihood gradient.' return ret
def _rmll_gradient(self, optSig02=True, optSig12=True, optSign2=True, optBeta=True): self._updateConstants() self._updateApproximation() W = self._W Wsq = self._Wsq f = self._f K = self._K K0 = self._K0 K1 = self._K1 m = self._mean a = self._a Ln = self._Ln X = self._X LnWsq = stl(Ln, NP.diag(Wsq)) LnWsqK = dot(LnWsq, K) d = self._dKn() h = self._likelihood.third_derivative_log(f) diags = (d - dotd(LnWsqK.T, LnWsqK)) * h ret = [] if optSig02: dK0a = dot(K0, a) dF0 = dK0a - dot(LnWsqK.T, dot(LnWsq, dK0a)) r = dot(a, dF0) - dot(a, dF0) + 0.5*dot(a, dK0a)\ + 0.5*NP.sum( diags*dF0 )\ - 0.5*trace2( LnWsq.T, dot(LnWsq,K0) ) ret.append(r) if optSig12: dK1a = dot(K1, a) dF1 = dK1a - dot(LnWsqK.T, dot(LnWsq, dK1a)) r = dot(a, dF1) - dot(a, dF1) + 0.5*dot(a, dK1a)\ + 0.5*NP.sum( diags*dF1 )\ - 0.5*trace2( LnWsq.T, dot(LnWsq,K1) ) ret.append(r) if optSign2: dFn = a - dot(LnWsqK.T, dot(LnWsq, a)) r = dot(a, dFn) - dot(a, dFn) + 0.5*dot(a, a)\ + 0.5*NP.sum( diags*dFn )\ - 0.5*trace2( LnWsq.T, LnWsq ) ret.append(r) if optBeta: dFmb = -dot(LnWsqK.T, dot(LnWsq, X)) dFb = dFmb + X r = dot(a, dFb) - dot(a, dFmb)\ + 0.5*NP.sum( diags*dFb.T, 1) ret += list(r) ret = NP.array(ret) assert NP.all(NP.isfinite( ret)), 'Not finite regular marginal loglikelihood gradient.' return ret
def _rmll_gradient(self, optSig02=True, optSig12=True, optSign2=True, optBeta=True): self._updateConstants() self._updateApproximation() (f, a) = (self._f, self._a) (W, Wsq) = (self._W, self._Wsq) Lk = self._Lk m = self._mean X = self._X G0 = self._G0 G1 = self._G1 sign2 = self._sign2 G01 = self._G01 #g = self._likelihood.gradient_log(f) #a==g h = self._likelihood.third_derivative_log(f) V = W / self._A d = self._dKn() G01tV = ddot(G01.T, V, left=False) H = stl(Lk, G01tV) dkH = self._ldotK(H) diags = (d - sign2**2 * V - dotd(G01, dot(dot(G01tV, G01), G01.T))\ - 2.0*sign2*dotd(G01, G01tV) + dotd(dkH.T, dkH)) * h ret = [] if optSig02: dK0a = dot(G0, dot(G0.T, a)) t = V * dK0a - dot(H.T, dot(H, dK0a)) dF0 = dK0a - self._rdotK(t) LkG01VG0 = dot(H, G0) VG0 = ddot(V, G0, left=True) ret0 = dot(a, dF0) - 0.5*dot(a, dK0a) + dot(f-m, t)\ + 0.5*NP.sum( diags*dF0 )\ + -0.5*trace2(VG0, G0.T) + 0.5*trace2( LkG01VG0.T, LkG01VG0 ) ret.append(ret0) if optSig12: dK1a = dot(G1, dot(G1.T, a)) t = V * dK1a - dot(H.T, dot(H, dK1a)) dF1 = dK1a - self._rdotK(t) LkG01VG1 = dot(H, G1) VG1 = ddot(V, G1, left=True) ret1 = dot(a, dF1)- 0.5*dot(a, dK1a) + dot(f-m, t)\ + 0.5*NP.sum( diags*dF1 )\ + -0.5*trace2(VG1, G1.T) + 0.5*trace2( LkG01VG1.T, LkG01VG1 ) ret.append(ret1) if optSign2: t = V * a - dot(H.T, dot(H, a)) dFn = a - self._rdotK(t) retn = dot(a, dFn)- 0.5*dot(a, a) + dot(f-m, t)\ + 0.5*NP.sum( diags*dFn )\ + -0.5*NP.sum(V) + 0.5*trace2( H.T, H ) ret.append(retn) if optBeta: t = ddot(V, X, left=True) - dot(H.T, dot(H, X)) dFbeta = X - self._rdotK(t) retbeta = dot(a, dFbeta) + dot(f - m, t) for i in range(dFbeta.shape[1]): retbeta[i] += 0.5 * NP.sum(diags * dFbeta[:, i]) ret.extend(retbeta) ret = NP.array(ret) assert NP.all(NP.isfinite( ret)), 'Not finite regular marginal loglikelihood gradient.' return ret