source("../Rcmd/master.R")
source("../Rcmd/master.R")
source("../Rcmd/master.R")
?if
?else
?control
??controlflow
?Control
source("../Rcmd/master.R")
# ABM simulations with Australian English sibilants
# preambel
# The term 'Harrington Rule' in the following refers to the basic idea that sound change from one agent group 
# in the direction of another agent group is driven by a simple rule, that only word tokens 
# are memorized by an agent, if they are close to the class distribution within the memory of the agent.
# pictures are created as PDF in dir figdir (defined below)
# several switches control the behaviour of the script, i.e. if plots are generated during 
# the simulations and whether and which time-slice pictures (*.pgn) are generated in figsdir that later 
# can be aggregated into animated GIFs (see boolean definitions below)
# Although it is possible to run the entire script, it is recommended to run only
# parts of it at a time to watch the online displays (if activated) and the results of the
# individual tests.
# Good places to stop are marked with '### STOP'.
############################################################
# CHANGE THIS IF YOU MOVE THE EXPERIMENT TO ANOTHER COMPUTER
# the master dir where this script resides (in subdir Rcmd)
pfad2="/homes/schiel/ABM/SibilantsAustralianEnglish2016"
############################################################
library(plyr)
library(lattice)
library(latticeExtra)
library(ez)
library(emuR)
library(mvtnorm)
pfadu="http://www.phonetik.uni-muenchen.de/~jmh/lehre/Rdf"
# functions for ezAnova post-hocs
source(file.path(pfadu, "phoc.txt"))
# function for converting trackdata to data-frame
source(file.path(pfadu, "tracklinear.R"))
source(file.path(pfadu, "readtrackfromurl.R"))
source(file.path(pfadu, "tracktodf.R"))
source(file.path(pfadu, "emu.track.S"))
# these are all fiddly functions for colour coding and legend using xyplot()
source(file.path(pfadu, "legendxyplot.R"))
source(file.path(pfadu, "legendxyplot_mod.R"))
source(file.path(pfadu, "buildsegno.R"))
source(file.path(pfadu, "buildsegnoxyplot.R"))
# sub-level directory where to store paper figs
figsdir = file.path(pfad2, "figs.test")
# sub-level directory of specific functions for this analysis
fndir = file.path(pfad2, "functions")
# functions for agent-based modelling
source(file.path(fndir, "agentfns.R"))
source(file.path(fndir, "sibilantagentfunctions.R"))
##########################################################################################
# Definitions
# make production data from scratch (F)(requires an intact Braidwood emuR online!), or load 
# pre-stored dataframe and power spectra (T)(filtered etc.) from disc
loadDataframe = F
# The following booleans define mainly the fig creations during the simulations.
dispPaperFigs = T    # display Paper figs on X device
printPaperFigs = F   # create all paper figs anew in figsdir
dispSim = T          # display plots during ABM2 simulation (part 3)
plotCloud = T        # display 3D plots of DCT space rather than 2-D plots
printPNG = F         # create 'Sim1###.png' files in dirPNG containing the steps of simulation
dirPNG = "."         # directory to create PNG time-series files of simulation 
                     # (default is the dir in which R was called)
                     # this numbered time-slice series of *.jpg can later be converted 
                     # into an animated GIF using e.g. 'convert'
speakerNormalize = T # speaker normalize production data before analysis and ABM using Lobanov 
                     # this means that the entire ABM runs in a 'normalized M1 space', that is 
                     # we assume that each agent has a perfect way to compensate for speaker 
                     # individual shifts and SD differences in M1; only relative changes within 
                     # an agents data set are modelled. This also changes all dimensions of 
                     # plots from Hertz to a dimensionless number between -1 and 1.
loadEmuData = F      # set to T, if you would like to process the original data anew and overwrite 
                     # the pre-processed dataframe on disk; otherwise (default) 
                     # the pre-processed dataframe is loaded
# set parameters of ABM2 (we do not ABM1 in this experiment)
# (note that for reproduction of the paper figs the numbers in comments *must* be used;
# however, for a smooth animation you might use the values given in comment 'animation' below
# the Mahalanobis threshold for acception an incoming token in /u/ fronting ABM2
simMahalThreshold = 2.5 # paper: 2.5
# number of iterations per simGroup
simGroupSize = 10000 # paper: 10000
simGroups = 5   # paper: 5
# values for smooth animation of ABM2:
#simGroupSize = 1000
#simGroups = 50
compressedSD = 1.0   # factor to compress production SD in str words in ABM 1C
threshold.sS = 4.0   # log MH threshold for sibilant perception of non 'str' words
threshold.str = 9999.0   # log MH threshold for sibilant perception of 'str' words
                         # extrem high number (default) means no Harrington Rule is applied (all tokens accepted)
###########################################################################################
cat("Script master.R invoked with the following parameters:\n\n")
cat("dispPaperFigs: ",dispPaperFigs,"\n")
cat("printPaperFigs: ",printPaperFigs,"\n")
cat("dispSim: ",dispSim,"\n")
cat("plotCloud: ",plotCloud,"\n")
cat("printPNG: ",printPNG,"\n")
cat("dirPNG: ",dirPNG,"\n\n")
cat("ABM2 parameters:\n")
cat("simMahalThreshold: ",simMahalThreshold,"\n")
cat("simGroupSize: ",simGroupSize,"\n")
cat("simGroups: ",simGroups,"\n\n")
inpu = readline("Continue? (Y/n) ")
  cat("Edit the script to change parameters and source() it again\n")
  stop()
}
###########################################################################################
inpu = readline("Continue? (Y/n) ")
source("../Rcmd/master.R")
source("../Rcmd/master.R")
source("../Rcmd/master.R")
q()
