:
Intelligens Rendszerek Gyakorlata Neurális hálózatok I.
dr. Kutor László http://mobil.nik.bmf.hu/tantargyak/ir2.html
2009. tavasz
BMF NIK,
dr. Kutor László
IRG 3/1
Trend osztályozás Pnndemo.exe
2009. tavasz
BMF NIK,
dr. Kutor László
IRG 3/2
Hangulat azonosítás Happy.exe
2009. tavasz
BMF NIK,
dr. Kutor László
IRG 3/3
Idősor közelítés Grnndemo.exe
2009. tavasz
BMF NIK,
dr. Kutor László
IRG 3/4
Pontsor közelítése függvénnyel Grnndemo.exe
2009. tavasz
BMF NIK,
dr. Kutor László
IRG 3/5
A neurális hálózat tervezésének lépései Reprezentatív tapasztalati adat gyűjtése (bemeneti adatok és elvárt válaszok)
Megfelelő neurális paradigma kiválasztása Rendszer paraméterek kiválasztása Teljesítmény mérő módszer kiválasztása A rendszer tanítása és tesztelése (amíg az elvárt eredményhez nem jutunk) 2009. tavasz
BMF NIK,
dr. Kutor László
IRG 3/6
Eldöntendő jellemzők a neurális hálózatok tervezésénél Processzor szinten: - a processzor átviteli függvénye - a bemenő jelek típusa Hálózat szinten: - a hálózat topológiája - rétegelt struktúránál a rétegek száma - processzorok száma a különböző rétegekben - processzorok típusa a különböző rétegekben Tanítási szinten - tanító algoritmus - tanítási paraméterek (pl.: α, β,….) - a tanítás megállásának feltételei 2009. tavasz
BMF NIK,
dr. Kutor László
IRG 3/7
Az alap „neuron”(processzor) felépítése n
I1 I2
wj1
i O Ii i
In-1 In
j
wj2 wji
S j = ∑ w ji I i
Sj T wjn
i =1
Oj
i
Wji
j
IB I – bemenet), wji súlytényezők, T – Átviteli (Transzfer) függvény IRG 3/8 2009. tavasz BMF NIK, dr. Kutor László
Leggyakrabban használt átviteli függvények 1. Ugrás függvény: Oj = 0 vagy -1, ha S <= 0, Oj = 1 ha S > 0 1
1
S
S
2. Korlátozott lineáris függvény -1 Oj = 0, ha S <= 0, 1 Oj = S ha 0 <= S < 1 Oj = 1 ha S > 1 0 1 3. Szimoid függvény Oj = 1 - 1/(1+S) ha S >= 0 Oj = 1/(1+e-Sj) Oj = -1 + 1/(1-S) ha S < 0 1 1 S -1 2009. tavasz
BMF NIK,
dr. Kutor László
S
IRG 3/9
Tipikus neurális hálózat összeköttetések 1. Előrecsatolt (rétegelt) neurális hálózat
(topológia)
Kimenetek
Bemenetek bemeneti réteg „rejtett” réteg
kimeneti réteg
„súlytényező” 2009. tavasz
BMF NIK,
dr. Kutor László
IRG 3/10
Az előrecsatolt hálóztok ábrázolása I1
I2
Ii
Súlymátrix
In-1 In
O1 O2 Oj Om
O = f (S) S=I*W Mátrix műveletek !
súlytényező 2009. tavasz
w11 w12 w1i -- w1n w21 w22 w2i -- w2n wj1 wj2 wji -- wjn wm1wm2wmi -- wmn
BMF NIK,
dr. Kutor László
IRG 3/11
Visszacsatolt neurális hálózat Rétegelt
I1 I2
Teljesen összekötött
I3
1
i j
2
k
3 2009. tavasz
BMF NIK,
Oi Oj
O = I x W1+ O x W2
Ok dr. Kutor László
IRG 3/12
A hálózat hibája felügyelt tanítás esetén Egy tanító mintánál:
E = ½ ∑(Tk-Ok)2
A teljes tanító mintára:
E = ½ ∑∑ (Tk-Ok)2
k
pk
A tanítás (súlytényező változtatás) mottója: „hiba visszaterjesztés = Back error Propagation” „ A hálózat súlytényezőit a hiba létrehozásában játszott szerepükkel arányosan változtatjuk.” = A súlytényezőket a hibafüggvény parciális deriváltja szerint változtatjuk 2009. tavasz
BMF NIK,
dr. Kutor László
IRE 8/13
Tanítási szabályok Tanítás = súlytényezők (kis lépésekkel (?) való) beállítása Tanítási típusok: 1. Felügyelt (felügyeletes) tanítás 2. Felügyelet nélküli (önszerveződő) tanítás Alap tanítási szabályok: i O i
wji j Oj
i O i
wji j Oj Cj
2009. tavasz
Hebb szabály (Donald O. Hebb) wji(t+1) = wji (t) + α* Oi * Oj ahol α = tanítási tényező, 0 <= α <= 1
Delta szabály (Widrow- Hoff) wji(t+1) = wji (t) + α * Oi * (Cj – Oj) ahol Cj – Oj= Δj BMF NIK,
dr. Kutor László
IRG 3/14
Mottó:
A felügyeletes tanítás lényege, algoritmusa
Addig hangoljuk a súlytényezőket, amíg a bemenetre a hálózat megfelelő-, előre kiszámított választ nem ad. Algoritmusa: 1. Kezdeti súlytényezők beállítása 2. A tanítóminta bemeneti értéke alapján a hálózat kimeneti értékének kiszámítása. 3. A tanítóminta célértékének összehasonlítása a hálózat célértékével. 4. Szükség esetén a hálózat súlytényezőinek módosítása. 5. A tanítás folytatása mindaddig, amíg a hálózat az összes tanítómintára – egy előre rögzített hibahatárnál kisebb hibával a célértéknek megfelelő kimeneti értéket nem tudja előállítani. 2009. tavasz
BMF NIK,
dr. Kutor László
IRE 8/15
A perceptron tanító algoritmus (delta szabállyal) Kezdeti súlytényezők beállítása (random !?) Tanítás iter amíg a hiba el nem éri a hibahatárt (Hi <= Hh) k= 0, Hi= 0 Minták iter amíg k = p nem teljesül (ahol p = tanító minták száma) A k.-ik tanítóminta bemeneti vektora alapján processzoronként az aktiváció kiszámítása Sjk= ∑Ijk * Wji A köszöb átviteli függvény alapján processzoronként a kimeneti értékek kiszámítása. (Oj) A hálózat súlytényezőinek módosítása. wji(t+1) = wji (t) + α * Oi * (Cj – Oj) ahol Cj – Oj= az eltérés (Δj) A hálózat hibájának kiszámítása Hjk=Cjk-Ojk A hibák összesítése Hi=Hi+Hj K:=K+1 Minták end Tanítás end IRE 8/16 2009. tavasz BMF NIK, dr. Kutor László
A delta szabály matematikai értelmezése I1 I2 Ii In
S
Sj= ∑wji * Ii ; Oj = Sj ; E = ½ * ∑ ( Tj – Oj)2 j i Lineáris átviteli függvény esetén Oj Tj E
j
Wji(t+1)=wji(t)- α*Oj*δE/δwji
δE/δwji= δE/δOj * δOj/δSj * δSj/δwj wi δE/δOj = ½ * 2 * (Tj-Oj) * -1= - (Tj-Oj) δOj/δSj=1 i O i
2009. tavasz
Wi+1
Δw
δSj/δwj= δ(wj1*I1+…wji*Ii…+ wjn*In)= Ii
wji j Oj Tj
Delta szabály
wji(t+1) = wji (t) + α * Ii * Δj ahol α = tanítási tényező, 0 <= α <= 1, Δj = Tj – Oj IRE 8/17 BMF NIK, dr. Kutor László
Többrétegű neurális hálózatok tanítása (Általánosított delta szabállyal) Hálózat topológia
Oi wji Oj
i
k
j H
N
i
j
wkj Ok
Tk
k
M
Processzor:
Oi
Sj
f(s)
Oj
N
S j = ∑ w ji Oi i =1
j 2009. tavasz
BMF NIK,
dr. Kutor László
Oj=f(S)= 1/(1+e-S) IRE 8/18
A hiba „visszavezetése” (Általánosított delta szabállyal) Hálózat topológia
Oi wji Oj
i
k
j N
Δj
H
i
w1j w2j wkj Ok
j
Δ2 Tk
k
M
ΔM-1 wMj
Átviteli függvények
Ok= f(Sk) 2009. tavasz
Δ1
BMF NIK,
ΔM
Oj=f(S)= 1/(1+e-S) dr. Kutor László
IRE 8/19
Tanítást leíró összefüggések a többrétegű hálózatoknál Általánosított delta szabály: (deriválás a lánc szabály alapján) δE/δwkj = δE/δOk * δOk/δSk * δSk/δwkj Súlytényező változtatás a kimeneti rétegben Wkj(t+1) = Wkj(t) + αΔkOj = Δk Wkj(t+1) =Wkj(t) + α*(Tk-Ok)*f(Sk)*(1-f(Sk))*Oj Súlytényező változtatás a „rejtett” rétegben Δj M
Wji(t+1) = Wji(t) + α*f(Sj)*(1-f(Sj ) *∑(Δk*Wkj))*Oi (A levezetés a javasolt olvasmányok között található) 2009. tavasz
BMF NIK,
dr. Kutor László
k=1
IRE 8/20
Versengéses (competitive) tanulás Carpenter, Grossberg 1988 I1 Processzor I i IN
Sj f
Oj = f (Sj)
Sj= ∑ Ii * wji
1
f (Sj)
Sj
Topológia: egy rétegű előrecsatolt, teljesen összekötött Megkötések: 1.) ∑ wji= 1 2.) Súly értékek: 0<Wj<1 3.) A bemenő vektor bináris 2009. tavasz
BMF NIK,
dr. Kutor László
IRE 8/21
A versengéses tanító algoritmus Mottó:
(Grossberg) A győztes visz mindent
1. Kezdeti súlytényezők beállítása (inicializálás, véletlenszerű) 0<Wj<1 2. A tanítóminta i-ik értéke (vektora) alapján, a processzorok kimeneti értékeinek kiszámítása. S = ∑ O * w Oj = f (Sj) j i ji, 3. A legnagyobb kimeneti értékű processzor kiválasztása. A győztes visz mindent elv alapján, a győztes kimeneti értéket 1-re, az összes többi kimeneti értéket 0-ra változtatjuk 3. A győztes elem súlytényezőit megváltoztatjuk (csak azokat!)
Δ Wji (t+1) = Wji (t) + Δ wji, Δwji = α (Oi/m-wji(t)) ahol α = tanulási együttható, 0 < α << 1 (tipikusan 0.01-0.3) m = az aktív bemenetek száma 5. A 2. 3. 4. pont ismétlése amíg a kimenetek két egymást követő tanítási ciklus során nem változnak. IRE 8/22 2009. tavasz BMF NIK, dr. Kutor László
Teljesítmény mérési lehetőségek 1. Az összes tanító mintát figyelembe véve, mekkora az eltérés RMS (Root-Mean-Square)
Egy tanító mintánál:
E = ½ ∑(Tk-Ok)2
A teljes tanító mintára:
E = ½ ∑∑ (Tk-Ok)2 Mk
RMS= √E/(M*K)
M= tanító minták száma K= kimenetek száma
2. A helyes és hibás eredmények aránya 2009. tavasz
BMF NIK,
dr. Kutor László
IRE 8/23
Logikai függvények tanítása logikai ÉS I1 * I2 O 0 0 1 1
0 1 0 1
0 0 0 1
Kizáró VAGY I1 1
I1 + I2 O 1
0 0 1 1
I2
logikai VAGY I1 +I2 O 0 0 1 1 2009. tavasz
0 1 0 1
0 1 1 1
0 1 0 1
0 1 1 0
I1
I1
1
1
1
I2
BMF NIK,
1 dr. Kutor László
I2 IRE 8/24
A négy kvadráns 1 „1”
1
„0”
0.5
0.5 „0”
0
2009. tavasz
0
„1” 0.5
0
0 0.5 1
1 BMF NIK,
dr. Kutor László
IRE 8/25
Neurális hálózat szimulátorok NWDemo http://mobil.nik.bmf.hu/tantargyak/ir2.html C++ Neural Network Simulation Software http://www.bedaux.net/nnet/ Stuttgart Neural Network Simulator http://www.ra.cs.uni-tuebingen.de/SNNS/ Emergent Neural Network Simulation System http://grey.colorado.edu/emergent/index.php/Main_Page
2009. tavasz
BMF NIK,
dr. Kutor László
IRE 8/26
Neurális hálózat szimulátorok
2009. tavasz
BMF NIK,
dr. Kutor László
IRE 8/27
Az első mesterséges neurális hálózat: a Perceptron Frank Rosenblatt (1957) (amit a következő órán meg kell valósítani) Vetített nyomtatott betűk felismerése tanítás alapján • 20 x 20 fotóérzékelő • Mc. Culloch-Pitts neuronok • Előrecsatolt egyrétegű hálózat I1 O1
I400 2009. tavasz
O36 BMF NIK,
dr. Kutor László
IRE 8/28