• 大小: 98KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-29
  • 语言: C#
  • 标签: 神经网络  

资源简介

神经网络的C#代码,很强大,您恶搞运行!

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

using AForge;
using AForge.Neuro;
using AForge.Neuro.Learning;
using AForge.Controls;

namespace bpannIris
{
    class Program
    {
        private static double premnmx( double num  double min  double max  )
        {
            if (num > max)
                num = max;
            if (num < min)
                num = min; 

            return 2*(num - min) / (max - min) - 1;
        }

        private static double premnmx1(double num double min double max)
        {
            if (num > max)
                num = max;
            if (num < min)
                num = min;

            return (num - min) / (max - min);
        }
        
        static void Main(string[] args)
        {
            int trainNum = 75 ; 
            int testNum = 75 ; 
            double [][] trainInput = new double[trainNum][] ;
            double[][] trainOutput = new double[trainNum][];

            double [] max = new double [4] ; 
            double [] min = new double [4] ;
            for (int i = 0; i < 4; ++i)
            {
                max[i] = double.MinValue;
                min[i] = double.MaxValue; 
            }

            // 读取训练数据
            StreamReader reader = new StreamReader(“trainData.txt“);

            for (int i = 0; i < trainNum; ++i)
            {
                string value = reader.ReadLine();

                string[] temp = value.Split(‘\t‘);

                trainInput[i] = new double[4] ;
                trainOutput[i] = new double[3] ;

                for (int j = 0; j < 4; ++j)
                {
                    trainInput[i][j] = double.Parse(temp[j]);
                    if (trainInput[i][j] > max[j])
                        max[j] = trainInput[i][j];

                    if (trainInput[i][j] < min[j])
                        min[j] = trainInput[i][j];
                }
                for (int j = 0; j < 3; ++j)
                    trainOutput[i][j] = 0;
                trainOutput[i][ int.Parse( temp[4]  ) -1 ] = 1; 
            }

            // 归一化
            for (int i = 0; i < trainNum; ++i)
            {
                for (int j = 0; j < 4; ++j)
                {
                    trainInput[i][j] = premnmx(trainInput[i][j] min[j] max[j]);
                }
            }
            
            //训练网络

            // create multi-layer neural network
            ActivationNetwork network = new ActivationNetwork( new SigmoidFunction(3) 4 5 3 );
            // create teacher
            BackPropagationLearning teacher = new BackPropagationLearning(network);
            // set learning rate and momentum
            teacher.LearningRate = 0.1;
            teacher.Momentum = 0;

            int iteration = 1 ; 

            while( iteration < 500 ) 
            {
                teacher.RunEpoch( 

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      20480  2006-11-18 14:14  AForge.NET实现\bpannIris\bpannIris\bin\Debug\AForge.Controls.dll

     文件      16384  2006-11-18 14:14  AForge.NET实现\bpannIris\bpannIris\bin\Debug\AForge.dll

     文件      28672  2006-11-18 14:14  AForge.NET实现\bpannIris\bpannIris\bin\Debug\AForge.Neuro.dll

     文件       6656  2011-01-01 07:12  AForge.NET实现\bpannIris\bpannIris\bin\Debug\bpannIris.exe

     文件      15872  2011-01-01 07:12  AForge.NET实现\bpannIris\bpannIris\bin\Debug\bpannIris.pdb

     文件      11600  2011-01-01 07:15  AForge.NET实现\bpannIris\bpannIris\bin\Debug\bpannIris.vshost.exe

     文件        490  2010-03-17 22:39  AForge.NET实现\bpannIris\bpannIris\bin\Debug\bpannIris.vshost.exe.manifest

     文件       1349  2011-07-10 13:38  AForge.NET实现\bpannIris\bpannIris\bin\Debug\testData.txt

     文件       2708  2011-07-10 13:42  AForge.NET实现\bpannIris\bpannIris\bin\Debug\totalData.txt

     文件       1359  2011-07-10 13:39  AForge.NET实现\bpannIris\bpannIris\bin\Debug\trainData.txt

     文件      20480  2006-11-18 14:14  AForge.NET实现\bpannIris\bpannIris\bin\Release\AForge.Controls.dll

     文件      16384  2006-11-18 14:14  AForge.NET实现\bpannIris\bpannIris\bin\Release\AForge.dll

     文件      28672  2006-11-18 14:14  AForge.NET实现\bpannIris\bpannIris\bin\Release\AForge.Neuro.dll

     文件       6656  2013-06-07 10:46  AForge.NET实现\bpannIris\bpannIris\bin\Release\bpannIris.exe

     文件      17920  2013-06-07 10:46  AForge.NET实现\bpannIris\bpannIris\bin\Release\bpannIris.pdb

     文件      22984  2013-06-07 10:46  AForge.NET实现\bpannIris\bpannIris\bin\Release\bpannIris.vshost.exe

     文件        490  2012-06-06 02:06  AForge.NET实现\bpannIris\bpannIris\bin\Release\bpannIris.vshost.exe.manifest

     文件       1349  2011-07-10 13:38  AForge.NET实现\bpannIris\bpannIris\bin\Release\testData.txt

     文件       2708  2011-07-10 13:42  AForge.NET实现\bpannIris\bpannIris\bin\Release\totalData.txt

     文件       1359  2011-07-10 13:39  AForge.NET实现\bpannIris\bpannIris\bin\Release\trainData.txt

     文件       3033  2010-12-28 16:26  AForge.NET实现\bpannIris\bpannIris\bpannIris.csproj

     文件       1139  2011-01-01 07:15  AForge.NET实现\bpannIris\bpannIris\obj\x86\Debug\bpannIris.csproj.FileListAbsolute.txt

     文件       6656  2011-01-01 07:12  AForge.NET实现\bpannIris\bpannIris\obj\x86\Debug\bpannIris.exe

     文件      15872  2011-01-01 07:12  AForge.NET实现\bpannIris\bpannIris\obj\x86\Debug\bpannIris.pdb

     文件       6424  2011-01-01 07:15  AForge.NET实现\bpannIris\bpannIris\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件      22519  2011-01-01 05:43  AForge.NET实现\bpannIris\bpannIris\obj\x86\Debug\ResolveAssemblyReference.cache

     文件       3857  2013-06-07 10:46  AForge.NET实现\bpannIris\bpannIris\obj\x86\Release\bpannIris.csproj.FileListAbsolute.txt

     文件      16752  2013-06-06 15:03  AForge.NET实现\bpannIris\bpannIris\obj\x86\Release\bpannIris.csprojResolveAssemblyReference.cache

     文件       6656  2013-06-07 10:46  AForge.NET实现\bpannIris\bpannIris\obj\x86\Release\bpannIris.exe

     文件      17920  2013-06-07 10:46  AForge.NET实现\bpannIris\bpannIris\obj\x86\Release\bpannIris.pdb

............此处省略26个文件信息

评论

共有 条评论