[Swift-commit] r2111 - in SwiftApps/SIDGrid/swift/projects/skenny/openmx: . scripts
noreply at svn.ci.uchicago.edu
noreply at svn.ci.uchicago.edu
Thu Jul 10 13:32:22 CDT 2008
Author: skenny
Date: 2008-07-10 13:32:22 -0500 (Thu, 10 Jul 2008)
New Revision: 2111
Added:
SwiftApps/SIDGrid/swift/projects/skenny/openmx/scripts/
SwiftApps/SIDGrid/swift/projects/skenny/openmx/scripts/SimpleCovariance.R
SwiftApps/SIDGrid/swift/projects/skenny/openmx/scripts/mxModelGen.R
Log:
R scritps for processing
Added: SwiftApps/SIDGrid/swift/projects/skenny/openmx/scripts/SimpleCovariance.R
===================================================================
--- SwiftApps/SIDGrid/swift/projects/skenny/openmx/scripts/SimpleCovariance.R (rev 0)
+++ SwiftApps/SIDGrid/swift/projects/skenny/openmx/scripts/SimpleCovariance.R 2008-07-10 18:32:22 UTC (rev 2111)
@@ -0,0 +1,34 @@
+library(OpenMx)
+
+## will need something like: R_SWIFT_ARGS=1_model.rdata
+
+inputfile <- Sys.getenv("R_INPUT")
+allinputs <- Sys.getenv("R_SWIFT_ARGS")
+
+print(allinputs)
+print(inputfile)
+
+covfile <- noquote(strsplit(inputfile," ")[[1]][1])
+modelobject <- noquote(strsplit(allinputs," ")[[1]][2])
+
+print(covfile)
+print(modelobject)
+
+covMatrix = matrix(c(read.table(covfile)))
+model = MxModel(); model = load(modelobject); model = saveLoadReference
+
+objective <- CovarianceObjective(model$cov, covMatrix)
+job <- MxJob(model, objective)
+jobClosure <- createMxClosure(job, use_R=TRUE)
+
+jobClosure();
+
+# user will get these output in the mediator's .tar file
+write.table(model$A$.values, file=paste(outname,"_asymmetric_coef.txt",sep=""), row.names=FALSE, col.names=FALSE)
+write.table(model$S$.values, file=paste(outname,"_symmetric_coef.txt",sep=""), row.names=FALSE, col.names=FALSE)
+save.Object(model,file="model.rdata")
+# swift will request this file explicitly to be used for model comparison
+# to reinvoke saved model:
+#
+
+
Added: SwiftApps/SIDGrid/swift/projects/skenny/openmx/scripts/mxModelGen.R
===================================================================
--- SwiftApps/SIDGrid/swift/projects/skenny/openmx/scripts/mxModelGen.R (rev 0)
+++ SwiftApps/SIDGrid/swift/projects/skenny/openmx/scripts/mxModelGen.R 2008-07-10 18:32:22 UTC (rev 2111)
@@ -0,0 +1,89 @@
+# generates all models for given number of connections
+# and writes them out as mxmodel objects
+
+library(OpenMx)
+dyn.load("/home/ac/skenny/perm.so")
+
+## should be like R_SWIFT_ARGS=3 3
+
+## get number of connections and array size (will be converted to nxn)
+
+allinputs <- Sys.getenv("R_SWIFT_ARGS")
+
+print(allinputs)
+
+connections <- noquote(strsplit(allinputs," ")[[1]][1])
+
+print(connections)
+
+numcol <- noquote(strsplit(allinputs," ")[[1]][2])
+
+print(numcol)
+
+rowcol = as.integer(numcol)
+size = rowcol*rowcol
+
+
+# creates the .adat files
+
+.C("run_perm", connections=as.integer(connections), size=as.integer(size))
+
+# read files and generate associated ap.adat, s.dat and sp.dat files
+# will do this in the c code
+
+# read in the data files to generate models and write as objects
+
+# dot is wildcard here, will need to adjust to it gets all 3 dat's
+count = 0
+for (i in list.files(pattern=".adat")){
+ model = MxModel()
+# model$A <- FullMatrix(rowcol, rowcol, free=TRUE)
+# model$S <- DiagMatrix(rowcol, rowcol)
+ model$F <- IdenMatrix(rowcol, rowcol) # modifiable in future, for now no filter
+ model$I <- IdenMatrix(rowcol, rowcol)
+ model$cov <- MxAlgebra(model$F %&% (solve(model$I - model$A) %&% model$S))
+
+# hard-coding for now
+a = double(length = size)
+apar = double(length = size)
+xindex = array(c(1:rowcol))
+yindex = array(c(1:rowcol))
+ apar = matrix(c(read.table(i)), nrow = rowcol, ncol = rowcol)
+ cnt = rowcol+1.0
+for(x in xindex)
+{
+ for(y in yindex)
+ {
+ if (apar[x,y] == 1){
+ apar[x,y] = cnt
+ cnt = cnt + 1}
+
+ }
+}
+print(apar)
+aval = matrix(c(read.table(i)), nrow = rowcol, ncol = rowcol)
+
+for(x in xindex)
+{
+ for(y in yindex)
+ {
+ if (aval[x,y] == 1)
+ aval[x,y] = 0.75
+
+ }
+}
+print(aval)
+
+
+ s = matrix(c(read.table("matrices/s.dat")), nrow = rowcol, ncol = rowcol)
+ spar = matrix(c(read.table("matrices/sp.dat")), nrow = rowcol, ncol = rowcol)
+
+ model$A$values <- aval
+ model$A$parameters <- apar
+ model$S$values <- s
+ model$S$parameters <- spar
+ count = count+1
+print(model$S)
+ save.Object(model,file=paste(count,"_model.rdata", sep=""))
+}
+system("tar -cf models.tar *rdata")
More information about the Swift-commit
mailing list