这是一个轻量、无依赖、单文件的 C 语言神经网络库,内含丰富的示例和测试。代码简洁易读,适合作为初学者学习神经网络的入门项目。
#include"genann.h"
/* Not shown, loading your training and test data. */ double **training_data_input, **training_data_output, **test_data_input;
/* New network with 2 inputs, * 1 hidden layer of 3 neurons each, * and 2 outputs. */ genann *ann = genann_init(2, 1, 3, 2);
/* Learn on the training set. */ for (i = 0; i 300; ++i) { for (j = 0; j 100; ++j) genann_train(ann, training_data_input[j], training_data_output[j], 0.1); }
/* Run the network and see what it predicts. */ doubleconst *prediction = genann_run(ann, test_data_input[0]); printf("Output for the first test data point is: %f, %f\n", prediction[0], prediction[1]);