Ejemplo n.º 1
0
    theta_true = 0.1
    Qxi = Q[0, 0].reshape((1, 1))
    Qz = Q[1, 1].reshape((1, 1))
    P0 = numpy.eye(2)
    # How many steps forward in time should our simulation run
    steps = 200
    # model = ParticleParamTrans((theta_true,), R=R, Qxi=Qxi, Qz=Qz)
    model = ParticleParamTrans((theta_true, ), R=R, Qxi=Qxi, Qz=Qz)
    if (gradient_test):

        num = 50
        nums = 5
        # numpy.random.seed(1)
        x0 = numpy.vstack((xi0_true, z0_true))
        (y, x) = generate_reference(x0, P0, theta_true, steps)
        gt = gradienttest.GradientTest(model, u=None, y=y)
        gt.set_params(numpy.array((theta_true, )))
        gt.simulate(num, nums)
        param_steps = 101
        param_vals = numpy.linspace(-0.1, 0.4, param_steps)
        gt.test(0, param_vals, num=num, nums=nums)
        plt.ion()
        plt.figure(1)
        plt.clf()
        plt.plot(range(steps + 1), x[:, 0], 'r-')
        plt.plot(range(steps + 1), x[:, 1], 'b-')

        sest = gt.straj.get_smoothed_estimates()
        for j in xrange(nums):
            plt.plot(range(steps + 1), sest[:, j, 0], 'g--')
            plt.plot(range(steps + 1), sest[:, j, 1], 'k--')
Ejemplo n.º 2
0
if __name__ == '__main__':
    theta_true = 2.5
    # How many steps forward in time should our simulation run
    steps = 200

    uvec = -10.0 * numpy.hstack(
        (-1.0 * numpy.ones(steps / 4), 1.0 * numpy.ones(steps / 2),
         -1.0 * numpy.ones(steps / 4)))

    if (gradient_test):
        num = 50
        nums = 5
        # numpy.random.seed(1)
        model = ParticleParamOutput((theta_true, ))
        (u, y, x) = generate_reference(uvec, steps, theta_true)
        gt = gradienttest.GradientTest(model, u=u, y=y)
        gt.set_params(numpy.array((theta_true, )))
        gt.simulate(num, nums)
        param_steps = 101
        param_vals = numpy.linspace(-10.0, 10.0, param_steps)
        gt.test(0, param_vals, num=num, nums=nums)
        plt.ion()
        plt.figure(1)
        plt.clf()
        plt.plot(range(steps + 1), x[:, 0], 'r-')
        plt.plot(range(steps + 1), x[:, 1], 'b-')

        sest = gt.straj.get_smoothed_estimates()
        for j in xrange(nums):
            plt.plot(range(steps + 1), sest[:, j, 0], 'g--')
            plt.plot(range(steps + 1), sest[:, j, 1], 'k--')