• 大小: 881KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-05-24
  • 语言: C#
  • 标签: c#  

资源简介

C#开发的BP神经网络代码,有多种传递函数和训练方式

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.IO;
namespace BP
{
    class BP_Algorithm
    {
        struct Node {
            public double lr mturn; //学习速率,动量因子
            public double k _k; //阈值及阈值变化量
            public double[] w;
            public double[] _w; //权值及权值变化量
            public double x y; //输入与输出
            public double err;//误差信号δ
        }
        private ArrayList netWork = new ArrayList(); //BP网络
        private ArrayList dataSet = new ArrayList(); //数据集合
        public void DataClear() { dataSet.Clear(); }
        private double lRate momentum;
        private double xmin xmax;
        private int inSum outSum functionLex;
        private double[] expectOut;//期望输出
        private double actualOutAvg expectOutAvg sqrtErr; //实际输出均值,期望输出均值,总体均方误差
        public double ActualOutAvg {
            get { return _Normalizing(actualOutAvg); }
        }
        public double ExpectOutAvg {
            get { return _Normalizing(expectOutAvg); }
        }
        public double SqrtErr {
            get { return sqrtErr; }
        }
        private ArrayList netError = new ArrayList();
        public void build(参数设置 stf) {
            lRate = stf.LRate; momentum = stf.Momentum; 
            inSum = stf.InSum; outSum = stf.OutSum;
            functionLex = stf.FunchtionLex; //传递函数类型
            netWork.Clear(); //销毁原先网络,按照新的参数构建网络
            ArrayList al = stf.Hlayers;
            al.Insert(0 stf.InSum); //插入输入层
            al.Add(stf.OutSum); //添加输出层
            Random rd = new Random(DateTime.Now.Millisecond);
            int s sn;
            for (int i = 0; i < al.Count; i++) {
                s = (int)al[i]; //当前层的结点数
                if (i < al.Count - 1)
                    sn = (int)al[i + 1]; //下一层的结点数
                else
                    sn = 0; //输出层,无下一层
                ArrayList newlayer = new ArrayList(); //在网络中创建一个新的层
                for (int j = 0; j < s; j++) {
                    Node newNode = new Node(); //创建新的节点
                    newNode._w = new double[sn];
                    newNode.w = new double[sn];
                    for (int k = 0; k < sn; k++) {
                        newNode.w[k] = rd.NextDouble();//w.Add(rd.NextDouble()); //初始化权值(随机)
                        newNode._w[k] = 0;//.Add(0.0); //初始化权值增量为0
                    }
                    newNode.k = 0;//((i > 0 && i < al.Count - 1) ? 1 : 0); //初始化阈值
                    newNode.lr=lRate;
                    newNode.mturn=momentum;
                    newlayer.Add(newNode);
                }
                netWork.Add(newlayer);
            }
            expectOut = new double[outSum];
        }
        public void AddData(string sLine) { //数据
            ArrayList d = new ArrayList();
            string [] num = sLine.Split(‘ ‘‘\t‘);
            for (int i = 0; i < num.Length; i

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2009-11-24 00:19  BP\
     目录           0  2009-11-24 00:19  BP\BP\
     目录           0  2009-11-24 00:19  BP\BP\BP\
     文件         896  2009-11-09 22:37  BP\BP\BP.sln
     文件       23552  2010-01-20 09:57  BP\BP\BP.suo
     文件       12340  2009-11-16 11:33  BP\BP\BP\BP.cs
     文件        4571  2009-11-18 17:45  BP\BP\BP\BP.csproj
     文件       25635  2009-11-30 00:26  BP\BP\BP\Form1.Designer.cs
     文件       12028  2009-11-30 00:26  BP\BP\BP\Form1.cs
     文件        6012  2009-11-30 00:26  BP\BP\BP\Form1.resx
     文件         154  2009-11-10 23:52  BP\BP\BP\Hiddenlayer.cs
     文件         483  2009-11-11 08:50  BP\BP\BP\Program.cs
     目录           0  2009-11-24 00:19  BP\BP\BP\Properties\
     文件        1336  2009-11-09 22:37  BP\BP\BP\Properties\AssemblyInfo.cs
     文件        2854  2009-11-09 22:37  BP\BP\BP\Properties\Resources.Designer.cs
     文件        5612  2009-11-09 22:37  BP\BP\BP\Properties\Resources.resx
     文件        1087  2009-11-09 22:37  BP\BP\BP\Properties\Settings.Designer.cs
     文件         249  2009-11-09 22:37  BP\BP\BP\Properties\Settings.settings
     目录           0  2009-11-24 00:19  BP\BP\BP\bin\
     目录           0  2009-11-24 00:19  BP\BP\BP\bin\Debug\
     文件       33280  2009-11-18 17:45  BP\BP\BP\bin\Debug\BP.exe
     文件       65024  2009-11-18 17:45  BP\BP\BP\bin\Debug\BP.pdb
     文件       14328  2010-01-20 09:57  BP\BP\BP\bin\Debug\BP.vshost.exe
     文件         490  2007-07-21 02:33  BP\BP\BP\bin\Debug\BP.vshost.exe.manifest
     文件      335872  2007-11-28 17:13  BP\BP\BP\bin\Debug\ZedGraph.dll
     文件     1510947  2007-11-28 17:13  BP\BP\BP\bin\Debug\ZedGraph.xml
     目录           0  2009-11-24 00:19  BP\BP\BP\bin\Debug\de\
     文件        5120  2007-11-28 17:13  BP\BP\BP\bin\Debug\de\ZedGraph.resources.dll
     目录           0  2009-11-24 00:19  BP\BP\BP\bin\Debug\es\
     文件        5120  2007-11-28 17:13  BP\BP\BP\bin\Debug\es\ZedGraph.resources.dll
     目录           0  2009-11-24 00:19  BP\BP\BP\bin\Debug\fr\
............此处省略132个文件信息

评论

共有 条评论