Skip to content

Commit 05969ab

Browse files
committed
Updated DDM recovery code
1 parent def1baa commit 05969ab

File tree

2 files changed

+33
-19
lines changed

2 files changed

+33
-19
lines changed

code/ddm/ssp_recovery/SSP_DDM_recover_params.R

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -187,13 +187,15 @@ fitFunctionSSP <- function(
187187
}# End of fitFunctionSSP
188188
#------------------------------------------------------------------------------
189189

190-
analysis_path = "/Users/fzaki001/thrive-theta-ddm/" # local
191-
# analysis_path = "/home/data/NDClab/analyses/thrive-theta-ddm/" # HPC
192-
output_sim_path <- '/Users/fzaki001/thrive-theta-ddm/derivatives/behavior/ddm_recovery/sim_data'
193-
output_fit_path <- '/Users/fzaki001/thrive-theta-ddm/derivatives/behavior/ddm_recovery/fit_data'
190+
# analysis_path = "/Users/fzaki001/thrive-theta-ddm/" # local
191+
# analysis_path = "/Users/fzaki001/thrive-theta-ddm/" # local
192+
analysis_path = "/home/data/NDClab/analyses/thrive-theta-ddm/" # HPC
193+
output_sim_path <- sprintf("%s/derivatives/behavior/ddm_recovery/sim_data/", analysis_path)
194+
output_fit_path <- sprintf("%s/derivatives/behavior/ddm_recovery/fit_data/", analysis_path)
194195

195196
# how many trials to simulate per condition
196-
nTrials_to_sim = c(50, 100, 200, 500, 1000, 5000)
197+
#nTrials_to_sim = c(50, 100, 200, 500, 1000, 5000)
198+
nTrials_to_sim = c(5, 10, 25)
197199

198200
dt <- 0.001
199201
vari <- 0.01
@@ -202,14 +204,25 @@ vari <- 0.01
202204
Upper <- c(0.232, 0.420, 0.630, 0.067, 3.093); #mean of white 2011 Exp1 plus 5 sd
203205
Lower <- c(0.032, 0.180, 0.130, 0.0001, 0.493); #mean of white 2011 Exp1 minus 5 sd
204206
nTrials <- 10000
205-
output_fit_file <- "recovered_params.csv"
207+
output_fit_file <- sprintf(
208+
"recovered_params_%s.csv",
209+
format(Sys.time(),'%y_%m_%d_%H_%M_%S') # will indicate start time
210+
)
206211
numParams <- length(Upper)
207212

213+
fitOutput <-data.frame(matrix(ncol=9, nrow=0))
214+
colnames(fitOutput) <- c("subject", "a", "ter", "p", "rd", "sda", "fitStat", "iteNum", "seed")
215+
fitOutput <- data.frame(fitOutput)
216+
217+
# also write a .csv to append parms to at the end of loops
218+
write.csv(fitOutput, sprintf("%s/%s", output_fit_path, output_fit_file), row.names=FALSE, na="", quote = F)
219+
208220
for (condition in nTrials_to_sim) {
209221

210-
for (cb in seq(1, 100)) {
211-
set.seed(cb) # For reproducibility
212-
output_fit_file <- sprintf("%s/fit_data_%s_%s.csv", output_fit_path, condition, cb)
222+
for (cb in seq(1, 100)[96:100]) {
223+
start_time <- Sys.time()
224+
seed <- cb + sample(1:10e6, 1)
225+
set.seed(seed) # For reproducibility
213226
sim_data <- read.csv(sprintf("%s/sim_data_%s_%s.csv", output_sim_path, condition, cb))
214227

215228
HumanTrialCounts <- numeric(2) # just a vector of zeros
@@ -340,7 +353,7 @@ for (condition in nTrials_to_sim) {
340353
condition, cb
341354
)
342355
)
343-
# print(c(modelStart, s, subList[s], " pre_accuracy: ", preAccuracy, " condition_soc: ", conditionSoc))
356+
344357
# perform the fit
345358
OptimFitResults <- DEoptim(
346359
fitFunctionSSP,
@@ -389,7 +402,7 @@ for (condition in nTrials_to_sim) {
389402

390403
newRow<- NULL
391404
# make new row with values created above
392-
newRow <- data.frame(subject, bestParms1, bestParms2, bestParms3, bestParms4, bestParms5, bestFitStat, iter, preAccuracy, conditionSoc)
405+
newRow <- data.frame(subject, bestParms1, bestParms2, bestParms3, bestParms4, bestParms5, bestFitStat, iter, seed)
393406

394407
# appending the parms to the csv created before the loops
395408
write.table(newRow, file=sprintf("%s/%s", output_fit_path, output_fit_file), sep=",", append=TRUE, col.names = FALSE, row.names = FALSE)
@@ -401,6 +414,6 @@ for (condition in nTrials_to_sim) {
401414
alloc_time / 60)
402415
)
403416
} # end cb (cb) lop
404-
} # end nntrials (condition) loop
417+
} # end ntrials (condition) loop
405418

406-
sink()
419+
sink()

code/ddm/ssp_recovery/SSP_DDM_simulate_data.R

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,19 @@ start_time <- Sys.time()
77

88
library("DEoptim")
99
library("Rcpp")
10-
analysis_path = "/Users/fzaki001/thrive-theta-ddm/" # local
11-
# analysis_path = "/home/data/NDClab/analyses/thrive-theta-ddm/" # HPC
12-
output_sim_path <- '/Users/fzaki001/thrive-theta-ddm/derivatives/behavior/ddm_recovery/sim_data'
13-
output_fit_path <- '/Users/fzaki001/thrive-theta-ddm/derivatives/behavior/ddm_recovery/fit_data'
10+
# analysis_path = "/Users/fzaki001/thrive-theta-ddm/" # local
11+
analysis_path = "/home/data/NDClab/analyses/thrive-theta-ddm/" # HPC
12+
output_sim_path <- sprintf("%s/derivatives/behavior/ddm_recovery/sim_data/", analysis_path)
13+
output_fit_path <- sprintf("%s/derivatives/behavior/ddm_recovery/fit_data/", analysis_path)
1414

1515
# set up parameter range to sample for simulation of data
1616
Upper <- c(.19, .45, .55, .026, 2.6); # from White 2018: a ter p rd sda
1717
Lower <- c(.07, .15, .2, .01, 1); # from White 2018: a ter p rd sda
1818
numParams <- length(Upper)
1919

2020
# how many trials to simulate per condition
21-
nTrials_to_sim = c(50, 100, 200, 500, 1000, 5000)
21+
#nTrials_to_sim = c(50, 100, 200, 500, 1000, 5000)
22+
nTrials_to_sim = c(5, 10, 25)
2223

2324
dt <- 0.001
2425
vari <- 0.01
@@ -71,4 +72,4 @@ print(
7172
alloc_time / 60)
7273
)
7374

74-
sink()
75+
sink()

0 commit comments

Comments
 (0)