plt.scatter(x[i,0], x[i,1], marker='^', c='r', s=200) else: plt.scatter(x[i,0], x[i,1], marker='^', c='b', s=200) """ # 主程序 if __name__ == '__main__': # data reader = SimpleDataReader() reader.ReadData() draw_source_data(reader, show=True) # net num_input = 2 num_output = 1 params = HyperParameters(num_input, num_output, eta=0.1, max_epoch=10000, batch_size=10, eps=1e-3, net_type=NetType.BinaryClassifier) net = NeuralNet(params) net.train(reader, checkpoint=10) # show result draw_source_data(reader, show=False) draw_predicate_data(net) draw_split_line(net) plt.show()
def ShowResult(net, dataReader, title): # draw train data X,Y = dataReader.XTrain, dataReader.YTrain plt.plot(X[:,0], Y[:,0], '.', c='b') # create and draw visualized validation data TX1 = np.linspace(0,1,100).reshape(100,1) TX = np.hstack((TX1, TX1[:,]**2)) TX = np.hstack((TX, TX1[:,]**3)) TX = np.hstack((TX, TX1[:,]**4)) TX = np.hstack((TX, TX1[:,]**5)) TY = net.inference(TX) plt.plot(TX1, TY, 'x', c='r') plt.title(title) plt.show() #end def if __name__ == '__main__': dataReader = DataReaderEx(file_name) dataReader.ReadData() dataReader.Add() print(dataReader.XTrain.shape) # net num_input = 5 num_output = 1 params = HyperParameters(num_input, num_output, eta=0.2, max_epoch=10000, batch_size=10, eps=0.005, net_type=NetType.Fitting) net = NeuralNet(params) net.train(dataReader, checkpoint=10) ShowResult(net, dataReader, params.toString())
plt.plot(X[:,0], Y[:,0], '.', c='b') # create and draw visualized validation data TX1 = np.linspace(0,1,100).reshape(100,1) TX2 = np.hstack((TX1, TX1[:,]**2)) TX3 = np.hstack((TX2, TX1[:,]**3)) TX4 = np.hstack((TX3, TX1[:,]**4)) TX5 = np.hstack((TX4, TX1[:,]**5)) TX6 = np.hstack((TX5, TX1[:,]**6)) TX7 = np.hstack((TX6, TX1[:,]**7)) TX8 = np.hstack((TX7, TX1[:,]**8)) TY = net.inference(TX8) plt.plot(TX1, TY, 'x', c='r') plt.title(title) plt.show() #end def if __name__ == '__main__': dataReader = DataReaderEx(file_name) dataReader.ReadData() dataReader.Add() print(dataReader.XTrain.shape) # net num_input = 8 num_output = 1 params = HyperParameters(num_input, num_output, eta=0.2, max_epoch=50000, batch_size=10, eps=1e-3, net_type=NetType.Fitting) #params = HyperParameters(eta=0.2, max_epoch=1000000, batch_size=10, eps=1e-3, net_type=NetType.Fitting) net = NeuralNet(params) net.train(dataReader, checkpoint=500) ShowResult(net, dataReader, "Polynomial")
# Copyright (c) Microsoft. All rights reserved. # Licensed under the MIT license. See LICENSE file in the project root for full license information. from HelperClass.NeuralNet import * from HelperClass.HyperParameters import * if __name__ == '__main__': sdr = SimpleDataReader() sdr.ReadData() params = HyperParameters(1, 1, eta=0.1, max_epoch=100, batch_size=1, eps = 0.02) net = NeuralNet(params) net.train(sdr)
def inference(net, reader): xt_raw = np.array([5, 1, 7, 6, 5, 6, 2, 7]).reshape(4, 2) xt = reader.NormalizePredicateData(xt_raw) output = net.inference(xt) r = np.argmax(output, axis=1) + 1 print("output=", output) print("r=", r) # 主程序 if __name__ == '__main__': num_category = 3 reader = SimpleDataReader() reader.ReadData() reader.NormalizeX() reader.ToOneHot(num_category, base=1) num_input = 2 params = HyperParameters(num_input, num_category, eta=0.1, max_epoch=100, batch_size=10, eps=1e-3, net_type=NetType.MultipleClassifier) net = NeuralNet(params) net.train(reader, checkpoint=1) inference(net, reader)