Exemple #1
0
n_static_sound_test = 100
n_random_sound_test = 100

static_test = True
static_sound_test = True
random_sound_test = True

if __name__ == '__main__':
    static_commands = get_random_motor_set(mldiva_synth, n_static_test)

    print("Validating with static samples...")
    for i in range(n_static_test):
        try:
            Aud_ml, Som_ml, Outline_ml, af_ml = mldiva_synth.get_audsom(
                static_commands[i, :])
            Aud, Som, Outline, af = pydiva_synth.get_audsom(
                static_commands[i, :])
        except ValueError:
            print(static_commands[i, :])
            sys.exit()
        err_aud = np.linalg.norm(Aud_ml - Aud)
        err_som = np.linalg.norm(Som_ml - Som)
        err_ol = np.linalg.norm(np.nan_to_num(Outline_ml - Outline))
        err_af = np.linalg.norm(af_ml - af)

        if err_aud > 1e-3 or err_som > 1e-3 or err_ol > 1e-3 or err_af > 1e-3:
            print("Validation failed in static test.")
            print(err_aud)
            print(err_som)
            print(err_ol)
            print(err_af)
            print(static_commands[i, :])
Exemple #2
0
        0.21783021, 0.74918289, 0.48187699
    ]

    art = h5_to_ndarray('arts', '../data/hard_arts.h5')

    # art = [0.1]*10 + [1]*3

    # Using get_sample
    aud, som, outline, af, d = diva_synth.get_sample(np.array(art[0, :]))
    print(aud)
    print(som)
    print(af)

    # Using get_audsom
    arts = np.tile(art, (100, 1))
    aud, som, outline, af = diva_synth.get_audsom(arts.transpose())
    fig1, ax1 = plt.subplots(2, 2)
    plt.sca(ax1[0, 0])
    plt.plot(aud)
    plt.sca(ax1[0, 1])
    plt.plot(som)

    # Using plot_outline
    diva_synth.plot_outline(art, axes=ax1[1, 0])

    # Using get_sound  and play_sound
    sound = diva_synth.get_sound(art)
    sound2 = diva_synth_ml.get_sound(art)
    plt.sca(ax1[1, 1])
    plt.plot(sound)
    plt.hold(True)
system = Diva()
system.n_motor = 13
system.min_motor_values = np.array([-3]*10+[0]*3)
system.max_motor_values = np.array([3]*10+[1]*3)

n_samples_train = 1000000
n_samples_test = 1000
motor_commands = get_random_motor_set(system, n_samples_train)
motor_commands_test = get_random_motor_set(system, n_samples_test)

af_train = np.zeros((n_samples_train, 220))
ss_train = np.zeros((n_samples_train, 6))
for i in range(n_samples_train):
    # print(motor_commands[i,:])
    a,ss,c,af = system.get_audsom(motor_commands[i,:])
    af_train[i,:len(af)] = af
    ss_train[i,:] = ss[:6]
    if i/n_samples_train in [0.2, 0.4, 0.6, 0.8]:
        print('{}% of training samples has been obtained'.format(i/n_samples_train*100))

af_test = np.zeros((n_samples_test, 220))
ss_test = np.zeros((n_samples_test, 6))
for i in range(n_samples_test):
    # print(motor_commands[i,:])
    a,ss,c,af = system.get_audsom(motor_commands_test[i,:])
    af_test[i,:len(af)] = af
    ss_test[i,:] = ss[:6]
    if i/n_samples_test in [0.2, 0.4, 0.6, 0.8]:
        print('{}% of test samples has been obtained'.format(i/n_samples_test*100))