UNIVERSITAD DE LAS AMERICAS - PUEBLA

PIERRE DERRIER # 203293

 

 

REDES NEURONALES

TAREA I

 

 

El objectivo de este tarea es de hacer la simulación de un red simple de perceptrónes feed-forward del tipo siguiente :

 

 

-> Con varios niveles escondidos

 

Por eso usamos MATLAB y hacemos dos simulaciones; una en cual calculamos la salida “manualmente”, es decir sin usar la libraría de redes neuronales incluida en MATLAB, y luego usamos la libraría.

 

 

%------------------------------------

% SIN LA LIBRARIA INCLUIDA EN MATLAB

%------------------------------------

 

%ask user to input datas

MInput = input('Enter input vector [x1 x2 x3 ... xn]:');

NbOut=input('Enter number of outputs:');

NbHidLayers=input('Enter number of hidden layers (except input and output) – Each hidden layer will contain 3 neurons:');

 

%generate table of number of neurons for each layers

NbLayers=NbHidLayers+2;

NbNeuronesInLayer=zeros(1,NbLayers);

NbNeuronesInLayer(1) = max(size(MInput));

NbNeuronesInLayer(NbLayers) = NbOut;

for I=2:(NbHidLayers+1),

    NbNeuronesInLayer(I)=3;

end

 

%verbose

NbNeuronesInLayer

MaxNbNeurones=max(max(NbNeuronesInLayer))

 

%create weights matrice

MPoids=rand(MaxNbNeurones,NbHidLayers+1);

 

%prepare output matrice

MOutput=zeros(MaxNbNeurones,NbLayers);

for I=1:max(size(MInput)),

    MOutput(I,1)=MInput(I);

end

 

 

%calcul of the output

for I = 2:NbLayers,

    for J = 1:NbNeuronesInLayer(I),

        EntreeTotale=0;

        for K=1:NbNeuronesInLayer(I-1),

            EntreeTotale=EntreeTotale+MOutput(K,I-1)*MPoids(K,I-1);

        end

        MOutput(J,I)=logsig(EntreeTotale);

    end

end

 

%verbose

MPoids

MOutput

           


 

%------------------------------------

% CON LA LIBRARIA INCLUIDA EN MATLAB

%------------------------------------

 

%creacion y simulación de un red con :

%4 neurones en entrada,

%2 niveles escondidos con 3 neurones cada uno

%2 salidas

 

net = newff([0 1; 0 1; 0 1; 0 1],[3 3 2],{'logsig','logsig','logsig'})

input = [1;0;1;1];

output=sim(net,input)

 

 

 

 

Los resultados obtenidos son :

 

>> test

Enter input vector [x1 x2 x3 ... xn]:[1 0 1 1]

Enter number of outputs:2

Enter number of hidden layers (except input and output):2

 

NbNeuronesInLayer =

 

     4     3     3     2

 

MaxNbNeurones =

 

     4

 

MPoids =

 

    0.9501    0.8913    0.8214

    0.2311    0.7621    0.4447

    0.6068    0.4565    0.6154

    0.4860    0.0185    0.7919

 

MOutput =

( entrada – niveles escondidos …- salida)

 

    1.0000    0.8852    0.8662    0.8361

         0        0.8852    0.8662    0.8361

    1.0000    0.8852    0.8662         0

    1.0000         0          0                0

 


 

 

(Luego, con la libraría incluida en MATLAB)

 

net =

 

    Neural Network object:

 

    architecture:

 

         numInputs: 1

         numLayers: 3

       biasConnect: [1; 1; 1]

      inputConnect: [1; 0; 0]

      layerConnect: [0 0 0; 1 0 0; 0 1 0]

     outputConnect: [0 0 1]

     targetConnect: [0 0 1]

 

        numOutputs: 1  (read-only)

        numTargets: 1  (read-only)

    numInputDelays: 0  (read-only)

    numLayerDelays: 0  (read-only)

 

    subobject structures:

 

            inputs: {1x1 cell} of inputs

            layers: {3x1 cell} of layers

           outputs: {1x3 cell} containing 1 output

           targets: {1x3 cell} containing 1 target

            biases: {3x1 cell} containing 3 biases

      inputWeights: {3x1 cell} containing 1 input weight

      layerWeights: {3x3 cell} containing 2 layer weights

 

    functions:

 

          adaptFcn: 'trains'

           initFcn: 'initlay'

        performFcn: 'mse'

          trainFcn: 'trainlm'

 

    parameters:

 

        adaptParam: .passes

         initParam: (none)

      performParam: (none)

        trainParam: .epochs, .goal, .max_fail, .mem_reduc,

                    .min_grad, .mu, .mu_dec, .mu_inc,

                    .mu_max, .show, .time

 

    weight and bias values:

 

                IW: {3x1 cell} containing 1 input weight matrix

                LW: {3x3 cell} containing 2 layer weight matrices

                 b: {3x1 cell} containing 3 bias vectors

 

    other:

 

          userdata: (user stuff)

 

 

output =

 

    0.5678

    0.0228