diff --git a/07_final_assignment/baboonSimulation.R b/07_final_assignment/baboonSimulation.R index 0e0976e..2fc52a0 100644 --- a/07_final_assignment/baboonSimulation.R +++ b/07_final_assignment/baboonSimulation.R @@ -136,4 +136,52 @@ expect_equal(nrow(trials), count) expect_equal(length(stimuli$StimulusType[stimuli$StimulusType == "LearnedWord"]), 102) }) + +MakeMonkey <- function(cueset, outcomeset=c("Word", "Nonword"), alpha=sqrt(0.001), beta=sqrt(0.001), lambda=1.0){ + weights <- matrix(0, length(cueset), length(outcomeset)) + rownames(weights) <- cueset + colnames(weights) <- outcomeset + + learner <- function(stim, resp){ + cues <- unlist(strsplit(stim, "_")) + print(cat("Cues: ", cues)) + print(cat("Outcome: ", resp)) + print("Weights: ",weights) + print(outcomeset) + print(weights[,outcomeset]) + totalActivation <- sum(weights[cues, outcomeset]) + + print(str(cues)) + for (j in 1:length(cues)) { + print("HIIIER") + if (resp == "Nonword") { + yesType <- "Nonword" + noType <- "Word" + } else if (resp == "Word") { + yesType <- "Word" + noType <- "Nonword" + } else { + stop("Unknown outcome", resp) + } + weights[cues[j],yesType] <<- weigths[cues[j],yesType] + + alpha * beta * (lambda - totalActivation[yesType]) + weights[cues[j],noType] <<- weights[cues[j],noType] + + alpha * beta * (0 - totalActivation[noType]) + } + } + + list( + Weights=weights, + Learner=learner + ) +} + +test_that("MakeMonkey",{ + cueset <- c("a","b","c") + + monkey <- MakeMonkey(cueset) + print(str(monkey)) + monkey$Learner("a_a_b_c","Word") + print(monkey$Weigths) +}) # EOF