用c语言实现蚂蚁算法,BP算法程序C语言实现

本文介绍了一个用C语言实现的BP神经网络算法程序,该程序能够读取指定路径下的训练样本,并通过迭代学习来调整神经网络的权重和阈值。程序还包括了开始和结束界面的显示,以及对用户使用的指导说明。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

41528d3028836879cd698677c3999917.gifBP算法程序C语言实现

文件输入输出目录为:F:\BP\ 训练样本文件名:训练样本.txt 值为: 1 1 -1 1 -1 1 0 1 0 1 输出文件名为:阈值.txt 权值.txt ========================= #include “stdlib.h“ #include “math.h“ #include “conio.h“ #include “stdio.h“ #define N 2 /*/学习样本个数*/ #define IN 3 /*/输入层神经元数目*/ #define HN 3 /*/隐层神经元数目*/ #define ON 2 /*/输出层神经元数目*/ #define Z 20 /*旧权值保存,每次study的权值都保存下来*/ double P[IN]; /*单个样本输入数据*/ double T[ON]; /*单个样本输出数据*/ double W[HN][IN]; /*/输入层至隐层权值*/ double V[ON][HN]; /*/隐层至输出层权值*/ double X[HN]; /*/隐层的输入*/ double Y[ON]; /*/输出层的输入*/ double H[HN]; /*/隐层的输出*/ double O[ON]; /*/输出层的输出*/ double YU_HN[HN]; /*/隐层的阈值*/ double YU_ON[ON]; /*/输出层的阈值*/ double err m[N]; /*/第m个样本的总误差*/ double a; /*/输出层至隐层的学习效率*/ double b; /*/隐层至输入层学习效率*/ double alpha; /*/动量因子,改进型bp算法使用*/ double d err[ON]; FILE *fp; /*定义一个放学习样本的结构*/ struct { double [IN]; double teach[ON]; }Study_Data[N]; /*改进型bp算法用来保存每次计算的权值*/ struct { double old_W[HN][IN]; double old_V[ON][HN]; }Old_WV[Z]; 显示开始界面 int Start_Show() { clrscr(); printf(“\n ***********************\n“); printf(“ * Welcome to use *\n“); printf(“ * this program of *\n“); printf(“ * calculating the BP *\n“); printf(“ * model! *\n“); printf(“ * Happy every day! *\n“); printf(“ ***********************\n“); printf(“\n\n Before starting, please read the follows carefully:\n\n“); printf(“ 1.Please ensure the Path of the 训练样本.txt (xunlianyangben.txt) is \n correct, like F:\BP\训练样本.txt !\n“); printf(“ 2.The calculating results will be saved in the Path of F:\\BP\\ !\n“); printf(“ 3.The program will load 10 datas when running from F:\\BP\\训练样本.txt !\n“); printf(“ 4.The program of BP can study itself for no more than 30000 times.\n And surpassing the number, the program will be ended by itself in\n preventing running infinitely because of error!\n“); printf(“\n\n\n“); printf(“Now press any key to start.\n“); getch(); getch(); clrscr(); } 显示结束界面 int End_Show() { printf(“\n\n---------------------------------------------------\n“); printf(“The program has reached the end successfully!\n\n Press any key to exit!\n\n“); printf(“\n ***********************\n“); printf(“ * This is the end *\n“); printf(“ * of the program which*\n“); printf(“ * can calculate the BP*\n“); printf(“ * model! *\n“); printf(“ ***********************\n“); printf(“ * Thanks for using! *\n“); printf(“ * Happy every day! *\n“); printf(“ ***********************\n“); getch(); exit(0); } 获取训练样本 GetTrainingData() /*OK*/ { int m,i,j; int datr; if((fp=(“f:\\bp\\训练样本

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值