aboutsummaryrefslogtreecommitdiff
path: root/src/lib/include/neuralnet/neuralnet.h
blob: 05c9406948a1ce5908d50f112db53d9d53ad5ec7 (plain)
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
61
62
63
64
65
66
#pragma once

#include <neuralnet/types.h>

typedef struct nnMatrix nnMatrix;

typedef struct nnNeuralNetwork nnNeuralNetwork;
typedef struct nnQueryObject   nnQueryObject;

/// Neuron activation.
typedef enum nnActivation {
  nnIdentity,
  nnSigmoid,
  nnRelu,
} nnActivation;

/// Create a network.
nnNeuralNetwork* nnMakeNet(
    int num_layers, const int* layer_sizes, const nnActivation* activations);

/// Delete the network and free its internal memory.
void nnDeleteNet(nnNeuralNetwork**);

/// Set the network's weights.
void nnSetWeights(nnNeuralNetwork*, const R* weights);

/// Set the network's biases.
void nnSetBiases(nnNeuralNetwork*, const R* biases);

/// Query the network.
///
/// |input| is a matrix of inputs, one row per input and as many columns as the
/// input's dimension.
///
/// The query object's output matrix (see nnQueryOutputs()) is a matrix of
/// outputs, one row per output and as many columns as the output's dimension.
void nnQuery(const nnNeuralNetwork*, nnQueryObject*, const nnMatrix* input);

/// Query the network, array version.
void nnQueryArray(
    const nnNeuralNetwork*, nnQueryObject*, const R* input, R* output);

/// Create a query object.
///
/// The query object holds all the internal memory required to query a network.
/// Query objects allocate all memory up front so that network queries can run
/// without additional memory allocation.
nnQueryObject* nnMakeQueryObject(const nnNeuralNetwork*, int num_inputs);

/// Delete the query object and free its internal memory.
void nnDeleteQueryObject(nnQueryObject**);

/// Return the outputs of the query.
const nnMatrix* nnNetOutputs(const nnQueryObject*);

/// Return the network's input size.
int nnNetInputSize(const nnNeuralNetwork*);

/// Return the network's output size.
int nnNetOutputSize(const nnNeuralNetwork*);

/// Return the layer's input size.
int nnLayerInputSize(const nnMatrix* weights);

/// Return the layer's output size.
int nnLayerOutputSize(const nnMatrix* weights);