2018-03-30 23:04:37 +03:00
|
|
|
#pragma once
|
2018-03-29 06:41:08 +03:00
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2018-03-31 14:29:03 +03:00
|
|
|
float* w; // All the weights.
|
|
|
|
float* x; // Hidden to output layer weights.
|
|
|
|
float* b; // Biases.
|
|
|
|
float* h; // Hidden layer.
|
|
|
|
float* o; // Output layer.
|
2018-03-30 23:04:37 +03:00
|
|
|
|
2018-04-02 03:01:42 +03:00
|
|
|
int nb; // Number of biases - always two - Tinn only supports a single hidden layer.
|
|
|
|
int nw; // Number of weights.
|
2018-03-31 01:42:20 +03:00
|
|
|
|
2018-03-30 23:04:37 +03:00
|
|
|
int nips; // Number of inputs.
|
|
|
|
int nhid; // Number of hidden neurons.
|
|
|
|
int nops; // Number of outputs.
|
2018-03-29 06:41:08 +03:00
|
|
|
}
|
|
|
|
Tinn;
|
|
|
|
|
2018-03-31 01:42:20 +03:00
|
|
|
// Trains a tinn with an input and target output with a learning rate.
|
|
|
|
// Returns error rate of the neural network.
|
2018-03-31 14:29:03 +03:00
|
|
|
float xttrain(const Tinn, const float* in, const float* tg, float rate);
|
2018-03-29 06:41:08 +03:00
|
|
|
|
2018-03-31 01:42:20 +03:00
|
|
|
// Builds a new tinn object given number of inputs (nips),
|
|
|
|
// number of hidden neurons for the hidden layer (nhid),
|
|
|
|
// and number of outputs (nops).
|
2018-03-30 23:04:37 +03:00
|
|
|
Tinn xtbuild(int nips, int nhid, int nops);
|
2018-03-29 06:41:08 +03:00
|
|
|
|
2018-03-31 01:42:20 +03:00
|
|
|
// Returns an output prediction given an input.
|
2018-03-31 14:29:03 +03:00
|
|
|
float* xpredict(const Tinn, const float* in);
|
2018-03-31 01:42:20 +03:00
|
|
|
|
|
|
|
// Saves the tinn to disk.
|
|
|
|
void xtsave(const Tinn, const char* path);
|
|
|
|
|
|
|
|
// Loads a new tinn from disk.
|
|
|
|
Tinn xtload(const char* path);
|
|
|
|
|
|
|
|
// Frees a tinn from the heap.
|
|
|
|
void xtfree(const Tinn);
|