Пример #1
0
def plot_latex_for_compasison(figure_paths, method_names, name_out_path):

    methods = len(figure_paths)

    tex_file = []
    tex_file.append('\\documentclass{article}')
    tex_file.append('\\usepackage{geometry}')
    tex_file.append('\\usepackage[usenames, dvipsnames]{color}')
    tex_file.append('\\geometry{margin=1cm}')
    tex_file.append('\\usepackage[english]{babel}')
    tex_file.append('\\usepackage{graphicx}')
    tex_file.append('\\begin{document}')

    count = 0

    for t in xrange(5):
        for f in ['nasal', 'no', 'non-nasal']:
            for v in ['long', 'short']:
                name = '{}_{}_{}'.format(t, v, f)

                #------------ Figure ----------------#
                print '{}/{}.eps'.format(figure_paths[0], name)

                if Utility.is_file_exist('{}/{}.eps'.format(
                        figure_paths[0], name)):
                    tex_file.append('\\begin{figure}[t]')

                    # minipage #
                    for idx, i in enumerate(figure_paths):
                        eps = '{}/{}.eps'.format(figure_paths[idx], name)
                        if Utility.is_file_exist(eps):
                            tex_file.append(
                                '\\begin{{minipage}}[b]{{{}\\textwidth}}'.
                                format(1.0 / float(methods) - 0.01))
                            tex_file.append('\\centering')
                            tex_file.append(
                                '\\includegraphics[width=\\textwidth]{{{}/{}.eps}}'
                                .format(figure_paths[idx], name))
                            tex_file.append('{}'.format(method_names[idx]))
                            tex_file.append('\\end{minipage}')

                    # minipage #
                    tex_file.append('\\caption{{{}}}'.format(
                        name.replace('_', '\_')))
                    tex_file.append('\\end{figure}')

                #------------ Figure ----------------#

                count = count + 1
                if count == 4:
                    tex_file.append('\\clearpage')
                    count = 0

    tex_file.append('\\end{document}')

    Utility.write_to_file_line_by_line(name_out_path, tex_file)

    pass
def plot_latent_space(base_path, db_file, name_out_path):

    names_file = '{}/names.pkl'.format(base_path)
    out_data = '{}/x.pkl'.format(base_path)
    input_sensitivity = '{}/input_sensitivity.pkl'.format(base_path)

    if not Utility.is_file_exist(out_data):
        print out_data
        print 'Not exist'
        return

    names = Utility.load_obj(names_file)

    db = Utility.load_obj(db_file)

    name_list = []
    for d in db:
        name_list.append(d['id'])

    label = []
    for nn in names:
        idx = name_list.index(nn)
        label.append(db[idx]['stress'])

    out = Utility.load_obj(out_data)

    print out.shape

    input_sent = Utility.load_obj(input_sensitivity)
    print input_sent
    most_dominants = Utility.get_input_sensitivity(input_sent, 2)

    x = out[:, most_dominants[0]]
    y = out[:, most_dominants[1]]

    label = map(int, label)
    label = np.array(label)

    print set(label)

    colors = ['red', 'green', 'blue', 'purple']

    plt.clf()
    plt.scatter(x, y, c=label, cmap=matplotlib.colors.ListedColormap(colors))
    plt.savefig(name_out_path)
Пример #3
0
    out_path = '/work/w23/decha/decha_w23/Second_Journal/Latent_space_training_result/05_02a_with_no_duration/input_dim_10/'

    print out_path

    for t in [0]:
        for f in ['nasal', 'no', 'non-nasal']:
            for v in ['long', 'short']:
                name = '{}_{}_{}'.format(t, v, f)
                db_file = '{}/{}.npy'.format(db_path, name)

                name_out_path = '{}/{}/'.format(out_path, name)

                Utility.make_directory(name_out_path)

                if Utility.is_file_exist(db_file):
                    run_training(db_file, name_out_path)

    # t = '4'
    # v = 'long'
    # f = 'no'

    # name = '{}_{}_{}'.format(t, v, f)
    # db_file = '{}/{}.npy'.format(db_path, name)

    # name_out_path = '{}/{}/'.format(out_path, name)

    # Utility.make_directory(name_out_path)

    # if Utility.is_file_exist(db_file):
    #     run_training(db_file, name_out_path)
        set_syllable_full_path = '{}/{}/'.format(syllable_full_path, ch)

        set_out_path = '{}/{}/'.format(out_path, ch)

        Utility.make_directory(set_out_path)

        if Utility.is_dir_exists(set_stress_path) & Utility.is_dir_exists(set_utt_base_path):
            print ch

            for i in xrange(1, 51):

                name = 'tscsd{}{}'.format(ch, Utility.fill_zero(i, 2))

                yaml_filename = '{}/{}.utt.yaml'.format(set_utt_base_path, name )
                if not Utility.is_file_exist(yaml_filename):
                    continue

                full_file = '{}/{}.lab'.format(set_syllable_full_path, name)

                count = [0]
                yaml = Utility.yaml_load(yaml_filename)
                add_stress(yaml, count, name)

                if not (len(Utility.read_file_line_by_line(full_file)) == count[0] ):
                    print 'Not equal'
                    print name, len(Utility.read_file_line_by_line(full_file)), count[0]

                out_file = '{}/{}.utt.yaml'.format(set_out_path, name)
                Utility.yaml_save(out_file, yaml)
def get_data(path):

    clustered_label = Utility.load_obj('{}/clustered_label.npy'.format(path))
    # print len(clustered_label)
    best_measure_params = Utility.load_obj('{}/best_measure_params.npy'.format(path))
    # print best_measure_params
    name_index = np.array( Utility.load_obj('{}/name_index.npy'.format(path)) )
    # print len(name_index)
    m = Utility.load_obj('{}/GP_model.npy'.format(path))
    model = m.X.mean
    model = np.array(model)
    # print model

    input_sensitivity = m.input_sensitivity()
    print 'Input sent : ', input_sensitivity

    group_list = ['-1', '0', '1', '2']

    sort_list = []

    for group in group_list:
        g = '{}/group_list/{}.npy'.format(path, group)
        if Utility.is_file_exist(g):
            names = Utility.load_obj(g)
            sort_list.append((group, len(names)))

    Utility.sort_by_index(sort_list, 1)
    print sort_list

    unstressed_mean = get_means(sort_list, len(sort_list)-1, name_index, model, path)
    unstressed_list = Utility.load_obj( '{}/group_list/{}.npy'.format(path, sort_list[len(sort_list)-1][0]) )

    stressed_mean = get_means(sort_list, len(sort_list)-2, name_index, model, path)
    stressed_list = Utility.load_obj( '{}/group_list/{}.npy'.format(path, sort_list[len(sort_list)-2][0]) )

    Utility.save_obj( 
        {'unstress_mean': unstressed_mean, 'stress_mean': stressed_mean}, 
        '{}/mean_of_unstress_stress.npy'.format(path) )

    lengthscale=1/np.array(input_sensitivity, dtype=float)
    kernel = GPy.kern.RBF(10, lengthscale=lengthscale, ARD=True)

    print len(unstressed_list), len(stressed_list)

    for idx, g in enumerate(sort_list):
        if idx == (len(sort_list)-2): break
        names = Utility.load_obj('{}/group_list/{}.npy'.format(path, g[0]))

        print len(names)

        latent_data = get_data_from_a_giving_name_index(names, name_index, model)

        stu = np.array([unstressed_mean, stressed_mean])
        distance = -1*np.log(kernel.K( latent_data, stu ))

        for n, dis in zip(names, distance):
            if dis[0] > dis[1]:
                unstressed_list = np.append(unstressed_list, n)
            else : 
                stressed_list = np.append(stressed_list, n)

    print len(unstressed_list), len(stressed_list)
    # print unstressed_list, stressed_list

    unstressed_data = get_data_from_a_giving_name_index(unstressed_list, name_index, model)
    stressed_data = get_data_from_a_giving_name_index(stressed_list, name_index, model)

    unstress_distance = -1*np.log(kernel.K( unstressed_data, np.array([stressed_mean]) ))
    # print unstress_distance

    unstress_distance = np.append(unstress_distance, 0.0)
    unstress_distance = np.reshape(unstress_distance, (len(unstress_distance),1 ))

    min_max_scaler = preprocessing.MinMaxScaler()
    unstress_distance = min_max_scaler.fit_transform(unstress_distance)
    unstress_distance = np.reshape(unstress_distance, len(unstress_distance))

    unstress_distance = 1 - unstress_distance
    # print unstress_distance
    # print min(unstress_distance), max(unstress_distance)

    for nam, dis in zip(unstressed_list, unstress_distance):
        out_dict[nam] = float("{0:.4f}".format(dis)) 

    for nam, dis in zip(stressed_list, [1.0] * len(stressed_list)):
        out_dict[nam] = dis

    # print out_dict

    return (unstressed_list, stressed_list)
def get_training_object(train_list, feature, duration, delta_bool, delta2_bool,
                        base_path):
    syl_list = []
    for t in train_list:
        syl_obj = Utility.load_obj(t)
        syl_list += syl_obj.syllables_list
    syllable_management_object = SyllableDatabaseManagement(
        syllable_list=syl_list)
    Y, names, tone, stress, syllable_short_long_type, syllalbe_position, phoneme, syllable_type = syllable_management_object.get_GP_LVM_training_data(
        feature_key=feature,
        dur_position=duration,
        # dur_position=[],
        delta_bool=delta_bool,
        delta2_bool=delta2_bool,
        num_sampling=50,
        get_only_stress='1')

    tone = np.array(tone)

    Y = np.array(Y)
    for r in range(len(Y[0])):
        Y[:, r] = preprocessing.normalize(Y[:, r])

    arr = np.arange(len(Y))
    np.random.shuffle(arr)

    label_feature = tone
    alldata = ClassificationDataSet(len(Y[0]),
                                    1,
                                    nb_classes=len(set(label_feature)))
    for a in arr:
        alldata.addSample(Y[a], label_feature[a])

    alldata._convertToOneOfMany()

    if Utility.is_file_exist('{}/GP_model.npy'.format(base_path)):

        model = Utility.load_obj('{}/GP_model.npy'.format(base_path))
        input_sensitivity = model.input_sensitivity()

        latent_data = np.array(
            Utility.load_obj('{}/GP_model.npy'.format(base_path)).X.mean)
        name_index = np.array(
            Utility.load_obj('{}/name_index.npy'.format(base_path)))

        latent_Y = []
        for n in names:
            ind = np.where(name_index == n)
            # print latent_data[ind][0].shape
            latent_Y.append(latent_data[ind][0])

        latent_Y = np.array(latent_Y)
        print latent_Y.shape

        for r in range(len(latent_Y[0])):
            # latent_Y[:,r] = preprocessing.normalize(latent_Y[:,r])
            latent_Y[:, r] = preprocessing.normalize(latent_Y[:, r] *
                                                     input_sensitivity[r])

        lat_data = ClassificationDataSet(len(latent_Y[0]),
                                         1,
                                         nb_classes=len(set(label_feature)))
        for a in arr:
            # print latent_Y[a], a
            lat_data.addSample(latent_Y[a], label_feature[a])

    else:
        lat_data = ClassificationDataSet(len(latent_Y[0]),
                                         1,
                                         nb_classes=len(set(label_feature)))

    lat_data._convertToOneOfMany()
    return (alldata, lat_data)
Пример #7
0
        syllable_predicted_basepath, 'all', data_dict[training_size],
        data_dict[training_size], block_size, block_size)

    zero_coeff_predicted_dct_path = '{}/out_{}/tsc/a-{}/infer/a-{}/demo/seed-00/M-{}/B-{}/num_iters-5/dur/predictive_distribution/'.format(
        zero_coeff_predicted_basepath, 'all', data_dict[training_size],
        data_dict[training_size], block_size, block_size)

    #----------Running------------#

    main_out_data = dict()
    for num in range(1, 51):

        name = '{}{}'.format(basename, Utility.fill_zero(num, 2))
        f = '{}/{}.pkl'.format(non_optimal_path, name)

        if Utility.is_file_exist(f):
            main_out_data[name] = Utility.load_obj(f)
            continue

        # outfile = '{}/{}.npy'.format(outpath, name)

        base_path = '{}/{}/'.format(frame_predicted_lf0_path, name)
        label_path = '{}/{}.lab'.format(syl_duration_path, name)

        phone_label_path = '{}/{}.lab'.format(ph_duration_path, name)

        var_path = '{}/inv_dimension_cov.npy'.format(frame_predicted_lf0_path)

        #--------Phone--------#

        phone_base_path = '{}/{}/'.format(phone_predicted_dct_path, name)
Пример #8
0
def plot_latent_space(base_path, db_file, name_out_path):

    names_file = '{}/names.pkl'.format(base_path)
    out_data = '{}/x.pkl'.format(base_path)
    input_sensitivity = '{}/input_sensitivity.pkl'.format(base_path)

    if not Utility.is_file_exist(out_data) : 
        print out_data
        print 'Not exist'
        return

    names = Utility.load_obj(names_file)

    db = Utility.load_obj(db_file)

    name_list = []
    for d in db:
        name_list.append( d['id'] )

    label = []
    for nn in names:
        idx = name_list.index(nn)
        
        if db[idx]['stress'] == '1':
            label.append(db[idx]['stress'])
        elif nn in potential_list:
            label.append('3')
        else :
            label.append(db[idx]['stress'])


    out = Utility.load_obj(out_data)

    # print out.shape

    input_sent = Utility.load_obj(input_sensitivity)
    # print 'input_sensitivity : ', sorted(input_sent)
    most_dominants = Utility.get_input_sensitivity(input_sent, 2)

    x = out[ :, most_dominants[0] ]
    y = out[ :, most_dominants[1] ]

    label = map(int, label)
    label = np.array(label)

    # print set(label)

    train = np.append( out[label==2] , out[label==3], axis=0 )
    # train = out[label==2] 
    # print train.shape

    test = out[label==0]

    lengthscale=1/np.array(input_sent, dtype=float)
    k = GPy.kern.RBF(len(train[0]), ARD=True, lengthscale=lengthscale)

    plt.clf()

    colors = ['red','green','blue','purple']

    md = most_dominants[0]

    mean = np.mean(train, axis=0)
    var = np.var(train, axis=0)
    # rv = multivariate_normal(mean=np.mean(train, axis=0), cov=np.var(train, axis=0))

    sd = np.std(train[:,most_dominants[0]], axis=0)

    for idx, lab in enumerate(label): 
        # if lab == 2: continue
        # if lab == 3: continue

        # print out[idx][md], mean

        d = distance.euclidean(out[idx][md], mean[md])
        # print d

        if d < sd:
            # label[idx] = 4
            label[idx] = 2
        elif d < 2*sd:
            # label[idx] = 6
            label[idx] = 2
            pass

    label[label==3] = 2
    print len(out), len(names)
    print set(label), len(label)

    if len(set(label)) > 3:
        print 'error : ', name_out_path
        raise

    global syl_dict

    for n, lab in zip(names, label) :
        syllable = dict()
        syllable['stress'] = lab
        syl_dict[n] = syllable

    # print names
    # print label

    # return

    for idx, s in enumerate( [0,1,4,5,6,2,3] ):
        # if (s == 3) | (s == 2):
        if (s == 2):
            # plt.scatter(x[label==s], y[label==s], c=colors[s], label=s, s=100)
            plt.scatter(x[label==s], y[label==s], c=colors[s], label='Manual weak stress labeling', s=100)
            pass
        elif (s==-1):
            plt.scatter(x[label==s], y[label==s], c='red', label=s, s=20)
        elif (s==1):
            plt.scatter(x[label==s], y[label==s], c='red', label='Stress', s=7)
            pass
        elif (s==5):
            # plt.scatter(x[label==s], y[label==s], c='yellow', label=s, s=20, marker='^', linewidth='0')
            pass
        elif (s==4):
            plt.scatter(x[label==s], y[label==s], c='green', label='Weak stress in 1 SD', s=20, marker='*', linewidth='0')
        elif (s==6):
            plt.scatter(x[label==s], y[label==s], c='orange', label='Weak stress in 2 SD', s=20, marker='h', linewidth='0')
        # else:
        elif (s==0):
            plt.scatter(x[label==s], y[label==s], c='black', label='Unstress', s=7, marker='.', linewidth='0')
            pass

    plt.scatter(mean[most_dominants[0]], mean[most_dominants[1]], c='red', label=s, s=200, marker='x')

    x_lim = plt.xlim()
    y_lim = plt.ylim()

    xx, yy = np.mgrid[x_lim[0]:x_lim[1]:.01, y_lim[0]:y_lim[1]:.01]
    pos = np.empty(xx.shape + (2,))
    pos[:, :, 0] = xx; pos[:, :, 1] = yy

    x_train = train[ :, most_dominants[0] ]
    y_train = train[ :, most_dominants[1] ]

    # rv = multivariate_normal(
    #     [mean[most_dominants[0]], mean[most_dominants[1]] ], 
    #     [var[most_dominants[0]], var[most_dominants[1]] ])
    # print rv
    # print 'means : ', rv.pdf([np.mean(x_train), np.mean(y_train)])

    # plt.contourf(xx, yy, rv.pdf(pos), alpha=0.5)

    # plt.legend(prop={'size':12})
    plt.savefig( name_out_path )
def plot_latent_space(base_path, db_file, name_out_path):

    names_file = '{}/names.pkl'.format(base_path)
    out_data = '{}/x.pkl'.format(base_path)
    input_sensitivity = '{}/input_sensitivity.pkl'.format(base_path)

    if not Utility.is_file_exist(out_data):
        print out_data
        print 'Not exist'
        return

    names = Utility.load_obj(names_file)

    db = Utility.load_obj(db_file)

    name_list = []
    for d in db:
        name_list.append(d['id'])

    label = []
    iden = []

    target_id = []

    for nn in names:
        idx = name_list.index(nn)
        label.append(db[idx]['stress'])
        iden.append(nn)
        if nn in ['tscsdm38_55', 'tscsdu01_32', 'tscsdg02_21']:
            target_id.append(idx)

    target_id = np.array(target_id)

    out = Utility.load_obj(out_data)

    iden = np.array(iden)

    print out.shape

    input_sent = Utility.load_obj(input_sensitivity)
    print input_sent
    most_dominants = Utility.get_input_sensitivity(input_sent, 2)

    x = out[:, most_dominants[0]]
    y = out[:, most_dominants[1]]

    label = map(int, label)
    label = np.array(label)

    print set(label)

    # ind = np.random.choice(len(label), 20)
    # x = x[ind]
    # y = y[ind]
    # label = label[ind]
    # iden = iden[ind]

    colors = ['red', 'green', 'blue', 'purple']

    plt.clf()
    plt.scatter(x,
                y,
                c=label,
                cmap=matplotlib.colors.ListedColormap(colors),
                alpha=0.5)

    el = Ellipse((2, -1), 0.5, 0.5)

    for lab, xx, yy, yyy in zip(['Unstress', 'Strong stress', 'Weak stress'],
                                x[target_id], y[target_id], [50, 100, 50]):
        # for lab, xx, yy in zip(iden, x, y):
        # yyy = 20
        plt.annotate(lab,
                     xy=(xx, yy),
                     xytext=(0, yyy),
                     textcoords='offset points',
                     ha='left',
                     va='bottom',
                     bbox=dict(boxstyle='round,pad=0.5',
                               fc='yellow',
                               alpha=0.5),
                     arrowprops=dict(arrowstyle="simple",
                                     fc="0.6",
                                     ec="none",
                                     patchB=el,
                                     connectionstyle="arc3,rad=0.3",
                                     color='g'))
    plt.savefig(name_out_path)
Пример #10
0
import numpy as np
import matplotlib.pyplot as plt

if __name__ == '__main__':

    frame_less_count = 0

    count = 0

    for t in [0,1,2,3,4]:
        for l in ['short', 'long']:
            for n in ['no', 'nasal', 'non-nasal']:

                path = '/work/w2/decha/Data/GPR_speccom_data/syllable_database/04_data_with_intepolate_for_training/{}_{}_{}.npy'.format(t, l, n)

                if Utility.is_file_exist(path):

                    syl_dict = Utility.load_obj(path)

                    for s in syl_dict: 

                        syl = s

                        dur = 0.0
                        for i, d in enumerate(syl['dur']):
                            if i == 0: continue
                            dur = dur + float(d)

                        # print dur 
                        # print syl['dur']
                        frame = dur/50000.0
Пример #11
0
        print outpath

        label_path = '/work/w2/decha/Data/GPR_speccom_data/00_syllable_level_data/mono/tsc/sd/'
        for s in Utility.char_range('a', 'z'):
            set_label_path = '{}/{}/'.format(label_path, s)

            set_dct_path = '{}/{}/'.format(outpath, s)
            Utility.make_directory(set_dct_path)

            for x in range(1, 51):

                name = 'tscsd{}{}'.format(s, Utility.fill_zero(x, 2))

                file_path = '{}/{}.lab'.format(set_label_path, name)

                if not Utility.is_file_exist(file_path): continue

                dur_list, names = PoGUtility.gen_dur_and_name_list(
                    file_path, name)

                if len(dur_list) != len(names):
                    print name

                # print names

                dct_list = []

                for n in names:
                    if n in syl_dict:
                        if incl_zero == 'not_include_zero_coeff':
                            dct_list.append(syl_dict[n][1:num_coeff])
import matplotlib.pyplot as plt

if __name__ == '__main__':

    base_path = '/work/w13/decha/Inter_speech_2016_workplace/Tonal_projection/10_tone_classification/'
    for v in Utility.list_file(base_path):
        if '.' in v: continue
        for dims in Utility.list_file('{}/{}/'.format(base_path, v)):
            if '.' in dims: continue
            for delta in Utility.list_file('{}/{}/{}/'.format(
                    base_path, v, dims)):
                if '.' in delta: continue
                for tone in Utility.list_file('{}/{}/{}/{}/'.format(
                        base_path, v, dims, delta)):
                    if '.' in tone: continue
                    tone_path = '{}/{}/{}/{}/{}/'.format(
                        base_path, v, dims, delta, tone)
                    print tone_path

                    gp_model = '{}/GP_model.npy'.format(tone_path)
                    if Utility.is_file_exist(gp_model):
                        m = Utility.load_obj(gp_model)
                        data = m.X.mean
                        data = np.array(data)
                        # print data
                        Utility.save_obj(
                            data, '{}/readable_gp_model.npy'.format(tone_path))
                        # sys.exit()

    pass
Пример #13
0
def gen_latex(db_filepath, figure_path_name, name_out_path, syl_db_name):

    print db_filepath

    syl_list = Utility.load_obj(db_filepath)

    print 'List length : {}'.format(len(syl_list))

    fig_path = '{}/{}/'.format(figure_path, figure_path_name)

    tex_file = []
    tex_file.append('\\documentclass{article}')
    tex_file.append('\\usepackage{geometry}')
    tex_file.append('\\usepackage[usenames, dvipsnames]{color}')
    tex_file.append('\\geometry{margin=1cm}')
    tex_file.append('\\usepackage[english]{babel}')
    tex_file.append('\\usepackage{graphicx}')
    tex_file.append('\\begin{document}')
    tex_file.append('\\begin{figure}[t]')

    count = 0

    db = Utility.load_obj(syl_db_name)

    for syl in syl_list:
        # print syl
        name = syl[0]

        syl_info = find_syl(db, name)

        # print name
        tex_file.append('\\begin{minipage}[b]{.24\\textwidth}')

        if (syl_info['id'] in potential_list) & (syl[2] == '1'):
            tex_file.append('\colorbox{yellow}{Stress and potent}')
        elif (syl_info['id'] in potential_list) & (syl[2] == '2'):
            tex_file.append('\colorbox{green}{May Stress and potent}')
        elif syl[2] == '1':
            tex_file.append('\colorbox{red}{Stress}')
        elif syl[2] == '2':
            tex_file.append('\colorbox{blue}{May Stress}')
        elif syl_info['id'] in potential_list:
            tex_file.append('\colorbox{Apricot}{Potent}')
        else:
            tex_file.append('UnStress')
        tex_file.append('\\centering')

        eps = None
        long_eps = '/work/w2/decha/Data/GPR_speccom_data/figure/lf0_plot_by_vowel_finalconsonant/{}_long_{}/{}.eps'.format(
            figure_path_name.split('_')[0],
            figure_path_name.split('_')[1], name)
        if Utility.is_file_exist(long_eps):
            eps = long_eps
        else:
            eps = '/work/w2/decha/Data/GPR_speccom_data/figure/lf0_plot_by_vowel_finalconsonant/{}_short_{}/{}.eps'.format(
                figure_path_name.split('_')[0],
                figure_path_name.split('_')[1], name)

        tex_file.append(
            '\\includegraphics[width=\\textwidth]{{{}}}'.format(eps))
        tex_file.append('{} {}-{}-{}-{} {}'.format(
            name.replace('_', '-'), syl_info['consonant'], syl_info['vowel'],
            syl_info['finalconsonant'].replace('^', '\\textasciicircum'),
            syl_info['tone'], syl[1] / 50000))
        tex_file.append('\\end{minipage}')

        count = count + 1
        if count == 20:
            tex_file.append('\\end{figure}')
            tex_file.append('\\clearpage')
            tex_file.append('\\begin{figure}[t]')
            count = 0
        elif count % 4 == 0:
            tex_file.append('\\end{figure}')
            tex_file.append('')
            tex_file.append('\\begin{figure}[t]')

    # if not count == 0:
    tex_file.append('\\end{figure}')

    tex_file.append('\\end{document}')

    Utility.write_to_file_line_by_line(name_out_path, tex_file)

    pass
Пример #14
0
        # sys.exit()


if __name__ == '__main__':

    syllable = dict()

    outpath_file = '/work/w2/decha/Data/GPR_speccom_data/Interspeech2017/syllable_dictionary_data_with_delta_deltadelta.pkl'

    base = '/work/w2/decha/Data/GPR_speccom_data/syllable_database/04_data_with_intepolate_for_training/'

    for tone in [0, 1, 2, 3, 4]:
        for vowel in ['long', 'short']:
            for final in ['nasal', 'non-nasal', 'no']:

                name = '{}_{}_{}'.format(tone, vowel, final)
                datafile = '{}/{}.npy'.format(base, name)

                print datafile

                if Utility.is_file_exist(datafile):

                    mix_data(datafile)

                    # sys.exit()

    Utility.save_obj(syllable, outpath_file)

    pass
Пример #15
0
if __name__ == '__main__':

    method_path = '/work/w23/decha/decha_w23/Second_Journal/Latent_space_training_result/12c_normalization_by_preprocessing_of_11_data/input_dim_10/'
    out_main_path = '/work/w23/decha/decha_w23/Second_Journal/Unsupervised_learning_result/12c_normalization_by_preprocessing_of_11_data/'

    Utility.make_directory(out_main_path)

    for t in xrange(5):
        for f in ['nasal', 'no', 'non-nasal']:
            for v in ['long', 'short']:
                name = '{}_{}_{}'.format(t, v, f)

                base_path = '{}/{}/'.format(method_path, name)

                data_path = '{}/x.pkl'.format(base_path)
                inverselengthscale_path = '{}/input_sensitivity.pkl'.format(
                    base_path)

                out_base_path = '{}/{}/'.format(out_main_path, name)

                if Utility.is_file_exist(data_path):
                    Utility.make_directory(out_base_path)
                    call_run_dbscan(data_path, inverselengthscale_path,
                                    out_base_path)
                else:
                    print 'no ', data_path

        # sys.exit()

    pass
        d[n] = {'stress': lab}

    pass


d = dict()

if __name__ == '__main__':

    name_path = '/work/w23/decha/decha_w23/Second_Journal/Latent_space_training_result/14_merge_vowel_13_data/input_dim_10/'
    best_predicted_path = '/work/w23/decha/decha_w23/Second_Journal/Unsupervised_learning_result/01a_gplvm_rerun_dim10/'

    outpath = '/work/w23/decha/decha_w23/Second_Journal/Evaluation_result/gplvm_result.pkl'

    for t in xrange(5):
        for f in ['nasal', 'no', 'non-nasal']:
            name = '{}_{}'.format(t, f)

            name_file = '{}/{}/names.pkl'.format(name_path, name)
            label_file = '{}/{}/prediction_labels.pkl'.format(
                best_predicted_path, name)

            if Utility.is_file_exist(name_file):
                load_name_and_label(name_file, label_file)

        # sys.exit()

    Utility.save_obj(d, outpath)

    pass