// nothing to do
}
// else
-// fprintf(stderr,"%s: unknown mode. Mode was set to \
-// HUNGARIAN_MODE_MINIMIZE_COST !\n", __FUNCTION__);
+// fprintf(stderr,"%s: unknown mode. Mode was set to HUNGARIAN_MODE_MINIMIZE_COST !\n", __FUNCTION__);
return rows;
}
}
//TODO: re-code this algorithm in a more readable way, based on
-//https://www.topcoder.com/community/data-science/data-science-tutorials/\
-// assignment-problem-and-hungarian-algorithm/
+//https://www.topcoder.com/community/data-science/data-science-tutorials/assignment-problem-and-hungarian-algorithm/
// Get the optimal assignment, by calling hungarian_solve above; "distances" in columns
void hungarianAlgorithm(double* distances, int* pn, int* assignment)
{
#!/bin/bash
-#PBS -l nodes=1:ppn=15,mem=8gb,pmem=512mb
-#PBS -j oe
-
-#PBS -o .output
+#$ -N morpheus
+#$ -m abes
+#$ -M benjamin@auder.net
+#$ -pe make 5
+#$ -l h_vmem=1G
+#$ -j y
+#$ -o .output
rm -f .output
WORKDIR=/workdir2/auder/morpheus/reports
cd $WORKDIR
-module load R
+module load R/3.6.0
+
+N=1000
+n=1e5
+nc=50
+
+link=logit
+# and disable d=20 to run faster
# arg --vanilla maybe possible on cluster
-for d in 2 5 10 20; do
- for link in "logit" "probit"; do
- R --slave --args N=1000 n=1e5 nc=15 d=$d link=$link <accuracy.R >out$d$link 2>&1
- done
+for d in 2 5 10; do
+ #for link in "logit" "probit"; do
+ R --slave --args N=$N n=$n nc=$nc d=$d link=$link <accuracy.R >out_$n$link$d 2>&1
+ #done
done
#for d in 2 5; do
# for n in 5000 10000 100000 500000 1000000; do
# for link in "logit" "probit"; do
-# R --slave --args N=1000 n=$n nc=64 d=$d link=$link <accuracy.R >out_$n$link$d 2>&1
+# R --slave --args N=$N n=$n nc=$nc d=$d link=$link <accuracy.R >out_$n$link$d 2>&1
# done
# done
#done
--- /dev/null
+library(morpheus)
+morph <- function(fargs) {
+ K <- fargs$optargs$K
+ M <- computeMoments(fargs$X, fargs$Y)
+ fargs$optargs$M <- M
+ mu <- computeMu(fargs$X, fargs$Y, fargs$optargs)
+ res2 <- NULL
+ tryCatch({
+ op <- optimParams(K,link,fargs$optargs)
+ x_init <- list(p=rep(1/K,K-1), beta=mu, b=rep(0,K))
+ res2 <- do.call(rbind, op$run(x_init))
+ }, error = function(e) {
+ res2 <- NA
+ })
+ res2
+}
+
+#model = binomial; default values:
+link = "probit"
+N <- 10
+d <- 2
+n <- 1e4
+ncores <- 1
+
+if (d == 2) {
+ K <- 2
+ p <- .5
+ b <- c(-.2, .5)
+ beta <- matrix( c(1,-2, 3,1), ncol=K )
+} else if (d == 5) {
+ K <- 2
+ p <- .5
+ b <- c(-.2, .5)
+ beta <- matrix( c(1,2,-1,0,3, 2,-3,0,1,0), ncol=K )
+} else if (d == 10) {
+ K <- 3
+ p <- c(.3, .3)
+ b <- c(-.2, 0, .5)
+ beta <- matrix( c(1,2,-1,0,3,4,-1,-3,0,2, 2,-3,0,1,0,-1,-4,3,2,0, -1,1,3,-1,0,0,2,0,1,-2), ncol=K )
+} else if (d == 20) {
+ K <- 3
+ p <- c(.3, .3)
+ b <- c(-.2, 0, .5)
+ beta <- matrix( c(1,2,-1,0,3,4,-1,-3,0,2,2,-3,0,1,0,-1,-4,3,2,0, -1,1,3,-1,0,0,2,0,1,-2,1,2,-1,0,3,4,-1,-3,0,2, 2,-3,0,1,0,-1,-4,3,2,0,1,1,2,2,-2,-2,3,1,0,0), ncol=K )
+}
+
+fargs = list(n=n, p=p, beta=beta, b=b)
+fargs$optargs = list(link=link)
+
+io = generateSampleIO(fargs$n, fargs$p, fargs$beta, fargs$b, fargs$optargs$link)
+fargs$X = io$X
+fargs$Y = io$Y
+fargs$optargs$K = ncol(fargs$beta)
+fargs$optargs$M = computeMoments(io$X,io$Y)
+
+res2 <- morph(fargs)
+
+save("res2", file="test.RData")