def cross_validation_test(): glogger.setLoggingLevel(glogger.nothing) filename = "/home/gibson/jonask/Dropbox/Ann-Survival-Phd/Two_thirds_of_SA_1889_dataset.txt" #try: # columns = input("Which columns to include? (Do NOT forget trailing comma if only one column is used, e.g. '3,'\nAvailable columns are: 2, -4, -3, -2, -1. Just press ENTER for all columns.\n") #except SyntaxError: columns = (2, -4, -3, -2, -1) print('\nIncluding columns: ' + str(columns)) P, T = parse_file(filename, targetcols = [4, 5], inputcols = columns, ignorerows = [0], normalize = True) #remove tail censored P, T = copy_without_tailcensored(P, T) #try: # comsize = input("Number of networks to cross-validate [10]: ") #except SyntaxError: comsize = 10 print('Number of networks to cross-validate: ' + str(comsize)) #try: # netsize = input('Number of hidden nodes [3]: ') #except SyntaxError as e: if len(sys.argv) < 2: netsize = 3 else: netsize = sys.argv[1] print("Number of hidden nodes: " + str(netsize)) #try: # pop_size = input('Population size [50]: ') #except SyntaxError as e: pop_size = 50 print("Population size: " + str(pop_size)) #try: # mutation_rate = input('Please input a mutation rate (0.25): ') #except SyntaxError as e: mutation_rate = 0.25 print("Mutation rate: " + str(mutation_rate)) #try: # epochs = input("Number of generations (200): ") #except SyntaxError as e: epochs = 200 print("Epochs: " + str(epochs)) com = build_feedforward_committee(comsize, len(P[0]), netsize, 1, output_function = 'linear') #1 is the column in the target array which holds teh binary censoring information test_errors, vald_errors = train_committee(com, train_evolutionary, P, T, 1, epochs, error_function = c_index_error, population_size = pop_size, mutation_chance = mutation_rate) print('\nTest Errors, Validation Errors:') for terr, verr in zip(test_errors.values(), vald_errors.values()): print(str(terr) + ", " + str(verr)) print('\nTest average, Validation average:') print(str(sum(test_errors.values()) / len(test_errors.values())) + ', ' + str(sum(vald_errors.values()) / len(vald_errors.values())))
print('Aaawww....') outputs = net.sim(P) plot_network_weights(net) plt.figure() plt.title('Scatter plot sum square error\n' + filename) plt.xlabel('Survival time years') plt.ylabel('Network output') try: plt.scatter(T.flatten(), outputs.flatten(), c = 'g', marker = 's') plt.plot(T.flatten(), T.flatten(), 'r-') except: pass if __name__ == "__main__": logging.basicConfig(level = logging.INFO) glogger.setLoggingLevel(glogger.info) p = 4 #number of input covariates #net = load_network('/home/gibson/jonask/Projects/aNeuralN/ANNs/PERCEPTRON.ann') net = build_feedforward(p, 10, 1, output_function = "linear") lineartarget_nn = '/home/gibson/jonask/Dropbox/Ann-Survival-Phd/fake_data_set/lineartarget_no_noise.txt' nonlineartarget_nn = '/home/gibson/jonask/Dropbox/Ann-Survival-Phd/fake_data_set/nonlineartarget_no_noise.txt' lineartarget_wn = '/home/gibson/jonask/Dropbox/Ann-Survival-Phd/fake_data_set/lineartarget_with_noise.txt' nonlineartarget_wn = '/home/gibson/jonask/Dropbox/Ann-Survival-Phd/fake_data_set/nonlineartarget_with_noise.txt' while True: experiment(net, nonlineartarget_wn, 500) plt.show()
try: #net = train_cox(net, (P, T), (None, None), timeslots, epochs, learning_rate = learning_rate) net = traingd(net, (P, T), (None, None), epochs, learning_rate, block_size, error_module = cox_error) except FloatingPointError: print('Aaawww....') outputs = net.sim(P) c_index = get_C_index(T, outputs) logger.info("C index = " + str(c_index)) plot_network_weights(net) return net if __name__ == "__main__": logging.basicConfig(level = logging.INFO) glogger.setLoggingLevel(glogger.debug) filename = "/home/gibson/jonask/Dropbox/Ann-Survival-Phd/Two_thirds_of_SA_1889_dataset.txt" P, T = parse_file(filename, targetcols = [4, 5], inputcols = [2, -4, -3, -2, -1], ignorerows = [0], normalize = True) #P, T = parse_file(filename, targetcols = [4, 5], inputcols = [2, -3], ignorerows = [0], normalize = True) #Remove tail censored P, T = copy_without_tailcensored(P, T) #Limit to incourage overtraining! #rows = sample(range(len(T)), 100) #P = P[rows] #T = T[rows] p = len(P[0]) #number of input covariates
outputs = net.sim(P) c_index = get_C_index(T, outputs) logger.info("C index = " + str(c_index)) #plot_network_weights(net) kaplanmeier(time_array = T[:, 0], event_array = T[:, 1], output_array = outputs[:, 0]) if vP is not None and len(vP) > 0: outputs = net.sim(vP) kaplanmeier(time_array = vT[:, 0], event_array = vT[:, 1], output_array = outputs[:, 0]) return net if __name__ == "__main__": logging.basicConfig(level = logging.INFO) glogger.setLoggingLevel(glogger.nothing) filename = "/home/gibson/jonask/Dropbox/Ann-Survival-Phd/Two_thirds_of_SA_1889_dataset.txt" #try: # columns = input("Which columns to include? (Do NOT forget trailing comma if only one column is used, e.g. '3,'\nAvailable columns are: 2, -4, -3, -2, -1. Just press ENTER for all columns.\n") #except SyntaxError: columns = (2, -4, -3, -2, -1) print('\nIncluding columns: ' + str(columns)) P, T = parse_file(filename, targetcols = [4, 5], inputcols = columns, ignorerows = [0], normalize = True) #remove tail censored #print('\nRemoving tail censored...') #P, T = copy_without_tailcensored(P, T) try: