⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 digitalneuralgate.vb

📁 neural networks applications
💻 VB
字号:

'Let us import the brainnet framework
Imports BrainNet.NeuralFramework

'<summary> Our simple digital neural gate class </summary>
Public Class DigitalNeuralGate

    'A variable to hold our network
    Private network As BrainNet.NeuralFramework.NeuralNetwork

    '<summary> This is the constructor. Here, we will create a 2-2-1 network </summary>
    Public Sub New()

        'Create the factory to create a Backward Propagation Neural Network
        'Backward Propagation neural network is a commonly used neural network model
        Dim factory As New BrainNet.NeuralFramework.BackPropNetworkFactory()

        'This is an arralist which holds the number of neurons in each layer
        Dim layers As New ArrayList()

        'We need 2 neurons in first layer
        layers.Add(2)
        'We need 2 neurons in the second layer (the second layer is the first
        'hidden layer)
        layers.Add(2)
        'We need one neuron in the output layer
        layers.Add(1)

        'Provide the arraylist as the parameter, to create a network
        network = factory.CreateNetwork(layers)

        'Now, network holds a 2-2-1 neural network object in it.

    End Sub


    '<summary> This is the function for training the network using
    'the brainnet library </summary>
    Public Sub Train(ByVal input1 As Long, ByVal input2 As Long, ByVal output As Long)

        'Create a training data object
        Dim td As New TrainingData()

        'Add inputs to the training data object
        td.Inputs.Add(input1)
        td.Inputs.Add(input2)

        'Add expected output to the training data object
        td.Outputs.Add(output)

        'Train the network one time
        network.TrainNetwork(td)

    End Sub

    '<summary> This is the function for running the network using the
    'brainnet library </summary>
    Public Function Run(ByVal input1 As Long, ByVal input2 As Long) As Double

        'Declare an arraylist to provide as input to the Run method
        Dim inputs As New ArrayList()

        'Add the first input
        inputs.Add(input1)
        'Add the second input
        inputs.Add(input2)

        'Get the output, by calling the network's RunNetwork method
        Dim outputs As ArrayList = network.RunNetwork(inputs)

        'As we have only one neuron in the output layer,
        'let us return its output
        Return outputs(0)

    End Function

    '<summary> This is the function is for saving this gate to 
    'an xml file </summary>
    Public Sub Save(ByVal file As String)
        Dim ser As New BrainNet.NeuralFramework.NetworkSerializer()
        ser.SaveNetwork(file, network)
    End Sub

    '<summary> This is the function is for loading this gate 
    'from an xml file </summary>
    Public Sub Load(ByVal file As String)
        Dim ser As New BrainNet.NeuralFramework.NetworkSerializer()
        ser.LoadNetwork(file, network)
    End Sub




End Class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -