-
大小: 39KB文件類型: .zip金幣: 2下載: 2 次發(fā)布日期: 2021-06-24
- 語言: C/C++
- 標(biāo)簽: 神經(jīng)網(wǎng)絡(luò)??
資源簡介
基于BP神經(jīng)網(wǎng)絡(luò)的簡單字符識別算法自小結(jié)(C語言版)

代碼片段和文件信息
/******************************************************************************
???Copyright?(C)?2014-????Zjut?Image?Processing?Lab.????All?rights?reserved.?
*******************************************************************************
?*?File?Name?:?bp_alg_api.c
?*?Version?:?1.0
?*?Author?:?gzz
?*?Created?:?2014/6/4
?*?Last?Modified?:
??Description???:?BP?Neural?Net?Algorithm?API
?*?Function?List?:
??????????????adjust_layer_weight
??????????????alloc_1d_char_buf
??????????????alloc_1d_double_buf
??????????????alloc_2d_char_buf
??????????????alloc_2d_double_buf
??????????????bp_hidlayer_deltas
??????????????bp_layerforward
??????????????bp_outlayer_deltas
??????????????bp_randomize_weights
??????????????bp_random_seed
??????????????bp_train
??????????????bp_zero_weights
??????????????calculate_err2
??????????????free_alloc_buf
??????????????get_random
??????????????init_bp_core_params
??????????????init_bp_weight
??????????????squash
?*?Modification?History?:
???1.Date?:?2014/6/4
?????Author?:?gzz
?????Modification?:?Created?file
?
******************************************************************************/
#include?
#include?
#include?
#include?
#include?“bp_alg_api.h“
/*Default?Macro?params?for?BP?Neural?Net*/
#define?DEF_ERR2_THROLD?0.001
//#define?DEF_ETA?0.005
#define?DEF_ETA?0.012
#define?DEF_MOMENTUM?0
#define?DEF_SAMPLE_NUM?30
#define?DEF_ITE_NUM?5000000
/*Macro?for?image?sample?information*/
#define?SAMPLE_IMAGE_W?16
#define?SAMPLE_IMAGE_H?16
#define?INPUT_WEIGHT_FILE??“/home/A31_Android4.2.2/Bp_NeuralNet/input_weight.dat“
#define?HIDEN_WEIGHT_FILE?“/home/A31_Android4.2.2/Bp_NeuralNet/hiden_weight.dat“
/*30?samples?one?sample?include?32?Characters*/
extern?double?normalized_sample[][32];
extern?double?sample[][32];
/*Number?Target?Code:?0-9*/
double?out_target[][4]?=?{
????{0.10.10.10.1}?
????{0.10.10.10.9}
????{0.10.10.90.1}
????{0.10.10.90.9}
????{0.10.90.10.1}
????{0.10.90.10.9}
????{0.10.90.90.1}
????{0.10.90.90.9}
????{0.90.10.10.1}
????{0.90.10.10.9}
????};
/*******************************************************************************
***************************隨機(jī)值操作API**********************************/
/***?設(shè)置隨機(jī)數(shù)種子?***/
void?bp_random_seed(int?seed)
{
//printf(“Random?number?generator?seed:?%d\n“?seed);
srand(seed);
}
/***?設(shè)置-1.0到1.0之間的雙精度隨機(jī)數(shù)?***/
double?get_random()
{
????return?(((double)rand()/(double)RAND_MAX)*2.0-1.0);????
}
/***?隨機(jī)初始化權(quán)值?***/
void?bp_randomize_weights(double?**w?int?m?int?n)
{
int?i?j;
for?(i?=?0;?i?<=?m;?i++)?{
for?(j?=?0;?j?<=?n;?j++)?{
w[i][j]?=?get_random();
????????????
????????????DEG(“bp_randomize_weights?=%f“?w[i][j]);
}
}
}
/***初始化權(quán)值為0?***/
void?bp_zero_weights(double?**w?int?m?int?n)
{
int?i?j;
for?(i?=?0;?i?<=?m;?i++)?{
for?(j?=?0;?j?<=?n;?j++)?{
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件???????23884??2014-06-22?22:08??Bp_NeuralNet\bp_alg_api.c
?????文件????????5139??2014-07-08?10:47??Bp_NeuralNet\bp_alg_api.h
?????文件???????31952??2014-06-22?22:08??Bp_NeuralNet\bp_alg_api.o
?????文件???????39107??2014-06-22?22:08??Bp_NeuralNet\bp_test
?????文件?????????440??2014-06-22?22:30??Bp_NeuralNet\hiden_weight.dat
?????文件????????2904??2014-06-22?22:30??Bp_NeuralNet\input_weight.dat
?????文件????????1422??2014-06-24?15:33??Bp_NeuralNet\main.c
?????文件????????7680??2014-06-22?22:08??Bp_NeuralNet\main.o
?????文件?????????615??2014-06-20?20:42??Bp_NeuralNet\Makefile
?????文件????????8362??2014-06-20?15:13??Bp_NeuralNet\template.c
?????文件??????????56??2014-06-20?15:14??Bp_NeuralNet\template.h
?????文件???????11672??2014-06-22?22:08??Bp_NeuralNet\template.o
評論
共有 條評論