def model(dataReader): num_input = 2 num_hidden = 3 num_output = 1 max_epoch = 1000 batch_size = 5 learning_rate = 0.1 params = HyperParameters_4_0( learning_rate, max_epoch, batch_size, net_type=NetType.BinaryClassifier, init_method=InitialMethod.Xavier, stopper=Stopper(StopCondition.StopLoss, 0.02)) net = NeuralNet_4_0(params, "Arc") fc1 = FcLayer_1_0(num_input, num_hidden, params) net.add_layer(fc1, "fc1") sigmoid1 = ActivationLayer(Sigmoid()) net.add_layer(sigmoid1, "sigmoid1") fc2 = FcLayer_1_0(num_hidden, num_output, params) net.add_layer(fc2, "fc2") logistic = ClassificationLayer(Logistic()) net.add_layer(logistic, "logistic") net.train(dataReader, checkpoint=10, need_test=True) return net
def model(): dataReader = LoadData() num_input = 1 num_hidden1 = 4 num_output = 1 max_epoch = 10000 batch_size = 10 learning_rate = 0.5 eps = 1e-5 params = HyperParameters_4_0(learning_rate, max_epoch, batch_size, net_type=NetType.Fitting, init_method=InitialMethod.Xavier, stopper=Stopper(StopCondition.StopLoss, 0.001)) net = NeuralNet_4_0(params, "Level1_CurveFittingNet") fc1 = FcLayer_1_0(num_input, num_hidden1, params) net.add_layer(fc1, "fc1") sigmoid1 = ActivationLayer(Sigmoid()) net.add_layer(sigmoid1, "sigmoid1") fc2 = FcLayer_1_0(num_hidden1, num_output, params) net.add_layer(fc2, "fc2") net.train(dataReader, checkpoint=100, need_test=True) net.ShowLossHistory() ShowResult(net, dataReader)
def model(dr): num_input = dr.num_feature # num_hidden1 = 32 # num_hidden2 = 16 # num_hidden3 = 8 # num_hidden4 = 4 nums_hidden = [64, 32, 16, 8, 4] num_output = 1 max_epoch = 2000 batch_size = 16 learning_rate = 0.1 params = HyperParameters_4_0(learning_rate, max_epoch, batch_size, net_type=NetType.Fitting, init_method=InitialMethod.MSRA, stopper=Stopper(StopCondition.StopDiff, 1e-7)) net = NeuralNet_4_0(params, "HouseSingle") fc1 = FcLayer_1_0(num_input, nums_hidden[0], params) net.add_layer(fc1, "fc1") r1 = ActivationLayer(Relu()) net.add_layer(r1, "r1") fc2 = FcLayer_1_0(nums_hidden[0], nums_hidden[1], params) net.add_layer(fc2, "fc2") r2 = ActivationLayer(Relu()) net.add_layer(r2, "r2") fc3 = FcLayer_1_0(nums_hidden[1], nums_hidden[2], params) net.add_layer(fc3, "fc3") r3 = ActivationLayer(Relu()) net.add_layer(r3, "r3") fc4 = FcLayer_1_0(nums_hidden[2], nums_hidden[3], params) net.add_layer(fc4, "fc4") r4 = ActivationLayer(Relu()) net.add_layer(r4, "r4") if len(nums_hidden) == 4: fc5 = FcLayer_1_0(nums_hidden[3], num_output, params) net.add_layer(fc5, "fc5") if len(nums_hidden) == 5: fc5 = FcLayer_1_0(nums_hidden[3], nums_hidden[4], params) net.add_layer(fc5, "fc5") r5 = ActivationLayer(Relu()) net.add_layer(r5, "r5") fc6 = FcLayer_1_0(nums_hidden[4], num_output, params) net.add_layer(fc6, "fc6") net.train(dr, checkpoint=10, need_test=True) return net
def model(): dr = LoadData() num_input = dr.num_feature num_hidden1 = 64 num_hidden2 = 64 num_hidden3 = 32 num_hidden4 = 16 num_output = 1 max_epoch = 100 batch_size = 16 learning_rate = 0.1 params = HyperParameters_4_0(learning_rate, max_epoch, batch_size, net_type=NetType.BinaryClassifier, init_method=InitialMethod.Xavier, stopper=Stopper(StopCondition.StopDiff, 1e-3)) net = NeuralNet_4_0(params, "Income") fc1 = FcLayer_1_0(num_input, num_hidden1, params) net.add_layer(fc1, "fc1") a1 = ActivationLayer(Relu()) net.add_layer(a1, "relu1") fc2 = FcLayer_1_0(num_hidden1, num_hidden2, params) net.add_layer(fc2, "fc2") a2 = ActivationLayer(Relu()) net.add_layer(a2, "relu2") fc3 = FcLayer_1_0(num_hidden2, num_hidden3, params) net.add_layer(fc3, "fc3") a3 = ActivationLayer(Relu()) net.add_layer(a3, "relu3") fc4 = FcLayer_1_0(num_hidden3, num_hidden4, params) net.add_layer(fc4, "fc4") a4 = ActivationLayer(Relu()) net.add_layer(a4, "relu4") fc5 = FcLayer_1_0(num_hidden4, num_output, params) net.add_layer(fc5, "fc5") logistic = ClassificationLayer(Logistic()) net.add_layer(logistic, "logistic") #net.load_parameters() net.train(dr, checkpoint=10, need_test=True) net.ShowLossHistory()
def model(dr, lr, bs): num_input = dr.num_feature num_hidden1 = 32 num_hidden2 = 16 num_hidden3 = 8 num_hidden4 = 4 num_output = 1 max_epoch = 1000 #batch_size = 16 batch_size = bs learning_rate = lr params = HyperParameters_4_0(learning_rate, max_epoch, batch_size, net_type=NetType.Fitting, init_method=InitialMethod.MSRA, stopper=Stopper(StopCondition.StopDiff, 1e-7)) net = NeuralNet_4_0(params, "HouseSingle") fc1 = FcLayer_1_0(num_input, num_hidden1, params) net.add_layer(fc1, "fc1") r1 = ActivationLayer(Relu()) net.add_layer(r1, "r1") fc2 = FcLayer_1_0(num_hidden1, num_hidden2, params) net.add_layer(fc2, "fc2") r2 = ActivationLayer(Relu()) net.add_layer(r2, "r2") fc3 = FcLayer_1_0(num_hidden2, num_hidden3, params) net.add_layer(fc3, "fc3") r3 = ActivationLayer(Relu()) net.add_layer(r3, "r3") fc4 = FcLayer_1_0(num_hidden3, num_hidden4, params) net.add_layer(fc4, "fc4") r4 = ActivationLayer(Relu()) net.add_layer(r4, "r4") fc5 = FcLayer_1_0(num_hidden4, num_output, params) net.add_layer(fc5, "fc5") net.train(dr, checkpoint=10, need_test=True) return net
def model_sigmoid(num_input, num_hidden, num_output, hp): net = NeuralNet_4_0(hp, "chinabank_sigmoid") fc1 = FcLayer_1_0(num_input, num_hidden, hp) net.add_layer(fc1, "fc1") s1 = ActivationLayer(Sigmoid()) net.add_layer(s1, "Sigmoid1") fc2 = FcLayer_1_0(num_hidden, num_output, hp) net.add_layer(fc2, "fc2") softmax1 = ClassificationLayer(Softmax()) net.add_layer(softmax1, "softmax1") net.train(dataReader, checkpoint=50, need_test=True) net.ShowLossHistory() ShowResult(net, hp.toString()) ShowData(dataReader)
def model_relu(num_input, num_hidden, num_output, hp): net = NeuralNet_4_0(hp, "chinabank_relu") fc1 = FcLayer_1_0(num_input, num_hidden, hp) net.add_layer(fc1, "fc1") r1 = ActivationLayer(Relu()) net.add_layer(r1, "Relu1") fc2 = FcLayer_1_0(num_hidden, num_hidden, hp) net.add_layer(fc2, "fc2") r2 = ActivationLayer(Relu()) net.add_layer(r2, "Relu2") fc3 = FcLayer_1_0(num_hidden, num_output, hp) net.add_layer(fc3, "fc3") softmax = ClassificationLayer(Softmax()) net.add_layer(softmax, "softmax") net.train(dataReader, checkpoint=50, need_test=True) net.ShowLossHistory() ShowResult(net, hp.toString()) ShowData(dataReader)
num_hidden2 = 64 num_hidden3 = 32 num_hidden4 = 16 num_output = 10 max_epoch = 30 batch_size = 64 learning_rate = 0.1 params = HyperParameters_4_0(learning_rate, max_epoch, batch_size, net_type=NetType.MultipleClassifier, init_method=InitialMethod.MSRA, stopper=Stopper(StopCondition.StopLoss, 0.26)) net = NeuralNet_4_0(params, "Cifar10") fc1 = FcLayer_1_0(num_input, num_hidden1, params) net.add_layer(fc1, "fc1") r1 = ActivationLayer(Relu()) net.add_layer(r1, "r1") fc2 = FcLayer_1_0(num_hidden1, num_hidden2, params) net.add_layer(fc2, "fc2") r2 = ActivationLayer(Relu()) net.add_layer(r2, "r2") fc3 = FcLayer_1_0(num_hidden2, num_hidden3, params) net.add_layer(fc3, "fc3") r3 = ActivationLayer(Relu()) net.add_layer(r3, "r3")
def model(): dr = LoadData() num_input = dr.num_feature num_hidden1 = 32 num_hidden2 = 16 num_hidden3 = 8 num_hidden4 = 4 num_output = 1 max_epoch = 1000 batch_size = 16 learning_rate = 0.01 params = HyperParameters_4_0(learning_rate, max_epoch, batch_size, net_type=NetType.Fitting, init_method=InitialMethod.Xavier, stopper=Stopper(StopCondition.StopDiff, 1e-6)) net = NeuralNet_4_0(params, "HouseSingle") fc1 = FcLayer_1_0(num_input, num_hidden1, params) net.add_layer(fc1, "fc1") r1 = ActivationLayer(Relu()) net.add_layer(r1, "r1") fc2 = FcLayer_1_0(num_hidden1, num_hidden2, params) net.add_layer(fc2, "fc2") r2 = ActivationLayer(Relu()) net.add_layer(r2, "r2") fc3 = FcLayer_1_0(num_hidden2, num_hidden3, params) net.add_layer(fc3, "fc3") r3 = ActivationLayer(Relu()) net.add_layer(r3, "r3") fc4 = FcLayer_1_0(num_hidden3, num_hidden4, params) net.add_layer(fc4, "fc4") r4 = ActivationLayer(Relu()) net.add_layer(r4, "r4") fc5 = FcLayer_1_0(num_hidden4, num_output, params) net.add_layer(fc5, "fc5") #ShowResult(net, dr) #net.load_parameters() #Inference(net, dr) #exit() #ShowResult(net, dr) net.train(dr, checkpoint=10, need_test=True) output = net.inference(dr.XTest) real_output = dr.DeNormalizeY(output) mse = np.sum((dr.YTestRaw - real_output)**2) / dr.YTest.shape[0] / 10000 print("mse=", mse) net.ShowLossHistory() ShowResult(net, dr)
num_hidden2 = 12 num_output = 10 max_epoch = 40 batch_size = 128 learning_rate = 0.1 eta = 0.2 eps = 0.01 params = HyperParameters_4_0(learning_rate, max_epoch, batch_size, net_type=NetType.Fitting, init_method=InitialMethod.Xavier, stopper=Stopper(StopCondition.StopDiff, 1e-7)) net = NeuralNet_4_0(params, "SAFE") fc1 = FcLayer_1_0(num_input, num_hidden1, params) net.add_layer(fc1, "fc1") r1 = ActivationLayer(Sigmoid()) net.add_layer(r1, "r1") fc2 = FcLayer_1_0(num_hidden1, num_hidden2, params) net.add_layer(fc2, "fc2") r2 = ActivationLayer(Sigmoid()) net.add_layer(r2, "r2") fc3 = FcLayer_1_0(num_hidden2, num_output, params) net.add_layer(fc3, "fc3") r3 = ActivationLayer(Sigmoid()) net.add_layer(r3, "r3")
num_hidden2 = 64 num_hidden3 = 32 num_hidden4 = 16 num_output = 10 max_epoch = 20 batch_size = 64 learning_rate = 0.1 params = HyperParameters_4_0(learning_rate, max_epoch, batch_size, net_type=NetType.MultipleClassifier, init_method=InitialMethod.MSRA, stopper=Stopper(StopCondition.StopLoss, 0.12)) net = NeuralNet_4_0(params, "MNIST") fc1 = FcLayer_1_0(num_input, num_hidden1, params) net.add_layer(fc1, "fc1") r1 = ActivationLayer(Relu()) net.add_layer(r1, "r1") fc2 = FcLayer_1_0(num_hidden1, num_hidden2, params) net.add_layer(fc2, "fc2") r2 = ActivationLayer(Relu()) net.add_layer(r2, "r2") fc3 = FcLayer_1_0(num_hidden2, num_hidden3, params) net.add_layer(fc3, "fc3") r3 = ActivationLayer(Relu()) net.add_layer(r3, "r3")
num_input = 2 num_hidden = 2 num_output = 1 max_epoch = 10000 batch_size = 5 learning_rate = 0.1 params = HyperParameters_4_0(learning_rate, max_epoch, batch_size, net_type=NetType.BinaryClassifier, init_method=InitialMethod.Xavier, stopper=Stopper(StopCondition.StopLoss, 0.05)) net = NeuralNet_4_0(params, "Arc") fc1 = FcLayer_1_0(num_input, num_hidden, params) net.add_layer(fc1, "fc1") sigmoid1 = ActivationLayer(Sigmoid()) net.add_layer(sigmoid1, "sigmoid1") fc2 = FcLayer_1_0(num_hidden, num_output, params) net.add_layer(fc2, "fc2") logistic = ClassificationLayer(Logistic()) net.add_layer(logistic, "logistic") #net.load_parameters() net.train(dataReader, checkpoint=10, need_test=True) net.ShowLossHistory()