←to practical programming

Homework "Artificial Neural Networks"

  1. (6 points)

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

    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 ]
                              /                 \w1
                             /                   \
                            /                  w2 \
    x  --->[identity neuron]---[hidden neuron]----[summation neuron]--->  y=Fp(x)
                            \                     /
                             \                   /
                              \                 /w3
                               [ hidden neuron ]
    

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

    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, yi, as

    yi=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 network response Fp(x) is then given as

    Fp(x)=∑i f((x-ai)/bi)*wi
    

    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 cost function

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

    which amounts to minimization of the cost function C(p) in the space of the parameters of the network. This minimization should be done with your own minimization routine.

    Your ann.h header file could be like this,

    #include"gsl/gsl_vector.h"
    #ifndef HAVE_ANN_H
    #define HAVE_ANN_H
    typedef struct { int n; double(*f)(double); gsl_vector* params; } ann;
    ann*   ann_alloc   (int n,double(*f)(double));
    void   ann_free    (ann* network);
    double ann_response(ann* network,double x);
    void   ann_train   (ann* network,gsl_vector* xs,gsl_vector* ys);
    #endif
    
  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) .

←to practical programming