。Data Importation
。Data Introduction
。Model Fitting
。Results
。Data Importation
。Data Introduction
。Model Fitting
。Results
。Data Importation
。Data Introduction
。Model Fitting
。Results
自適應共振理論網路(ART)是一種非監督式學習網路,源自於認知學當中的記憶系統,一個好的記憶系統必須具有兩個要求:
穩定性(stability):當新的事物輸入時,舊的事物應適當地保留
可塑性(plasticity):當新的事物輸入時,應迅速地學習
由於穩定性和可塑性有時會有衝突,因此自適應共振理論網路採用「警戒值測試」(VigilanceTest)來解決此一矛盾。
警戒值測試利用一個警戒參數ρ(Vigilance Parameter; 0 < ρ < 1)來做測試,基本原理如下:
如果新的事物之特性與「某一個」舊的事物之特性夠相似(即通過警戒值測試),則只修改系統中該舊事物的部份記憶,使其能同時滿足新舊事物之特性,使得舊的事物可適當地保留,可滿足穩定性的要求。
如果新的事物之特性與舊的事物之特性均不太相似(即未通過警戒值測試),則此系統為此新事物建立全新的記憶,以迅速地學習此新事物,便可滿足可塑性的要求。
Basic ART structure
一開始輸出層在學習過程初期只有一個,隨著學習的進展會逐漸增加,最後會穩定在一定的數目,學習過程即結束。這和其它神經網路模式輸出層處理單元的數目為固定值很不相同。
每個輸入層處理單元與輸出層處理單元間有兩個連結:由下而上加權值Wb與由上而下加權值Wt,這一點也和其它模式很不相同。
由下而上加權值 \(W^b\):
為介於0到1之間,用來計算匹配值。匹配值高的輸出層單元,將優先被用來做警戒值測試。
匹配值計算公式:\[net j = Σi W^b_{ij} × X_i\]
由上而下加權值 \(W^t\):
為0與1之二元值,用來計算相似值。相似值用來與警戒參數ρ做比較,以判斷是否通過警戒值測試。
相似值計算公式:\[Vj = (Σi W^t_{ij}× X_i) /Σ i X_i\]
在此筆記內對於ART的基本方法(ART1, ART2, ARTMAP),我們皆使用Package“RSNNS”來實作
ART1僅用於二進制(binary)輸入,如果您有實值(real-valued)輸入,請使用ART2。
library(RSNNS) # 讀取所需的package
## Loading required package: Rcpp
data(snnsData)
class(snnsData) # 觀察資料型態
## [1] "list"
簡單觀察資料形態過後,我們將要分群的圖片資料畫出來:
patterns <- snnsData$art1_letters.pat # 選擇list中我們想辨別的資料集
head(patterns) # 可觀察到此資料皆為binary,符合ART1的需求
## in1 in2 in3 in4 in5 in6 in7 in8 in9 in10 in11 in12 in13 in14 in15
## pattern1 0 1 1 1 0 1 0 0 0 1 1 0 0 0 1
## pattern2 1 1 1 1 0 1 0 0 0 1 1 0 0 0 1
## pattern3 0 1 1 1 0 1 0 0 0 1 1 0 0 0 0
## pattern4 1 1 1 1 0 1 0 0 0 1 1 0 0 0 1
## pattern5 1 1 1 1 1 1 0 0 0 0 1 0 0 0 0
## pattern6 1 1 1 1 1 1 0 0 0 0 1 0 0 0 0
## in16 in17 in18 in19 in20 in21 in22 in23 in24 in25 in26 in27 in28
## pattern1 1 1 1 1 1 1 0 0 0 1 1 0 0
## pattern2 1 1 1 1 0 1 0 0 0 1 1 0 0
## pattern3 1 0 0 0 0 1 0 0 0 0 1 0 0
## pattern4 1 0 0 0 1 1 0 0 0 1 1 0 0
## pattern5 1 1 1 1 0 1 0 0 0 0 1 0 0
## pattern6 1 1 1 1 0 1 0 0 0 0 1 0 0
## in29 in30 in31 in32 in33 in34 in35
## pattern1 0 1 1 0 0 0 1
## pattern2 0 1 1 1 1 1 0
## pattern3 0 1 0 1 1 1 0
## pattern4 0 1 1 1 1 1 0
## pattern5 0 0 1 1 1 1 1
## pattern6 0 0 1 0 0 0 0
inputMaps <- matrixToActMapList(patterns, nrow=7) # 將原先的每筆資料轉為7*5的矩陣
# 總共有26張圖(26個字母)
# 取前9張圖代表,創1個3*3的圖片矩陣空間
par(mfrow=c(3,3))
for (i in 1:9) {
plotActMap(inputMaps[[i]])
}
model <- art1(patterns, dimX=7, dimY=5, f2Units = 5) # f2Units 可決定總共要分幾群
model # 觀察所使用之參數
## Class: art1->rsnns
## Number of inputs: 35
## Number of outputs: 5
## Maximal iterations: 100
## Initialization function: ART1_Weights
## Initialization function parameters: 1 1
## Learning function: ART1
## Learning function parameters: 0.9 0 0
## Update function:ART1_Stable
## Update function parameters: 0
## Patterns are shuffled internally: TRUE
## Compute error in every iteration: FALSE
## Architecture Parameters:
## $f2Units
## [1] 5
##
## $dimX
## [1] 7
##
## $dimY
## [1] 5
##
## All members of model:
## [1] "nInputs" "maxit"
## [3] "initFunc" "initFuncParams"
## [5] "learnFunc" "learnFuncParams"
## [7] "updateFunc" "updateFuncParams"
## [9] "shufflePatterns" "computeIterativeError"
## [11] "snnsObject" "archParams"
## [13] "fitted.values" "nOutputs"
labels <- encodeClassLabels(model$fitted.values) # 分群後各觀測值所屬的群數
labels
## [1] 1 1 2 5 4 4 5 1 2 3 4 2 5 1 5 1 5 1 2 4 5 5 5 4 4 3
ART2與ART1非常相似,但適用於實值輸入。
與ART1相反,ART2在實作上不假設二維輸入。
data(snnsData)
patterns_2 <- snnsData$art2_tetra_med.pat
簡單觀察資料形態過後,我們將要分群的圖片資料畫出來:
patterns <- snnsData$art1_letters.pat # 選擇list中我們想辨別的資料集
head(patterns_2) # 可觀察到此資料皆為real_valued,選擇ART2模型較為合適
## in1 in2 in3
## pattern1 0.863768 0.938372 0.968274
## pattern2 1.018000 2.943250 1.096770
## pattern3 0.992644 1.877340 2.660770
## pattern4 0.125113 2.143530 1.526980
## pattern5 0.984390 0.860563 0.930223
## pattern6 1.093690 2.930590 1.216960
inputMaps_2 <- matrixToActMapList(patterns_2, nrow=3)
# 總共有40張圖
# 取前9張圖代表,創1個3*3的圖片矩陣空間
par(mfrow=c(3,3))
for (i in 1:9) {
plotActMap(inputMaps_2[[i]])
}
model_2 <- art2(patterns_2, f2Units=5, learnFuncParams=c(0.99, 20, 20, 0.1, 0),
updateFuncParams=c(0.99, 20, 20, 0.1, 0))
model_2 # 觀察所使用之參數
## Class: art2->rsnns
## Number of inputs: 3
## Number of outputs: 5
## Maximal iterations: 100
## Initialization function: ART2_Weights
## Initialization function parameters: 0.9 2
## Learning function: ART2
## Learning function parameters: 0.99 20 20 0.1 0
## Update function:ART2_Stable
## Update function parameters: 0.99 20 20 0.1 0
## Patterns are shuffled internally: TRUE
## Compute error in every iteration: FALSE
## Architecture Parameters:
## $f2Units
## [1] 5
##
## All members of model:
## [1] "nInputs" "maxit"
## [3] "initFunc" "initFuncParams"
## [5] "learnFunc" "learnFuncParams"
## [7] "updateFunc" "updateFuncParams"
## [9] "shufflePatterns" "computeIterativeError"
## [11] "snnsObject" "archParams"
## [13] "fitted.values" "nOutputs"
testPatterns <- snnsData$art2_tetra_high.pat
predictions <- predict(model_2, testPatterns) # 使用訓練好的ART2模型預測資料集內的測試集
predictions
## [,1] [,2] [,3] [,4] [,5]
## pattern1 0.0 0.0 0.0 0.9 0
## pattern2 0.0 0.9 0.0 0.0 0
## pattern3 0.9 0.0 0.0 0.0 0
## pattern4 0.0 0.0 0.9 0.0 0
## pattern5 0.9 0.0 0.0 0.0 0
## pattern6 0.0 0.9 0.0 0.0 0
## pattern7 0.9 0.0 0.0 0.0 0
## pattern8 0.0 0.0 0.9 0.0 0
## pattern9 0.9 0.0 0.0 0.0 0
## pattern10 0.0 0.9 0.0 0.0 0
## pattern11 0.9 0.0 0.0 0.0 0
## pattern12 0.0 0.0 0.9 0.0 0
## pattern13 0.9 0.0 0.0 0.0 0
## pattern14 0.0 0.9 0.0 0.0 0
## pattern15 0.9 0.0 0.0 0.0 0
## pattern16 0.0 0.0 0.9 0.0 0
## pattern17 0.9 0.0 0.0 0.0 0
## pattern18 0.0 0.9 0.0 0.0 0
## pattern19 0.9 0.0 0.0 0.0 0
## pattern20 0.0 0.0 0.9 0.0 0
## pattern21 0.9 0.0 0.0 0.0 0
## pattern22 0.0 0.9 0.0 0.0 0
## pattern23 0.9 0.0 0.0 0.0 0
## pattern24 0.0 0.0 0.9 0.0 0
## pattern25 0.0 0.0 0.9 0.0 0
## pattern26 0.0 0.9 0.0 0.0 0
## pattern27 0.9 0.0 0.0 0.0 0
## pattern28 0.0 0.9 0.0 0.0 0
## pattern29 0.9 0.0 0.0 0.0 0
## pattern30 0.0 0.9 0.0 0.0 0
## pattern31 0.9 0.0 0.0 0.0 0
## pattern32 0.0 0.9 0.0 0.0 0
## pattern33 0.9 0.0 0.0 0.0 0
## pattern34 0.0 0.9 0.0 0.0 0
## pattern35 0.9 0.0 0.0 0.0 0
## pattern36 0.0 0.9 0.0 0.0 0
## pattern37 0.9 0.0 0.0 0.0 0
## pattern38 0.0 0.9 0.0 0.0 0
## pattern39 0.9 0.0 0.0 0.0 0
## pattern40 0.0 0.9 0.0 0.0 0
ARTMAP為一種監督式學習,ART旨在解決穩定性/可塑性困境。
因此,ARTMAP的優勢在於它是一種有監督的學習機制,可以保證穩定性。
data(snnsData)
trainData <- snnsData$artmap_train.pat
testData <- snnsData$artmap_test.pat
# 將trainData轉為矩陣並將其視覺化
inputMaps <- matrixToActMapList(trainData, nrow=15) # 將原先的每筆資料轉為15*5的矩陣
par(mfrow=c(3,3))
for (i in 1:9) plotActMap(inputMaps[[i]])
model <- artmap(trainData, nInputsTrain=70, nInputsTargets=5,
nUnitsRecLayerTrain=50, nUnitsRecLayerTargets=26) # nUnitsRecLayerTargets 可決定總共要分幾群
model # 觀察所使用之參數
## Class: artmap->rsnns
## Number of inputs: 75
## Number of outputs: 26
## Maximal iterations: 1
## Initialization function: ARTMAP_Weights
## Initialization function parameters: 1 1 1 1 0
## Learning function: ARTMAP
## Learning function parameters: 0.8 1 1 0 0
## Update function:ARTMAP_Stable
## Update function parameters: 0.8 1 1 0 0
## Patterns are shuffled internally: TRUE
## Compute error in every iteration: FALSE
## Architecture Parameters:
## $nInputsTrain
## [1] 70
##
## $nInputsTargets
## [1] 5
##
## $nUnitsRecLayerTrain
## [1] 50
##
## $nUnitsRecLayerTargets
## [1] 26
##
## $nRowInputsTrain
## [1] 1
##
## $nRowInputsTargets
## [1] 1
##
## $nRowUnitsRecLayerTrain
## [1] 1
##
## $nRowUnitsRecLayerTargets
## [1] 1
##
## All members of model:
## [1] "nInputs" "maxit"
## [3] "initFunc" "initFuncParams"
## [5] "learnFunc" "learnFuncParams"
## [7] "updateFunc" "updateFuncParams"
## [9] "shufflePatterns" "computeIterativeError"
## [11] "snnsObject" "archParams"
## [13] "fitted.values" "nOutputs"
由下列的結果可看出分為26群的話,各個字母能完美分群。
predict(model, testData)
## [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12]
## pattern1 1 0 0 0 0 0 0 0 0 0 0 0
## pattern2 0 1 0 0 0 0 0 0 0 0 0 0
## pattern3 0 0 1 0 0 0 0 0 0 0 0 0
## pattern4 0 0 0 1 0 0 0 0 0 0 0 0
## pattern5 0 0 0 0 1 0 0 0 0 0 0 0
## pattern6 0 0 0 0 0 1 0 0 0 0 0 0
## pattern7 0 0 0 0 0 0 1 0 0 0 0 0
## pattern8 0 0 0 0 0 0 0 1 0 0 0 0
## pattern9 0 0 0 0 0 0 0 0 1 0 0 0
## pattern10 0 0 0 0 0 0 0 0 0 1 0 0
## pattern11 0 0 0 0 0 0 0 0 0 0 1 0
## pattern12 0 0 0 0 0 0 0 0 0 0 0 1
## pattern13 0 0 0 0 0 0 0 0 0 0 0 0
## pattern14 0 0 0 0 0 0 0 0 0 0 0 0
## pattern15 0 0 0 0 0 0 0 0 0 0 0 0
## pattern16 0 0 0 0 0 0 0 0 0 0 0 0
## pattern17 0 0 0 0 0 0 0 0 0 0 0 0
## pattern18 0 0 0 0 0 0 0 0 0 0 0 0
## pattern19 0 0 0 0 0 0 0 0 0 0 0 0
## pattern20 0 0 0 0 0 0 0 0 0 0 0 0
## pattern21 0 0 0 0 0 0 0 0 0 0 0 0
## pattern22 0 0 0 0 0 0 0 0 0 0 0 0
## pattern23 0 0 0 0 0 0 0 0 0 0 0 0
## pattern24 0 0 0 0 0 0 0 0 0 0 0 0
## pattern25 0 0 0 0 0 0 0 0 0 0 0 0
## pattern26 0 0 0 0 0 0 0 0 0 0 0 0
## [,13] [,14] [,15] [,16] [,17] [,18] [,19] [,20] [,21] [,22]
## pattern1 0 0 0 0 0 0 0 0 0 0
## pattern2 0 0 0 0 0 0 0 0 0 0
## pattern3 0 0 0 0 0 0 0 0 0 0
## pattern4 0 0 0 0 0 0 0 0 0 0
## pattern5 0 0 0 0 0 0 0 0 0 0
## pattern6 0 0 0 0 0 0 0 0 0 0
## pattern7 0 0 0 0 0 0 0 0 0 0
## pattern8 0 0 0 0 0 0 0 0 0 0
## pattern9 0 0 0 0 0 0 0 0 0 0
## pattern10 0 0 0 0 0 0 0 0 0 0
## pattern11 0 0 0 0 0 0 0 0 0 0
## pattern12 0 0 0 0 0 0 0 0 0 0
## pattern13 1 0 0 0 0 0 0 0 0 0
## pattern14 0 1 0 0 0 0 0 0 0 0
## pattern15 0 0 1 0 0 0 0 0 0 0
## pattern16 0 0 0 1 0 0 0 0 0 0
## pattern17 0 0 0 0 1 0 0 0 0 0
## pattern18 0 0 0 0 0 1 0 0 0 0
## pattern19 0 0 0 0 0 0 1 0 0 0
## pattern20 0 0 0 0 0 0 0 1 0 0
## pattern21 0 0 0 0 0 0 0 0 1 0
## pattern22 0 0 0 0 0 0 0 0 0 1
## pattern23 0 0 0 0 0 0 0 0 0 0
## pattern24 0 0 0 0 0 0 0 0 0 0
## pattern25 0 0 0 0 0 0 0 0 0 0
## pattern26 0 0 0 0 0 0 0 0 0 0
## [,23] [,24] [,25] [,26]
## pattern1 0 0 0 0
## pattern2 0 0 0 0
## pattern3 0 0 0 0
## pattern4 0 0 0 0
## pattern5 0 0 0 0
## pattern6 0 0 0 0
## pattern7 0 0 0 0
## pattern8 0 0 0 0
## pattern9 0 0 0 0
## pattern10 0 0 0 0
## pattern11 0 0 0 0
## pattern12 0 0 0 0
## pattern13 0 0 0 0
## pattern14 0 0 0 0
## pattern15 0 0 0 0
## pattern16 0 0 0 0
## pattern17 0 0 0 0
## pattern18 0 0 0 0
## pattern19 0 0 0 0
## pattern20 0 0 0 0
## pattern21 0 0 0 0
## pattern22 0 0 0 0
## pattern23 1 0 0 0
## pattern24 0 1 0 0
## pattern25 0 0 1 0
## pattern26 0 0 0 1