def FoN(inputs, outputs): seed(tmpObject.i) tmpObject.i = tmpObject.i + 1 m = MultilayerPerceptron(inputs, nbHidden, outputs, learning_rate=lrate, momentum=momentum, grid=mode) m.init_weights_randomly(-1, 1) tmpObject.net = m return m
def SoN(inputs, outputs): n = MultilayerPerceptron(nbHidden, 20, 2, learning_rate=0.15, momentum=0.5, grid=mode) n.init_weights_randomly(-1, 1) return n
def SoN(inputs, outputs): return MultilayerPerceptron(inputs // 4, inputs // 2, inputs + inputs // 4 + outputs, learning_rate=lrate, momentum=momentum, grid=mode)
def SoN(inputs, outputs): return MultilayerPerceptron(nbr_hidden, nbr_hidden * 2, inputs + nbr_hidden + outputs, learning_rate=lrate, momentum=momentum, grid=mode)
def SoN(inputs, outputs): return MultilayerPerceptron(nbHidden, 20, 2, learning_rate=0.1, momentum=0., grid=mode)
def FoN2(inputs, outputs): return MultilayerPerceptron(inputs, inputs // 4, outputs, learning_rate=lrate, momentum=momentum, grid=mode)
def SoN(inputs, outputs): tmpObject.last2 = MultilayerPerceptron(inputs // 4, inputs // 2, inputs + inputs // 4 + outputs, learning_rate=lrate, momentum=momentum, grid=mode) return tmpObject.last2
def control(inputs, outputs): seed(tmpObject.i) tmpObject.i = tmpObject.i + 1 tmpObject.control = MultilayerPerceptron(inputs, nbHidden, outputs, learning_rate=lrate, momentum=momentum, grid=mode) tmpObject.control.init_weights_randomly(-1, 1) return tmpObject.control
from data import DataFile if __name__ == '__main__': mode = MultilayerPerceptron.R0to1 nbr_network = 5 momentum = 0.5 nbEpoch = 201 nbTry = 50 display_interval = range(nbEpoch)[3::5] #create all networks networks = [{} for _ in range(nbr_network)] for i in range(nbr_network): seed(i) first_order = MultilayerPerceptron(16 * 16, 100, 10, learning_rate=0.15, momentum=momentum, grid=mode) first_order.init_weights_randomly(-1, 1) high_order_h = PRenforcement(100, temperature=1.) networks[i] = {'first_order' : first_order, 'high_order_h' : high_order_h} #create example examples = DataFile("digit_handwritten_16.txt", mode) #3 curves y_plot = {'first_order' : [] , 'high_order_h' : [], 'high_order_l': []} y_perfo = {'first_order' : [] ,
return (True, random() < 0.7) else: return (False, random() < 0.3) if __name__ == '__main__': plt.title("low") grid = MultilayerPerceptron.R0to1 nbr_network = 30 nbr_epoch = 200 nbr_trial = 10 first_order = [] high_order = [] for _ in range(nbr_network): fo = MultilayerPerceptron(5, 40, 4, grid, 0.002, 0., 1., False, True) fo.init_weights_randomly(-1, 1) first_order.append(fo) #0.0003 or 0.015 ho = MultilayerPerceptron(40, 40, 2, grid, 0.0003, 0., 1., False, True) ho.init_weights_randomly(-1, 1) high_order.append(ho) #trials wins = [] wagers = [] last_output = [ [0 for _ in range(5)] for _ in range(nbr_network)] for epoch in range(nbr_epoch):
def pattern_to_list(pat): res = [] for i in range(8): res.append(index_max(pat[i * 6:i * 6 + 6])) return res if __name__ == '__main__': ptrain_pattern = [random_pattern() for _ in range(80)] # print(ptrain_pattern[0][0]) # print(pattern_to_list(ptrain_pattern[0][0])) # exit() first_order = MultilayerPerceptron(48, 40, 48, 0, 0.4, 0.5, 1., False, True) first_order.init_weights_randomly(-1, 1) high_order = [ PerceptronR0to1(48, 0.4, 0.5, 1., Perceptron.OUTPUT, False, True) for _ in range(2) ] # high_order = [PerceptronN0to1(48, 0.4, 0.5, False) for _ in range(2)] high_order[0].init_weights_randomly(0., 0.1) high_order[1].init_weights_randomly(0., 0.1) print("pre-training") err = 0. the = 0. rms = [] rms2 = []
else: return (False, random() < 0.2) if __name__ == '__main__': grid = MultilayerPerceptron.R0to1 nbr_network = 50 nbr_epoch = 200 nbr_trial = 10 displays = range(nbr_epoch)[::5] first_order = [] high_order = [] for _ in range(nbr_network): fo = MultilayerPerceptron(5, 40, 4, grid, 0.002, 0., 1., False, True) fo.init_weights_randomly(-1, 1) first_order.append(fo) #0.0003 or 0.015 ho = MultilayerPerceptron(40, 40, 2, grid, 0.015, 0., 1., False, True) ho.init_weights_randomly(-1, 1) high_order.append(ho) #trials wins = [] wagers = [] last_output = [[0 for _ in range(5)] for _ in range(nbr_network)] for epoch in range(nbr_epoch): nbr_win = 0
# examples = DataFileR("iris.txt") momentum = 0.9 nbInputs = len(examples.inputs[0]) nbHidden = 10 nbOutputs = len(examples.outputs[0]) nbShape = nbOutputs #create all networks networks = [{} for _ in range(nbr_network)] for i in range(nbr_network): first_order = MultilayerPerceptron(nbInputs, nbHidden, nbOutputs, learning_rate=lrate, momentum=momentum, grid=mode) high_order_10 = MultilayerPerceptron(nbHidden, nbHidden * 2, nbInputs + nbHidden + nbOutputs, learning_rate=lrate, momentum=momentum, grid=mode) networks[i] = { 'first_order': first_order, 'high_order_10': high_order_10 } learned = [[0 for _ in range(nbShape)] for _ in range(nbDiscre**nbHidden)]
def FoN(inputs, outputs): tmpObject.last = MultilayerPerceptron(inputs, nbr_hidden, outputs, learning_rate=lrate, momentum=momentum, grid=mode) return tmpObject.last
if __name__ == '__main__': mode = MultilayerPerceptron.R0to1 nbr_network = 5 momentum = 0.9 lrate = 0.1 nbEpoch = 1000 display_interval = [0, 25, 50, 100, 200, 500, 999] display_interval2 = range(nbEpoch)[::7] #create all networks networks = [{} for _ in range(nbr_network)] for i in range(nbr_network): first_order = MultilayerPerceptron(20, 5, 10, learning_rate=lrate, momentum=momentum, grid=mode) high_order_10 = MultilayerPerceptron(5, 10, 35, learning_rate=lrate, momentum=momentum, grid=mode) high_order_5 = MultilayerPerceptron(5, 5, 35, learning_rate=lrate, momentum=momentum, grid=mode)
mode = MultilayerPerceptron.R0to1 nbr_network = 5 momentum = 0.5 nbEpoch = 201 nbTry = 50 display_interval = range(nbEpoch)[3::5] seed(100) #create all networks networks = [{} for _ in range(nbr_network)] for i in range(nbr_network): seed(i) control = MultilayerPerceptron(16 * 16, 100, 10, learning_rate=0.15, momentum=momentum, grid=mode) control.init_weights_randomly(-1, 1) high_order_h = MultilayerPerceptron(100, 20, 2, learning_rate=0.1, momentum=0., grid=mode) first_order = AdHock(control) networks[i] = { 'first_order': first_order, 'high_order_h': high_order_h,
if __name__ == '__main__': mode = MultilayerPerceptron.R0to1 nbr_network = 5 momentum = 0.5 nbEpoch = 201 nbTry = 50 display_interval = range(nbEpoch)[3::5] #create all networks networks = [{} for _ in range(nbr_network)] for i in range(nbr_network): seed(i) control = MultilayerPerceptron(16 * 16, 100, 10, learning_rate=0.15, momentum=momentum, grid=mode, temperature=1, random=False, enable_bias=True) control.init_weights_randomly(-1, 1) first_order = AdHock(control) networks[i] = {'first_order' : first_order, 'control': control} #create example examples = DataFile("digit_handwritten_16.txt", mode) #3 curves y_perfo = {'first_order' : [] , 'high_order_h' : [], 'wager_proportion': [], 'feedback' : [],
import matplotlib.pyplot as plt from data import DataFile if __name__ == '__main__': mode = MultilayerPerceptron.R0to1 nbr_network = 5 momentum = 0.5 nbEpoch = 201 display_interval = range(nbEpoch)[3::5] #create all networks networks = [{} for _ in range(nbr_network)] for i in range(nbr_network): first_order = MultilayerPerceptron(7, 100, 10, learning_rate=0.15, momentum=momentum, grid=mode) high_order_h = MultilayerPerceptron(100, 100, 2, learning_rate=0.1, momentum=0, grid=mode) high_order_l = MultilayerPerceptron(100, 100, 2, learning_rate=10e-7, momentum=0, grid=mode) networks[i] = {'first_order' : first_order, 'high_order_h' : high_order_h, 'high_order_l' : high_order_l} for network in networks: for k in network.keys(): if(k == 'first_order'): network[k].init_weights_randomly(-1, 1) #create example examples = DataFile("digital_shape.txt", mode)
def pattern_to_list(pat): res = [] for i in range(8): res.append(index_max(pat[i * 6 : i * 6 + 6])) return res if __name__ == "__main__": ptrain_pattern = [random_pattern() for _ in range(80)] # print(ptrain_pattern[0][0]) # print(pattern_to_list(ptrain_pattern[0][0])) # exit() first_order = MultilayerPerceptron(48, 40, 48, 0, 0.4, 0.5, 1.0, False, True) first_order.init_weights_randomly(-1, 1) high_order = [PerceptronR0to1(48, 0.4, 0.5, 1.0, Perceptron.OUTPUT, False, True) for _ in range(2)] # high_order = [PerceptronN0to1(48, 0.4, 0.5, False) for _ in range(2)] high_order[0].init_weights_randomly(0.0, 0.1) high_order[1].init_weights_randomly(0.0, 0.1) print("pre-training") err = 0.0 the = 0.0 rms = [] rms2 = [] nbEpoch = 60