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_1(learning_rate, max_epoch, batch_size, net_type=NetType.BinaryClassifier, init_method=InitialMethod.Xavier, stopper=Stopper(StopCondition.StopLoss, 0.02)) net = NeuralNet_4_1(params, "Arc") fc1 = FcLayer_1_1(num_input, num_hidden, params) net.add_layer(fc1, "fc1") sigmoid1 = ActivationLayer(Sigmoid()) net.add_layer(sigmoid1, "sigmoid1") fc2 = FcLayer_1_1(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(): 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 eps = 1e-3 params = HyperParameters40(learning_rate, max_epoch, batch_size, eps, net_type=NetType.BinaryClassifier, init_method=InitialMethod.Xavier) net = NeuralNet40(params, "Income") fc1 = FcLayer(num_input, num_hidden1, params) net.add_layer(fc1, "fc1") a1 = ActivatorLayer(Relu()) net.add_layer(a1, "relu1") fc2 = FcLayer(num_hidden1, num_hidden2, params) net.add_layer(fc2, "fc2") a2 = ActivatorLayer(Relu()) net.add_layer(a2, "relu2") fc3 = FcLayer(num_hidden2, num_hidden3, params) net.add_layer(fc3, "fc3") a3 = ActivatorLayer(Relu()) net.add_layer(a3, "relu3") fc4 = FcLayer(num_hidden3, num_hidden4, params) net.add_layer(fc4, "fc4") a4 = ActivatorLayer(Relu()) net.add_layer(a4, "relu4") fc5 = FcLayer(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("epoch")
def model(dr): num_input = dr.num_feature num_hidden1 = 32 num_hidden2 = 16 num_hidden3 = 8 num_hidden4 = 4 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.MSRA, 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.train(dr, checkpoint=1, need_test=True) return net
def model_sigmoid(num_input, num_hidden, num_output, hp): net = NeuralNet_4_1(hp, "chinabank_sigmoid") fc1 = FcLayer_1_1(num_input, num_hidden, hp) net.add_layer(fc1, "fc1") s1 = ActivationLayer(Sigmoid()) net.add_layer(s1, "Sigmoid1") fc2 = FcLayer_1_1(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 = NeuralNet40(hp, "chinabank_relu") fc1 = FcLayer(num_input, num_hidden, hp) net.add_layer(fc1, "fc1") r1 = ActivatorLayer(Relu()) net.add_layer(r1, "Relu1") fc2 = FcLayer(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("epoch") ShowResult(net, hp.toString()) ShowData(dataReader)
def Net(subfolder, dataReader, num_input, num_hidden, num_output, params, show_history=True): net = NeuralNet_4_2(params, subfolder) fc1 = FcLayer_2_0(num_input, num_hidden, params) net.add_layer(fc1, "fc1") relu1 = ActivatorLayer(Relu()) net.add_layer(relu1, "relu1") fc2 = FcLayer_2_0(num_hidden, num_hidden, params) net.add_layer(fc2, "fc2") relu2 = ActivatorLayer(Relu()) net.add_layer(relu2, "relu2") fc3 = FcLayer_2_0(num_hidden, num_hidden, params) net.add_layer(fc3, "fc3") relu3 = ActivatorLayer(Relu()) net.add_layer(relu3, "relu3") fc4 = FcLayer_2_0(num_hidden, num_hidden, params) net.add_layer(fc4, "fc4") relu4 = ActivatorLayer(Relu()) net.add_layer(relu4, "relu4") fc5 = FcLayer_2_0(num_hidden, num_output, params) net.add_layer(fc5, "fc5") softmax = ClassificationLayer(Softmax()) net.add_layer(softmax, "softmax") net.train(dataReader, checkpoint=1, need_test=True) if show_history: net.ShowLossHistory(XCoordinate.Iteration) return net
def Net(dataReader, num_input, num_hidden, num_output, params, show_history=True): net = NeuralNet41(params, "mnist_overfitting") fc1 = FcLayer(num_input, num_hidden, params) net.add_layer(fc1, "fc1") relu1 = ActivatorLayer(Relu()) net.add_layer(relu1, "relu1") fc2 = FcLayer(num_hidden, num_hidden, params) net.add_layer(fc2, "fc2") relu2 = ActivatorLayer(Relu()) net.add_layer(relu2, "relu2") fc3 = FcLayer(num_hidden, num_hidden, params) net.add_layer(fc3, "fc3") relu3 = ActivatorLayer(Relu()) net.add_layer(relu3, "relu3") fc4 = FcLayer(num_hidden, num_hidden, params) net.add_layer(fc4, "fc4") relu4 = ActivatorLayer(Relu()) net.add_layer(relu4, "relu4") fc5 = FcLayer(num_hidden, num_output, params) net.add_layer(fc5, "fc5") softmax = ClassificationLayer(Softmax()) net.add_layer(softmax, "softmax") net.train(dataReader, checkpoint=1, need_test=True) if show_history: net.ShowLossHistory() return net
max_epoch = 10000 batch_size = 5 learning_rate = 0.1 eps = 1e-3 params = HyperParameters40(learning_rate, max_epoch, batch_size, eps, net_type=NetType.BinaryClassifier, init_method=InitialMethod.Xavier) net = NeuralNet40(params, "Arc") fc1 = FcLayer(num_input, num_hidden, params) net.add_layer(fc1, "fc1") sigmoid1 = ActivatorLayer(Sigmoid()) net.add_layer(sigmoid1, "sigmoid1") fc2 = FcLayer(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("epoch") ShowResult2D(net, dataReader)
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") softmax = ClassificationLayer(Softmax()) net.add_layer(softmax, "softmax") #net.load_parameters() net.train(dataReader, checkpoint=0.1, need_test=True) net.ShowLossHistory(xcoord=XCoordinate.Iteration)
def model(): dr = LoadData() num_input = dr.num_feature num_hidden1 = 128 num_hidden2 = 64 num_hidden3 = 32 num_hidden4 = 16 num_hidden5 = 8 num_hidden6 = 4 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_hidden5, params) net.add_layer(fc5, "fc5") a5 = ActivationLayer(Relu()) net.add_layer(a5, "relu5") fc6 = FcLayer_1_0(num_hidden5, num_hidden6, params) net.add_layer(fc6, "fc") a6 = ActivationLayer(Relu()) net.add_layer(a6, "relu6") fc7 = FcLayer_1_0(num_hidden6, num_output, params) net.add_layer(fc7, "fc7") logistic = ClassificationLayer(Logistic()) net.add_layer(logistic, "logistic") #net.load_parameters() net.train(dr, checkpoint=1, need_test=True) net.ShowLossHistory()