#Limit to incourage overtraining! #rows = sample(range(len(T)), 100) #P = P[rows] #T = T[rows] p = len(P[0]) #number of input covariates #net = load_network('/home/gibson/jonask/Projects/aNeuralN/ANNs/4x10x10x1.ann') net = build_feedforward(p, 30, 1, output_function = 'linear') #Initial state outputs = net.sim(P) orderscatter(outputs, T, filename, 's') for var in xrange(len(P[0, :])): plot_input(P[:, var]) glogger.show() epochs = 20000 rate = 1 block_size = 0 for times in range(100): net = test(net, P, T, filename, epochs, rate, block_size) outputs = net.sim(P) orderscatter(outputs, T, filename, 'o') raw_input("Press enter to show plots...") glogger.show()
def train_single(): try: netsize = input('Number of hidden nodes? [3]: ') except SyntaxError as e: netsize = 3 try: pop_size = input('Population size? [50]: ') except SyntaxError as e: pop_size = 50 try: mutation_rate = input('Please input a mutation rate (0.25): ') except SyntaxError as e: mutation_rate = 0.25 SB22 = "/home/gibson/jonask/Dropbox/Ann-Survival-Phd/Two_thirds_of_SA_1889_dataset_SB22.txt" Benmargskohorten = "/home/gibson/jonask/Dropbox/Ann-Survival-Phd/Two_thirds_of_SA_1889_dataset_Benmargskohorten.txt" SB91b = "/home/gibson/jonask/Dropbox/Ann-Survival-Phd/Two_thirds_of_SA_1889_dataset_SB91b.txt" all_studies = "/home/gibson/jonask/Dropbox/Ann-Survival-Phd/Two_thirds_of_SA_1889_dataset.txt" #Real data print("Studies to choose from:") print("1: SB22") print("2: Benmargskohorten") print("3: SB91b") print("0: All combined (default)") try: study = input("Which study to train on? [0]: ") except SyntaxError as e: study = 0 if study == 1: filename = SB22 elif study == 2: filename = Benmargskohorten elif study == 3: filename = SB91b else: filename = all_studies 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) #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 = columns, ignorerows = [0], normalize = True) #Used for output comparison studies = {} studies[SB22] = parse_file(SB22, targetcols = [4, 5], inputcols = columns, ignorerows = [0], normalize = True) studies[Benmargskohorten] = parse_file(Benmargskohorten, targetcols = [4, 5], inputcols = columns, ignorerows = [0], normalize = True) studies[SB91b] = parse_file(SB91b, targetcols = [4, 5], inputcols = columns, ignorerows = [0], normalize = True) studies[all_studies] = parse_file(all_studies, targetcols = [4, 5], inputcols = columns, ignorerows = [0], normalize = True) #remove tail censored #P, T = copy_without_tailcensored(P, T) #Divide into validation sets #((tP, tT), (vP, vT)) = get_validation_set(P, T, validation_size = 0.25, binary_column = 1) TandV = get_cross_validation_sets(P, T, 2 , binary_column = 1) #Network part p = len(P[0]) #number of input covariates net = build_feedforward(p, netsize, 1, output_function = 'linear') #net = build_feedforward_multilayered(p, [7, 10], 1, output_function = 'linear') try: epochs = input("Number of generations (200): ") except SyntaxError as e: epochs = 200 for times, ((tP, tT), (vP, vT)) in zip(xrange(2), TandV): #train net = test(net, tP, tT, vP, vT, filename, epochs, population_size = pop_size, mutation_rate = mutation_rate) raw_input("Press enter to show plots...") glogger.show()