Commit f017117e authored by Vivien Kraus's avatar Vivien Kraus
Browse files

Document the API

parent c2e5c0e8
Pipeline #188030 passed with stages
in 11 minutes and 47 seconds
......@@ -113,10 +113,13 @@ julien_alloc (size_t dim_input, size_t dim_output, size_t n_hidden,
void
julien_free (struct julien *julien)
{
free (julien->parameters);
free (julien->dim_hidden);
free (julien->forward);
free (julien->backward);
if (julien != NULL)
{
free (julien->parameters);
free (julien->dim_hidden);
free (julien->forward);
free (julien->backward);
}
free (julien);
}
......
......@@ -506,4 +506,49 @@ that the function learnt is actually correct. Given that we only kept
./predict
#+END_SRC
* TODO Library API
* Library API
** =struct julien=
This opaque structure holds everything required to predict and learn a
perceptron. It is allocated by =julien_alloc=, and discarded with
=julien_free=. The perceptron data are initialized with a very weak
pseudo-random number generator; maybe you will want to initialize it
yourself with =julien_set_data=.
** =struct julien *= /=julien_alloc=/ (=size_t= /dim\_input/, =size_t= /dim\_output/, =size_t= /n\_hidden/, =const size_t *restrict= /dim\_hidden/)
Allocate and initialize a new perceptron with /dim\_input/ inputs,
/dim\_output/ outputs, and /n\_hidden/ layers (with respective
dimensions /dim\_hidden/). The returned object must be freed with
=julien_free=.
** =void= /=julien_free=/ (=struct julien *= /julien/)
Free the resources used by /julien/, as allocated by =julien_alloc=.
** =const double *= /=julien_data=/ (=const struct julien *= /julien/, =size_t *= /n\_parameters/)
Return a pointer to the internal data of /julien/, and set
/n\_parameters/ (if it is not =NULL=) to the size of the return value.
** =void= /=julien_set_data=/ (=struct julien *= /julien/, =size_t= /start/, =size_t= /n/, =const double *restrict= /parameters/)
Skip the /start/ first parameters in /julien/, then initialize the
following /n/ /parameters/.
** =double= /=julien_learn=/ (=struct julien *= /julien/, =size_t= /dim\_input/, =const double *restrict= /input/, =size_t= /dim\_output/, =const double *restrict= /output/, =double= /learning\_rate/)
Teach /julien/ to learn the /output/ array (of dimension
/dim\_output/) when seing the /input/ array (of dimension
/dim\_input/). Learning is more efficient as /learning\_rate/ grows,
but if it is too high then there is a risk /julien/ would forget too
fast to learn anything.
Both /dim\_input/ and /dim\_output/ need not be of the expected
dimension (as given at allocation time to =julien_alloc=). If the
dimensions are too high, then only the first elements are considered.
If the arrays are too small, then the remaining elements will be set
to 0.
Return the mean update to the internal weights. If this value is
close to 0, then /julien/ does not learn anymore and you can stop it.
** =size_t= /=julien_predict=/ (=struct julien *= /julien/, =size_t= /dim\_input/, =const double *restrict= /input/, =size_t= /max\_output/, =size_t= /start\_output/, =double *restrict= /output/)
Use /julien/ to predict the /output/ given /input/. More
specifically, discard the first /start\_output/ elements, then store
up to the following /max\_output/ elements into /output/, and return
the total number of elements.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment