def calc2(MS, R0=None, R1=None): if R0 == None: R0 = numpy.arange(0.05, 1.0, 0.05) if R1 == None: R1 = numpy.arange(0.05, 1.1, 0.05) LLmax = float('-inf') Mfit = copy.deepcopy(MS.M) print('Turning debugging OFF') fitglobals.debugoff() f = open('data.txt', 'w') f.write('# A0 A1 LL\n') for A0 in R0: for A1 in R1: # Mfit.P.A = numpy.matrix([[A0, 0], [0,A1]]) MS.setParams(A0, A1, Mfit) LL = fitEKF.ekf(MS.Data, Mfit) if LL > LLmax: A0max = A0 A1max = A1 LLmax = LL f.write('%s %s %s\n' % (A0, A1, LL)) print A0, A1, LL f.write('\n') print "" f.close() print 'Max Like =', LLmax, '@ (A0,A1) =', [A0max, A1max] simParams = MS.getParams() LLsim = MS.loglike(simParams[0], simParams[1]) print 'Sim Like =', LLsim, '@ (A0, A1) =', simParams[0], simParams[1]
def fitloglike(self, A0=None, A1=None): simParams = self.getParams() if A0 == None: A0 = simParams[0] if A1 == None: A1 = simParams[1] Mtest = copy.deepcopy(self.M) self.setParams(A0, A1, Mtest) LL = fitEKF.ekf(self.Data, Mtest) return LL
P.tstop = 20 P.dt = 0.1 P.A = numpy.matrix(0.5) P.B = numpy.matrix([0.5, 0.4, 0.3]) P.InitialCov = numpy.matrix(1) O1 = models.ObserveState0(P,5) O2 = models.ObserveState0(P,6) O1.Times.set([2,4,6,8,10,12,14,16,18,20]) O2.Times.set([3,6,9,12,15,18]) O1.sigma = 0.001 O2.sigma = 0.0001 Obs = models.ObservationModel(P,5,[O1,O2]) #Sys = models.DecayModel(P,0,3) Sys = models.NeuronModel(P,0,3) Sys.Injection.set([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]) M = models.Model(Sys,Obs,P) # Turn noise off and simulate P.B = numpy.matrix([0.,0.,0.]) # Not needed: change(P) M.Obs.C[0].sigma = 0 M.Obs.C[1].sigma = 0 Data = M.sim() # Turn noise back on and calculate log-likelihood P.B = numpy.matrix([0.5, 0.4, 0.3]) # Not needed: change(P) M.Obs.C[0].sigma = 0.001 M.Obs.C[1].sigma = 0.0001 LL = fitEKF.ekf(Data,M)
def calc0(MS): Mfit = copy.deepcopy(MS.M) LL = fitEKF.ekf(MS.Data, Mfit) print 'Like =', LL