def Input_data():
    f = open('x.txt', 'r')
    all_x = f.readlines()
    f.close()

    f = open('y.txt', 'r')
    all_y = f.readlines()
    f.close()

    xlist = []
    ylist = []
    gender = []
    location = []
    for line in all_x:
        linestr = line.strip()
        linestrlist = linestr.split()
        XX = [int(i) for i in linestrlist]
        xlist.append(XX)
    for line in all_y:
        linestr = line.strip()
        linestrlist = linestr.split()
        YY = [int(i) for i in linestrlist]
        # emotions
        ylist.append(YY[0:5])
        # gender
        gender.append(YY[5])
        # location
        location.append(YY[6:len(YY)])

    count = len(all_x)
    train_len = count * 2 / 3

    train_x = xlist[:train_len]
    train_y = ylist[:train_len]
    train_gender = gender[:train_len]
    train_location = location[:train_len]
    test_x = xlist[train_len: count]
    test_y = ylist[train_len: count]
    test_gender = gender[train_len: count]
    test_location = location[train_len: count]

    return train_x, train_y, train_gender, train_location, test_x, test_y, test_gender, test_location


def format_data(x, y, gender, location):
    ng = 2
    nl = 33
    newx = x
    newy = [[] for i in range(5)]
    L = len(x)
    gender_information = [[] for i in range(ng)]
    location_information = [[] for i in range(nl)]

    # y and info format: the length is the number of class --- [[] [] [] [] [] --- the number of class]
    for i in range(L):
        for k in range(5):
            newy[k].append(y[i][k])
        if gender[i] == 1:   # female
            gender_information[0].append(0)  # male
            gender_information[1].append(1)  # female
        else:
            gender_information[0].append(1)
            gender_information[1].append(0)
        for k in range(nl):
            location_information[k].append(location[i][k])

    return newx, newy, gender_information, location_information