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
|
#pragma once
#include <neuralnet/neuralnet.h>
#include <stdbool.h>
#include <stdint.h>
typedef struct nnMatrix nnMatrix;
/// Weight initialization strategy.
///
/// Note that regardless of strategy, a layer's weights are scaled by the
/// layer's size. This is to avoid saturation when, e.g., using a sigmoid
/// activation with many inputs. Thus, a (0,1) initialization is really
/// (0,scale), for example.
typedef enum nnWeightInitStrategy {
nnWeightInit01, // (0,1) range.
nnWeightInit11, // (-1,+1) range.
nnWeightInitNormal, // Normal distribution.
} nnWeightInitStrategy;
/// Network training parameters.
typedef struct nnTrainingParams {
R learning_rate;
int max_iterations;
uint64_t seed;
nnWeightInitStrategy weight_init;
bool debug;
} nnTrainingParams;
/// Train the network.
///
/// |inputs| is a matrix of inputs, one row per input and as many columns as
/// the input's dimension.
///
/// |targets| is a matrix of targets, one row per target and as many columns as
/// the target's dimension.
void nnTrain(
nnNeuralNetwork*,
const nnMatrix* inputs,
const nnMatrix* targets,
const nnTrainingParams*);
|