-
大小: 2KB文件類型: .cpp金幣: 1下載: 0 次發(fā)布日期: 2021-06-10
- 語(yǔ)言: C/C++
- 標(biāo)簽: 神經(jīng)網(wǎng)絡(luò)??異或??ANN??
資源簡(jiǎn)介
用ANN實(shí)現(xiàn)的異或,使用了單隱層的BP算法。
代碼片段和文件信息
#include?
#include?
#include?
#include?
#include?
#define?N_SAMPLES?4
/***************
網(wǎng)絡(luò)如下:?
o-------
0??\????\
???2o----o3
1??/????/
o-------
****************/
float?X[N_SAMPLES][2]?=?{10011100};???????????//每個(gè)訓(xùn)練的輸入?
float?d[N_SAMPLES]?=?{1100};?????????????????????????//每個(gè)訓(xùn)練的標(biāo)準(zhǔn)輸出?
float?w03w02w13w12w23;
float?theta[4];
float?delta[4];
float?e;
float?E_sum;
float?E_bar;
float?E?=?0.000001;
float?eta?=?0.001;
float?v[4];
float?y[4];
float?abs(float?a)
{
??????if(a>=0)?return?a;
??????if(a<0)?return?(0-a);
}?
float?sigmoid(float?v)?????????????
{
float?f;
f=1/(1+exp(-v));
return?f;
}
float?sigmoid_1(float?v)
{
????return?sigmoid(v)*(1-sigmoid(v));
}
int?init()
{
????srand((unsigned)time(NULL));
????w03?=?rand()/32767.0?-?0.5;
????w02?=?rand()/32767.0?-?0.5;
????w13?=?rand()/32767.0?-?0.5;
????w12?=?rand()/32767.0?-?0.5;
????w23?=?rand()/32767.0?-?0.5;
????theta[0]?=?rand()/32767.0?-?0.5;
????theta[1]?=?rand()/32767.0?-?0.5;
????theta[2]?=?rand()/32767.0?-?0.5;
????theta[3]?=?rand()/32767.0?-?0.5;
}
int?main()
{
????init();
????do
????{
????????E_sum?=?0.0;
????????int?i;
????????for?(i?=?0;
- 上一篇:基于IE瀏覽器的源代碼
- 下一篇:C++實(shí)現(xiàn)日志庫(kù)
評(píng)論
共有 條評(píng)論