mirror of
https://github.com/glouw/tinn
synced 2024-11-21 22:11:21 +03:00
doc update
This commit is contained in:
parent
63ba88bbb8
commit
10eb871ca7
20
README.md
20
README.md
@ -84,6 +84,26 @@ This gives 10 outputs to the neural network. The test program will output the
|
|||||||
accuracy for each digit. Expect above 99% accuracy for the correct digit, and
|
accuracy for each digit. Expect above 99% accuracy for the correct digit, and
|
||||||
less that 1% accuracy for the other digits.
|
less that 1% accuracy for the other digits.
|
||||||
|
|
||||||
|
# Tips
|
||||||
|
|
||||||
|
* Tinn will never use more than the C standard library.
|
||||||
|
|
||||||
|
* Tinn is great for embedded systems. Train a model on your powerful desktop and load
|
||||||
|
it onto a microcontroller and use the analog to digital converter to predict real time events.
|
||||||
|
|
||||||
|
* The Tinn source code will always be less than 200 lines. Functions externed in the Tinn header
|
||||||
|
are protected with the _xt_ namespace standing for _externed tinn_.
|
||||||
|
|
||||||
|
* Tinn can easily be multi-threaded with a bit of ingenuity but the master branch will remain
|
||||||
|
single threaded to aid development for embedded systems.
|
||||||
|
|
||||||
|
* Tinn does not seed the random number generator. Do not forget to do so yourself.
|
||||||
|
|
||||||
|
* Always shuffle your input data. Shuffle again after every training iteration.
|
||||||
|
|
||||||
|
* Get greater training accuracy by annealing your learning rate. For instance, multiply
|
||||||
|
your learning rate by 0.99 every training iteration. This will zero in on a good learning minima.
|
||||||
|
|
||||||
# Disclaimer
|
# Disclaimer
|
||||||
|
|
||||||
Tinn is not a fully featured neural network C library like Kann, or Genann:
|
Tinn is not a fully featured neural network C library like Kann, or Genann:
|
||||||
|
9
Tinn.c
9
Tinn.c
@ -121,12 +121,15 @@ static void* ecalloc(const size_t nmemb, const size_t size)
|
|||||||
return mem;
|
return mem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Returns an output prediction given an input.
|
||||||
float* xtpredict(const Tinn t, const float* const in)
|
float* xtpredict(const Tinn t, const float* const in)
|
||||||
{
|
{
|
||||||
fprop(t, in);
|
fprop(t, in);
|
||||||
return t.o;
|
return t.o;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Trains a tinn with an input and target output with a learning rate.
|
||||||
|
// Returns error rate of the neural network.
|
||||||
float xttrain(const Tinn t, const float* const in, const float* const tg, float rate)
|
float xttrain(const Tinn t, const float* const in, const float* const tg, float rate)
|
||||||
{
|
{
|
||||||
fprop(t, in);
|
fprop(t, in);
|
||||||
@ -134,6 +137,9 @@ float xttrain(const Tinn t, const float* const in, const float* const tg, float
|
|||||||
return toterr(tg, t.o, t.nops);
|
return toterr(tg, t.o, t.nops);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Builds a new tinn object given number of inputs (nips),
|
||||||
|
// number of hidden neurons for the hidden layer (nhid),
|
||||||
|
// and number of outputs (nops).
|
||||||
Tinn xtbuild(const int nips, const int nhid, const int nops)
|
Tinn xtbuild(const int nips, const int nhid, const int nops)
|
||||||
{
|
{
|
||||||
Tinn t;
|
Tinn t;
|
||||||
@ -152,6 +158,7 @@ Tinn xtbuild(const int nips, const int nhid, const int nops)
|
|||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Saves the tinn to disk.
|
||||||
void xtsave(const Tinn t, const char* const path)
|
void xtsave(const Tinn t, const char* const path)
|
||||||
{
|
{
|
||||||
FILE* const file = efopen(path, "w");
|
FILE* const file = efopen(path, "w");
|
||||||
@ -163,6 +170,7 @@ void xtsave(const Tinn t, const char* const path)
|
|||||||
fclose(file);
|
fclose(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Loads a new tinn from disk.
|
||||||
Tinn xtload(const char* const path)
|
Tinn xtload(const char* const path)
|
||||||
{
|
{
|
||||||
FILE* const file = efopen(path, "r");
|
FILE* const file = efopen(path, "r");
|
||||||
@ -180,6 +188,7 @@ Tinn xtload(const char* const path)
|
|||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Frees a tinn from the heap.
|
||||||
void xtfree(const Tinn t)
|
void xtfree(const Tinn t)
|
||||||
{
|
{
|
||||||
free(t.w);
|
free(t.w);
|
||||||
|
47
Tinn.h
47
Tinn.h
@ -2,38 +2,39 @@
|
|||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
float* w; // All the weights.
|
// All the weights.
|
||||||
float* x; // Hidden to output layer weights.
|
float* w;
|
||||||
float* b; // Biases.
|
// Hidden to output layer weights.
|
||||||
float* h; // Hidden layer.
|
float* x;
|
||||||
float* o; // Output layer.
|
// Biases.
|
||||||
|
float* b;
|
||||||
|
// Hidden layer.
|
||||||
|
float* h;
|
||||||
|
// Output layer.
|
||||||
|
float* o;
|
||||||
|
|
||||||
int nb; // Number of biases - always two - Tinn only supports a single hidden layer.
|
// Number of biases - always two - Tinn only supports a single hidden layer.
|
||||||
int nw; // Number of weights.
|
int nb;
|
||||||
|
// Number of weights.
|
||||||
|
int nw;
|
||||||
|
|
||||||
int nips; // Number of inputs.
|
// Number of inputs.
|
||||||
int nhid; // Number of hidden neurons.
|
int nips;
|
||||||
int nops; // Number of outputs.
|
// Number of hidden neurons.
|
||||||
|
int nhid;
|
||||||
|
// Number of outputs.
|
||||||
|
int nops;
|
||||||
}
|
}
|
||||||
Tinn;
|
Tinn;
|
||||||
|
|
||||||
// Trains a tinn with an input and target output with a learning rate.
|
|
||||||
// Returns error rate of the neural network.
|
|
||||||
float xttrain(Tinn, const float* in, const float* tg, float rate);
|
|
||||||
|
|
||||||
// Builds a new tinn object given number of inputs (nips),
|
|
||||||
// number of hidden neurons for the hidden layer (nhid),
|
|
||||||
// and number of outputs (nops).
|
|
||||||
Tinn xtbuild(int nips, int nhid, int nops);
|
|
||||||
|
|
||||||
// Returns an output prediction given an input.
|
|
||||||
float* xtpredict(Tinn, const float* in);
|
float* xtpredict(Tinn, const float* in);
|
||||||
|
|
||||||
// Saves the tinn to disk.
|
float xttrain(Tinn, const float* in, const float* tg, float rate);
|
||||||
|
|
||||||
|
Tinn xtbuild(int nips, int nhid, int nops);
|
||||||
|
|
||||||
void xtsave(Tinn, const char* path);
|
void xtsave(Tinn, const char* path);
|
||||||
|
|
||||||
// Loads a new tinn from disk.
|
|
||||||
Tinn xtload(const char* path);
|
Tinn xtload(const char* path);
|
||||||
|
|
||||||
// Frees a tinn from the heap.
|
|
||||||
void xtfree(Tinn);
|
void xtfree(Tinn);
|
||||||
|
Loading…
Reference in New Issue
Block a user