neurostat-develop
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Neurostat-develop] First working R-library


From: Joseph Rynkiewicz
Subject: [Neurostat-develop] First working R-library
Date: Wed, 09 Oct 2002 00:25:53 +0200
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.0) Gecko/20020529

Hi,

After a long time, I post first working R-library
cooked by me and dimitri.

The previous code posted on Savannah has been discarding,
it was not suitable to our aim, because the
standard way to interface C code with "R" is to use
the R-primitive : ".C" which allow only simple pointer arguments : int *, double *, Rcomplex * and char**.

So, we have rewritten our library using only int* and double* for the functions involving the MLP. (We have only used a double ** for the layer functions but they are never called directly by R).

We have created, a type t_mlp containing the architecture of the mlp (represented by a lot of offset vectors), the active units (neurons) and the jacobian vector. Remember that the jacobian contains partial derivatives of the "error" with respect to the output of the neurons. Hence we can use it to calcul the derivative with respect to the paramters (the weights), but also to calcul the derivative with respect to the inputs.

Since the resulting code is more complex we have simplified the API in the following way :

void        propagate(t_mlp *mlp, double *weights, double *input)

void        back_propagate(t_mlp *mlp, double *weights, double *error)
void weights_derivative(t_mlp *mlp, double *w_jacobian)

We have decided to simplify the API because it was totally useless for the R-library to keep outside objects naturally embedded in the MLP.

Moreover if we want externalise some object (like neurons or jacobians) it is easy to do later.

This C library in positively oriented to be a R-library, but it seems better to do a simple good R-library rather than a generic, not so good, library. If this code is used for an other purpose the adaptation would be not so difficult because the functions for the propagation, back_propagation derivative are very compact and because we have 2 mode of allocation of memory whether the variable RMEMALLOC is defined in the Makefile or not.

An other argument for embedded more things in the MLP, is the interaction with the Garbadge Collector of evoluted langages like "R" or "OCAML" and maybe JAVA which compel us to keep a local copy of the objects in the MLP. The main difficulty in our code is the API of the "constructor" of the MLP. Since we have to pass to this function a lot of precalculated offsets it is nearly impossible for a human being to use this API, the arguments have to be calculated by another function. In our library this calculus is done by the "R" function "buildArrays".


Finally the last but not the least R-library orientation is the organisation of the files which is totally determinated by the package structure of R. The installation of the library is then done with a classical "R CMD INSTALL neurostat" (don't forget to install ATLAS, f2c and spblastk0.9 before)

For the moment, only a simple batch learning is implemented, but conjugated gradient algorithm, BFGS, and stochastic algorithm would be easy to develop, since we can calculate the gradient in a vector form.

tests, fix, and improving of the code are particulary welcome.

Joseph







reply via email to

[Prev in Thread] Current Thread [Next in Thread]