Cognitive Modeling, R, and Reproducible Research 進度報告
研究目的
在心理學認知模擬的領域中,一般研究者要複製他人的研究最常遇到的問 題就是文獻中認知模型的實做及電腦模擬的程序,但由於這些難點是屬於技術層 次而不在理論層次上,所以一般心理學文獻不會包含這一個部份。本研究目的是 在心理學認知模擬的領域中,使用 R 軟體來開發可再生複製的研究(Reproducible Research)模式的工具。本計畫實做的認知模型將包含學習、記憶、分類、因果 推論等領域。這些認知模型被實做在開放原始碼、一般用途的計算平台上,使用 的工具軟體包含 R、LaTeX,可建構在 Windows 或 UNIX/Linux 作業系統中。
文獻探討
認知科學的焦點是希望藉由以完成複雜作業的方式來了解大腦的運作,這 些作業包含知覺、學習、記憶、思考、決策、問題解決等。認知模擬(Cognitive Modeling)的目的則是想要說明一個或多個的認知處理歷程(cognitive
processes),或說明這些認知處理歷程的交互作用。在目前,認知處理程序能夠
呈現在計算環境中的像是 ACT-R(1993)或 Cogent(1998),這些程式要不是本 身是有專利的就是被建構在專利的作業平台上,像是建構在 Matlab 或
Mathematica(Gronlund, Sheu & Ratcliff, 1990; Duncan & Tweney, 1997),有些是 使用程式語言,像是 C++(Masters, 1993)撰寫,所以電腦科技的進步對於認知 心理學實徵及理論研究扮演了重要的角色(Ratciff, 1994)。本計畫目前是利用成 熟的開放軟體(open software)將認知模型實做在非專利的計算環境中。
預計要實做的認知模型在學習領域的有 The configural model of Pearce
(Macho, 2002)、A model of the go/no-go discrimination task(Yechiam, et al., 2006;
Helmers et al., 1995)、A signal detction analysis of contingency judgment(Allen,
MINERVA-DM(Dougherty, Getty & Ogden, 1999)、REM(Shiffrin & Steyvers, 1997;
Shiffrin, 2003),在分類領域有 ALCOVE(Kruschke, 1992)、ATRIUM(Erickson
& Kruschke, 1998, 2002)、SUSTAIN(Love, Medin, & Gureckis, 2004),在因果推 論領域的有 Causal inferences as perceptual judgments(Anderson & Sheu, 1995)、
Optimal prediction of everyday cognition(Griffths & Tenenbaum, 2006)等。
研究方法
這計畫一開始的靈感是來自我們努力去瞭解使用 Macho(2002)論文中以 Excel 軟體實做的認知模型時所招遇的困難,在考慮到軟體專利問題、對數學及 統計計算的功能、參考文獻的資源、程式學習及撰寫的方便性,我們選擇使用開 放原始碼的 R 軟體。
R 軟體是用來進行數學運算及繪圖的一種程式語言、執行環境,它是開放 原始碼的自由軟體,允許使用者自行開發附屬功能(package)並上傳公告,用以擴 充功能。官方網站網址 http://www.r-project.org/。本計畫的目標之一就是開發一 個能自由散佈的認知模型的 R package。
可再生複製研究(Reproducible Research)的緣起是因為應用計算機科學所 產生的最後知識通常不是文字文件,而是用來產生論文結果的軟體環境。本計畫 研究方法的最後一個部份就是組合一套軟體工具用來再生複製認知模擬及電腦 實驗,所以需要可計算式文件(literate programming)及開放原始碼的程式設計 工具。可計算式文件(literate programming)是由 Knuth (1992)所提出的一種方 法,能將資料及數學計算程序鑲嵌在文件中,方便由該文件重新獲得原作者的結 論。在實做上需要 LaTeX 及 R 兩種工具軟體相互配合。
TeX 是 Donald E. Knuth 所發展,它是一套功能強大的幕後排版系統,而且 是系統結構有很大彈性的低階排版語言。但是由於不夠方便、直觀,因此 Leslie Lamport 修改原 TeX 定義的巨集,改寫成 LaTeX,此版主要是把版面配置和文章 內容適度的分開處理,只要使用者選定了一種類別,整本書或整篇文章的結構就
是按照這個類別來安排版面,讓寫文件的人只要專注於文章內容就可以了,版面 配置就完全交給 TeX/LaTeX 去處理。官方網站 http://www.latex-project.org/。
LaTeX 的軟體有很多不同版本(有部分是商業版),彼此間功能大同小異,在 Win32 環境中通常使用 MikTeX (http://miktex.org/ ),和在 Unix/Linux 環境中較常使用的 TeXLive (http://www.tug.org/texlive/),都屬於開放原始碼的自由軟體。使用一般 文字編輯器即可編輯 TeX/LaTeX 文件,副檔名為.tex。單一個 TeX/LaTeX 文件,
可編譯成 Text、HTML、 DVI、PostScript、PDF 等多種文件格式。
Sweave,是 Friedlich Leisch(2002)製作的 R 套件(package),它能將混合 了 R 及 TeX 的非網頁文件(noweb document, Ramsay, 1994)轉換成 LaTeX 文件 並且將已經由 R 執行過的結果置換原文件中鑲嵌的 R 程式碼。這項技術被應用 到實做可計算式文件的概念中。應用 Sweave 的技術到本計畫預計要製作的認知 模型中,能讓我們隨著對認知模型的瞭解做動態的實做、管理及更新。
計畫成果自評
本計畫首先選擇將 CMP(configoral model of Pearce)模型實做在 R 軟體上。
CMP(Pearce, 1994)是一個關聯模型(connectionist model)用來模擬連結學習
(associative learning)。它被 Macho(2002)延伸應用來解釋 Shanks, Charles, Darby
& Azmi(1998)區辨學習實驗的結果。Harris(2006)提出對 CMP 的改良版本,
稱為 Harris associative model(HAM),也納為實做項目之一。
CMP 及 HAM 已撰寫成 R script function。隨著已建構好的 LaTeX 及製作 R package 的環境,CMP 及 HAM 已經能被製作成 R package。在附錄中將以 CMP 為例示範如何使用本計劃製作的 R package(package name: ConfiguralModel)。目 前計畫進行順利,原計畫之其它項目也將陸續進行。
本研究計劃目前成果預計在六月底投交簡介及計畫書至 Society for Computers in Psychology(SCiP),參加 2008 年 12 月的 SCiP 年會。
參考文獻
1. Allen, L.G., Siegel, S., & Tangen, J.M. (2005). A signal detection analysis of contingency data. Learning & Behavior , 33(2), 250-263.
2. Anderson, J.R. (1990). The adaptive character of thought . Hillsdale, NJ:
Lawrence Erlbaum Associates, Inc.
3. Anderson, J.R. (1995). Rules of the mind . Hillsdale, NJ: Lawrence Erlbaum Associates, Inc.
4. Bickel, P.J., & Doksum, J.A. (1977). Mathematical statistics. Upper Saddle River, NJ: Prentice-Hall.
5. Barlow, H.B. & Mollon, J.D. ( Eds.) (1982). The Senses. Cambridge: The Cambridge University Press.
6. Bush, R.R., & Mosteller, F. (1951). A mathematical model for simple learning. Psychological Review, 58, 313-323.
7. Coombs, C.H., Dawes, R.M., & Tversky, A. (1970). Mathematical psychology:
An elementary introduction. Oxford, England: Prentice-Hall.
8. Cooper, R. & Fox, J. (1998). Cogent: A visual design environment for cognitive modeling. Behavior Research Methods, Instruments, & Computers , 30, 553-564.
9. De Leeuw, J. (2001). Reproducible research: The bottom line. Statistics Program, Department of Statistics, University of California, Los Angeles, CA, USA.
10. Dougherty, M.R.P., Getteys, C.F., & Ogden, E.E. (1999). MINERVADM:
A memory process model for judgment of likelihood. Psychological Review, 106(1), 180-209.
11. Duncan, S.C. & Tweney, R.D. (1997). Mathematica: A flexible design environment for neural networks. Behavior Research Methods, Instruments,
& Computers, 29, 194-199.
12. Erickson, M.A., & Kruschke, J.K. (1998). Rules and exemplars in category learning. Journal of Experimental Psychology: General , 127, 107-140.
13. Erickson, M.A., & Kruschke, J.K. (2002). Rule -based extrapolation in perceptual categorization. Psychonomic Bulletin & Review , 9, 160 -168.
14. Gelman, A., Carlin, J.B., Stern, H.S., & Rubin, D. B. (2003). Bayesian data analysis. 2nd Ed. Boca Raton, FL:Chapman & Hall/CRC.
15. Glanzer, M., & Adams, J.K. (1990). The mirror effect in recognition memory:
Data and theory. Psychological Review, 100, 546-567.
16. Goldinger, S.L. (1998). Echoes of echoes? An epis odic theory of l exical access.
Psychological Review, 105(2), 251-279.
17. Gronlund, S.D., Sheu, C. -F., & Ratcliff (1990). Implementation of global
memory models that does symbolic computation. Behavior Research Methods, Instruments, & Computers , 22, 228-235.
18. Hintzman, D. (1984). MINERVA2: A simulation model of human memory.
Behavior Research Methods, Instruments, & Computers , 16, 96 -101.
19. Hintzman, D. (1988). Judgments of frequency and recognition memory in a multiple-trace memoy. Psychological Review, 96, 528-551.
20. Husson, F., & L e, S. SensoMineR: a package for sensory data analysis with R. Paper presented at the R User Conference, Vienna, Asutria. June, 2006.
21. Ihaka, R., & Gentleman, R. (1996). R: a language for data analysis and graphics. Journal of Computation al and Graphical Statistics, 5, 299-314.
22. Jacobs, R.A., Jordan, M.I., Nowlan, S.J., & Hinton, G.E. (1991). Adaptive mixtures of local experts. Neural Computation, 3, 79 -87.
23. Knuth, D.E. (1992). Literate programming. Number 27 in CSLI Lecture Notes. Center fo r the Study of Language and Information. Stanford University, CA, USA.
24. Kruschke, J.K. (1992). ALCOVE: An exemplar-based connectionist model of category learning. Psychological Review, 99, 22 -44.
25. Leisch, F. & Rossini, A.J. (2003). Reproducible statistical r esearch. Chance, 16(2), 46 -50.
26. Love, B.C., Medin, D.L., & Gureckis, T.M (2004). SUSTAIN: A Network Model of Category Learning. Psychological Review, 111, 309-332.
27. Macho, S. (2002). Cognitive modeling with spreadsheets. Behavior Research Methods, 34, 19 -36.
28. Masters, T. (1993). Practical neural network recipes in C++ . San Diego, CA: Academic Press.
29. Parzen, E. (1960). Modern probability theory and its applications . New york:
John Wiley and Sons, Inc.
30. Pearce, J.M. (1994). Similarity and discrimination: A select ive review and a connectionist model. Psychological Review, 101, 587-607.
31. Polk, T.A., & Seifert, C.M. (Eds.) (2002). Cognitive modeling. Cambridge, MA: The MIT Press.
32. Ramsey, N. (1994). Literate programming simplified. IEEE Software, 11(5), 97-105.
33. Ratcliff, R., Clark, S.E., & Shiffrin, R.M. (1990). List -strength effect: I. Data and discussion. Journal of Experimental Psychology: Learning, Memory, &
Cognition, 16, 163-178.
34. Ratcliff, R., McKoon, G., & Tindall, M. (1994). Empirical generality of data from recognition memory receiver-operating characteristic functions and
implications for the global memory models. Journal of Experimental Psychology: Learning, Memory, & Cognition , 20, 763-785.
35. Ratcliff, R. (1994). Using computers in empirical and theoretical wor k in cognitive psychology. Behavior Research Methods, Instruments, &
Computers, 26, 94 -106.
36. R Development Core Team (2006). R: A language and environment for statistical computing. R Foundation for Statistical Computing, Vienna, Austria.
37. Rescorla, R.A., & Wagner, A.R. (1972). A theory in Pavlovian conditioning:
Variation in the effectiveness of reinforcement and nonreinforcement . In A.H.
Blach & W.F. Prokasy (Eds.), Classical conditioning II: Current research and theory (pp. 64 -99). New York: Appleton-Century-Crofts.
38. Schwab, M., Karrenbach, M. & Claerbout, J. (2000). Making scientific computations reproducible.Computing in Science and Engineering , 2, 61-67.
39. Shanks, D.R., Charles, D., Darby, R.J., & Azmi, A. (1998). Configural processes in hu man associative learning.Journal of Experimental Psychology:
Learning, Memory, & Cognition , 24, 1353-1378.
40. Sheu, C. -F. (1992). A Note on the multiple -trace memory model without simulation. Journal of Mathematical Psychology , 36, 592-597.
41. Sheu, C. -F., & O ’Curry, S.L. (1998). Simulation-based Bayesian inference using BUGS. Behavior Research Methods, Instruments, & Computers , 30, 232-237.
42. Sheu, C. -F., & Chen, C. -T. Turning output of item response theory data analysis into graphs with R. Paper presented at the R User Conference, Vienna, Austria. June, 2006.
43. Shriffin, R.M. (2003). Modeling memory and perception. Cognitive Science, 27, 341-378.
44. Shriffin, R.M., & Steyvbers, M. (1997). A model for recognition memory:
REM-retrieving effectively from memory. Psychonomic Bulletion & Review, 4, 145-166.
45. Spiegelhalter, D.J., Thomas, A., Best, N.G. & Gilks, W. (1997). BUGS:
Bayesian inference using Gibbs sampling, Version 0.60. Cambridge: Medical Research Council Biostatistic Unit.
46. Venables, W. & Ripley, B. (2004). S programming. New York: Springer.
47. Wolfram, S. (1996). Mathematica (version 3) [Computer programming language] Cambridge, MA: Cambridge University Press.
48. Yang, L -X., & Lewandowsky, S. (2004). Knowledge partitioning in categorization: constraints on exemplar models. Journal of Experimental
Psychology: Learning, Memory, & Cognition , 30, 1045-1064.
附錄 A
1. 進入 R 執行環境中,載入 ConfiguralModel package,並將 R 的工作目錄切換 至 CMP-demo.Rnw 檔所在目錄。
2. 執行 R 指令 Sweave(“CMP-demo.Rnw”)產生 CMP-demo.tex 檔,及
cmpdemo-002.pdf、cmpdemo-004.pdf 檔,其中 CMP-demo.tex 為 TeX 格式檔 案,cmpdemo-002.pdf、cmpdemo-004.pdf 為 Sweave 執行後產生的圖檔。
3. 使用 TeX 編輯器編輯 CMP-demo.tex,將 \usepackage{c:\program~1\ ...
\Sweave},改成 \usepackage{Sweave}。
4. 複製 R 的 Sweave.sty,並與 CMP-demo.tex 置於相同目錄 5. 使用 LaTeX 編譯 CMP-demo.tex 成 CMP-demo.pdf
附錄 B
# CMP-demo.Rnw
# file start
\documentclass[10pt]{article}
\usepackage{amsmath}
\begin{document}
CMP Learning Stage 1.
\\
<<LS1>>=
library(ConfiguralModelPearce)
try(data(LS1InputPattern,LS2InputPattern,ConfiguralPattern))
ShankLS1.cmp <- CMP(LS1InputPattern,ConfiguralPattern,'','','','',nb=15)
@
<<fig=TRUE, echo=FALSE>>=
CMP.plot(ShankLS1.cmp,nb=15,nl=6,lineslabel=c("A+","AB-","AC+","D+","DE-","DF+"
))
@
\\
CMP Learning Stage 2.
\\
<<LS2>>=
ShankLS2.cmp <-CMP(LS2InputPattern,ConfiguralPattern,ShankLS1.cmp[[1]], ShankLS1.cmp[[2]],ShankLS1.cmp[[3]],ShankLS1.cmp[[4]],nb=10)
@
<<fig=TRUE, echo=FALSE>>=
CMP.plot(ShankLS2.cmp,nb=10,nl=3,lineslabel=c("B+","AB-","DE+"))
@
\end{document}
# file end
附錄 C
# CMP-demo.tex
# file start
\documentclass[10pt]{article}
\usepackage{amsmath}
\usepackage{Sweave}
\begin{document}
CMP Learning Stage 1.
\\
\begin{Schunk}
\begin{Sinput}
> library(ConfiguralModelPearce)
> try(data(LS1InputPattern, LS2InputPattern, ConfiguralPattern))
> ShankLS1.cmp <- CMP(LS1InputPattern, ConfiguralPattern, "", "", "", "", nb = 15)
\end{Sinput}
\end{Schunk}
\includegraphics{cmpdemo-002}
\\
CMP Learning Stage 2.
\\
\begin{Schunk}
\begin{Sinput}
> ShankLS2.cmp <- CMP(LS2InputPattern, ConfiguralPattern, ShankLS1.cmp[[1]], ShankLS1.cmp[[2]],
+ ShankLS1.cmp[[3]], ShankLS1.cmp[[4]], nb = 10)
\end{Sinput}
\end{Schunk}
\includegraphics{cmpdemo-004}
\end{document}
# file end
#cmpdemo-002.pdf
#cmpdemo-004.pdf