示例#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 = HyperParameters20(n_input, n_hidden, n_output, eta, max_epoch, batch_size, eps, NetType.BinaryClassifier, InitialMethod.Xavier)
    net = NeuralNet20(hp, "Arc_221_epoch")
    
    #net.LoadResult()
    net.train(dataReader, 5, True)
    #net.ShowTrainingTrace()
    
    ShowTransformation(net, dataReader, max_epoch)
    ShowResult2D(net, dataReader, max_epoch)
示例#2
0
    # 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 = DataReader20(train_data_name, test_data_name)
    dataReader.ReadData()
    dataReader.GenerateValidationSet()

    n_input, n_hidden, n_output = 1, 3, 1
    eta, batch_size, max_epoch = 0.5, 10, 10000
    eps = 0.001

    hp = HyperParameters20(n_input, n_hidden, n_output, eta, max_epoch,
                           batch_size, eps, NetType.Fitting,
                           InitialMethod.Xavier)
    net = NeuralNet20(hp, "complex_131")

    net.train(dataReader, 50, True)
    net.ShowTrainingTrace()
    ShowResult(net, dataReader, hp.toString())
示例#3
0
    fig = plt.figure(figsize=(6,6))
    p1,= plt.plot(TX,net.A1[:,0],'.',c='r')
    p2,= plt.plot(TX,net.A1[:,1],'.',c='g')
    p3,= plt.plot(TX,net.Z2[:,0],'x',c='blue')
    plt.legend([p1,p2,p3], ["a1","a2","z"])
    plt.show()

if __name__ == '__main__':
    dataReader = DataReader20(train_data_name, test_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 = HyperParameters20(n_input, n_hidden, n_output, eta, max_epoch, batch_size, eps, NetType.Fitting, InitialMethod.Xavier)
    net = NeuralNet20(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())

示例#4
0
    dataReader.NormalizeY(NetType.MultipleClassifier, base=1)

    fig = plt.figure(figsize=(6, 6))
    DrawThreeCategoryPoints(dataReader.XTrainRaw[:, 0],
                            dataReader.XTrainRaw[:, 1], dataReader.YTrain,
                            "Source Data")
    plt.show()

    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 = HyperParameters20(n_input, n_hidden, n_output, eta, max_epoch,
                           batch_size, eps, NetType.MultipleClassifier,
                           InitialMethod.Xavier)
    net = NeuralNet20(hp, "Bank_233")
    net.train(dataReader, 100, True)
    net.ShowTrainingTrace()

    fig = plt.figure(figsize=(6, 6))
    DrawThreeCategoryPoints(dataReader.XTrain[:, 0], dataReader.XTrain[:, 1],
                            dataReader.YTrain, hp.toString())
    ShowClassificationResult25D(net, 50, hp.toString())
    plt.show()
示例#5
0
def Test(dataReader, net):
    print("testing...")
    X,Y = dataReader.GetTestSet()
    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 = HyperParameters20(n_input, n_hidden, n_output, eta, max_epoch, batch_size, eps, NetType.BinaryClassifier, InitialMethod.Xavier)
    net = NeuralNet20(hp, "Xor_221")

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

    print(Test(dataReader, net))
示例#6
0
def train(hp, folder):
    net = NeuralNet20(hp, folder)
    net.train(dataReader, 50, True)
    trace = net.GetTrainingTrace()
    return trace
示例#7
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.NeuralNet20 import *

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

if __name__ == '__main__':
    dataReader = DataReader20(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 = HyperParameters20(n_input, n_hidden, n_output, eta, max_epoch,
                           batch_size, eps, NetType.BinaryClassifier,
                           InitialMethod.Xavier)
    net = NeuralNet20(hp, "Arc_221")
    net.train(dataReader, 5, True)
    net.ShowTrainingTrace()