-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathneural_network.h
60 lines (51 loc) · 1.65 KB
/
neural_network.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//
// Created by afan on 2024/7/6.
//
#ifndef NEURAL_NETWORK_H
#define NEURAL_NETWORK_H
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
typedef enum {
RELU,
SIGMOID,
TANH,
LINEAR,
LEAKY_RELU
} ActivationFunction;
typedef enum {
MSE,
CROSS_ENTROPY,
BINARY_CROSS_ENTROPY,
MAE
} LossFunction;
typedef struct {
double *weights;
double bias;
double output;
double delta;
} Neuron;
typedef struct {
int num_neurons;
Neuron *neurons;
} Layer;
typedef struct {
int num_layers;
Layer *layers;
LossFunction loss_function;
ActivationFunction activation;
} NeuralNetwork;
// 函數宣告
NeuralNetwork* create_network(int num_layers, const int *neurons_per_layer, ActivationFunction activation, LossFunction lossFunction);
void free_network(NeuralNetwork *network);
void initialize_weights(NeuralNetwork *network, double min, double max);
void forward_propagation(NeuralNetwork *network, const double *input);
void backward_propagation(NeuralNetwork *network, double *expected_output, double learning_rate);
double activation_function(double x, ActivationFunction func);
double activation_function_derivative(double x, ActivationFunction func);
double compute_loss(double *output, double *expected_output, int length, LossFunction loss_function);
double compute_loss_derivative(double output, double expected_output, LossFunction loss_function);
double compute_error(double output, double expected_output);
void save_network(NeuralNetwork *network, const char *filename);
NeuralNetwork *load_network(const char *filename);
#endif // NEURAL_NETWORK_H