PageRenderTime 4ms CodeModel.GetById 2ms app.highlight 0ms RepoModel.GetById 1ms app.codeStats 1ms

/entrega2/ejercicio1/neurona_no_lineal.m~

http://github.com/melisabok/RedesNeuronales
Unknown | 49 lines | 26 code | 23 blank | 0 comment | 0 complexity | 29ad462c2b7d5537871f02f2f712fd7f MD5 | raw file
 1function[ite, W, b] = neurona_no_lineal(P, T, alfa, CotaError, MAX_ITE, funcion)
 2
 3
 4[CantAtrib, CantPatrones] = size(P);
 5
 6W = rand(1,CantAtrib) - 0.5 * ones(1,CantAtrib); 
 7b = rand - 0.5;
 8
 9
10errorAct = 1;
11ite = 0;
12
13while (ite < MAX_ITE) & (errorAct > CotaError)
14
15    ite = ite + 1;
16    errorAct = 0;
17    
18    for patr = 1 : CantPatrones
19    
20        neta = W*P(:,patr) + b;
21        f_neta = feval(funcion, neta);
22        f_prima_neta = feval([ 'd' funcion], neta, f_neta);
23        
24        errorK = T(patr) - f_neta;
25        gradiente = -2*errorK*f_prima_neta*P(:, patr);
26        
27        W = W - alfa * gradiente';  
28        b = b - alfa * (-2*errorK*f_prima_neta);
29        errorAct = errorAct + errorK^2;
30    
31    end
32    
33    %[ite ErrorAct]
34    if (mod(ite,100) == 0)
35        correctos_train = evaluar_clase_funcion(T, feval(funcion, W*P+b), funcion);
36        [alfa ite correctos_train (correctos_train / CantPatrones) * 100]
37    end
38    
39    
40end
41%fprintf('Salida, ite: %d  error: %.8f\n', ite, suma_error);
42
43
44
45
46
47
48
49