Example #1
0
def train(dataReader, max_epoch):
    n_input = dataReader.num_feature
    n_hidden = 2
    n_output = 1
    eta, batch_size = 0.1, 5
    eps = 0.01

    hp = HyperParameters2(n_input, n_hidden, n_output, eta, max_epoch, batch_size, eps, NetType.BinaryClassifier, InitialMethod.Xavier)
    net = NeuralNet2(hp, "Arc_221_epoch")
    
    #net.LoadResult()
    net.train(dataReader, 5, True)
    #net.ShowTrainingTrace()
    
    ShowTransformation(net, dataReader, max_epoch)
    ShowResult2D(net, dataReader, max_epoch)
Example #2
0
def train(n_hidden):

    n_input = dataReader.num_feature
    n_output = dataReader.num_category
    eta, batch_size, max_epoch = 0.1, 10, 10000
    eps = 0.01

    hp = HyperParameters2(n_input, n_hidden, n_output, eta, max_epoch, batch_size, eps, NetType.MultipleClassifier, InitialMethod.Xavier)
    net = NeuralNet2(hp, "Bank_2N3")
    net.train(dataReader, 100, True)
    net.ShowTrainingTrace()
    loss = net.GetLatestAverageLoss()

    fig = plt.figure(figsize=(6,6))
    ShowDataByOneHot2D(dataReader.XTrain[:,0], dataReader.XTrain[:,1], dataReader.YTrain, hp.toString())
    ShowClassificationResult25D(net, 50, str.format("{0}, loss={1:.3f}", hp.toString(), loss))
    plt.show()
    # draw train data
    X, Y = dataReader.XTrain, dataReader.YTrain
    plt.plot(X[:, 0], Y[:, 0], '.', c='b')
    # create and draw visualized validation data
    TX = np.linspace(0, 1, 100).reshape(100, 1)
    TY = net.inference(TX)
    plt.plot(TX, TY, 'x', c='r')
    plt.title(title)
    plt.show()


#end def

if __name__ == '__main__':
    dataReader = DataReader(train_data_name, test_data_name)
    dataReader.ReadData()
    dataReader.GenerateValidationSet()

    n_input, n_hidden, n_output = 1, 4, 1
    eta, batch_size, max_epoch = 0.7, 15, 10000
    eps = 0.001

    hp = HyperParameters2(n_input, n_hidden, n_output, eta, max_epoch,
                          batch_size, eps, NetType.Fitting,
                          InitialMethod.Xavier)
    net = NeuralNet2(hp, "complex_121")

    net.train(dataReader, 50, True)
    net.ShowTrainingTrace()
    ShowResult(net, dataReader, hp.toString())
def train(hp, folder):
    net = NeuralNet2(hp, folder)
    net.train(dataReader, 50, True)
    trace = net.GetTrainingTrace()
    return trace
Example #5
0
    p2, = plt.plot(TX, net.A1[:, 1], '.', c='g')
    p3, = plt.plot(TX, net.Z2[:, 0], '.', c='blue')
    plt.legend([p1, p2, p3], ["a1", "a2", "z"])
    plt.show()


if __name__ == '__main__':
    dataReader = DataReader(x_data_name, y_data_name)
    dataReader.ReadData()
    dataReader.GenerateValidationSet()

    n_input, n_hidden, n_output = 1, 2, 1
    eta, batch_size, max_epoch = 0.05, 10, 5000
    eps = 0.001

    hp = HyperParameters2(n_input, n_hidden, n_output, eta, max_epoch,
                          batch_size, eps, NetType.Fitting,
                          InitialMethod.Xavier)
    net = NeuralNet2(hp, "sin_121")

    net.LoadResult()
    print(net.wb1.W)
    print(net.wb1.B)
    print(net.wb2.W)
    print(net.wb2.B)

    #net.train(dataReader, 50, True)
    #net.ShowTrainingTrace()
    #ShowResult(net, dataReader, hp.toString())
    ShowResult2D(net, hp.toString())
Example #6
0
# Copyright (c) Microsoft. All rights reserved.
# Licensed under the MIT license. See LICENSE file in the project root for full license information.

import numpy as np

from HelperClass2.DataReader import *
from HelperClass2.HyperParameters2 import *
from HelperClass2.NeuralNet2 import *

train_data_name = "../../Data/ch10.train.npz"
test_data_name = "../../Data/ch10.test.npz"

if __name__ == '__main__':
    dataReader = DataReader(train_data_name, test_data_name)
    dataReader.ReadData()
    dataReader.NormalizeX()
    dataReader.Shuffle()
    dataReader.GenerateValidationSet()

    n_input = dataReader.num_feature
    n_hidden = 2
    n_output = 1
    eta, batch_size, max_epoch = 0.1, 5, 10000
    eps = 0.08

    hp = HyperParameters2(n_input, n_hidden, n_output, eta, max_epoch, batch_size, eps, NetType.BinaryClassifier, InitialMethod.Xavier)
    net = NeuralNet2(hp, "Arc_221")
    net.train(dataReader, 5, True)
    net.ShowTrainingTrace()
    
Example #7
0
    for i in range(count):
        for j in range(Y.shape[1]):
            if Y[i,j] == 1:
                ax.scatter(net.A1[i,0],net.A1[i,1],net.A1[i,2], color=colors[j], marker=shapes[j])
    plt.show()


if __name__ == '__main__':
    dataReader = DataReader(train_data_name, test_data_name)
    dataReader.ReadData()
    dataReader.NormalizeY(YNormalizationMethod.MultipleClassifier, base=1)

    dataReader.NormalizeX()
    dataReader.Shuffle()
    dataReader.GenerateValidationSet()

    n_input = dataReader.num_feature
    n_hidden = 3
    n_output = dataReader.num_category
    eta, batch_size, max_epoch = 0.1, 10, 5000
    eps = 0.1

    hp = HyperParameters2(n_input, n_hidden, n_output, eta, max_epoch, batch_size, eps, NetType.MultipleClassifier, InitialMethod.Xavier)
    net = NeuralNet2(hp, "Bank_233_2")
    
    #net.LoadResult()
    net.train(dataReader, 100, True)
    net.ShowTrainingTrace()

    Show3D(net, dataReader)
    A2 = net.inference(X)
    print("A2=", A2)
    diff = np.abs(A2 - Y)
    result = np.where(diff < 1e-2, True, False)
    if result.sum() == dataReader.num_test:
        return True
    else:
        return False


if __name__ == '__main__':
    dataReader = XOR_DataReader()
    dataReader.ReadData()
    dataReader.GenerateValidationSet()

    n_input = dataReader.num_feature
    n_hidden = 2
    n_output = 1
    eta, batch_size, max_epoch = 0.1, 1, 10000
    eps = 0.005

    hp = HyperParameters2(n_input, n_hidden, n_output, eta, max_epoch,
                          batch_size, eps, NetType.BinaryClassifier,
                          InitialMethod.Xavier)
    net = NeuralNet2(hp, "Xor_221")

    net.train(dataReader, 100, True)
    net.ShowTrainingTrace()

    print(Test(dataReader, net))