Ejemplo n.º 1
0
def LaserStates(data_dir, Nt, O_Par):
    global Y
    aM = Nt * [None]
    ll = EKF.LogLike(O_Par, Y[0:Nt], aM=aM)
    f = open(join(data_dir, 'LaserStates'), 'w')
    for x in aM:
        print(x.A[0, 0], x.A[2, 0], file=f)
    f.close()
    return aM
Ejemplo n.º 2
0
def NegLogLike(P):
    """Use EKF.LogLike to calculate the log likelihood of the first Nt
    values in the Y sequence.
    """
    global Y, Nt, best
    rad, Tr = P[0:2]
    devEp, devEta = P[8:10]
    if rad * rad > 0.25 or Tr < 0.5 or devEp < 0.0 or devEta < 0.0:
        return 1e20  # If parameters are bad, return big number
    try:
        L = ParamCalc(*P[:10])
        cost = -EKF.LogLike(L, Y[0:Nt]) + (devEta / 1e-2)**2
    except (ValueError, RuntimeError) as err:
        #print 'NegLogLike returning 1e20 because ', err
        return 1e20
    if cost < best - 1:
        best = cost
        print("best=%f" % best)
    return cost
Ejemplo n.º 3
0
def LaserLogLike(
        data_dir,
        O_Par,
        N_step,  # Number of steps away from peak in each direction
        Nt):
    s = O_Par[4]
    b = O_Par[5]
    Frange = numpy.arange(-N_step, N_step + 1, 1.0)
    s_range = (Frange * 5e-3 / N_step + 1.0) * s
    b_range = (Frange * 5e-3 / N_step + 1.0) * b
    Par = copy.copy(O_Par)
    f = open(join(data_dir, 'LaserLogLike'), 'w')
    for ss in s_range:
        for bb in (b_range):
            Par[4] = ss
            Par[5] = bb
            ll = EKF.LogLike(Par, Y[0:Nt])
            print(ss, bb, ll, file=f)
        print(' ', file=f)
    f.close()
Ejemplo n.º 4
0
def NLL_Fixed_Noise(P):
    """Use EKF.LogLike to calculate the log likelihood of the first Nnll
    values in the Y sequence.  Like NegLogLike() but noise is fixed.
    """
    global Y, best
    Nnll = 250
    rad = P[0]
    Tr = P[1]

    if rad**2 > 0.25 or Tr < 0.5:
        return 1e20
    try:
        L = ParamCalc(*(list(P[0:8]) + [4.0 / P[7], 1e-7]))
        # P[7] is scale.  The above line sticks dev_eps = 4.0 channels
        # and dev_eta = 1e-7 on to the end of the parameter list and
        # converts from (rad,Tr) to ic.
        LL = EKF.LogLike(L, Y[0:Nnll])
    except ValueError as err:
        #print 'NLL_Fixed_noise returning 1e20 because ', err
        return 1e20
    if -LL < best - 1:
        best = -LL
        print("best=%f" % best)
    return (-LL)