Академический Документы
Профессиональный Документы
Культура Документы
FACULTAD DE INGENIERA
ESCUELA DE FORMACIN PROFESIONAL DE SISTEMAS Y COMPUTACIN
Figura 1: Robot
Tabla 7.1 Comportamiento del robot
S1 S2 S3 S4 M1 M2
1 1 1 1 -1 -1
-1 1 1 1 -1 1
1 1 -1 -1 1 -1
-1 -1 -1 -1 1 1
1 -1 1 1 1 -1
1 1 -1 1 -1 1
1 1 1 -1 1 -1
UNIVERSIDAD NACIONAL DANIEL ALCIDES CARRIN
FACULTAD DE INGENIERA
ESCUELA DE FORMACIN PROFESIONAL DE SISTEMAS Y COMPUTACIN
Figura 3.
UNIVERSIDAD NACIONAL DANIEL ALCIDES CARRIN
FACULTAD DE INGENIERA
ESCUELA DE FORMACIN PROFESIONAL DE SISTEMAS Y COMPUTACIN
Figura 4
Seleccione Data Entry (Figura 5) e ingrese los datos de la Tabla 1, para entrenar la red
neuronal (Figura 6). Se sugiere para el entrenamiento duplicar estos datos dos veces salvo el
ttulo de cada columna.
Figura 5
UNIVERSIDAD NACIONAL DANIEL ALCIDES CARRIN
FACULTAD DE INGENIERA
ESCUELA DE FORMACIN PROFESIONAL DE SISTEMAS Y COMPUTACIN
Figura 6
Luego de ingresar los datos cierre la ventana despus de haber grabado estos con File, Save
File.
Figura 7
Figura 8
UNIVERSIDAD NACIONAL DANIEL ALCIDES CARRIN
FACULTAD DE INGENIERA
ESCUELA DE FORMACIN PROFESIONAL DE SISTEMAS Y COMPUTACIN
Figura 9
Figura 10
UNIVERSIDAD NACIONAL DANIEL ALCIDES CARRIN
FACULTAD DE INGENIERA
ESCUELA DE FORMACIN PROFESIONAL DE SISTEMAS Y COMPUTACIN
Figura 11
Figura 12
UNIVERSIDAD NACIONAL DANIEL ALCIDES CARRIN
FACULTAD DE INGENIERA
ESCUELA DE FORMACIN PROFESIONAL DE SISTEMAS Y COMPUTACIN
Figura 13
El cdigo generado en Visual Basic se genera en un archivo que tiene la extensin .VB y es un
procedimiento en Visual Basic; que contiene el conocimiento en una red neuronal. Para nuestro
caso el archivo es ROBOT.VB y se encuentra en la carpeta APLICACIN ROBOT del CD que
acompaa al libro, cuyo contenido es:
Insert this code into your VB program tofire the D:\IA\ROBOT network
' This code is designed to be simple and fast for porting to any machine.
' Therefore all code and weights are inline without looping or data storage
' which might be harder to port between compilers.
Sub Fire_ROBOT (inarray(), outarray())
Dim netsum as double
Static feature2(3) as double
' inarray(1) is S1
' inarray(2) is S2
' inarray(3) is S3
' inarray(4) is S4
' outarray(1) is M1
' outarray(2) is M2
if (inarray(1)<-1) then inarray(1) = -1
if (inarray(1)> 1) then inarray(1) = 1
inarray(1) = (inarray(1) + 1) / 2
if (inarray(2)> 1) then inarray(2) = 1
inarray(2) = (inarray(2) + 1) / 2
UNIVERSIDAD NACIONAL DANIEL ALCIDES CARRIN
FACULTAD DE INGENIERA
ESCUELA DE FORMACIN PROFESIONAL DE SISTEMAS Y COMPUTACIN
Ahora debemos generar una aplicacin en Visual Basic 6.0, que nos permita utilizar el cdigo
que contiene a la red neuronal.
UNIVERSIDAD NACIONAL DANIEL ALCIDES CARRIN
FACULTAD DE INGENIERA
ESCUELA DE FORMACIN PROFESIONAL DE SISTEMAS Y COMPUTACIN
Iniciamos creando un formulario que permita manipular las entra- das y salidas que tiene la red
neuronal (figura 14).
Figura 14. Formulario en Visual Basic que manipula las entradas y salidas de la red neuronal.
Luego modificamos el cdigo por defecto que tiene el formulario. El cdigo modificado debe
quedar tal como se muestra en el listado siguiente:
Private Sub Command1_Click()
Dim e(4) As Double
Dim s(2) As Double
Asignacion de entradas
e(1) = Val(Text1.Text)
e(2) = Val(Text2.Text)
e(3) = Val(Text3.Text)
e(4) = Val(Text4.Text)
llamada a la red neuronal Call
Fire_ROBOT(e, s)
If (s(1) >= 0.9 And s(1) <= 1) Then
Text5.Text = " motor gira hacia adelante"
End If
If (s(1) >= -1 And s(1) <= -0.9) Then
Text5.Text = " motor gira hacia atrs"
End If
If (s(2) >= 0.9 And s(2) <= 1) Then
Text6.Text = " motor gira hacia adelante"
End If
If (s(2) >= -1 And s(2) <= -0.9) Then
Text6.Text = " motor gira hacia atrs"
End If
End Sub
' Insert this code into your VB program to fire the D:\
IA\ROBOT network
UNIVERSIDAD NACIONAL DANIEL ALCIDES CARRIN
FACULTAD DE INGENIERA
ESCUELA DE FORMACIN PROFESIONAL DE SISTEMAS Y COMPUTACIN
' This code is designed to be simple and fast for porting to any machine.
' Therefore all code and weights are inline without looping or data storage
' which might be harder to port between compilers.
Sub Fire_ROBOT(inarray() As Double, outarray() As Double)
Dim netsum As Double
Static feature2(3) As Double
'inarray(1) is S1
' inarray(2) is S2
' inarray(3) is S3
' inarray(4) is S4
'outarray(1) is M1
' outarray(2) is M2
If (inarray(1) < -1) Then inarray(1) = -1
If (inarray(1) > 1) Then inarray(1) = 1
inarray(1) = (inarray(1) + 1) / 2
If (inarray(2) < -1) Then inarray(2) = -1
If (inarray(2) > 1) Then inarray(2) = 1
inarray(2) = (inarray(2) + 1) / 2
If (inarray(3) < -1) Then inarray(3) = -1
If (inarray(3) > 1) Then inarray(3) = 1
inarray(3) = (inarray(3) + 1) / 2
If (inarray(4) < -1) Then inarray(4) = -1
If (inarray(4) > 1) Then inarray(4) = 1
inarray(4) = (inarray(4) + 1) / 2
netsum = -0.7532668
netsum = netsum + inarray(1) * 7.551737
netsum = netsum + inarray(2) * 0.2998328
netsum = netsum + inarray(3) * 7.341322
netsum = netsum + inarray(4) * -6.852577
feature2(1) = 1 / (1 + Exp(-netsum))
netsum = -2.495483
netsum = netsum + inarray(1) * -5.648689
netsum = netsum + inarray(2) * 1.05053
netsum = netsum + inarray(3) * -5.979871
netsum = netsum + inarray(4) * 6.870361
feature2(2) = 1 / (1 + Exp(-netsum))
netsum = -0.04198974
netsum = netsum + inarray(1) * 4.999131
netsum = netsum + inarray(2) * -3.897346
etsum = netsum + inarray(3) * 0.00002603323
netsum = netsum + inarray(4) * -3.897321
feature2(3) = 1 / (1 + Exp(-netsum))
netsum = 0.1287855
netsum = netsum + feature2(1) * -2.675452
netsum = netsum + feature2(2) * -2.65109
UNIVERSIDAD NACIONAL DANIEL ALCIDES CARRIN
FACULTAD DE INGENIERA
ESCUELA DE FORMACIN PROFESIONAL DE SISTEMAS Y COMPUTACIN
Ntese que tambin se ha agregado el cdigo generado por el Neu- roshell (contenido del archivo
ROBOT.VB)
Una vez modificado el cdigo ejecutamos el programa e ingresamos las entradas de la red neuronal
y al presionar el botn De- terminar la accin de los motores del robot con una red neuronal se
debe obtener la salida que ofrece la red neuronal. Para nuestro caso se ha realizado la ejecucin con
las entradas del ltimo patrn de entrenamiento de la Tabla 1, esta ejecucin se muestra en la figura
15.
Cabe mencionar que las salidas de la red neuronal son cercanas o iguales a 1 -1 y se debe
aproximar estas salidas a estos valores. Esta aproximacin se realiza a travs del siguiente cdigo:
UNIVERSIDAD NACIONAL DANIEL ALCIDES CARRIN
FACULTAD DE INGENIERA
ESCUELA DE FORMACIN PROFESIONAL DE SISTEMAS Y COMPUTACIN