Example #1
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 HelperClass.NeuralNet import *
from HelperClass.HyperParameters import *

# 主程序
if __name__ == '__main__':
    # data
    reader = SimpleDataReader()
    reader.ReadData()
    # net
    num_input = 2
    num_output = 1
    params = HyperParameters(num_input,
                             num_output,
                             eta=0.1,
                             max_epoch=100,
                             batch_size=10,
                             eps=1e-3,
                             net_type=NetType.BinaryClassifier)
    net = NeuralNet(params)
    net.train(reader, checkpoint=1)

    # inference
    x_predicate = np.array([0.58, 0.92, 0.62, 0.55, 0.39, 0.29]).reshape(3, 2)
    a = net.inference(x_predicate)
    print("A=", a)
# Copyright (c) Microsoft. All rights reserved.
# Licensed under the MIT license. See LICENSE file in the project root for full license information.

# warning: 运行本程序将会得到失败的结果,这是by design的,是为了讲解课程内容,后面的程序中会有补救的方法

import numpy as np
from HelperClass.NeuralNet import *

if __name__ == '__main__':
    # data
    reader = SimpleDataReader()
    reader.ReadData()
    # net
    params = HyperParameters(eta=0.1, max_epoch=10, batch_size=1, eps = 1e-5)
    net = NeuralNet(params, 2, 1)
    net.train(reader, checkpoint=0.1)
    # inference
    x1 = 15
    x2 = 93
    x = np.array([x1,x2]).reshape(1,2)
    print(net.inference(x))
Example #3
0
# Licensed under the MIT license. See LICENSE file in the project root for full license information.

import numpy as np
from HelperClass.NeuralNet import *

# main
if __name__ == '__main__':
    # data
    reader = SimpleDataReader()
    reader.ReadData()
    reader.NormalizeX()
    reader.NormalizeY()
    # net
    params = HyperParameters(2,
                             1,
                             eta=0.01,
                             max_epoch=200,
                             batch_size=10,
                             eps=1e-5)
    net = NeuralNet(params)
    net.train(reader, checkpoint=0.1)
    # inference
    x1 = 15
    x2 = 93
    x = np.array([x1, x2]).reshape(1, 2)
    x_new = reader.NormalizePredicateData(x)
    z = net.inference(x_new)
    print("z=", z)
    Z_real = z * reader.Y_norm[0, 1] + reader.Y_norm[0, 0]
    print("Z_real=", Z_real)
Example #4
0
    q = np.linspace(0, 1)
    P, Q = np.meshgrid(p, q)
    R = np.hstack((P.ravel().reshape(2500, 1), Q.ravel().reshape(2500, 1)))
    Z = net.inference(R)
    Z = Z.reshape(50, 50)
    ax.plot_surface(P, Q, Z, cmap='rainbow')
    plt.show()


if __name__ == '__main__':
    # data
    reader = SimpleDataReader()
    reader.ReadData()
    reader.NormalizeX()
    # net
    params = HyperParameters(2,
                             1,
                             eta=0.1,
                             max_epoch=10,
                             batch_size=1,
                             eps=1e-5)
    #params = HyperParameters(2, 1, eta=0.01, max_epoch=500, batch_size=10, eps = 1e-5)
    net = NeuralNet(params)
    net.train(reader, checkpoint=0.1)
    # inference
    x1 = 15
    x2 = 93
    x = np.array([x1, x2]).reshape(1, 2)
    print("z=", net.inference(x))

    ShowResult(net, reader)
    plt.legend([p13,p23,p12], ["13","23","12"])
    plt.axis([-0.1,1.1,-0.1,1.1])

    DrawThreeCategoryPoints(xt[:,0], xt[:,1], yt[:], xlabel="x1", ylabel="x2", show=True, isPredicate=True)
    """
    for i in range(xt.shape[0]):
        plt.scatter(xt[i,0], xt[i,1], marker='^', s=200)
    plt.show()
    """
# 主程序
if __name__ == '__main__':
    num_category = 3
    reader = SimpleDataReader()
    reader.ReadData()
    reader.ToOneHot(num_category, base=1)
    # show raw data before normalization
    ShowData(reader.XRaw, reader.YTrain)
    reader.NormalizeX()

    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)

    xt_raw = np.array([5,1,7,6,5,6,2,7]).reshape(4,2)
    xt = reader.NormalizePredicateData(xt_raw)
    output = net.inference(xt)
    print(output)

    ShowResult(reader.XTrain, reader.YTrain, xt, output)