file.write("Last Node :" + str(last_node) + '\n')
        file.write("Units :" + str(units) + '\n')
        file.write("filter_A :" + str(filter_A) + '\n')
        file.write("filter_B :" + str(filter_B) + '\n')
        # file.write("filter_C :" + str(filter_C) + '\n')
        file.write("Optimizer :" + str(optimizer) + '\n\n')

        stop_tset = clock()
        elap_tset = stop_tset - start_tset
        Total_time_tset = int(elap_tset / 60)
        file.write("The Elapsed Time for this test set :" + str(Total_time_tset) + ' min' + '\n')
        print ("The Elapsed Time for this test set :" + str(Total_time_tset) + ' min' + '\n')
        file.write('===================================================================' + '\n\n')

        file.close()
        finish_alarm.ring('piano01')

        print('Test set ' + str(tn) + ' is complete.')

        score_recog = '{0:.3f}'.format(score[1])
        mv_score = '{0:.3f}'.format(mv_score)

        if speak ==1:
            try:
                speak_str('Test set. ' + str(tn) + ' is complete.')
                speak_str('The recognition score is, ' + score_recog +'.' + score_recog +'.')
                speak_str('and the majority vote score is, ' + mv_score +'.' + mv_score +'.')

            finally:
                print ()
def set_data(open_data,test_set_num, valid_set_num, speak):
    '''
        set_file.py
        This python file divides pickle data into Train set, Valid set, Test set.
    '''
    #############################################################################
    # open_data = 'data_j1_01010101_SR48kHz'
    # open_data = 'data_j1_11111111_SR48kHz'
    # open_data = 'class13_data_j1_01010101_SR48kHz'
    #############################################################################
    pickle_path = 'pickle_folder/'
    with open(pickle_path + open_data + '.pickle') as f:
        sum_mat_X_data, sum_mat_y_data, sum_mat_k_data, sum_mat_D_data, jump_num, FN, nb_classes = pickle.load(f)

    print "The feature data per one inst sample is (=jump_num) :", jump_num

    ## Set the key for test set and validation set.
    ## The whole data is divided into 10 different data sets.
    ## You can choose a key number from 1 to 10.


    # val_key = [[8],[9]]
    # # val_key = []
    # tst_key = [[7],[1]]
    val_key = [valid_set_num]
    # val_key =[]
    tst_key = [test_set_num]

    # print "shape of sum_mat_X_data", shape(sum_mat_X_data)
    # print "shape of sum_mat_y_data", shape(sum_mat_y_data)
    # print "shape of sum_mat_k_data", shape(sum_mat_k_data)
    # print "shape of sum_mat_D_data", shape(sum_mat_D_data)

    # print sum_mat_k_data

    ## Call "test_set.set_train_data" function to divide data
    X_train, X_test, X_valid, y_train, y_test, y_valid, k_train, k_test, k_valid, D_train, D_test, D_valid \
        = test_set_val.set_train_data(sum_mat_X_data,sum_mat_y_data,sum_mat_k_data, sum_mat_D_data, tst_key, val_key)

    # print "k_test:", k_test.T
    # print "y_test:", y_test.T
    # print "y_train:", y_train.T

    # print "shape of X_train", shape(X_train).
    # print "shape of X_test",  shape(X_test).
    # print "shape of X_valid", shape(X_valid)

    # print "shape of X_train", shape(X_train)
    # print "shape of X_test",  shape(X_test)
    # print "shape of X_valid", shape(X_valid)
    #
    # print "shape of y_train", shape(y_train)
    # print "shape of y_test",  shape(y_test)
    # print "shape of y_valid", shape(y_valid)
    #
    #
    # print "shape of k_train", shape(k_train)
    # print "shape of k_test",  shape(k_test)
    # print "shape of k_valid", shape(k_valid)
    #
    # print "shape of D_train", shape(D_train)
    # print "shape of D_test",  shape(D_test)
    # print "shape of D_valid", shape(D_valid)
    print "\n" + open_data + " : DATA set ready! \n"



    # speak_str('Data seperation for test set '+ str(test_set_num) +' is complete.')
    if speak == 1 :
        try:
            speak_str('Initiate classification for test set '+ str(test_set_num)+ '.'+'\n')
        except ConnectionError as e:
            print ('ConnectionError \n')

    finish_alarm.ring('guitar_c3_04')

    return X_train, X_test, X_valid, y_train, y_test, y_valid, D_train, D_test, D_valid, jump_num, FN, nb_classes, open_data
    file.write( vars_str[k] + ":"+ str(var) +"\n")

file.write(  "random seed" + ":" + str(seed_n) + "\n")
file.write(  "div_margin" + ":" + str(div_margin) + "\n")
file.write(  "min_margin" + ":" + str(min_margin) + "\n")
file.write(  "nb_classes is :"+str(nb_classes)+"\n")
file.write(  "inst_index"+str(inst_index)+"\n")
file.write(  "itv_stride"+str(itv_stride)+"\n\n")
file.write(  "Instruments(folder_name) : " + str(folder_name[family]) + "\n" )
file.write( data_note +'\n')
file.close()


# print sum_mat_D_data
t_stop = clock()
elapsed_time = int(int(t_stop - t_start)/60)
print 'Feature extraction process for ' + rand_animal + ' is complete'
print 'Elapsed time is :'+ str(elapsed_time) +' minutes '
print pickle_file + ' has been finished.'


if speak == 1:
    try:
        finish_alarm.ring('bell01')
        speak_str('Feature extraction process for ' + rand_animal + ' is complete.')
        speak_str('Elapsed time is :'+ str(elapsed_time) +' minutes ')
    except ConnectionError as e:
        print ('ConnectionError! Check the Wifi Connection. \n')

print 'sample count:', sample_count