Exemplo n.º 1
0
 def manual_labelling(self):
     """---------------------
         Manual Labelling
     ------------------------"""
     # By manually labelling 1 run of data we extract a mean and cov to begin the iterations
     print("-------> manual labelling of run1 ")
     mu0 = np.zeros((n_primitives, N))
     cov0 = np.zeros((n_primitives, N, N))
     tlabels = np.genfromtxt(
         "../data/medium_cap/raw_medium_cap/run1_tlabels", dtype=float)
     tlabels = np.insert(tlabels, 0, 0.0)
     labels = [
         Pr(int(idx)) for idx in np.genfromtxt(
             "../data/medium_cap/raw_medium_cap/run1_prmlabels")
     ]
     for prim in [
             Pr.none, Pr.fsm, Pr.align, Pr.engage, Pr.screw, Pr.tighten
     ]:
         tpairs = []
         for i in range(
                 len(labels)
         ):  #collect different labels and time periods corresponding to this primitive
             if (labels[i] == prim):
                 tpairs.append([tlabels[i], tlabels[i + 1]])
         time, X = read_data1(
             '../data/medium_cap/raw_medium_cap/run1',
             '../data/medium_cap/raw_medium_cap/bias.force',
             output_fmt='array',
             tpairlist=tpairs)
         #each row of X is an observation
         #each column of X is a variable
         mu0[prim.value] = np.mean(X[:, subset], axis=0)
         cov0[prim.value] = np.cov(X[:, subset], rowvar=False)
     return mu0, cov0
def interactive_omega_plot(experiment_name, run_number): 
	'''
	"interactive" angular velocities plot with tooltip 
	to give x,y values when hovering over a line on the plot
	'''
	print("patito eligiendo tiempos")
	t, p1, vels, euler, omegas, F, M = read_data1('../data/{0}/raw_{1}/run{2:d}'.format(experiment_name, experiment_name, run_number))
	fig = plt.figure()
	# plt = fig.add_subplot(111)
	plt.plot(t,omegas[:,0],'r',label='$\omega_x$')
	plt.plot(t,omegas[:,1],'g',label='$\omega_y$')
	plt.plot(t,omegas[:,2],'b',label='$\omega_z$')
	# plt.set_ylabel('rad/s')
	fig.canvas.mpl_connect('motion_notify_event', on_plot_hover)           
	plt.show()
Exemplo n.º 3
0
            2) Train on run1 using mu0, cov0 as seeds
            3) Test on the rest of the runs
            4) Update Transition Matrix based on all the labelled runs
            5) Train on 1 and Test on the rest again
            6) Repeat steps 4 and 5 for several iterations until labelling success wrt manually labelled runs improves
    """
    myConstraints = initializeConstraints()

    for i in range(numTMatrixUpdates):

        # ------------------------
        #       Train on run 1
        # ------------------------
        time, X = read_data1('../data/medium_cap/raw_medium_cap/run1',
                             '../data/medium_cap/raw_medium_cap/bias.force',
                             output_fmt='array',
                             t0=0.0,
                             t1=10.5)

        # Init
        myGMM = GMM(X[:, subset])

        if i == 0:
            transition = initializeTransitionMatrix()
            # transition = initializeTransitionMatrix2Identity()
            createSuccessRateFile(1, i)
        else:
            transition = updatedTransition

        # Run training gmm
        print(">>>>>>>> TRAINING >>>>>>>>")
Exemplo n.º 4
0
        -- Cycle: 
            1) Manually label run1 to get mu0,cov0
            2) Train on run1 using mu0, cov0 as seeds
            3) Test on the rest of the runs
            4) Update Transition Matrix based on all the labelled runs
            5) Train on 1 and Test on the rest again
            6) Repeat steps 4 and 5 for several iterations until labelling success wrt manually labelled runs improves
    """
    myConstraints = initializeConstraints()

    for i in range(numTMatrixUpdates):

        # ------------------------
        #       Train on run 1  
        # ------------------------
        time,X = read_data1('../data/pipe/raw_pipe/run1', 
            output_fmt='array')#,t0=0.0, t1 = 18.0) #0 to 10.5 for cap
        
        # Init
        myGMM = GMM(X[:,subset])
        
        if i == 0:
            transition = initializeTransitionMatrix()
            # transition = initializeTransitionMatrix2Identity()
            # createSuccessRateFile(1,i)
        else: 
            transition = updatedTransition

        # Run training gmm
        print(">>>>>>>> TRAINING >>>>>>>>")
        mu0,cov0 = myGMM.manual_labelling()
        myGMM.train(mu0, cov0, numIterTrain, transition, i, time)
Exemplo n.º 5
0
tlabels = np.genfromtxt("../data2/run1_tlabels", dtype=float)
tlabels = np.insert(tlabels, 0, 0.0)
# vlines=np.array([0.0, 1.08, 3.27,4.2,5.5,6.72,6.9,7.44, 7.6, 8.02, 8.21, 8.68, 8.98, 10.5])
# np.savetxt("../data2/run1_tlabels",vlines[1:])
labels = [Pr(int(idx)) for idx in np.genfromtxt("../data2/run1_prmlabels")]
n_primitives = 5
for prim in [Pr.none, Pr.fsm, Pr.contact, Pr.align, Pr.screw]:
    tpairs = []
    for i in range(
            len(labels)
    ):  #collect different labels and time periods corresponding to this primitive
        if (labels[i] == prim):
            tpairs.append([tlabels[i], tlabels[i + 1]])
    print("Primitive: {0:s}".format(Pr(prim)))
    t, obs = read_data1('../data2/run1',
                        '../data2/bias.force',
                        output_fmt='obs',
                        tpairlist=tpairs)
    # print(tpairs)
    ntests = 6
    p = np.zeros((len(t), ntests))
    for i in range(len(t)):
        p[i] = observation_tests(obs[i])
    testname = ("vel = 0", "F = 0 ", "M = 0", "ang_vel = 0", "ang_vel_z = 0",
                "M_z = 0")
    for i in [0]:  #range(ntests):
        print_stats("p " + testname[i] + ": ", p[:, i])
    # t, p1, vels, euler, omegas, F, M = read_data1('../data2/run1', '../data2/bias.force',tpairlist=tpairs)
    # print_stats_xyz("velocity", vels)
    # plt.title(str(Pr(prim))+" M_z")
    # plt.hist(M[:,2],bins=200)
    # plt.show()
Exemplo n.º 6
0
            1) Manually label run1 to get mu0,cov0
            2) Train on run1 using mu0, cov0 as seeds
            3) Test on the rest of the runs
            4) Update Transition Matrix based on all the labelled runs
            5) Train on 1 and Test on the rest again
            6) Repeat steps 4 and 5 for several iterations until labelling success wrt manually labelled runs improves
    """
    myConstraints = initializeConstraints()

    for i in range(numTMatrixUpdates):

        # ------------------------
        #       Train on run 1
        # ------------------------
        time, X = read_data1(
            '../data/{0}/raw_{1}/run1'.format(setup, setup),
            output_fmt='array')  #,t0=0.0, t1 = 18.0) #0 to 10.5 for cap

        # Init
        myGMM = GMM(X[:, subset])

        if i == 0:
            transition = initializeTransitionMatrix()
            # transition = initializeTransitionMatrix2Identity()
            # createSuccessRateFile(1,i)
        else:
            transition = updatedTransition

        # Run training gmm
        print(">>>>>>>> TRAINING >>>>>>>>")
        mu0, cov0 = myGMM.manual_labelling()
Exemplo n.º 7
0
            for particle in range(n_particles_allocated, n):
                s[particle, t + 1] = s[i, t + 1]
            n_particles_allocated = n
        #count primtivies
        temp = collections.Counter(s[:, t + 1])
        for prim_idx in range(n_primitives):
            p_primitives[t + 1, prim_idx] = temp[prim_idx] / N_particles
    return p_primitives


if __name__ == "__main__":
    import matplotlib.pyplot as plt
    # from mpl_toolkits.mplot3d import Axes3D
    # from plot_helper import draw_2d, draw_3d
    # from matplotlib import rc
    T = initializeTransitionMatrix()
    t, obs = read_data1('../data2/run1',
                        '../data/bias.force',
                        obs_output=True,
                        t0=0.0,
                        t1=10.0)
    print(len(obs))
    p_primitives = particle_filter(obs, T)
    n_primitives = 5
    for i in range(n_primitives):
        plt.plot(t, p_primitives[:, i], label=Pr(i))
    plt.xlabel('t')
    plt.ylabel('probability')
    plt.legend()
    plt.show()