トップ 差分 一覧 ソース 検索 ヘルプ RSS ログイン

BugTrack-R備忘録/66

R備忘録 /状態空間モデリング/donlp2/その他のメモ

R備忘録 - 記事一覧

RSNNS

  • 投稿者: みゅ
  • カテゴリ: なし
  • 優先度: 普通
  • 状態: 完了
  • 日時: 2011年04月20日 22時42分18秒

内容

スクリプト

library(nnet)
library(RSNNS)
data(snnsData)
patterns <- snnsData$art1_letters.pat
par(mfrow=c(3,3))
for (i in 1:9) plotActMap(matrixToActMapList(patterns,7)[[i]])
res <- nnet(patterns, y=patterns, skip=T, size=35, MaxNWts=20000, maxit=1000, lineout=F)
par(mfrow=c(3,3))
for (i in 1:9) plotActMap(matrixToActMapList(res$fitted,7)[[i]])
for (i in 10:18) plotActMap(matrixToActMapList(res$fitted,7)[[i]])
for (i in 19:26) plotActMap(matrixToActMapList(res$fitted,7)[[i]])
testData <-
rbind(
as.vector(t(rbind(c(0,0,0,0,1), c(0,0,0,1,0), c(0,0,0,1,0), c(0,0,1,0,0), c(0,1,0,0,0), c(0,1,0,0,0), c(1,0,0,0,0)))), 
as.vector(t(rbind(c(1,0,0,0,0), c(1,0,0,0,0), c(0,1,0,0,0), c(0,0,1,0,0), c(0,0,0,1,0), c(0,0,0,0,1), c(0,0,0,0,1))))
)
par(mfrow=c(2,2))
plotActMap(matrixToActMapList(testData,7)[[1]])
plotActMap(matrixToActMapList(testData,7)[[2]])
pred <- predict(res, testData)
plotActMap(matrixToActMapList(pred,7)[[1]])
plotActMap(matrixToActMapList(pred,7)[[2]])
par(mfrow=c(2,2))
plotActMap(matrixToActMapList(testData,7)[[1]])
plotActMap(matrixToActMapList(testData,7)[[2]])
pred <- predict(res, pred)
plotActMap(matrixToActMapList(pred,7)[[1]])
plotActMap(matrixToActMapList(pred,7)[[2]])

library(genalg)
func <- function(param){
    res$wts <- param
    #sum(abs(patterns - predict(res,patterns)) %*% rep(1,35))
    sum((patterns - predict(res,patterns))^2 %*% rep(1,35))
}
func(runif(length(res$wts)))
monFunc <- function(obj){
    res$wts <- obj$population[1,]
    pred <- predict(res, patterns)
    par(mfrow=c(3,3))
    plotActMap(matrixToActMapList(patterns,7)[[1]])
    plotActMap(matrixToActMapList(patterns,7)[[2]])
    plotActMap(matrixToActMapList(patterns,7)[[3]])
    plotActMap(matrixToActMapList(pred,7)[[1]])
    plotActMap(matrixToActMapList(pred,7)[[2]])
    plotActMap(matrixToActMapList(pred,7)[[3]])
    plot(obj$best, ty="l")
    lines(obj$mean, col="red")
    #for (i in 1:9) plotActMap(matrixToActMapList(pred,7)[[i]])
}
monFunc(res_ga)
res_ga <- rbga(stringMin=rep(-1,length(res$wts)), stringMax=rep(1,length(res$wts)), evalFunc=func, monitorFunc=monFunc,
    verbose=T, iters=200, suggestions=rbind(res$wts,res$wts))
res_ga$population[1,]

res <- nnet(patterns, y=patterns, skip=T, size=35, MaxNWts=20000, maxit=1000, lineout=F, Wts=res_ga$population[1,])
par(mfrow=c(3,3))
for (i in 1:9) plotActMap(matrixToActMapList(res$fitted,7)[[i]])
for (i in 10:18) plotActMap(matrixToActMapList(res$fitted,7)[[i]])
for (i in 19:26) plotActMap(matrixToActMapList(res$fitted,7)[[i]])

res_ga <- rbga(stringMin=rep(-1,length(res$wts)), stringMax=rep(1,length(res$wts)), evalFunc=func, monitorFunc=monFunc,
    verbose=T, iters=200, suggestions=rbind(res$wts,res$wts))
# パターンをひっくり返す
patterns2 <- 1-patterns
par(mfrow=c(3,3))
for (i in 1:9) plotActMap(matrixToActMapList(patterns2,7)[[i]])
pred <- predict(res, patterns2)
for (i in 1:9) plotActMap(matrixToActMapList(pred,7)[[i]])
  • art1
library(RSNNS)
data(snnsData)
patterns <- snnsData$art1_letters.pat
inputMaps <- matrixToActMapList(patterns, nrow=7)
par(mfrow=c(3,3))
for (i in 1:9) plotActMap(inputMaps[[i]])
model <- art1(patterns, dimX=7, dimY=5)
encodeClassLabels(model$fitted.values)

> ls(envir=model$snnsObject@variables)
[1] "serialization"   "snnsCLibPointer"

predict(model, newdata=patterns)
encodeClassLabels(predict(model, newdata=patterns))
summary(model)
  • art2
library(RSNNS)
data(snnsData)
patterns <- snnsData$art2_tetra_med.pat
model <- art2(patterns, f2Units=5, learnFuncParams=c(0.99, 20, 20, 0.1, 0), updateFuncParams=c(0.99, 20, 20, 0.1, 0))
model
testPatterns <- snnsData$art2_tetra_med.pat
predictions <- predict(model, testPatterns)
library(scatterplot3d)
par(mfrow=c(1,2))
scatterplot3d(model$fitted.values[,1:3])
scatterplot3d(predictions[,1:3])
model
  • dlvq
library(RSNNS)
demo(dlvq_ziff)
data(snnsData)
dataset <- snnsData$dlvq_ziff_100.pat
inputs <- dataset[,inputColumns(dataset)]
outputs <- dataset[,outputColumns(dataset)]
model <- dlvq(inputs, outputs)
mean(fitted(model) - outputs)
confusionMatrix(outputs, fitted(model))

par(mfrow=c(2,2))
plotActMap(matrixToActMapList(inputs, 16)[[1]])
plotActMap(matrixToActMapList(inputs, 16)[[2]])
plotActMap(matrixToActMapList(inputs, 16)[[3]])
plotActMap(matrixToActMapList(inputs, 16)[[4]])
plotActMap(matrixToActMapList(inputs, 16)[[5]])
plotActMap(matrixToActMapList(inputs, 16)[[50]]) 
plotActMap(matrixToActMapList(inputs, 16)[[15]])

plotActMap(matrixToActMapList(inputs, 16)[[2]])
plotActMap(matrixToActMapList(inputs, 16)[[7]])
plotActMap(matrixToActMapList(inputs, 16)[[13]])

patterns <- dataset[,inputColumns(dataset)][c(1,2,3,4,5,6,8,10,11,12),]
plotActMap(matrixToActMapList(patterns,16)[[1]])
  • iris
> library(RSNNS)

> seed <- 2

> set.seed(seed)

> setSnnsRSeedValue(seed)
NULL

> data(iris)

> #shuffle the vector
> iris <- iris[sample(1:nrow(iris),length(1:nrow(iris))),1:ncol(iris)]

> irisValues <- iris[,1:4]

> irisTargets <- decodeClassLabels(iris[,5])

> #irisTargets <- decodeClassLabels(iris[,5], valTrue=0.9, valFalse=0.1)
>
> iris <- splitForTrainingAndTest(irisValues, irisTargets, ratio=0.15)

> #normalize data
> iris <- normTrainingAndTestSet(iris)

> #model <- mlp(iris$inputsTrain, iris$targetsTrain, size=5, learnFunc="Quickprop", learnFuncParams=c(0.1, 2.0, 0.0001, 0.1),
> #    maxit=50, inputsTest=iris$inputsTest, targetsTest=iris$targetsTest)
>
> model <- mlp(iris$inputsTrain, iris$targetsTrain, size=5, learnFunc="BackpropBatch", learnFuncParams=c(10, 0.1),
+     maxit=100, inputsTest=iris$inputsTest, targetsTest=iris$targetsTest)

> #model <- mlp(iris$inputsTrain, iris$targetsTrain, size=5, learnFunc="SCG", learnFuncParams=c(0, 0, 0, 0),
> #    maxit=30, inputsTest=iris$inputsTest, targetsTest=iris$targetsTest)
>
>
> #model <- rbfDDA(iris$inputsTrain, iris$targetsTrain)
>
> #model <- elman(iris$inputsTrain, iris$targetsTrain, size=5, learnFuncParams=c(0.1), maxit=100, inputsTest=iris$inputsTest, targetsTest=iris$targetsTest)
>
> #model <- rbf(iris$inputsTrain, iris$targetsTrain, size=40, maxit=200, initFuncParams=c(-4, 4,  0.0,  0.2,  0.04),
> #             learnFuncParams=c(1e-3, 0, 1e-3, 0.1, 0.8), linOut=FALSE)
>
> #model <- rbf(iris$inputsTrain, iris$targetsTrain, size=40, maxit=600, initFuncParams=c(0, 1,  0.0,  0.2,  0.04),
> #             learnFuncParams=c(1e-5, 0, 1e-5, 0.1, 0.8), linOut=TRUE)
>
> ##experimental..:
> ##model <- rbf(iris$inputsTrain, iris$targetsTrain, size=20, maxit=50, initFunc="RBF_Weights_Kohonen",
> ##    initFuncParams=c(50,  0.4,  0), learnFuncParams=c(0.01, 0, 0.01, 0.1, 0.8))
>
> #summary(model)
>
> par(mfrow=c(2,2))

> plotIterativeError(model)
 次の図を見るためには<Return>キーを押して下さい:

> predictions <- predict(model,iris$inputsTest)

> plotRegressionError(predictions[,2], iris$targetsTest[,2])

> confusionMatrix(iris$targetsTrain,fitted.values(model))
       predictions
targets  1  2  3
      1 41  0  0
      2  0 45  1
      3  0  0 40

> confusionMatrix(iris$targetsTest,predictions)
       predictions
targets 1 2 3
      1 9 0 0
      2 0 3 1
      3 0 1 9

> plotROC(fitted.values(model)[,2], iris$targetsTrain[,2])

> plotROC(predictions[,2], iris$targetsTest[,2])

> #confusion matrix with 402040-method
> confusionMatrix(iris$targetsTrain, encodeClassLabels(fitted.values(model),method="402040", l=0.4, h=0.6))
       predictions
targets  0  1  2  3
      1  0 41  0  0
      2  2  0 43  1
      3  2  0  0 38

> model
Class: mlp->rsnns
Number of inputs: 4
Number of outputs: 3
Maximal iterations: 100
Initialization function: Randomize_Weights
Initialization function parameters: -0.3 0.3
Learning function: BackpropBatch
Learning function parameters: 10 0.1
Update function:Topological_Order
Update function parameters: 0
Patterns are shuffled internally: TRUE
Compute error in every iteration: TRUE
Architecture Parameters:
$size
[1] 5

All members of model:
 [1] "nInputs"               "maxit"                 "initFunc"              "initFuncParams"        "learnFunc"             "learnFuncParams"
 [7] "updateFunc"            "updateFuncParams"      "shufflePatterns"       "computeIterativeError" "snnsObject"            "archParams"
[13] "IterativeFitError"     "IterativeTestError"    "fitted.values"         "fittedTestValues"      "nOutputs"

> weightMatrix(model)
           Input_1 Input_2 Input_3 Input_4 Hidden_2_1 Hidden_2_2 Hidden_2_3 Hidden_2_4 Hidden_2_5    Output_1  Output_2  Output_3
Input_1          0       0       0       0 -0.3508658  0.2684588 -0.5913861 -0.5612198  0.3195967  0.00000000  0.000000  0.000000
Input_2          0       0       0       0 -0.5082296 -0.9437067  1.2823328  0.9810203  0.2950290  0.00000000  0.000000  0.000000
Input_3          0       0       0       0  2.2801065  1.2012331 -1.8615422 -1.2803886 -1.9130263  0.00000000  0.000000  0.000000
Input_4          0       0       0       0  2.7568083  1.5704848 -1.6876845 -1.3023156 -2.6831374  0.00000000  0.000000  0.000000
Hidden_2_1       0       0       0       0  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000 -1.40362704 -3.796962  3.113594
Hidden_2_2       0       0       0       0  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000 -2.07435131  1.398071  1.325584
Hidden_2_3       0       0       0       0  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  2.11041474 -3.148410 -2.083688
Hidden_2_4       0       0       0       0  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  1.70966542 -1.791131 -2.028595
Hidden_2_5       0       0       0       0  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000 -0.04861032  3.213499 -3.448702
Output_1         0       0       0       0  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.00000000  0.000000  0.000000
Output_2         0       0       0       0  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.00000000  0.000000  0.000000
Output_3         0       0       0       0  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.00000000  0.000000  0.000000

> summary(model)
SNNS network definition file V1.4-3D
generated at Mon Sep  3 14:54:38 2012

network name : RSNNS_untitled
source files :
no. of units : 12
no. of connections : 35
no. of unit types : 0
no. of site types : 0


learning function : BackpropBatch
update function   : Topological_Order


unit default section :

act      | bias     | st | subnet | layer | act func     | out func
---------|----------|----|--------|-------|--------------|-------------
 0.00000 |  0.00000 | i  |      0 |     1 | Act_Logistic | Out_Identity
---------|----------|----|--------|-------|--------------|-------------


unit definition section :

no. | typeName | unitName   | act      | bias     | st | position | act func     | out func | sites
----|----------|------------|----------|----------|----|----------|--------------|----------|-------
  1 |          | Input_1    |  0.81788 |  0.12059 | i  | 1,0,0    | Act_Identity |          |
  2 |          | Input_2    | -0.09058 |  0.18581 | i  | 2,0,0    | Act_Identity |          |
  3 |          | Input_3    |  0.82358 | -0.24672 | i  | 3,0,0    | Act_Identity |          |
  4 |          | Input_4    |  1.07735 | -0.22711 | i  | 4,0,0    | Act_Identity |          |
  5 |          | Hidden_2_1 |  0.82712 | -3.04162 | h  | 1,2,0    |||
  6 |          | Hidden_2_2 |  0.97982 |  0.89637 | h  | 2,2,0    |||
  7 |          | Hidden_2_3 |  0.00414 | -1.53274 | h  | 3,2,0    |||
  8 |          | Hidden_2_4 |  0.01841 | -0.97075 | h  | 4,2,0    |||
  9 |          | Hidden_2_5 |  0.17175 |  2.65829 | h  | 5,2,0    |||
 10 |          | Output_1   |  0.01332 | -1.14370 | o  | 1,4,0    |||
 11 |          | Output_2   |  0.12910 | -0.64419 | o  | 2,4,0    |||
 12 |          | Output_3   |  0.88143 | -1.22978 | o  | 3,4,0    |||
----|----------|------------|----------|----------|----|----------|--------------|----------|-------


connection definition section :

target | site | source:weight
-------|------|---------------------------------------------------------------------------------------------------------------------
     5 |      |  4: 2.75681,  3: 2.28011,  2:-0.50823,  1:-0.35087
     6 |      |  4: 1.57048,  3: 1.20123,  2:-0.94371,  1: 0.26846
     7 |      |  4:-1.68768,  3:-1.86154,  2: 1.28233,  1:-0.59139
     8 |      |  4:-1.30232,  3:-1.28039,  2: 0.98102,  1:-0.56122
     9 |      |  4:-2.68314,  3:-1.91303,  2: 0.29503,  1: 0.31960
    10 |      |  9:-0.04861,  8: 1.70967,  7: 2.11041,  6:-2.07435,  5:-1.40363
    11 |      |  9: 3.21350,  8:-1.79113,  7:-3.14841,  6: 1.39807,  5:-3.79696
    12 |      |  9:-3.44870,  8:-2.02859,  7:-2.08369,  6: 1.32558,  5: 3.11359
-------|------|---------------------------------------------------------------------------------------------------------------------

> extractNetInfo(model)
$infoHeader
                name             value
1       no. of units                12
2 no. of connections                35
3  no. of unit types                 0
4  no. of site types                 0
5  learning function     BackpropBatch
6    update function Topological_Order

$unitDefinitions
   unitNo   unitName      unitAct   unitBias        type posX posY posZ      actFunc      outFunc sites
1       1    Input_1  0.817876339  0.1205858  UNIT_INPUT    1    0    0 Act_Identity Out_Identity
2       2    Input_2 -0.090580426  0.1858058  UNIT_INPUT    2    0    0 Act_Identity Out_Identity
3       3    Input_3  0.823582947 -0.2467227  UNIT_INPUT    3    0    0 Act_Identity Out_Identity
4       4    Input_4  1.077348471 -0.2271125  UNIT_INPUT    4    0    0 Act_Identity Out_Identity
5       5 Hidden_2_1  0.827119827 -3.0416200 UNIT_HIDDEN    1    2    0 Act_Logistic Out_Identity
6       6 Hidden_2_2  0.979820251  0.8963667 UNIT_HIDDEN    2    2    0 Act_Logistic Out_Identity
7       7 Hidden_2_3  0.004135765 -1.5327449 UNIT_HIDDEN    3    2    0 Act_Logistic Out_Identity
8       8 Hidden_2_4  0.018411839 -0.9707544 UNIT_HIDDEN    4    2    0 Act_Logistic Out_Identity
9       9 Hidden_2_5  0.171753630  2.6582935 UNIT_HIDDEN    5    2    0 Act_Logistic Out_Identity
10     10   Output_1  0.013317095 -1.1436981 UNIT_OUTPUT    1    4    0 Act_Logistic Out_Identity
11     11   Output_2  0.129099220 -0.6441937 UNIT_OUTPUT    2    4    0 Act_Logistic Out_Identity
12     12   Output_3  0.881433606 -1.2297773 UNIT_OUTPUT    3    4    0 Act_Logistic Out_Identity

$fullWeightMatrix
           Input_1 Input_2 Input_3 Input_4 Hidden_2_1 Hidden_2_2 Hidden_2_3 Hidden_2_4 Hidden_2_5    Output_1  Output_2  Output_3
Input_1          0       0       0       0 -0.3508658  0.2684588 -0.5913861 -0.5612198  0.3195967  0.00000000  0.000000  0.000000
Input_2          0       0       0       0 -0.5082296 -0.9437067  1.2823328  0.9810203  0.2950290  0.00000000  0.000000  0.000000
Input_3          0       0       0       0  2.2801065  1.2012331 -1.8615422 -1.2803886 -1.9130263  0.00000000  0.000000  0.000000
Input_4          0       0       0       0  2.7568083  1.5704848 -1.6876845 -1.3023156 -2.6831374  0.00000000  0.000000  0.000000
Hidden_2_1       0       0       0       0  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000 -1.40362704 -3.796962  3.113594
Hidden_2_2       0       0       0       0  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000 -2.07435131  1.398071  1.325584
Hidden_2_3       0       0       0       0  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  2.11041474 -3.148410 -2.083688
Hidden_2_4       0       0       0       0  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  1.70966542 -1.791131 -2.028595
Hidden_2_5       0       0       0       0  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000 -0.04861032  3.213499 -3.448702
Output_1         0       0       0       0  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.00000000  0.000000  0.000000
Output_2         0       0       0       0  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.00000000  0.000000  0.000000
Output_3         0       0       0       0  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.00000000  0.000000  0.000000
  • laser
library(RSNNS)
data(snnsData)
inputs <- snnsData$laser_1000.pat[,inputColumns(snnsData$laser_1000.pat)]
outputs <- snnsData$laser_1000.pat[,outputColumns(snnsData$laser_1000.pat)]
patterns <- splitForTrainingAndTest(inputs, outputs, ratio=0.15)
model <- elman(patterns$inputsTrain, patterns$targetsTrain, size=c(8,8), learnFuncParams=c(0.1), maxit=500, 
    inputsTest=patterns$inputsTest, targetsTest=patterns$targetsTest, linOut=FALSE)
modelJordan <- jordan(patterns$inputsTrain, patterns$targetsTrain, size=c(8), learnFuncParams=c(0.1), maxit=100, 
    inputsTest=patterns$inputsTest, targetsTest=patterns$targetsTest, linOut=FALSE)
modelMlp <- mlp(patterns$inputsTrain, patterns$targetsTrain, initFuncParams=c(-0.3,0.3),size=c(8), 
    learnFuncParams=c(0.05), maxit=500, inputsTest=patterns$inputsTest, targetsTest=patterns$targetsTest, linOut=TRUE)
names(model)
par(mfrow=c(3,3))
plotIterativeError(model)
plotIterativeError(modelJordan)
#plotIterativeError(modelMlp)
plotRegressionError(patterns$targetsTrain, model$fitted.values, main="Regression Plot Fit")
plotRegressionError(patterns$targetsTest, model$fittedTestValues, main="Regression Plot Test")
hist(model$fitted.values - patterns$targetsTrain, col="lightblue", main="Error Histogram Fit")
#model$IterativeFitError[length(model$IterativeFitError)]
plot(inputs, type="l")
plot(inputs[1:100], type="l")
lines(outputs[1:100], col="red")
lines(model$fitted.values[1:100], col="green")
  • som
library(RSNNS)
#data(snnsData)
#inputs <- snnsData$som_cube.pat
data(iris)
inputs <- normalizeData(iris[,1:4], "norm")
model <- som(inputs, mapX=16, mapY=16, maxit=500,  calculateActMaps=TRUE, targets=iris[,5])
par(mfrow=c(3,3))
for(i in 1:ncol(inputs)) plotActMap(model$componentMaps[[i]], col=rev(topo.colors(12)))
plotActMap(model$map, col=rev(heat.colors(12)))
plotActMap(log(model$map+1), col=rev(heat.colors(12)))
persp(1:model$archParams$mapX, 1:model$archParams$mapY, log(model$map+1), theta = 30, phi = 30, expand = 0.5, col = "lightblue")
plotActMap(model$labeledMap)   # 各セルがどのラベルを持つか
model$componentMaps   # 各ファクター(irisなら4ファクター)がマップ全体(各セル)にどのように分布しているかを示す
model$labeledUnits   # 各セルにどのクラスが存在しているか.model$mapの内訳
model$map   # 各セルに存在するデータの個数
names(model)
  • assoz
dataset <- snnsData$dlvq_ziff_100.pat
patterns <- dataset[,inputColumns(dataset)][c(1,2,3,4,5,6,8,10,11,12),]
model <- assoz(patterns, dimX=16, dimY=16)
#model$fitted.values
par(mfrow=c(3,3))
for (i in 1:9) plotActMap(matrixToActMapList(patterns,16)[[i]])
actMaps <- matrixToActMapList(model$fitted.values, nrow=16)
for (i in 1:9) plotActMap(actMaps[[i]])
pred <- predict(model, dataset[,inputColumns(dataset)])
for (i in 1:length(pred)) plotActMap(pred[[i]])
  • assoz
## Not run: demo(assoz_letters)
## Not run: demo(assoz_lettersSnnsR)
data(snnsData)
patterns <- snnsData$art1_letters.pat
model <- assoz(patterns, dimX=7, dimY=5)
actMaps <- matrixToActMapList(model$fitted.values, nrow=7)
par(mfrow=c(3,3))
for (i in 1:9) plotActMap(actMaps[[i]])
  • assoz
demo(assoz_letters)
library(RSNNS)
data(snnsData)
patterns <- snnsData$art1_letters.pat
model <- assoz(patterns, dimX=7, dimY=5)
#model$fitted.values
par(mfrow=c(3,3))
for (i in 1:9) plotActMap(model$fitted.values[[i]])
cbind(patterns[1,], as.vector(t(model$fitted[[1]])), predict(model, patterns)[1,])
testData <-
rbind(
as.vector(t(rbind(c(0,0,0,0,1), c(0,0,0,1,0), c(0,0,0,1,0), c(0,0,1,0,0), c(0,1,0,0,0), c(0,1,0,0,0), c(1,0,0,0,0)))), 
as.vector(t(rbind(c(1,0,0,0,0), c(1,0,0,0,0), c(0,1,0,0,0), c(0,0,1,0,0), c(0,0,0,1,0), c(0,0,0,0,1), c(0,0,0,0,1))))
)

model <- assoz(patterns[1:5,], dimX=7, dimY=5, maxit=1000)
testData <- rbind(patterns[1,], patterns[1,])
testData[2,1] <- 1
testData[2,2] <- 0
cbind(patterns[1,], as.vector(t(model$fitted[[1]])), testData[2,], predict(model, testData)[2,])
par(mfrow=c(2,2))
pred <- predict(model, testData)
plotActMap(matrixToActMapList(patterns,7)[[1]])
plotActMap(model$fitted[[1]])
plotActMap(matrixToActMapList(testData,7)[[2]])
plotActMap(matrixToActMapList(pred,7)[[2]])
pred <- predict(model, pred)
plotActMap(matrixToActMapList(testData,7)[[1]])
plotActMap(matrixToActMapList(pred,7)[[1]])
plotActMap(matrixToActMapList(testData,7)[[2]])
plotActMap(matrixToActMapList(pred,7)[[2]])

コメント