Exercise "Artificial Neural Networks"

  1. (6 points)

    In this exercise we construct a simplest artificial neural network which will be trained to interpolate tabulated functions.

    It is an ordinary three-layer neural network with one neuron in the input layer, several neurons in the hidden layer, and one neuron in the output layer,

                               [hidden neuron]
                              /               \
                             /                 \
                            /                   \
    x  --->[identity neuron]---[hidden neuron]---[summation neuron]--->  y=F(x)
                            \                   /  
                             \                 /  
                              \               /  
                               [hidden neuron]
    

    The input neuron is an identity neuron: it simply sends the input, a real number x, to all hidden neurons.

    The output neuron is a summation neuron: it sums the outputs of the hidden neurons and sends the result to the output.

    The hidden neurons are ordinary neurons: the neuron number i transforms its input signal, x, into the its output signal, y, as

    y=f((x-ai)/bi)*wi,

    where f is the activation function (the same for all hidden neurons) and where ai, bi, wi are the parameters of the neuron number i.

    The activation function can be

    or any another suitable function.

    The whole network then functions as one big non-linear multi-parameter function y=Fp(x), where p={ai,bi,wi}i=1..n is the set of parameters of the network.

    Given the tabulated function, {xk,yk}k=1..N, the training of the network consists of tuning its parameters to minimize the deviation

    δ(p)=∑k=1..N(Fp(xk)-yk,

    which amounts to minimization of the deviation δ(p) in the space of the parameters of the network. This minimization can be done with your own quasi-newton minimization routine or a minimization routine from GSL.

    A C-structure to hold this network could be in the form

    typedef struct {int n; double (*f)(double); gsl_vector* data;} ann;

    where n is the number of neurons in the hidden layer, f is the pointer to the activation function, and gsl_vector* data keeps the parameters {ai, bi, wi}i=1..n.

    You should build the following functions,

    ann* ann_alloc(int number_of_hidden_neurons, double(*activation_function)(double));
    void ann_free(ann* network);
    double ann_feed_forward(ann* network, double x);
    void ann_train(ann* network, gsl_vector* xlist, gsl_vector* ylist);
    
  2. (3 points) Modify the previous exercise such that the network, after training, could also approximate the derivative and the anti-derivative of the tabulated function.

  3. (1 point) Implement an artificial neural network that can be trained to approximate a solution to the differential equation

    Φ[y(x)]≡Φ(y'',y',y,x)=0,

    (where Φ is generally a non-linear function of its arguments) on an interval [a,b] with the boundary condition at a given point 'c',

    y(c)=yc, y'(c)=y'c,

    where c∈[a,b] and yc and y'c are given numbers.

    The cost function to minimize might be

    δ(p)=∫ab|Φ[Fp,x]|dx +|Fp(c)-yc|(b-a) +|Fp'(c)-y'c|(b-a) .

    or

    δ(p)=∫ab|Φ[Fp,x]|²dx +|Fp(c)-yc|²(b-a) +|Fp'(c)-y'c|²(b-a) .

  4. (alternative 1 point exercise) Build a network to recognize the 3x5 font digits

      x  xxx  xxx  x x  xxx  xxx  xxx  xxx  xxx  xxx
     xx    x    x  x x  x    x      x  x x  x x  x x
      x  xxx  xxx  xxx  xxx  xxx    x  xxx  xxx  x x
      x  x      x    x    x  x x    x  x x    x  x x
      x  xxx  xxx    x  xxx  xxx    x  xxx  xxx  xxx
    
    displayed by a dot-matrix-display of a larger size, say, 5x7.

    There are then 5x7=35 input neurons, several hidden neurons, and 10 output neurons. Each input neuron gets the brightness of one of the pixels of the display. The output neurons output the probability that the display displays the corresponding digit.

    The training data might consist of a set of 3x5 digits positioned at different locations on a 5x7 matrix display, like

    .....  .....  .x...
    .....  ..xxx  xx...
    xxx..  ....x  .x...
    ..x..  ..xxx  .x...
    xxx..  ....x  .x...
    ..x..  ..xxx  .....
    xxx..  .....  .....
    

    The application data might then be a set of the 3x5 digits positioned randomly on a 5x7 display where one of the pixels of the display is randomly distorted.