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

📄 nxml.vb

📁 neural networks applications
💻 VB
字号:
'------------------------------------------------------------------
' License Notice:
'------------------------------------------------------------------
' All Rights Reserved - Anoop Madhusudanan, 
' Mail: amazedsaint@gmail.com
' Website: http://amazedsaint.blogspot.com

' See my articles about BrainNet at 
' http://amazedsaint-articles.blogspot.com for details
'
' You can use this code (or part of it), for non 
' commercial and academic uses, as long as 
'   - You are keeping this notice along with it
'   - You are not making any profit out of this
'------------------------------------------------------------------

Imports BrainNet.NeuralFramework
Imports BrainNet.NeuralFramework.NeuralXML



'<summary>Neural XML interpreter </summary>
Module ModuleMain

    '<summary>Execution starts from here</summary>
    Sub Main()
        Dim vars() As String = Split(Trim(Command))

        If vars.Length < 2 Then
            WriteUsage()
            End
        End If

        Try
            Dim count As Long
            Dim filename As String = ""


            If LCase(vars(0)) = "-gen" Then
                'Network generation
                Console.WriteLine("Started generating network at " & Now())
                Dim layers As String = vars(1)
                For count = 2 To vars.Length - 1
                    filename = filename & vars(count)
                    If count < vars.Length - 1 Then filename = filename & " "
                Next
                GenerateNetwork(vars(1), filename)
                Console.WriteLine("Network generated to " & filename & " at " & Now)

            ElseIf LCase(vars(0)) = "-start" Then

                    'Interpret an nxml file to train and run a network
                    For count = 1 To vars.Length - 1
                        filename = filename & vars(count)
                        If count < vars.Length - 1 Then filename = filename & " "
                    Next
                    Console.WriteLine("Started interpreting nxml file at " & Now())
                    Interpret(filename)
                    Console.WriteLine("Finished interpreting nxml file at " & Now())

                Else
                    Throw New Exception("Unknown command switch")
                End If
        Catch ex As Exception
            Console.WriteLine("Error: " & ex.Message)
            Console.WriteLine()
            Console.WriteLine("Detailed Error Information:" & vbCrLf & ex.ToString)


        End Try



    End Sub


    '<summary>Generate a network</summary>
    Sub GenerateNetwork(ByVal layers As String, ByVal file As String)

        Dim i As Long
        Dim neuronlist As New ArrayList()
        Dim mynn As INeuralNetwork
        Try

            Dim neuronlistStr() As String = Split(layers, ",")


            For i = 0 To neuronlistStr.Length - 1
                neuronlist.Add(CType(neuronlistStr(i), Long))
            Next
        Catch ex As Exception
            Throw New Exception("Invalid layer information. You should specify neurons in layers, separted by comma ','")

        End Try

        mynn = New BackPropNetworkFactory().CreateNetwork(neuronlist)

        'Serialize it to a file
        Dim ser As New NetworkSerializer()
        ser.SaveNetwork(file, mynn)

    End Sub

    '<summary>Start the interpretation</summary>
    Sub Interpret(ByVal file As String)
        Dim interpreter As New NeuralXML.NXMLInterpreter()
        interpreter.Interpret(file)

    End Sub

    '<summary>Write the usage</summary>
    Sub WriteUsage()
        Console.WriteLine("You can use this program to create a multi layer back prop network, train it and run it")
        Console.WriteLine("All Rights Reserved (C) 2005-2006, Anoop Madhusudanan, http://amazedsaint.blogspot.com")
        Console.WriteLine()

        Console.WriteLine("Syntax:")
        Console.WriteLine("-----------")
        Console.WriteLine()
        Console.WriteLine("Syntax1: nxml -gen NeuronsInLayer1,NeuronsInLayer2,NeuronsInLayerN filename")
        Console.WriteLine()
        Console.WriteLine("Syntax2: nxml -start filename")
        Console.WriteLine()
        Console.WriteLine("Use the -start switch to train an run a network using an nxml file.")
        Console.WriteLine("Use the -gen switch to create a back propagation network and save it to a file")
        Console.WriteLine()
        Console.WriteLine("Examples:")
        Console.WriteLine("-----------")
        Console.WriteLine()
        Console.WriteLine("Example1: nxml -gen 10,10,4 mynetwork.xml")
        Console.WriteLine("The above example will create a network with 3 layers - 10 neurons in input layer, 10 neurons in hidden layer, and 4 neurons in output layer.")
        Console.WriteLine()
        Console.WriteLine("Example2: nxml -gen 3,3,3,2 mynetwork.xml")
        Console.WriteLine("The above example will create a network with 4 layers - 3 neurons in input layer, 3 neurons in first hidden layer, 3 neurons in second hidden layer, and 2 neurons in output layer.")
        Console.WriteLine()
        Console.WriteLine("Example3: nxml -start mynetworktrian.nxml")
        Console.WriteLine("The above example will execute the mynetworktrain.nxml file to train and run the network")
        Console.WriteLine()

    End Sub

End Module

⌨️ 快捷键说明

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