网络上怎么直接运行c语言,BP神经网络C语言代码_可以直接VC++上运行.pdf

这篇博客提供了一个完整的C语言实现的BP神经网络代码示例,该代码可以在VC++环境下直接运行。博主详细介绍了如何生成随机样本数据,并初始化神经网络结构,包括输入、输出、神经元数量及训练次数等参数。此外,还涵盖了权重更新和误差修正的算法。通过阅读此篇博客,读者可以深入理解BP神经网络的工作原理及其在C语言中的实现细节。
摘要由CSDN通过智能技术生成

BP神经网络C语言代码_可以直接VC上运行

// 个完整的C 语言的BP 神经网络代码,可以直接在VC++上运行。

#include

#include

#include

#include

#define Data 820 //样本数据量

#define In 2 // 输入

#define Out 1 //输出

#define Neuron 8 //神经元

#define TrainC 20000 //训练次数

#define A 0.2

#define B 0.4

#define a 0.2

#define b 0.3

double d_in[Data][In],d_out[Data][Out]; //样本输出和输出

double w [Neuron][In],o[Neuron],v[Out][Neuron]; //神经元的权值

double Maxin[In],Minin[In],Maxout[Out],Minout[Out];

double OutputData[Out]; //神经元的输出

double dv[Out][Neuron],dw[Neuron][In] ; //神经元的权值的修正量

double e;

//生成随机样本输入数据,输出数据根据输入来设置

void writeTest()

{

FILE *fp1,*fp2;

double r1,r2;

int i;

srand ((unsigned)time(NULL));

if((fp1=fopen ("in.txt","w"))==NULL)

{

printf("can not open 1 the in file\n");

exit(0);

}

if((fp2=fopen ("out.txt","w"))==NULL)

{

printf("can not open the out file\n");

exit(0);

}

for (i=0;i

{

r1=rand()%1000/100.0;

r2=rand()%1000/100.0;

fprintf(fp1,"%lf %lf\n",r1,r2);

fprintf(fp2,"%lf \n",r1*r2);

}

fclose(fp1);

fclose(fp2);

}

void readData(){

FILE *fp1,*fp2;

int i,j;

if((fp1=fopen ("in.txt","r"))==NULL)

{

printf("can not open the 2 in file\n");

exit(0);

}

for (i=0;i

for (j=0; j

fscanf(fp1,"%lf",&d_in[i][j]);

fclose(fp1);

if((fp2=fopen ("out.txt","r"))==NULL)

{

printf("can not open the out file\n");

exit(0);

}

for (i=0;i

for (j=0; j

fscanf(fp1,"%lf",&d_out[i][j]);

fclose(fp2);

}

//初始化神经网络

void initBPNework ()

{

int i,j;

//输入数据最大值,最小值

for (i=

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值