Пример #1
0
def lossfunction__old1(tr, sub):
    #@Borja(orginal)1

    # Where to create the loss using data from the subject class

    # First simple loss function---------------------------------------
    # Based in simple distance to subject base
    (xt, yt), radius = tr.pf.circle
    (xs, ys), radius = sub.circle

    distance = int(np.sqrt(np.power(xt - xs, 2) + np.power(yt - ys, 2)))

    # Second loss function---------------------------------------------
    # Based in normal probability density function of particles for
    # position and detection size

    (x, y), (h, w), a = sub.rot_box

    p = tr.pf.p
    p_star = tr.pf.p_star
    p_mean = tr.pf.p_mean

    # optimizacion --> no calcular constantemente mean y std, sino hacerlo antes de entrar aqui
    # loss = -x -y -vx -vy
    loss  = - np.log(normpdf(x, np.mean(p[:, 0]), np.std(p[:, 0]))) \
        - np.log(normpdf(y, np.mean(p[:, 1]), np.std(p[:, 1]))) \
        - np.log(normpdf(x - p_star[0], np.mean(p[:, 4]), np.std(p[:, 4]))) \
        - np.log(normpdf(y - p_star[1], np.mean(p[:, 5]), np.std(p[:, 5]))) 
        #- np.log(normpdf(sub.h, np.mean(p[:, 4]), np.std(p[:, 4])))

    debug_flag=0
    if debug_flag:
        """
        print '###'
        print normpdf(p_star[1] - y, np.mean(p[:, 5]), np.std(p[:, 5]))
        print x
        print y
        """

        """
        print '----'
        print 'x, y, h: %s, %s, %s' % (x, y, sub.h)
        #print 'x: %s' % - np.log(normpdf(x, np.mean(p[:, 0]), np.std(p[:, 0])))
        print 'vx: %s' % - np.log(normpdf(p_star[0] - x, np.mean(p[:, 4]), np.std(p[:, 4])))
        print 'vy: %s' % - np.log(normpdf(p_star[1] - y, np.mean(p[:, 5]), np.std(p[:, 5])))
        print '----'
        """

    return loss, distance
Пример #2
0
def lossfunction__old1(tr, sub):
    #@Borja(orginal)1

    # Where to create the loss using data from the subject class

    # First simple loss function---------------------------------------
    # Based in simple distance to subject base
    (xt, yt), radius = tr.pf.circle
    (xs, ys), radius = sub.circle

    distance = int(np.sqrt(np.power(xt - xs, 2) + np.power(yt - ys, 2)))

    # Second loss function---------------------------------------------
    # Based in normal probability density function of particles for
    # position and detection size

    (x, y), (h, w), a = sub.rot_box

    p = tr.pf.p
    p_star = tr.pf.p_star
    p_mean = tr.pf.p_mean

    # optimizacion --> no calcular constantemente mean y std, sino hacerlo antes de entrar aqui
    # loss = -x -y -vx -vy
    loss  = - np.log(normpdf(x, np.mean(p[:, 0]), np.std(p[:, 0]))) \
        - np.log(normpdf(y, np.mean(p[:, 1]), np.std(p[:, 1]))) \
        - np.log(normpdf(x - p_star[0], np.mean(p[:, 4]), np.std(p[:, 4]))) \
        - np.log(normpdf(y - p_star[1], np.mean(p[:, 5]), np.std(p[:, 5])))
    #- np.log(normpdf(sub.h, np.mean(p[:, 4]), np.std(p[:, 4])))

    debug_flag = 0
    if debug_flag:
        """
        print '###'
        print normpdf(p_star[1] - y, np.mean(p[:, 5]), np.std(p[:, 5]))
        print x
        print y
        """
        """
        print '----'
        print 'x, y, h: %s, %s, %s' % (x, y, sub.h)
        #print 'x: %s' % - np.log(normpdf(x, np.mean(p[:, 0]), np.std(p[:, 0])))
        print 'vx: %s' % - np.log(normpdf(p_star[0] - x, np.mean(p[:, 4]), np.std(p[:, 4])))
        print 'vy: %s' % - np.log(normpdf(p_star[1] - y, np.mean(p[:, 5]), np.std(p[:, 5])))
        print '----'
        """

    return loss, distance
Пример #3
0
def lossfunction(tr, sub):

    # Where to create the loss using data from the subject class

    # First simple loss function
    # Based in simple distance to subject base
    """
    (xt, yt), radius = tr.subject.circle
    (xs, ys), radius = sub.circle

    loss = int(np.sqrt(np.power(xt - xs, 2) + np.power(yt - ys, 2)))
    """

    # Second loss function
    # Based in normal probability density function of particles for
    # position and detection size

    (x, y), (h, w), a = sub.rot_box
    p = tr.pf.p

    """
    loss = stats.norm.pdf(
        h,
        np.mean(p[:, 2]),
        np.std(p[:, 2])
    ) * stats.multivariate_normal.pdf(
        np.array([x, y]),
        np.mean(p[:, 0:2], axis=0),
        np.cov(p[:, 0:2].T)
    )
    """
    loss = stats.norm.pdf(
        x,
        np.mean(p[:, 0]),
        np.std(p[:, 0])
    ) * stats.norm.pdf(
        y,
        np.mean(p[:, 1]),
        np.std(p[:, 1])
    )

    if loss == 0.0:
        loss = 100000000000000000000000000000000000

    else:
        loss = 1 / loss

    return loss
Пример #4
0
Файл: track.py Проект: d-val/TFM
    def updatescore(self, score):
        if len(self.score) > self.score_max:
            self.score.pop(0)

        self.score.append(score)
        self.score_sigma = np.std(self.score)
        self.score_mu = np.mean(self.score)
Пример #5
0
    def updatescore(self, score):
        if len(self.score) > self.score_max:
            self.score.pop(0)

        self.score.append(score)
        self.score_sigma = np.std(self.score)
        self.score_mu = np.mean(self.score)