Exemplo n.º 1
0
def eval_diff():
    model.load_state_dict(torch.load('weights/lstm'))
    model.eval()
    with torch.no_grad():
        X = np.zeros([T, 1, input_dim], dtype=np.float32)
        X[:, 0 ,0] = np.arange(T)
        X[:, 0 ,1] = 2 * np.arange(T)
        X[:, 0, 2] = np.sin(2 * np.arange(T)/10)

        maxi1 = np.max(X[:, :, 0])
        maxi2 = np.max(X[:, :, 1])
        maxi3 = np.max(X[:, :, 2])

        X[:, :, 0] = X[:, :, 0] / maxi1
        X[:, :, 1] = X[:, :, 1] / maxi2
        X[:, :, 2] = X[:, :, 2] / maxi3
        X = torch.from_numpy(X)
        pred_pos = model(X[:-1, : ,:])
        #print(X[1:, :, :])
        #print(pred_pos)
        #print(X[1:, : ,:] - pred_pos)
        #scale = torch.tensor([maxi1, maxi2, 1]).view(1,1,input_dim)
        X = X #* scale
        pred_pos = pred_pos #* scale
        #print(X)
        #print(pred_pos)
        #print(X[1:, : ,:] - pred_pos)
        data = torch.stack((pred_pos[:, 0, :], X[1:, 0, :]), 1)
        visualize(data, T)
Exemplo n.º 2
0
def eval_diff2():
    model.load_state_dict(torch.load('weights/lstm'))
    model.eval()
    with torch.no_grad():
        X = np.zeros([T, 1, input_dim], dtype=np.float32)
        speedup = 3
        times = np.arange(T) * speedup
        X[:, 0, 0] = times / (T * speedup) * 5 * np.sin(times / 32)
        X[:, 0, 1] = np.cos(times / 68)**2 * 5
        X[:, 0, 2] = np.sin(times / 20)**2 * times / (T * speedup) * 3

        maxi1 = np.max(X[:, :, 0])
        maxi2 = np.max(X[:, :, 1])
        maxi3 = np.max(X[:, :, 2])

        X[:, :, 0] = X[:, :, 0] / maxi1
        X[:, :, 1] = X[:, :, 1] / maxi2
        X[:, :, 2] = X[:, :, 2] / maxi3
        X = torch.from_numpy(X)
        pred_pos = model(X[:-1, :, :])
        # print(X[1:, :, :])
        # print(pred_pos)
        # print(X[1:, : ,:] - pred_pos)
        # scale = torch.tensor([maxi1, maxi2, 1]).view(1,1,input_dim)
        X = X  # * scale
        pred_pos = pred_pos  # * scale
        # print(X)
        # print(pred_pos)
        # print(X[1:, : ,:] - pred_pos)
        data = torch.stack((pred_pos[:, 0, :], X[1:, 0, :]), 1)
        visualize(data)
Exemplo n.º 3
0
def test1():
    a, b = loadbondingpair('c', 'd')
    a_site, b_site = reaction.getbondablesites(a, b)
    print('Bonding sites: ')
    print(a_site)
    print(b_site)
    c = particle.Atom.compose(Atom1=a, Atom2=b, int_site1=a_site, int_site2=b_site)
    print(c.rbn.summarystring())
    viz.visualize(c)
Exemplo n.º 4
0
def eval():
    model.load_state_dict(torch.load('weights/lstm'))
    model.eval()
    for n in range(N):
        with torch.no_grad():
            tag_scores = model(test_data[:-1, :, :])
            #print(tag_scores.shape)
            #print(torch.squeeze(tag_scores[:,n,:]))
            data = torch.stack((tag_scores[:,n,:], test_data[1:,n,:]),1)
            #print(data.shape)
            visualize(data, T)
Exemplo n.º 5
0
def eval():
    model.load_state_dict(torch.load('weights/lstm'))
    model.eval()
    with torch.no_grad():
        tag_scores = model(test_in[:-1, :, :])
        for n in range(10):
            center = torch.mean(tag_scores[:, n, :], dim=0)
            #print(tag_scores.shape)
            #print(torch.squeeze(tag_scores[:,n,:]))
            data = torch.stack(
                (tag_scores[:, n, :] - center, test_out[1:, n, :] - center), 1)
            #print(data.shape)
            visualize(data)
Exemplo n.º 6
0
def sample():
    """ test on all test data and random sample 1 hair to visualize """

    dataloader = Dataloader(args.data_dir, 0)
    test_x, test_y, angles = dataloader.get_test_data()
    n_tests = test_y.shape[0]

    # random permutation
    # order = np.random.permutation(test_y.shape[0])
    # test_x, test_y, angles = test_x[order], test_y[order], angles[order]

    config = tf.ConfigProto(device_count={'GPU': 1}, allow_soft_placement=True)
    with tf.Session(config=config) as sess:
        model = create_model(sess)
        # start testing
        loss, pos_err = 0, 0
        best_loss, best_err = 10, 10
        idx = 0
        for i in range(n_tests):
            enc_in, dec_out = np.expand_dims(test_x[i], 0), np.expand_dims(
                test_y[i], 0)  # input must be [?, 32, 32, 500]
            pos, curv, step_loss = model.step(sess, enc_in, dec_out, False)
            step_pos_err = evaluate_pos(pos[0], test_y[i, ..., 100:400],
                                        test_y[i, ..., :100])
            loss += step_loss
            pos_err += step_pos_err
            if step_loss < best_loss:
                idx = i
                best_loss = step_loss
                best_err = step_pos_err
                best_pos = pos

    # re_pos = reconstruction(pos, curv)
    # pos_re_err = evaluate_pos(re_pos, test_y[..., 100:400], test_y[..., :100])
    # print('position error after reconstruction: %.4e' % pos_re_err)
        print('==================================\n'
              'total loss avg:            %.4f\n'
              'position error avg(m):     %.4f\n'
              '==================================' %
              (loss / n_tests, pos_err / n_tests))
        print('best')
        print('==================================\n'
              'total loss avg:            %.4f\n'
              'position error avg(m):     %.4f\n'
              '==================================' % (best_loss, best_err))
    # choose the last one
    visualize(args.data_dir, test_x[idx], test_y[idx, ..., 100:400],
              best_pos[0], angles[idx])
Exemplo n.º 7
0
def test2():
    # Create a bonding pair and bond them.
    a, a_site, b, b_site = getbondingpair()    
    print("Atom a:")
    print(a)
    print("Atom b:")
    print(b)
    print('Bonding sites: ')
    print(a_site)
    print(b_site)
    c = particle.Atom.compose(Atom1=a, Atom2=b, int_site1=a_site, int_site2=b_site)
    print(a_site)
    print(b_site)
    print(c.rbn.summarystring())
    print(c)
    viz.visualize(c)
Exemplo n.º 8
0
Cauchy = np.zeros((3, 3), order='F')

enerintern = 0
enerinelas = 0

CompDam_DGD.dgd_mod.dgdevolve(u=U,
                              f=F,
                              f_old=F_old,
                              m=m,
                              p=p,
                              sv=sv,
                              ndir=3,
                              nshr=3,
                              dt=0,
                              density_abq=1,
                              cauchy=Cauchy,
                              enerintern=enerintern,
                              enerinelas=enerinelas,
                              fatigue_step=False)
# print Cauchy

CompDam_DGD.dgd_mod.log_close()

# Visualize
viz.visualize(lc=svarray[5:8],
              alpha=svarray[9],
              F=F,
              pathToLogFile='pyextmod_run_output.txt',
              initMD=1,
              initEQk=1)
Exemplo n.º 9
0
def visualize_snippet(snip):
    visualize(np.expand_dims(snip, axis=1), isNumpy=True)
transition_matrix = np.array([ [biggest_p, bigger_p, big_p, small_p, tiny_p],
                               [bigger_p, biggest_p, big_p, small_p, tiny_p],
                               [tiny_p, small_p, biggest_p, bigger_p, big_p],
                               [small_p, big_p, tiny_p, biggest_p, bigger_p],
                               [bigger_p, big_p, small_p, tiny_p, biggest_p]])

assert np.array_equal(np.sum(transition_matrix, axis=1), np.ones([np.shape(transition_matrix)[0]]))

snippets = [sitting_behaviour, walking_behaviour, starting_behaviour, flying_behaviour, landing_behaviour]

traj = simulate_trajectory(snippets, transition_matrix, 100)
print(np.shape(traj))
print(traj)

traj = traj / np.max(np.abs(traj), axis=0)

visualize(np.expand_dims(traj,axis=1), isNumpy=True)




# TODO 3: define markov chain to generate new behaviour
# TODO 4: visualize results
# TODO 5: refine markov chain in order to get smooth results, maybe with curves to transit in flying mode





Exemplo n.º 11
0
sv = CompDam_DGD.statevar_mod.loadstatevars(len(svarray), svarray, m)
# print sv


# Other inputs
F = np.array([
	[0.825492123341086E+00, 0.757572103784855E-03, 0.301104249035103E-03],
	[-.146788494201401E+00, 0.100523463166065E+01, 0.641873185909126E-03],
	[-.662872667983369E-03, 0.871848067078203E-04, 0.100738051937547E+01]])

F_old = np.array([
	[0.828052171305039E+00, 0.741124652528062E-03, 0.313281227086903E-03],
	[-.148260374255618E+00, 0.100527363842522E+01, 0.620850904202262E-03],
	[-.624763825230815E-03, 0.790313763395604E-04, 0.100728719006083E+01]])

U = np.array([
	[0.834616447357706E+00, -.799991473742500E-01, -.263339433701766E-03],
	[-.799991473742500E-01, 0.100204653434751E+01, 0.354440612331553E-03],
	[-.263339433701766E-03, 0.354440612331553E-03, 0.100738067209290E+01]])

Cauchy = np.zeros((3,3), order='F')

CompDam_DGD.dgd_mod.dgdevolve(u=U, f=F, f_old=F_old, m=m, p=p, sv=sv, ndir=3, nshr=3, dt=0, cauchy=Cauchy)
# print Cauchy

CompDam_DGD.dgd_mod.log_close()


# Visualize
viz.visualize(lc=svarray[5:8], alpha=svarray[9], F=F, pathToLogFile='pyextmod_run_output.txt', initMD=2, initEQk=1)