Download code/engine/neural_network/neural_network.h from HDTenEightyP/SeafarerEngine: direct link, hf CLI and curl.
- Browser
- Download file 2.51 kB
-
https://huggingface.co/HDTenEightyP/SeafarerEngine/resolve/main/code/engine/neural_network/neural_network.h
- Command line
-
hf download hf://HDTenEightyP/SeafarerEngine/code/engine/neural_network/neural_network.h
-
curl -L -o neural_network.h https://huggingface.co/HDTenEightyP/SeafarerEngine/resolve/main/code/engine/neural_network/neural_network.h
2.51 kB
| // -------------------------------------------------------- | |
| // 1. Structures | |
| // -------------------------------------------------------- | |
| typedef struct { | |
| int num_inputs; // Inputs from the previous NNLayer | |
| int num_neurons; // Neurons in this NNLayer | |
| double *weights; // 1D array of size [num_neurons * num_inputs] | |
| double *biases; // 1D array of size [num_neurons] | |
| double *outputs; // 1D array of size [num_neurons] | |
| double *deltas; // 1D array of size [num_neurons] for backprop | |
| } NNLayer; | |
| typedef struct { | |
| int num_inputs; // Network input size | |
| int num_NNLayers; // Total number of NNLayers (hidden + output) | |
| NNLayer *NNLayers; // Array of NNLayers | |
| } Network; | |
| // -------------------------------------------------------- | |
| // 2. Math & Activations | |
| // -------------------------------------------------------- | |
| // Generates a random double between -0.5 and 0.5 | |
| double random_weight(); | |
| // Sigmoid activation function | |
| double sigmoid(double x); | |
| // Derivative of sigmoid (assuming x is already activated) | |
| double sigmoid_derivative(double x); | |
| // -------------------------------------------------------- | |
| // 3. Initialization & Memory Management | |
| // -------------------------------------------------------- | |
| // Initialize a single NNLayer | |
| void init_NNLayer(NNLayer *NNLayer, int num_inputs, int num_neurons); | |
| // Create the network | |
| Network* create_network(int num_inputs, int num_hidden_NNLayers, int hidden_size, int num_outputs); | |
| // Free memory | |
| void free_network(Network *net); | |
| // -------------------------------------------------------- | |
| // 4. Feedforward & Backpropagation | |
| // -------------------------------------------------------- | |
| // Forward pass | |
| double* feed_forward(Network *net, double *inputs); | |
| // Train a single sample | |
| void backpropagate(Network *net, double *inputs, double *targets, double learning_rate); | |
| // -------------------------------------------------------- | |
| // 5. File Saving and Loading | |
| // -------------------------------------------------------- | |
| void save_network(Network *net, const char *filename); | |
| Network* load_network(const char *filename); | |
| // -------------------------------------------------------- | |
| // 6. Example Usage (Airplane Steering Context) | |
| // -------------------------------------------------------- | |
| int CreateNet(); | |