用c语言动态数组(不用c++的vector)实现:inputs = { {1, 1}, {1, 0} };数据targets={0,1}; 测试数据 inputs22 = { {1, 0}, {1,1} }; 构建神经网络,例如:NeuralNetwork nn({ 2, 4, 1 }); 则网络有四层、输入层2个节点、输出层1个节点、隐藏层4个节点、网络有梯度下降、反向传播…等。
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>float sigmoid(float x) {return 1 / (1 + exp(-x));
}float sigmoid_derivative(float x) {float s = sigmoid(x);return s * (1 - s);
}typedef struct {float*** weights;int num_layers;int* layer_sizes;float** layer_outputs;
} NeuralNetwork;NeuralNetwork initialize_nn(int* topology, int num_layers) {NeuralNetwork nn;nn.num_layers = num_layers;nn.layer_sizes = topology;nn.weights = (float***)malloc((num_layers - 1) * sizeof(float**));nn.layer_outputs = (float**)malloc(num_layers * sizeof(float*));srand(ti