[ddf0cf]: / R-scripts / scripts / simulated3.ipynb

Download this file

1838 lines (1837 with data), 76.7 kB

{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "equal\n",
      "5\n",
      "VAE_FCTAE_EM:\t0.8493348 0.8093381 0.8123563 0.7995556 0.8052937\n",
      "AE_FAETC_EM:\t0.7305929 0.7634619 0.7726853 0.7759933 0.7762746\n",
      "AE_FCTAE_EM:\t0.9207857 0.9088667 0.885019 0.8641048 0.8987\n",
      "DAE_FAETC_EM:\t0.7874571 0.7924825 0.7651413 0.7957556 0.7800365\n",
      "DAE_FCTAE_EM:\t0.8781365 0.8675444 0.8450683 0.8852254 0.881327\n",
      "SVAE_FCTAE_EM:\t0.2052535 0.1937893 0.2034376 0.2000667 0.2019203\n",
      "MMDVAE_EM:\t0.6907236 0.6775745 0.710492 0.6831872 0.6926301\n",
      "\n",
      "10\n",
      "VAE_FCTAE_EM:\t0.758355 0.7923074 0.7701208 0.7740536 0.8087662 0.8172028 0.7957532 0.7437403 0.7497229 0.7881303\n",
      "AE_FAETC_EM:\t0.7393333 0.7186667 0.7486667 0.7683333 0.808 0.7509298 0.7136667 0.7466667 0.7242632 0.7206667\n",
      "AE_FCTAE_EM:\t0.8967325 0.9245455 0.8673699 0.8439271 0.8613498 0.871089 0.8818107 0.843031 0.8663918 0.8250542\n",
      "DAE_FAETC_EM:\t0.7773333 0.7272857 0.7086667 0.7266667 0.7826667 0.7343333 0.7893333 0.696 0.6953333 0.7278571\n",
      "DAE_FCTAE_EM:\t0.8433333 0.8219167 0.8467436 0.8740769 0.8717576 0.8292857 0.8875833 0.8660256 0.8012632 0.856549\n",
      "SVAE_FCTAE_EM:\t0.1591708 0.1614971 0.1591587 0.1671023 0.1534171 0.1651873 0.1553616 0.1658601 0.1576142 0.1600094\n",
      "MMDVAE_EM:\t0.7594876 0.7254535 0.7869272 0.7070993 0.7475013 0.7432933 0.7412182 0.7654683 0.7333339 0.7375071\n",
      "\n",
      "15\n",
      "VAE_FCTAE_EM:\t0.7709058 0.7611685 0.725512 0.808956 0.7473828 0.7762308 0.780849 0.7431538 0.7846158 0.736652 0.7923278 0.7640842 0.758185 0.7601735 0.7866136\n",
      "AE_FAETC_EM:\t0.7297436 0.7172344 0.7522007 0.7530066 0.7293088 0.7411557 0.7702198 0.7845604 0.7910256 0.7465278 0.7661787 0.7752747 0.7341026 0.798315 0.7948022\n",
      "AE_FCTAE_EM:\t0.813515 0.8480553 0.8243242 0.8718315 0.8912238 0.8817043 0.8846588 0.8738062 0.8711538 0.8817353 0.8577216 0.8634115 0.8764802 0.8667021 0.83273\n",
      "DAE_FAETC_EM:\t0.727534 0.7280633 0.713112 0.735641 0.7145971 0.7652198 0.7589579 0.7907326 0.7353893 0.7689142 0.7683805 0.7324443 0.7603729 0.7205657 0.7750414\n",
      "DAE_FCTAE_EM:\t0.7940128 0.7661172 0.8568864 0.8181319 0.8360806 0.8290476 0.8168864 0.8033124 0.8276374 0.8017611 0.8383736 0.7887949 0.847478 0.8298736 0.8756777\n",
      "SVAE_FCTAE_EM:\t0.1765508 0.1663713 0.1715346 0.1762493 0.1786312 0.1758448 0.1786001 0.181078 0.1908793 0.1676178 0.1783602 0.1773119 0.1785067 0.1749671 0.1731573\n",
      "MMDVAE_EM:\t0.6988397 0.6905553 0.7603651 0.7306667 0.7253751 0.7249014 0.7041905 0.7156468 0.7549524 0.7276808 0.6985091 0.7295652 0.7046456 0.7887875 0.7003095\n",
      "\n",
      "heterogeneous\n",
      "5\n",
      "VAE_FCTAE_EM:\t0.788704 0.8800345 0.845978 0.8114592 0.7931384\n",
      "AE_FAETC_EM:\t0.6811634 0.6546725 0.7455464 0.7188325 0.7406956\n",
      "AE_FCTAE_EM:\t0.9001578 0.8711772 0.9118168 0.8735622 0.8756521\n",
      "DAE_FAETC_EM:\t0.7571631 0.7762026 0.7273021 0.7614543 0.7547438\n",
      "DAE_FCTAE_EM:\t0.7839074 0.7187035 0.7828717 0.7842619 0.7574162\n",
      "SVAE_FCTAE_EM:\t0.203859 0.2003706 0.2031883 0.2084795 0.1973851\n",
      "MMDVAE_EM:\t0.7006904 0.681042 0.7057124 0.6715363 0.6967064\n",
      "\n",
      "10\n",
      "VAE_FCTAE_EM:\t0.6597871 0.6756537 0.693256 0.7053431 0.7038487 0.6154055 0.6761671 0.7113576 0.6934843 0.7026042\n",
      "AE_FAETC_EM:\t0.7606359 0.7215738 0.7564599 0.726074 0.7819293 0.7207249 0.6776939 0.6747369 0.7217847 0.7451345\n",
      "AE_FCTAE_EM:\t0.8665326 0.8202176 0.840857 0.8251221 0.7967765 0.8630213 0.8476865 0.8508921 0.8323401 0.7981338\n",
      "DAE_FAETC_EM:\t0.7272786 0.7072266 0.6741613 0.7518748 0.7218129 0.7299205 0.7320382 0.685665 0.6905846 0.7430155\n",
      "DAE_FCTAE_EM:\t0.764177 0.7534933 0.7968361 0.7969159 0.8022471 0.8228534 0.7596997 0.8011668 0.853401 0.7809182\n",
      "SVAE_FCTAE_EM:\t0.154768 0.1544365 0.1490643 0.1518639 0.1515257 0.1461104 0.1511859 0.1519876 0.1473031 0.1464361\n",
      "MMDVAE_EM:\t0.651161 0.7064776 0.7003462 0.7564383 0.6819459 0.7054679 0.742896 0.7141084 0.72529 0.7240387\n",
      "\n",
      "15\n",
      "VAE_FCTAE_EM:\t0.6225732 0.5895894 0.534353 0.563673 0.5873184 0.5686807 0.6257382 0.6199699 0.5934381 0.6576383 0.5762374 0.6266566 0.5999495 0.6454765 0.6205498\n",
      "AE_FAETC_EM:\t0.6864116 0.7209304 0.6908687 0.6855 0.7564798 0.6772753 0.6749676 0.7431078 0.7049959 0.7238462 0.6737298 0.7303945 0.7581027 0.7177176 0.7307955\n",
      "AE_FCTAE_EM:\t0.7819762 0.8145357 0.8139048 0.7872857 0.7963254 0.7849502 0.7927619 0.8021746 0.7340159 0.8054502 0.7569167 0.7982738 0.7606284 0.8176389 0.7734127\n",
      "DAE_FAETC_EM:\t0.6111207 0.6625173 0.6101504 0.6825909 0.7029449 0.6546229 0.6301422 0.6386405 0.6269395 0.6753231 0.6376431 0.6977659 0.6822767 0.6368745 0.591305\n",
      "DAE_FCTAE_EM:\t0.7528929 0.7683135 0.7399141 0.7691389 0.7325833 0.7500079 0.7704181 0.7674524 0.7853135 0.7489141 0.7745296 0.7397143 0.8132024 0.7545159 0.7559499\n",
      "SVAE_FCTAE_EM:\t0.1592352 0.1555998 0.1569537 0.1621479 0.1506288 0.1664354 0.155096 0.1621046 0.1641762 0.1596278 0.1528357 0.1503384 0.154976 0.1440018 0.1500436\n",
      "MMDVAE_EM:\t0.6598508 0.6063754 0.6759849 0.6587856 0.6742041 0.6590008 0.6307302 0.6935759 0.6922985 0.6769722 0.6256822 0.6842047 0.5814451 0.6493218 0.5932973\n",
      "\n"
     ]
    }
   ],
   "source": [
    "library(\"clusterCrit\")\n",
    "datatypes<-c(\"equal\",\"heterogeneous\")\n",
    "typenums<-c(5,10,15)\n",
    "data_names<-c('VAE_FCTAE_EM','AE_FAETC_EM', 'AE_FCTAE_EM', 'DAE_FAETC_EM', 'DAE_FCTAE_EM','SVAE_FCTAE_EM','MMDVAE_EM')\n",
    "\n",
    "for(datatype in datatypes){\n",
    "    cat(datatype)\n",
    "    cat('\\n')\n",
    "    for(typenum in typenums){\n",
    "        cat(typenum)\n",
    "        cat('\\n')\n",
    "        for(data_name in data_names){\n",
    "            cat(data_name)\n",
    "            cat(':\\t')\n",
    "            number_cl=typenum\n",
    "            ind <- 0\n",
    "            JI_final <- matrix(data=NA, nrow=number_cl, ncol=1)\n",
    "            clpath=paste(\"../data/simulations_20210329212141/\",datatype,'/',typenum,'/','clusters.txt',sep='')\n",
    "            cl  <- as.matrix(read.table(clpath, \n",
    "                                        sep=\"\\t\", row.names=1, header=TRUE))\n",
    "            #cat(\"cl:\",cl,\"\\t\")\n",
    "            cl2 <- as.matrix(as.numeric(cl[,2]))\n",
    "            rownames(cl2) <- cl[,1]\n",
    "            datapath=paste(\"../data/simulations/\",datatype,'/',typenum,'/',data_name,'_',typenum,'.txt',sep='')\n",
    "            factorization=read.table(datapath, sep=\" \", row.names=cl[,1],header=FALSE)\n",
    "\n",
    "            factors <- factorization\n",
    "           \n",
    "            # Clustering by Kmeans\n",
    "            JI_good <- numeric(0)\n",
    "            for (run in 1:100) {\n",
    "            kmeans.out <- kmeans(factors, centers=number_cl) \n",
    "            clust_iCluster <- as.matrix(kmeans.out$cluster)\n",
    "\n",
    "            ######creation sets of samples\n",
    "            JI_mat <- numeric(0)\n",
    "            for (p in 1:number_cl) {\n",
    "                x1  <- rownames(clust_iCluster)[which(clust_iCluster[,1]==p)]\n",
    "\n",
    "\n",
    "                row <- numeric(0)\n",
    "                for(j in 1:number_cl) {\n",
    "                    x2  <- rownames(cl2)[which(cl2[,1]==j)]\n",
    "                    I   <- length(intersect(x1,x2))#交集\n",
    "                    S   <- I/(length(x1)+length(x2)-I)\n",
    "                    row <- cbind(row,S)\n",
    "                 }\n",
    "                 JI_mat <- rbind(JI_mat,row)\n",
    "\n",
    "\n",
    "             }\n",
    "             JI_good <- rbind(JI_good,apply(JI_mat,1,max))\n",
    "            }\n",
    "            JI_final[1:number_cl] <- apply(JI_good,2,mean)\n",
    "            cat(JI_final)\n",
    "            cat('\\n')\n",
    "\n",
    "        }\n",
    "        cat('\\n')\n",
    "    }\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "cl2: 4 7 3 1 5 4 3 3 10 4 5 5 9 3 10 5 6 8 2 2 1 7 3 1 1 5 9 10 3 2 8 2 8 1 10 2 8 9 6 8 2 6 8 6 5 2 7 4 4 1 5 8 6 1 3 2 6 9 1 1 9 1 4 6 8 6 1 9 8 1 10 1 4 5 2 10 6 8 6 4 3 10 3 9 5 4 9 9 9 5 1 7 10 1 7 10 4 10 3 2 \n",
      "clust_iCluster: 3 9 2 8 3 3 10 2 9 3 3 3 6 10 9 3 4 5 7 7 8 9 10 8 8 3 6 9 2 7 5 7 5 8 9 7 5 6 4 5 7 4 5 4 3 7 9 3 3 8 3 5 4 8 10 7 4 1 8 8 1 8 3 4 5 4 8 1 5 8 9 8 3 3 7 9 4 5 4 3 2 9 10 1 3 3 1 1 1 3 8 9 9 8 9 9 3 9 2 7 \n",
      "[1] \"subject58\" \"subject61\" \"subject68\" \"subject84\" \"subject87\" \"subject88\"\n",
      "[7] \"subject89\"\n",
      "x2: subject4 subject21 subject24 subject25 subject34 subject50 subject54 subject59 subject60 subject62 subject67 subject70 subject72 subject91 subject94 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 0 \n",
      "x2: subject19 subject20 subject30 subject32 subject36 subject41 subject46 subject56 subject75 subject100 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 0 0 \n",
      "x2: subject3 subject7 subject8 subject14 subject23 subject29 subject55 subject81 subject83 subject99 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 0 0 0 \n",
      "x2: subject1 subject6 subject10 subject48 subject49 subject63 subject73 subject80 subject86 subject97 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 0 0 0 0 \n",
      "x2: subject5 subject11 subject12 subject16 subject26 subject45 subject51 subject74 subject85 subject90 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 0 0 0 0 0 \n",
      "x2: subject17 subject39 subject42 subject44 subject53 subject57 subject64 subject66 subject77 subject79 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 0 0 0 0 0 0 \n",
      "x2: subject2 subject22 subject47 subject92 subject95 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 0 0 0 0 0 0 0 \n",
      "x2: subject18 subject31 subject33 subject37 subject40 subject43 subject52 subject65 subject69 subject78 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 0 0 0 0 0 0 0 0 \n",
      "x2: subject13 subject27 subject38 subject58 subject61 subject68 subject84 subject87 subject88 subject89 \n",
      "I: 7 \n",
      "S: 0.7 \n",
      "row: 0 0 0 0 0 0 0 0 0.7 \n",
      "x2: subject9 subject15 subject28 subject35 subject71 subject76 subject82 subject93 subject96 subject98 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 0 0 0 0 0 0 0 0 0.7 0 \n",
      "JI_mat: 0 0 0 0 0 0 0 0 0.7 0 \n",
      "     S S S S S S S S   S S\n",
      "[1,] 0 0 0 0 0 0 0 0 0.7 0\n",
      "[1] \"subject3\"  \"subject8\"  \"subject29\" \"subject81\" \"subject99\"\n",
      "x2: subject4 subject21 subject24 subject25 subject34 subject50 subject54 subject59 subject60 subject62 subject67 subject70 subject72 subject91 subject94 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 0 \n",
      "x2: subject19 subject20 subject30 subject32 subject36 subject41 subject46 subject56 subject75 subject100 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 0 0 \n",
      "x2: subject3 subject7 subject8 subject14 subject23 subject29 subject55 subject81 subject83 subject99 \n",
      "I: 5 \n",
      "S: 0.5 \n",
      "row: 0 0 0.5 \n",
      "x2: subject1 subject6 subject10 subject48 subject49 subject63 subject73 subject80 subject86 subject97 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 0 0 0.5 0 \n",
      "x2: subject5 subject11 subject12 subject16 subject26 subject45 subject51 subject74 subject85 subject90 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 0 0 0.5 0 0 \n",
      "x2: subject17 subject39 subject42 subject44 subject53 subject57 subject64 subject66 subject77 subject79 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 0 0 0.5 0 0 0 \n",
      "x2: subject2 subject22 subject47 subject92 subject95 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 0 0 0.5 0 0 0 0 \n",
      "x2: subject18 subject31 subject33 subject37 subject40 subject43 subject52 subject65 subject69 subject78 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 0 0 0.5 0 0 0 0 0 \n",
      "x2: subject13 subject27 subject38 subject58 subject61 subject68 subject84 subject87 subject88 subject89 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 0 0 0.5 0 0 0 0 0 0 \n",
      "x2: subject9 subject15 subject28 subject35 subject71 subject76 subject82 subject93 subject96 subject98 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 0 0 0.5 0 0 0 0 0 0 0 \n",
      "JI_mat: 0 0 0 0 0 0.5 0 0 0 0 0 0 0 0 0 0 0.7 0 0 0 \n",
      "     S S   S S S S S S   S S\n",
      "[1,] 0 0 0.0 0 0 0 0 0 0.7 0\n",
      "[2,] 0 0 0.5 0 0 0 0 0 0.0 0\n",
      " [1] \"subject1\"  \"subject5\"  \"subject6\"  \"subject10\" \"subject11\" \"subject12\"\n",
      " [7] \"subject16\" \"subject26\" \"subject45\" \"subject48\" \"subject49\" \"subject51\"\n",
      "[13] \"subject63\" \"subject73\" \"subject74\" \"subject80\" \"subject85\" \"subject86\"\n",
      "[19] \"subject90\" \"subject97\"\n",
      "x2: subject4 subject21 subject24 subject25 subject34 subject50 subject54 subject59 subject60 subject62 subject67 subject70 subject72 subject91 subject94 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 0 \n",
      "x2: subject19 subject20 subject30 subject32 subject36 subject41 subject46 subject56 subject75 subject100 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 0 0 \n",
      "x2: subject3 subject7 subject8 subject14 subject23 subject29 subject55 subject81 subject83 subject99 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 0 0 0 \n",
      "x2: subject1 subject6 subject10 subject48 subject49 subject63 subject73 subject80 subject86 subject97 \n",
      "I: 10 \n",
      "S: 0.5 \n",
      "row: 0 0 0 0.5 \n",
      "x2: subject5 subject11 subject12 subject16 subject26 subject45 subject51 subject74 subject85 subject90 \n",
      "I: 10 \n",
      "S: 0.5 \n",
      "row: 0 0 0 0.5 0.5 \n",
      "x2: subject17 subject39 subject42 subject44 subject53 subject57 subject64 subject66 subject77 subject79 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 0 0 0 0.5 0.5 0 \n",
      "x2: subject2 subject22 subject47 subject92 subject95 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 0 0 0 0.5 0.5 0 0 \n",
      "x2: subject18 subject31 subject33 subject37 subject40 subject43 subject52 subject65 subject69 subject78 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 0 0 0 0.5 0.5 0 0 0 \n",
      "x2: subject13 subject27 subject38 subject58 subject61 subject68 subject84 subject87 subject88 subject89 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 0 0 0 0.5 0.5 0 0 0 0 \n",
      "x2: subject9 subject15 subject28 subject35 subject71 subject76 subject82 subject93 subject96 subject98 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 0 0 0 0.5 0.5 0 0 0 0 0 \n",
      "JI_mat: 0 0 0 0 0 0 0 0.5 0 0 0 0.5 0 0 0.5 0 0 0 0 0 0 0 0 0 0.7 0 0 0 0 0 \n",
      "     S S   S   S   S S S S   S S\n",
      "[1,] 0 0 0.0 0.0 0.0 0 0 0 0.7 0\n",
      "[2,] 0 0 0.5 0.0 0.0 0 0 0 0.0 0\n",
      "[3,] 0 0 0.0 0.5 0.5 0 0 0 0.0 0\n",
      " [1] \"subject17\" \"subject39\" \"subject42\" \"subject44\" \"subject53\" \"subject57\"\n",
      " [7] \"subject64\" \"subject66\" \"subject77\" \"subject79\"\n",
      "x2: subject4 subject21 subject24 subject25 subject34 subject50 subject54 subject59 subject60 subject62 subject67 subject70 subject72 subject91 subject94 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 0 \n",
      "x2: subject19 subject20 subject30 subject32 subject36 subject41 subject46 subject56 subject75 subject100 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 0 0 \n",
      "x2: subject3 subject7 subject8 subject14 subject23 subject29 subject55 subject81 subject83 subject99 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 0 0 0 \n",
      "x2: subject1 subject6 subject10 subject48 subject49 subject63 subject73 subject80 subject86 subject97 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 0 0 0 0 \n",
      "x2: subject5 subject11 subject12 subject16 subject26 subject45 subject51 subject74 subject85 subject90 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 0 0 0 0 0 \n",
      "x2: subject17 subject39 subject42 subject44 subject53 subject57 subject64 subject66 subject77 subject79 \n",
      "I: 10 \n",
      "S: 1 \n",
      "row: 0 0 0 0 0 1 \n",
      "x2: subject2 subject22 subject47 subject92 subject95 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 0 0 0 0 0 1 0 \n",
      "x2: subject18 subject31 subject33 subject37 subject40 subject43 subject52 subject65 subject69 subject78 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 0 0 0 0 0 1 0 0 \n",
      "x2: subject13 subject27 subject38 subject58 subject61 subject68 subject84 subject87 subject88 subject89 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 0 0 0 0 0 1 0 0 0 \n",
      "x2: subject9 subject15 subject28 subject35 subject71 subject76 subject82 subject93 subject96 subject98 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 0 0 0 0 0 1 0 0 0 0 \n",
      "JI_mat: 0 0 0 0 0 0 0 0 0 0.5 0 0 0 0 0.5 0 0 0 0.5 0 0 0 0 1 0 0 0 0 0 0 0 0 0.7 0 0 0 0 0 0 0 \n",
      "     S S   S   S   S S S S   S S\n",
      "[1,] 0 0 0.0 0.0 0.0 0 0 0 0.7 0\n",
      "[2,] 0 0 0.5 0.0 0.0 0 0 0 0.0 0\n",
      "[3,] 0 0 0.0 0.5 0.5 0 0 0 0.0 0\n",
      "[4,] 0 0 0.0 0.0 0.0 1 0 0 0.0 0\n",
      " [1] \"subject18\" \"subject31\" \"subject33\" \"subject37\" \"subject40\" \"subject43\"\n",
      " [7] \"subject52\" \"subject65\" \"subject69\" \"subject78\"\n",
      "x2: subject4 subject21 subject24 subject25 subject34 subject50 subject54 subject59 subject60 subject62 subject67 subject70 subject72 subject91 subject94 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 0 \n",
      "x2: subject19 subject20 subject30 subject32 subject36 subject41 subject46 subject56 subject75 subject100 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 0 0 \n",
      "x2: subject3 subject7 subject8 subject14 subject23 subject29 subject55 subject81 subject83 subject99 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 0 0 0 \n",
      "x2: subject1 subject6 subject10 subject48 subject49 subject63 subject73 subject80 subject86 subject97 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 0 0 0 0 \n",
      "x2: subject5 subject11 subject12 subject16 subject26 subject45 subject51 subject74 subject85 subject90 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 0 0 0 0 0 \n",
      "x2: subject17 subject39 subject42 subject44 subject53 subject57 subject64 subject66 subject77 subject79 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 0 0 0 0 0 0 \n",
      "x2: subject2 subject22 subject47 subject92 subject95 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 0 0 0 0 0 0 0 \n",
      "x2: subject18 subject31 subject33 subject37 subject40 subject43 subject52 subject65 subject69 subject78 \n",
      "I: 10 \n",
      "S: 1 \n",
      "row: 0 0 0 0 0 0 0 1 \n",
      "x2: subject13 subject27 subject38 subject58 subject61 subject68 subject84 subject87 subject88 subject89 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 0 0 0 0 0 0 0 1 0 \n",
      "x2: subject9 subject15 subject28 subject35 subject71 subject76 subject82 subject93 subject96 subject98 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 0 0 0 0 0 0 0 1 0 0 \n",
      "JI_mat: 0 0 0 0 0 0 0 0 0 0 0 0.5 0 0 0 0 0 0.5 0 0 0 0 0.5 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0.7 0 0 0 0 0 0 0 0 0 \n",
      "     S S   S   S   S S S S   S S\n",
      "[1,] 0 0 0.0 0.0 0.0 0 0 0 0.7 0\n",
      "[2,] 0 0 0.5 0.0 0.0 0 0 0 0.0 0\n",
      "[3,] 0 0 0.0 0.5 0.5 0 0 0 0.0 0\n",
      "[4,] 0 0 0.0 0.0 0.0 1 0 0 0.0 0\n",
      "[5,] 0 0 0.0 0.0 0.0 0 0 1 0.0 0\n",
      "[1] \"subject13\" \"subject27\" \"subject38\"\n",
      "x2: subject4 subject21 subject24 subject25 subject34 subject50 subject54 subject59 subject60 subject62 subject67 subject70 subject72 subject91 subject94 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 0 \n",
      "x2: subject19 subject20 subject30 subject32 subject36 subject41 subject46 subject56 subject75 subject100 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 0 0 \n",
      "x2: subject3 subject7 subject8 subject14 subject23 subject29 subject55 subject81 subject83 subject99 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 0 0 0 \n",
      "x2: subject1 subject6 subject10 subject48 subject49 subject63 subject73 subject80 subject86 subject97 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 0 0 0 0 \n",
      "x2: subject5 subject11 subject12 subject16 subject26 subject45 subject51 subject74 subject85 subject90 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 0 0 0 0 0 \n",
      "x2: subject17 subject39 subject42 subject44 subject53 subject57 subject64 subject66 subject77 subject79 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 0 0 0 0 0 0 \n",
      "x2: subject2 subject22 subject47 subject92 subject95 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 0 0 0 0 0 0 0 \n",
      "x2: subject18 subject31 subject33 subject37 subject40 subject43 subject52 subject65 subject69 subject78 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 0 0 0 0 0 0 0 0 \n",
      "x2: subject13 subject27 subject38 subject58 subject61 subject68 subject84 subject87 subject88 subject89 \n",
      "I: 3 \n",
      "S: 0.3 \n",
      "row: 0 0 0 0 0 0 0 0 0.3 \n",
      "x2: subject9 subject15 subject28 subject35 subject71 subject76 subject82 subject93 subject96 subject98 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 0 0 0 0 0 0 0 0 0.3 0 \n",
      "JI_mat: 0 0 0 0 0 0 0 0 0 0 0 0 0 0.5 0 0 0 0 0 0 0.5 0 0 0 0 0 0.5 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0.7 0 0 0 0 0.3 0 0 0 0 0 0 \n",
      "     S S   S   S   S S S S   S S\n",
      "[1,] 0 0 0.0 0.0 0.0 0 0 0 0.7 0\n",
      "[2,] 0 0 0.5 0.0 0.0 0 0 0 0.0 0\n",
      "[3,] 0 0 0.0 0.5 0.5 0 0 0 0.0 0\n",
      "[4,] 0 0 0.0 0.0 0.0 1 0 0 0.0 0\n",
      "[5,] 0 0 0.0 0.0 0.0 0 0 1 0.0 0\n",
      "[6,] 0 0 0.0 0.0 0.0 0 0 0 0.3 0\n",
      " [1] \"subject19\"  \"subject20\"  \"subject30\"  \"subject32\"  \"subject36\" \n",
      " [6] \"subject41\"  \"subject46\"  \"subject56\"  \"subject75\"  \"subject100\"\n",
      "x2: subject4 subject21 subject24 subject25 subject34 subject50 subject54 subject59 subject60 subject62 subject67 subject70 subject72 subject91 subject94 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 0 \n",
      "x2: subject19 subject20 subject30 subject32 subject36 subject41 subject46 subject56 subject75 subject100 \n",
      "I: 10 \n",
      "S: 1 \n",
      "row: 0 1 \n",
      "x2: subject3 subject7 subject8 subject14 subject23 subject29 subject55 subject81 subject83 subject99 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 0 1 0 \n",
      "x2: subject1 subject6 subject10 subject48 subject49 subject63 subject73 subject80 subject86 subject97 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 0 1 0 0 \n",
      "x2: subject5 subject11 subject12 subject16 subject26 subject45 subject51 subject74 subject85 subject90 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 0 1 0 0 0 \n",
      "x2: subject17 subject39 subject42 subject44 subject53 subject57 subject64 subject66 subject77 subject79 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 0 1 0 0 0 0 \n",
      "x2: subject2 subject22 subject47 subject92 subject95 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 0 1 0 0 0 0 0 \n",
      "x2: subject18 subject31 subject33 subject37 subject40 subject43 subject52 subject65 subject69 subject78 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 0 1 0 0 0 0 0 0 \n",
      "x2: subject13 subject27 subject38 subject58 subject61 subject68 subject84 subject87 subject88 subject89 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 0 1 0 0 0 0 0 0 0 \n",
      "x2: subject9 subject15 subject28 subject35 subject71 subject76 subject82 subject93 subject96 subject98 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 0 1 0 0 0 0 0 0 0 0 \n",
      "JI_mat: 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0.5 0 0 0 0 0 0 0 0.5 0 0 0 0 0 0 0.5 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0.7 0 0 0 0 0.3 0 0 0 0 0 0 0 0 \n",
      "     S S   S   S   S S S S   S S\n",
      "[1,] 0 0 0.0 0.0 0.0 0 0 0 0.7 0\n",
      "[2,] 0 0 0.5 0.0 0.0 0 0 0 0.0 0\n",
      "[3,] 0 0 0.0 0.5 0.5 0 0 0 0.0 0\n",
      "[4,] 0 0 0.0 0.0 0.0 1 0 0 0.0 0\n",
      "[5,] 0 0 0.0 0.0 0.0 0 0 1 0.0 0\n",
      "[6,] 0 0 0.0 0.0 0.0 0 0 0 0.3 0\n",
      "[7,] 0 1 0.0 0.0 0.0 0 0 0 0.0 0\n",
      " [1] \"subject4\"  \"subject21\" \"subject24\" \"subject25\" \"subject34\" \"subject50\"\n",
      " [7] \"subject54\" \"subject59\" \"subject60\" \"subject62\" \"subject67\" \"subject70\"\n",
      "[13] \"subject72\" \"subject91\" \"subject94\"\n",
      "x2: subject4 subject21 subject24 subject25 subject34 subject50 subject54 subject59 subject60 subject62 subject67 subject70 subject72 subject91 subject94 \n",
      "I: 15 \n",
      "S: 1 \n",
      "row: 1 \n",
      "x2: subject19 subject20 subject30 subject32 subject36 subject41 subject46 subject56 subject75 subject100 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 1 0 \n",
      "x2: subject3 subject7 subject8 subject14 subject23 subject29 subject55 subject81 subject83 subject99 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 1 0 0 \n",
      "x2: subject1 subject6 subject10 subject48 subject49 subject63 subject73 subject80 subject86 subject97 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 1 0 0 0 \n",
      "x2: subject5 subject11 subject12 subject16 subject26 subject45 subject51 subject74 subject85 subject90 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 1 0 0 0 0 \n",
      "x2: subject17 subject39 subject42 subject44 subject53 subject57 subject64 subject66 subject77 subject79 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 1 0 0 0 0 0 \n",
      "x2: subject2 subject22 subject47 subject92 subject95 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 1 0 0 0 0 0 0 \n",
      "x2: subject18 subject31 subject33 subject37 subject40 subject43 subject52 subject65 subject69 subject78 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 1 0 0 0 0 0 0 0 \n",
      "x2: subject13 subject27 subject38 subject58 subject61 subject68 subject84 subject87 subject88 subject89 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 1 0 0 0 0 0 0 0 0 \n",
      "x2: subject9 subject15 subject28 subject35 subject71 subject76 subject82 subject93 subject96 subject98 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 1 0 0 0 0 0 0 0 0 0 \n",
      "JI_mat: 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0.5 0 0 0 0 0 0 0 0 0.5 0 0 0 0 0 0 0 0.5 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0.7 0 0 0 0 0.3 0 0 0 0 0 0 0 0 0 0 \n",
      "     S S   S   S   S S S S   S S\n",
      "[1,] 0 0 0.0 0.0 0.0 0 0 0 0.7 0\n",
      "[2,] 0 0 0.5 0.0 0.0 0 0 0 0.0 0\n",
      "[3,] 0 0 0.0 0.5 0.5 0 0 0 0.0 0\n",
      "[4,] 0 0 0.0 0.0 0.0 1 0 0 0.0 0\n",
      "[5,] 0 0 0.0 0.0 0.0 0 0 1 0.0 0\n",
      "[6,] 0 0 0.0 0.0 0.0 0 0 0 0.3 0\n",
      "[7,] 0 1 0.0 0.0 0.0 0 0 0 0.0 0\n",
      "[8,] 1 0 0.0 0.0 0.0 0 0 0 0.0 0\n",
      " [1] \"subject2\"  \"subject9\"  \"subject15\" \"subject22\" \"subject28\" \"subject35\"\n",
      " [7] \"subject47\" \"subject71\" \"subject76\" \"subject82\" \"subject92\" \"subject93\"\n",
      "[13] \"subject95\" \"subject96\" \"subject98\"\n",
      "x2: subject4 subject21 subject24 subject25 subject34 subject50 subject54 subject59 subject60 subject62 subject67 subject70 subject72 subject91 subject94 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 0 \n",
      "x2: subject19 subject20 subject30 subject32 subject36 subject41 subject46 subject56 subject75 subject100 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 0 0 \n",
      "x2: subject3 subject7 subject8 subject14 subject23 subject29 subject55 subject81 subject83 subject99 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 0 0 0 \n",
      "x2: subject1 subject6 subject10 subject48 subject49 subject63 subject73 subject80 subject86 subject97 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 0 0 0 0 \n",
      "x2: subject5 subject11 subject12 subject16 subject26 subject45 subject51 subject74 subject85 subject90 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 0 0 0 0 0 \n",
      "x2: subject17 subject39 subject42 subject44 subject53 subject57 subject64 subject66 subject77 subject79 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 0 0 0 0 0 0 \n",
      "x2: subject2 subject22 subject47 subject92 subject95 \n",
      "I: 5 \n",
      "S: 0.3333333 \n",
      "row: 0 0 0 0 0 0 0.3333333 \n",
      "x2: subject18 subject31 subject33 subject37 subject40 subject43 subject52 subject65 subject69 subject78 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 0 0 0 0 0 0 0.3333333 0 \n",
      "x2: subject13 subject27 subject38 subject58 subject61 subject68 subject84 subject87 subject88 subject89 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 0 0 0 0 0 0 0.3333333 0 0 \n",
      "x2: subject9 subject15 subject28 subject35 subject71 subject76 subject82 subject93 subject96 subject98 \n",
      "I: 10 \n",
      "S: 0.6666667 \n",
      "row: 0 0 0 0 0 0 0.3333333 0 0 0.6666667 \n",
      "JI_mat: 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0.5 0 0 0 0 0 0 0 0 0 0.5 0 0 0 0 0 0 0 0 0.5 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0.3333333 0 0 0 0 1 0 0 0 0 0.7 0 0 0 0 0.3 0 0 0 0 0 0 0 0 0 0 0 0.6666667 \n",
      "      S S   S   S   S S         S S   S         S\n",
      " [1,] 0 0 0.0 0.0 0.0 0 0.0000000 0 0.7 0.0000000\n",
      " [2,] 0 0 0.5 0.0 0.0 0 0.0000000 0 0.0 0.0000000\n",
      " [3,] 0 0 0.0 0.5 0.5 0 0.0000000 0 0.0 0.0000000\n",
      " [4,] 0 0 0.0 0.0 0.0 1 0.0000000 0 0.0 0.0000000\n",
      " [5,] 0 0 0.0 0.0 0.0 0 0.0000000 1 0.0 0.0000000\n",
      " [6,] 0 0 0.0 0.0 0.0 0 0.0000000 0 0.3 0.0000000\n",
      " [7,] 0 1 0.0 0.0 0.0 0 0.0000000 0 0.0 0.0000000\n",
      " [8,] 1 0 0.0 0.0 0.0 0 0.0000000 0 0.0 0.0000000\n",
      " [9,] 0 0 0.0 0.0 0.0 0 0.3333333 0 0.0 0.6666667\n",
      "[1] \"subject7\"  \"subject14\" \"subject23\" \"subject55\" \"subject83\"\n",
      "x2: subject4 subject21 subject24 subject25 subject34 subject50 subject54 subject59 subject60 subject62 subject67 subject70 subject72 subject91 subject94 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 0 \n",
      "x2: subject19 subject20 subject30 subject32 subject36 subject41 subject46 subject56 subject75 subject100 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 0 0 \n",
      "x2: subject3 subject7 subject8 subject14 subject23 subject29 subject55 subject81 subject83 subject99 \n",
      "I: 5 \n",
      "S: 0.5 \n",
      "row: 0 0 0.5 \n",
      "x2: subject1 subject6 subject10 subject48 subject49 subject63 subject73 subject80 subject86 subject97 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 0 0 0.5 0 \n",
      "x2: subject5 subject11 subject12 subject16 subject26 subject45 subject51 subject74 subject85 subject90 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 0 0 0.5 0 0 \n",
      "x2: subject17 subject39 subject42 subject44 subject53 subject57 subject64 subject66 subject77 subject79 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 0 0 0.5 0 0 0 \n",
      "x2: subject2 subject22 subject47 subject92 subject95 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 0 0 0.5 0 0 0 0 \n",
      "x2: subject18 subject31 subject33 subject37 subject40 subject43 subject52 subject65 subject69 subject78 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 0 0 0.5 0 0 0 0 0 \n",
      "x2: subject13 subject27 subject38 subject58 subject61 subject68 subject84 subject87 subject88 subject89 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 0 0 0.5 0 0 0 0 0 0 \n",
      "x2: subject9 subject15 subject28 subject35 subject71 subject76 subject82 subject93 subject96 subject98 \n",
      "I: 0 \n",
      "S: 0 \n",
      "row: 0 0 0.5 0 0 0 0 0 0 0 \n",
      "JI_mat: 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0.5 0 0 0 0 0 0 0 0.5 0 0 0.5 0 0 0 0 0 0 0 0 0 0.5 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.3333333 0 0 0 0 0 1 0 0 0 0 0 0.7 0 0 0 0 0.3 0 0 0 0 0 0 0 0 0 0 0 0 0.6666667 0 \n",
      "      S S   S   S   S S         S S   S         S\n",
      " [1,] 0 0 0.0 0.0 0.0 0 0.0000000 0 0.7 0.0000000\n",
      " [2,] 0 0 0.5 0.0 0.0 0 0.0000000 0 0.0 0.0000000\n",
      " [3,] 0 0 0.0 0.5 0.5 0 0.0000000 0 0.0 0.0000000\n",
      " [4,] 0 0 0.0 0.0 0.0 1 0.0000000 0 0.0 0.0000000\n",
      " [5,] 0 0 0.0 0.0 0.0 0 0.0000000 1 0.0 0.0000000\n",
      " [6,] 0 0 0.0 0.0 0.0 0 0.0000000 0 0.3 0.0000000\n",
      " [7,] 0 1 0.0 0.0 0.0 0 0.0000000 0 0.0 0.0000000\n",
      " [8,] 1 0 0.0 0.0 0.0 0 0.0000000 0 0.0 0.0000000\n",
      " [9,] 0 0 0.0 0.0 0.0 0 0.3333333 0 0.0 0.6666667\n",
      "[10,] 0 0 0.5 0.0 0.0 0 0.0000000 0 0.0 0.0000000\n",
      "JI_good: 0.7 0.5 0.5 1 1 0.3 1 1 0.6666667 0.5 \n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.7 0.5 0.5 1 1 0.3 1 1 0.6666667 0.5"
     ]
    }
   ],
   "source": [
    "number_cl=10\n",
    "ind <- 0\n",
    "JI_final <- matrix(data=NA, nrow=number_cl, ncol=1)\n",
    "#cat(JI_final,\"\\n\")\n",
    "# Read clusters imposed on simulated data \n",
    "cl  <- as.matrix(read.table(\"../data/simulations_20210329212141/equal/10/clusters.txt\", \n",
    "                            sep=\"\\t\", row.names=1, header=TRUE))\n",
    "#cat(\"cl:\",cl,\"\\t\")\n",
    "cl2 <- as.matrix(as.numeric(cl[,2]))\n",
    "cat(\"cl2:\",cl2[,1],\"\\n\")\n",
    "rownames(cl2) <- cl[,1]\n",
    "\n",
    "#factorization=read.table(\"../data/simulations_20210329212141/equal/10/AE_FAETC_EM.txt\", sep=\" \", row.names=cl[,1],header=FALSE)\n",
    "#factorization=read.table(\"../data/simulations_20210329212141/equal/10/AE_FCTAE_EM.txt\", sep=\" \", row.names=cl[,1],header=FALSE)\n",
    "#factorization=read.table(\"../data/simulations_20210329212141/equal/10/DAE_FAETC_EM.txt\", sep=\" \", row.names=cl[,1],header=FALSE)\n",
    "#factorization=read.table(\"../data/simulations_20210329212141/equal/10/DAE_FCTAE_EM.txt\", sep=\" \", row.names=cl[,1],header=FALSE)\n",
    "factorization=read.table(\"../data/simulations_20210329212141/equal/10/VAE_FCTAE_EM.txt\", sep=\" \", row.names=cl[,1],header=FALSE)\n",
    "#factorization=read.table(\"../data/simulations_20210329212141/equal/10/LSTMVAE_FCTAE_EM.txt\", sep=\" \", row.names=cl[,1],header=FALSE)\n",
    "\n",
    "\n",
    "\n",
    "factors <- factorization\n",
    "#factors <- factorizations[[i]][[1]]\n",
    "\n",
    "#print(factors)\n",
    "# Clustering by Kmeans\n",
    "JI_good <- numeric(0)\n",
    "for (run in 1:1) {\n",
    "kmeans.out <- kmeans(factors, centers=number_cl) \n",
    "clust_iCluster <- as.matrix(kmeans.out$cluster)\n",
    "cat(\"clust_iCluster:\",clust_iCluster,\"\\n\")\n",
    "######creation sets of samples\n",
    "JI_mat <- numeric(0)\n",
    "for (p in 1:number_cl) {\n",
    "    x1  <- rownames(clust_iCluster)[which(clust_iCluster[,1]==p)]\n",
    "    print(x1)\n",
    "\n",
    "    row <- numeric(0)\n",
    "    for(j in 1:number_cl) {\n",
    "        x2  <- rownames(cl2)[which(cl2[,1]==j)]\n",
    "        cat(\"x2:\",x2,\"\\n\")\n",
    "        I   <- length(intersect(x1,x2))#交集\n",
    "        cat(\"I:\",I,\"\\n\")\n",
    "        S   <- I/(length(x1)+length(x2)-I)\n",
    "        cat(\"S:\",S,\"\\n\")\n",
    "        row <- cbind(row,S)\n",
    "        cat(\"row:\",row,\"\\n\")\n",
    "     }\n",
    "     JI_mat <- rbind(JI_mat,row)\n",
    "     cat(\"JI_mat:\",JI_mat,\"\\n\")\n",
    "     print(JI_mat)\n",
    "\n",
    "\n",
    " }\n",
    " JI_good <- rbind(JI_good,apply(JI_mat,1,max))\n",
    " cat(\"JI_good:\",JI_good,\"\\n\")\n",
    "}\n",
    "JI_final[1:number_cl] <- apply(JI_good,2,mean)\n",
    "cat(JI_final)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "cl2: 4 7 3 1 5 4 3 3 10 4 5 5 9 3 10 5 6 8 2 2 1 7 3 1 1 5 9 10 3 2 8 2 8 1 10 2 8 9 6 8 2 6 8 6 5 2 7 4 4 1 5 8 6 1 3 2 6 9 1 1 9 1 4 6 8 6 1 9 8 1 10 1 4 5 2 10 6 8 6 4 3 10 3 9 5 4 9 9 9 5 1 7 10 1 7 10 4 10 3 2 \n"
     ]
    }
   ],
   "source": [
    "number_cl=10\n",
    "ind <- 0\n",
    "JI_final <- matrix(data=NA, nrow=number_cl, ncol=1)\n",
    "#cat(JI_final,\"\\n\")\n",
    "# Read clusters imposed on simulated data \n",
    "cl  <- as.matrix(read.table(\"../data/simulations_20210329212141/equal/10/clusters.txt\", \n",
    "                            sep=\"\\t\", row.names=1, header=TRUE))\n",
    "#cat(\"cl:\",cl,\"\\t\")\n",
    "cl2 <- as.matrix(as.numeric(cl[,2]))\n",
    "cat(\"cl2:\",cl2[,1],\"\\n\")\n",
    "rownames(cl2) <- cl[,1]\n",
    "\n",
    "#factorization=read.table(\"../data/simulations_20210329212141/equal/10/AE_FAETC_EM.txt\", sep=\" \", row.names=cl[,1],header=FALSE)\n",
    "#factorization=read.table(\"../data/simulations_20210329212141/equal/10/AE_FCTAE_EM.txt\", sep=\" \", row.names=cl[,1],header=FALSE)\n",
    "#factorization=read.table(\"../data/simulations_20210329212141/equal/10/DAE_FAETC_EM.txt\", sep=\" \", row.names=cl[,1],header=FALSE)\n",
    "#factorization=read.table(\"../data/simulations_20210329212141/equal/10/DAE_FCTAE_EM.txt\", sep=\" \", row.names=cl[,1],header=FALSE)\n",
    "factorization=read.table(\"../data/simulations_20210329212141/equal/10/VAE_FCTAE_EM.txt\", sep=\" \", row.names=cl[,1],header=FALSE)\n",
    "#factorization=read.table(\"../data/simulations_20210329212141/equal/10/LSTMVAE_FCTAE_EM.txt\", sep=\" \", row.names=cl[,1],header=FALSE)\n",
    "\n",
    "\n",
    "\n",
    "# factors <- factorization\n",
    "\n",
    "# # Clustering by Kmeans\n",
    "# JI_good <- numeric(0)\n",
    "# for (run in 1:100) {\n",
    "# kmeans.out <- kmeans(factors, centers=number_cl) \n",
    "# clust_iCluster <- as.matrix(kmeans.out$cluster)\n",
    "# cat(\"clust_iCluster:\",clust_iCluster,\"\\n\")\n",
    "# ######creation sets of samples\n",
    "# JI_mat <- numeric(0)\n",
    "# for (p in 1:number_cl) {\n",
    "#     x1  <- rownames(clust_iCluster)[which(clust_iCluster[,1]==p)]\n",
    "#     print(x1)\n",
    "\n",
    "#     row <- numeric(0)\n",
    "#     for(j in 1:number_cl) {\n",
    "#         x2  <- rownames(cl2)[which(cl2[,1]==j)]\n",
    "#         #cat(\"x2:\",x2,\"\\n\")\n",
    "#         I   <- length(intersect(x1,x2))#交集\n",
    "#         #cat(\"I:\",I,\"\\n\")\n",
    "#         S   <- I/(length(x1)+length(x2)-I)\n",
    "#         #cat(\"S:\",S,\"\\n\")\n",
    "#         row <- cbind(row,S)\n",
    "#         #cat(\"row:\",row,\"\\n\")\n",
    "#      }\n",
    "#      JI_mat <- rbind(JI_mat,row)\n",
    "#      cat(\"JI_mat:\",JI_mat,\"\\n\")\n",
    "#      #print(JI_mat)\n",
    "\n",
    "\n",
    "#  }\n",
    "#  JI_good <- rbind(JI_good,apply(JI_mat,1,max))\n",
    "#  cat(\"JI_good:\",JI_good,\"\\n\")\n",
    "# }\n",
    "# JI_final[1:number_cl] <- apply(JI_good,2,mean)\n",
    "# JI_final"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "number_cl=10\n",
    "ind <- 0\n",
    "JI_final <- matrix(data=NA, nrow=number_cl, ncol=1)\n",
    "#cat(JI_final,\"\\n\")\n",
    "# Read clusters imposed on simulated data \n",
    "cl  <- as.matrix(read.table(\"../data/simulations_20210329212141/equal/10/clusters.txt\", \n",
    "                            sep=\"\\t\", row.names=1, header=TRUE))\n",
    "#cat(\"cl:\",cl,\"\\t\")\n",
    "cl2 <- as.matrix(as.numeric(cl[,2]))\n",
    "cat(\"cl2:\",cl2[,1],\"\\n\")\n",
    "rownames(cl2) <- cl[,1]\n",
    "\n",
    "#factorization=read.table(\"../data/simulations_20210329212141/equal/10/AE_FAETC_EM.txt\", sep=\" \", row.names=cl[,1],header=FALSE)\n",
    "#factorization=read.table(\"../data/simulations_20210329212141/equal/10/AE_FCTAE_EM.txt\", sep=\" \", row.names=cl[,1],header=FALSE)\n",
    "#factorization=read.table(\"../data/simulations_20210329212141/equal/10/DAE_FAETC_EM.txt\", sep=\" \", row.names=cl[,1],header=FALSE)\n",
    "#factorization=read.table(\"../data/simulations_20210329212141/equal/10/DAE_FCTAE_EM.txt\", sep=\" \", row.names=cl[,1],header=FALSE)\n",
    "#factorization=read.table(\"../data/simulations_20210329212141/equal/10/VAE_FCTAE_EM.txt\", sep=\" \", row.names=cl[,1],header=FALSE)\n",
    "factorization=read.table(\"../data/simulations_20210329212141/equal/10/LSTMVAE_FCTAE_EM.txt\", sep=\" \", row.names=cl[,1],header=FALSE)\n",
    "\n",
    "\n",
    "\n",
    "factors <- factorization\n",
    "#factors <- factorizations[[i]][[1]]\n",
    "\n",
    "#print(factors)\n",
    "# Clustering by Kmeans\n",
    "JI_good <- numeric(0)\n",
    "for (run in 1:100) {\n",
    "kmeans.out <- kmeans(factors, centers=number_cl) \n",
    "clust_iCluster <- as.matrix(kmeans.out$cluster)\n",
    "cat(\"clust_iCluster:\",clust_iCluster,\"\\n\")\n",
    "######creation sets of samples\n",
    "JI_mat <- numeric(0)\n",
    "for (p in 1:number_cl) {\n",
    "    x1  <- rownames(clust_iCluster)[which(clust_iCluster[,1]==p)]\n",
    "    print(x1)\n",
    "\n",
    "    row <- numeric(0)\n",
    "    for(j in 1:number_cl) {\n",
    "        x2  <- rownames(cl2)[which(cl2[,1]==j)]\n",
    "        cat(\"x2:\",x2,\"\\n\")\n",
    "        I   <- length(intersect(x1,x2))#交集\n",
    "        cat(\"I:\",I,\"\\n\")\n",
    "        S   <- I/(length(x1)+length(x2)-I)\n",
    "        cat(\"S:\",S,\"\\n\")\n",
    "        row <- cbind(row,S)\n",
    "        cat(\"row:\",row,\"\\n\")\n",
    "     }\n",
    "     JI_mat <- rbind(JI_mat,row)\n",
    "     cat(\"JI_mat:\",JI_mat,\"\\n\")\n",
    "     print(JI_mat)\n",
    "\n",
    "\n",
    " }\n",
    " JI_good <- rbind(JI_good,apply(JI_mat,1,max))\n",
    " cat(\"JI_good:\",JI_good,\"\\n\")\n",
    "}\n",
    "JI_final[1:number_cl] <- apply(JI_good,2,mean)\n",
    "JI_final"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "number_cl=15\n",
    "ind <- 0\n",
    "JI_final <- matrix(data=NA, nrow=number_cl, ncol=1)\n",
    "#cat(JI_final,\"\\n\")\n",
    "# Read clusters imposed on simulated data \n",
    "cl  <- as.matrix(read.table(\"../data/simulations_20210329212141/equal/15/clusters.txt\", \n",
    "                            sep=\"\\t\", row.names=1, header=TRUE))\n",
    "#cat(\"cl:\",cl,\"\\t\")\n",
    "cl2 <- as.matrix(as.numeric(cl[,2]))\n",
    "cat(\"cl2:\",cl2[,1],\"\\n\")\n",
    "rownames(cl2) <- cl[,1]\n",
    "\n",
    "factorization=read.table(\"../data/simulations_20210329212141/equal/15/AE_FAETC_EM.txt\", sep=\" \", row.names=cl[,1],header=FALSE)\n",
    "#factorization=read.table(\"../data/simulations_20210329212141/equal/15/AE_FCTAE_EM.txt\", sep=\" \", row.names=cl[,1],header=FALSE)\n",
    "#factorization=read.table(\"../data/simulations_20210329212141/equal/15/DAE_FAETC_EM.txt\", sep=\" \", row.names=cl[,1],header=FALSE)\n",
    "#factorization=read.table(\"../data/simulations_20210329212141/equal/15/DAE_FCTAE_EM.txt\", sep=\" \", row.names=cl[,1],header=FALSE)\n",
    "#factorization=read.table(\"../data/simulations_20210329212141/equal/15/VAE_FCTAE_EM.txt\", sep=\" \", row.names=cl[,1],header=FALSE)\n",
    "#factorization=read.table(\"../data/simulations_20210329212141/equal/15/LSTMVAE_FCTAE_EM.txt\", sep=\" \", row.names=cl[,1],header=FALSE)\n",
    "\n",
    "\n",
    "\n",
    "factors <- factorization\n",
    "#factors <- factorizations[[i]][[1]]\n",
    "\n",
    "#print(factors)\n",
    "# Clustering by Kmeans\n",
    "JI_good <- numeric(0)\n",
    "for (run in 1:1000) {\n",
    "kmeans.out <- kmeans(factors, centers=number_cl) \n",
    "clust_iCluster <- as.matrix(kmeans.out$cluster)\n",
    "cat(\"clust_iCluster:\",clust_iCluster,\"\\n\")\n",
    "######creation sets of samples\n",
    "JI_mat <- numeric(0)\n",
    "for (p in 1:number_cl) {\n",
    "    x1  <- rownames(clust_iCluster)[which(clust_iCluster[,1]==p)]\n",
    "    print(x1)\n",
    "\n",
    "    row <- numeric(0)\n",
    "    for(j in 1:number_cl) {\n",
    "        x2  <- rownames(cl2)[which(cl2[,1]==j)]\n",
    "        #cat(\"x2:\",x2,\"\\n\")\n",
    "        I   <- length(intersect(x1,x2))#交集\n",
    "        #cat(\"I:\",I,\"\\n\")\n",
    "        S   <- I/(length(x1)+length(x2)-I)\n",
    "        #cat(\"S:\",S,\"\\n\")\n",
    "        row <- cbind(row,S)\n",
    "        #cat(\"row:\",row,\"\\n\")\n",
    "     }\n",
    "     JI_mat <- rbind(JI_mat,row)\n",
    "     cat(\"JI_mat:\",JI_mat,\"\\n\")\n",
    "     print(JI_mat)\n",
    "\n",
    "\n",
    " }\n",
    " JI_good <- rbind(JI_good,apply(JI_mat,1,max))\n",
    " cat(\"JI_good:\",JI_good,\"\\n\")\n",
    "}\n",
    "JI_final[1:number_cl] <- apply(JI_good,2,mean)\n",
    "JI_final"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "cl2: 7 7 12 2 5 15 7 10 15 8 13 4 3 7 15 10 2 2 9 14 2 13 10 10 13 8 1 9 10 11 12 15 9 2 12 14 6 11 3 1 5 8 6 2 13 11 5 4 8 7 5 1 1 12 14 15 3 9 5 10 1 13 11 6 5 3 4 6 6 8 3 9 11 6 14 14 7 13 6 4 9 15 13 11 12 11 2 5 3 9 15 14 4 1 1 7 8 12 4 3 \n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "IOPub data rate exceeded.\n",
      "The notebook server will temporarily stop sending output\n",
      "to the client in order to avoid crashing it.\n",
      "To change this limit, set the config variable\n",
      "`--NotebookApp.iopub_data_rate_limit`.\n",
      "\n",
      "Current values:\n",
      "NotebookApp.iopub_data_rate_limit=1000000.0 (bytes/sec)\n",
      "NotebookApp.rate_limit_window=3.0 (secs)\n",
      "\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<caption>A matrix: 15 × 1 of type dbl</caption>\n",
       "<tbody>\n",
       "\t<tr><td>0.7989517</td></tr>\n",
       "\t<tr><td>0.8052115</td></tr>\n",
       "\t<tr><td>0.8019024</td></tr>\n",
       "\t<tr><td>0.8157678</td></tr>\n",
       "\t<tr><td>0.7945885</td></tr>\n",
       "\t<tr><td>0.8191150</td></tr>\n",
       "\t<tr><td>0.8043023</td></tr>\n",
       "\t<tr><td>0.8144615</td></tr>\n",
       "\t<tr><td>0.8061806</td></tr>\n",
       "\t<tr><td>0.8206591</td></tr>\n",
       "\t<tr><td>0.8057421</td></tr>\n",
       "\t<tr><td>0.7979146</td></tr>\n",
       "\t<tr><td>0.8153197</td></tr>\n",
       "\t<tr><td>0.8033851</td></tr>\n",
       "\t<tr><td>0.8177235</td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "A matrix: 15 × 1 of type dbl\n",
       "\\begin{tabular}{l}\n",
       "\t 0.7989517\\\\\n",
       "\t 0.8052115\\\\\n",
       "\t 0.8019024\\\\\n",
       "\t 0.8157678\\\\\n",
       "\t 0.7945885\\\\\n",
       "\t 0.8191150\\\\\n",
       "\t 0.8043023\\\\\n",
       "\t 0.8144615\\\\\n",
       "\t 0.8061806\\\\\n",
       "\t 0.8206591\\\\\n",
       "\t 0.8057421\\\\\n",
       "\t 0.7979146\\\\\n",
       "\t 0.8153197\\\\\n",
       "\t 0.8033851\\\\\n",
       "\t 0.8177235\\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "A matrix: 15 × 1 of type dbl\n",
       "\n",
       "| 0.7989517 |\n",
       "| 0.8052115 |\n",
       "| 0.8019024 |\n",
       "| 0.8157678 |\n",
       "| 0.7945885 |\n",
       "| 0.8191150 |\n",
       "| 0.8043023 |\n",
       "| 0.8144615 |\n",
       "| 0.8061806 |\n",
       "| 0.8206591 |\n",
       "| 0.8057421 |\n",
       "| 0.7979146 |\n",
       "| 0.8153197 |\n",
       "| 0.8033851 |\n",
       "| 0.8177235 |\n",
       "\n"
      ],
      "text/plain": [
       "      [,1]     \n",
       " [1,] 0.7989517\n",
       " [2,] 0.8052115\n",
       " [3,] 0.8019024\n",
       " [4,] 0.8157678\n",
       " [5,] 0.7945885\n",
       " [6,] 0.8191150\n",
       " [7,] 0.8043023\n",
       " [8,] 0.8144615\n",
       " [9,] 0.8061806\n",
       "[10,] 0.8206591\n",
       "[11,] 0.8057421\n",
       "[12,] 0.7979146\n",
       "[13,] 0.8153197\n",
       "[14,] 0.8033851\n",
       "[15,] 0.8177235"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "number_cl=15\n",
    "ind <- 0\n",
    "JI_final <- matrix(data=NA, nrow=number_cl, ncol=1)\n",
    "#cat(JI_final,\"\\n\")\n",
    "# Read clusters imposed on simulated data \n",
    "cl  <- as.matrix(read.table(\"../data/simulations_20210329212141/equal/15/clusters.txt\", \n",
    "                            sep=\"\\t\", row.names=1, header=TRUE))\n",
    "#cat(\"cl:\",cl,\"\\t\")\n",
    "cl2 <- as.matrix(as.numeric(cl[,2]))\n",
    "cat(\"cl2:\",cl2[,1],\"\\n\")\n",
    "rownames(cl2) <- cl[,1]\n",
    "\n",
    "#factorization=read.table(\"../data/simulations_20210329212141/equal/15/AE_FAETC_EM.txt\", sep=\" \", row.names=cl[,1],header=FALSE)\n",
    "factorization=read.table(\"../data/simulations_20210329212141/equal/15/AE_FCTAE_EM.txt\", sep=\" \", row.names=cl[,1],header=FALSE)\n",
    "#factorization=read.table(\"../data/simulations_20210329212141/equal/15/DAE_FAETC_EM.txt\", sep=\" \", row.names=cl[,1],header=FALSE)\n",
    "#factorization=read.table(\"../data/simulations_20210329212141/equal/15/DAE_FCTAE_EM.txt\", sep=\" \", row.names=cl[,1],header=FALSE)\n",
    "#factorization=read.table(\"../data/simulations_20210329212141/equal/15/VAE_FCTAE_EM.txt\", sep=\" \", row.names=cl[,1],header=FALSE)\n",
    "#factorization=read.table(\"../data/simulations_20210329212141/equal/15/LSTMVAE_FCTAE_EM.txt\", sep=\" \", row.names=cl[,1],header=FALSE)\n",
    "\n",
    "\n",
    "\n",
    "factors <- factorization\n",
    "#factors <- factorizations[[i]][[1]]\n",
    "\n",
    "#print(factors)\n",
    "# Clustering by Kmeans\n",
    "JI_good <- numeric(0)\n",
    "for (run in 1:1000) {\n",
    "kmeans.out <- kmeans(factors, centers=number_cl) \n",
    "clust_iCluster <- as.matrix(kmeans.out$cluster)\n",
    "cat(\"clust_iCluster:\",clust_iCluster,\"\\n\")\n",
    "######creation sets of samples\n",
    "JI_mat <- numeric(0)\n",
    "for (p in 1:number_cl) {\n",
    "    x1  <- rownames(clust_iCluster)[which(clust_iCluster[,1]==p)]\n",
    "    print(x1)\n",
    "\n",
    "    row <- numeric(0)\n",
    "    for(j in 1:number_cl) {\n",
    "        x2  <- rownames(cl2)[which(cl2[,1]==j)]\n",
    "        cat(\"x2:\",x2,\"\\n\")\n",
    "        I   <- length(intersect(x1,x2))#交集\n",
    "        cat(\"I:\",I,\"\\n\")\n",
    "        S   <- I/(length(x1)+length(x2)-I)\n",
    "        cat(\"S:\",S,\"\\n\")\n",
    "        row <- cbind(row,S)\n",
    "        cat(\"row:\",row,\"\\n\")\n",
    "     }\n",
    "     JI_mat <- rbind(JI_mat,row)\n",
    "     cat(\"JI_mat:\",JI_mat,\"\\n\")\n",
    "     print(JI_mat)\n",
    "\n",
    "\n",
    " }\n",
    " JI_good <- rbind(JI_good,apply(JI_mat,1,max))\n",
    " cat(\"JI_good:\",JI_good,\"\\n\")\n",
    "}\n",
    "JI_final[1:number_cl] <- apply(JI_good,2,mean)\n",
    "JI_final"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "cl2: 7 7 12 2 5 15 7 10 15 8 13 4 3 7 15 10 2 2 9 14 2 13 10 10 13 8 1 9 10 11 12 15 9 2 12 14 6 11 3 1 5 8 6 2 13 11 5 4 8 7 5 1 1 12 14 15 3 9 5 10 1 13 11 6 5 3 4 6 6 8 3 9 11 6 14 14 7 13 6 4 9 15 13 11 12 11 2 5 3 9 15 14 4 1 1 7 8 12 4 3 \n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "IOPub data rate exceeded.\n",
      "The notebook server will temporarily stop sending output\n",
      "to the client in order to avoid crashing it.\n",
      "To change this limit, set the config variable\n",
      "`--NotebookApp.iopub_data_rate_limit`.\n",
      "\n",
      "Current values:\n",
      "NotebookApp.iopub_data_rate_limit=1000000.0 (bytes/sec)\n",
      "NotebookApp.rate_limit_window=3.0 (secs)\n",
      "\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<caption>A matrix: 15 × 1 of type dbl</caption>\n",
       "<tbody>\n",
       "\t<tr><td>0.7532231</td></tr>\n",
       "\t<tr><td>0.7563619</td></tr>\n",
       "\t<tr><td>0.7594553</td></tr>\n",
       "\t<tr><td>0.7525584</td></tr>\n",
       "\t<tr><td>0.7487293</td></tr>\n",
       "\t<tr><td>0.7492135</td></tr>\n",
       "\t<tr><td>0.7440258</td></tr>\n",
       "\t<tr><td>0.7524720</td></tr>\n",
       "\t<tr><td>0.7362969</td></tr>\n",
       "\t<tr><td>0.7606681</td></tr>\n",
       "\t<tr><td>0.7808652</td></tr>\n",
       "\t<tr><td>0.7486006</td></tr>\n",
       "\t<tr><td>0.7620518</td></tr>\n",
       "\t<tr><td>0.7535825</td></tr>\n",
       "\t<tr><td>0.7502729</td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "A matrix: 15 × 1 of type dbl\n",
       "\\begin{tabular}{l}\n",
       "\t 0.7532231\\\\\n",
       "\t 0.7563619\\\\\n",
       "\t 0.7594553\\\\\n",
       "\t 0.7525584\\\\\n",
       "\t 0.7487293\\\\\n",
       "\t 0.7492135\\\\\n",
       "\t 0.7440258\\\\\n",
       "\t 0.7524720\\\\\n",
       "\t 0.7362969\\\\\n",
       "\t 0.7606681\\\\\n",
       "\t 0.7808652\\\\\n",
       "\t 0.7486006\\\\\n",
       "\t 0.7620518\\\\\n",
       "\t 0.7535825\\\\\n",
       "\t 0.7502729\\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "A matrix: 15 × 1 of type dbl\n",
       "\n",
       "| 0.7532231 |\n",
       "| 0.7563619 |\n",
       "| 0.7594553 |\n",
       "| 0.7525584 |\n",
       "| 0.7487293 |\n",
       "| 0.7492135 |\n",
       "| 0.7440258 |\n",
       "| 0.7524720 |\n",
       "| 0.7362969 |\n",
       "| 0.7606681 |\n",
       "| 0.7808652 |\n",
       "| 0.7486006 |\n",
       "| 0.7620518 |\n",
       "| 0.7535825 |\n",
       "| 0.7502729 |\n",
       "\n"
      ],
      "text/plain": [
       "      [,1]     \n",
       " [1,] 0.7532231\n",
       " [2,] 0.7563619\n",
       " [3,] 0.7594553\n",
       " [4,] 0.7525584\n",
       " [5,] 0.7487293\n",
       " [6,] 0.7492135\n",
       " [7,] 0.7440258\n",
       " [8,] 0.7524720\n",
       " [9,] 0.7362969\n",
       "[10,] 0.7606681\n",
       "[11,] 0.7808652\n",
       "[12,] 0.7486006\n",
       "[13,] 0.7620518\n",
       "[14,] 0.7535825\n",
       "[15,] 0.7502729"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "number_cl=15\n",
    "ind <- 0\n",
    "JI_final <- matrix(data=NA, nrow=number_cl, ncol=1)\n",
    "#cat(JI_final,\"\\n\")\n",
    "# Read clusters imposed on simulated data \n",
    "cl  <- as.matrix(read.table(\"../data/simulations_20210329212141/equal/15/clusters.txt\", \n",
    "                            sep=\"\\t\", row.names=1, header=TRUE))\n",
    "#cat(\"cl:\",cl,\"\\t\")\n",
    "cl2 <- as.matrix(as.numeric(cl[,2]))\n",
    "cat(\"cl2:\",cl2[,1],\"\\n\")\n",
    "rownames(cl2) <- cl[,1]\n",
    "\n",
    "#factorization=read.table(\"../data/simulations_20210329212141/equal/15/AE_FAETC_EM.txt\", sep=\" \", row.names=cl[,1],header=FALSE)\n",
    "#factorization=read.table(\"../data/simulations_20210329212141/equal/15/AE_FCTAE_EM.txt\", sep=\" \", row.names=cl[,1],header=FALSE)\n",
    "factorization=read.table(\"../data/simulations_20210329212141/equal/15/DAE_FAETC_EM.txt\", sep=\" \", row.names=cl[,1],header=FALSE)\n",
    "#factorization=read.table(\"../data/simulations_20210329212141/equal/15/DAE_FCTAE_EM.txt\", sep=\" \", row.names=cl[,1],header=FALSE)\n",
    "#factorization=read.table(\"../data/simulations_20210329212141/equal/15/VAE_FCTAE_EM.txt\", sep=\" \", row.names=cl[,1],header=FALSE)\n",
    "#factorization=read.table(\"../data/simulations_20210329212141/equal/15/LSTMVAE_FCTAE_EM.txt\", sep=\" \", row.names=cl[,1],header=FALSE)\n",
    "\n",
    "\n",
    "\n",
    "factors <- factorization\n",
    "#factors <- factorizations[[i]][[1]]\n",
    "\n",
    "#print(factors)\n",
    "# Clustering by Kmeans\n",
    "JI_good <- numeric(0)\n",
    "for (run in 1:1000) {\n",
    "kmeans.out <- kmeans(factors, centers=number_cl) \n",
    "clust_iCluster <- as.matrix(kmeans.out$cluster)\n",
    "cat(\"clust_iCluster:\",clust_iCluster,\"\\n\")\n",
    "######creation sets of samples\n",
    "JI_mat <- numeric(0)\n",
    "for (p in 1:number_cl) {\n",
    "    x1  <- rownames(clust_iCluster)[which(clust_iCluster[,1]==p)]\n",
    "    print(x1)\n",
    "\n",
    "    row <- numeric(0)\n",
    "    for(j in 1:number_cl) {\n",
    "        x2  <- rownames(cl2)[which(cl2[,1]==j)]\n",
    "        cat(\"x2:\",x2,\"\\n\")\n",
    "        I   <- length(intersect(x1,x2))#交集\n",
    "        cat(\"I:\",I,\"\\n\")\n",
    "        S   <- I/(length(x1)+length(x2)-I)\n",
    "        cat(\"S:\",S,\"\\n\")\n",
    "        row <- cbind(row,S)\n",
    "        cat(\"row:\",row,\"\\n\")\n",
    "     }\n",
    "     JI_mat <- rbind(JI_mat,row)\n",
    "     cat(\"JI_mat:\",JI_mat,\"\\n\")\n",
    "     print(JI_mat)\n",
    "\n",
    "\n",
    " }\n",
    " JI_good <- rbind(JI_good,apply(JI_mat,1,max))\n",
    " cat(\"JI_good:\",JI_good,\"\\n\")\n",
    "}\n",
    "JI_final[1:number_cl] <- apply(JI_good,2,mean)\n",
    "JI_final"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "cl2: 7 7 12 2 5 15 7 10 15 8 13 4 3 7 15 10 2 2 9 14 2 13 10 10 13 8 1 9 10 11 12 15 9 2 12 14 6 11 3 1 5 8 6 2 13 11 5 4 8 7 5 1 1 12 14 15 3 9 5 10 1 13 11 6 5 3 4 6 6 8 3 9 11 6 14 14 7 13 6 4 9 15 13 11 12 11 2 5 3 9 15 14 4 1 1 7 8 12 4 3 \n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "IOPub data rate exceeded.\n",
      "The notebook server will temporarily stop sending output\n",
      "to the client in order to avoid crashing it.\n",
      "To change this limit, set the config variable\n",
      "`--NotebookApp.iopub_data_rate_limit`.\n",
      "\n",
      "Current values:\n",
      "NotebookApp.iopub_data_rate_limit=1000000.0 (bytes/sec)\n",
      "NotebookApp.rate_limit_window=3.0 (secs)\n",
      "\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<caption>A matrix: 15 × 1 of type dbl</caption>\n",
       "<tbody>\n",
       "\t<tr><td>0.7940330</td></tr>\n",
       "\t<tr><td>0.8056647</td></tr>\n",
       "\t<tr><td>0.7995865</td></tr>\n",
       "\t<tr><td>0.7820629</td></tr>\n",
       "\t<tr><td>0.7863840</td></tr>\n",
       "\t<tr><td>0.7954261</td></tr>\n",
       "\t<tr><td>0.7985005</td></tr>\n",
       "\t<tr><td>0.7922929</td></tr>\n",
       "\t<tr><td>0.7948400</td></tr>\n",
       "\t<tr><td>0.8013052</td></tr>\n",
       "\t<tr><td>0.8022179</td></tr>\n",
       "\t<tr><td>0.7860330</td></tr>\n",
       "\t<tr><td>0.8102876</td></tr>\n",
       "\t<tr><td>0.7921890</td></tr>\n",
       "\t<tr><td>0.7864014</td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "A matrix: 15 × 1 of type dbl\n",
       "\\begin{tabular}{l}\n",
       "\t 0.7940330\\\\\n",
       "\t 0.8056647\\\\\n",
       "\t 0.7995865\\\\\n",
       "\t 0.7820629\\\\\n",
       "\t 0.7863840\\\\\n",
       "\t 0.7954261\\\\\n",
       "\t 0.7985005\\\\\n",
       "\t 0.7922929\\\\\n",
       "\t 0.7948400\\\\\n",
       "\t 0.8013052\\\\\n",
       "\t 0.8022179\\\\\n",
       "\t 0.7860330\\\\\n",
       "\t 0.8102876\\\\\n",
       "\t 0.7921890\\\\\n",
       "\t 0.7864014\\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "A matrix: 15 × 1 of type dbl\n",
       "\n",
       "| 0.7940330 |\n",
       "| 0.8056647 |\n",
       "| 0.7995865 |\n",
       "| 0.7820629 |\n",
       "| 0.7863840 |\n",
       "| 0.7954261 |\n",
       "| 0.7985005 |\n",
       "| 0.7922929 |\n",
       "| 0.7948400 |\n",
       "| 0.8013052 |\n",
       "| 0.8022179 |\n",
       "| 0.7860330 |\n",
       "| 0.8102876 |\n",
       "| 0.7921890 |\n",
       "| 0.7864014 |\n",
       "\n"
      ],
      "text/plain": [
       "      [,1]     \n",
       " [1,] 0.7940330\n",
       " [2,] 0.8056647\n",
       " [3,] 0.7995865\n",
       " [4,] 0.7820629\n",
       " [5,] 0.7863840\n",
       " [6,] 0.7954261\n",
       " [7,] 0.7985005\n",
       " [8,] 0.7922929\n",
       " [9,] 0.7948400\n",
       "[10,] 0.8013052\n",
       "[11,] 0.8022179\n",
       "[12,] 0.7860330\n",
       "[13,] 0.8102876\n",
       "[14,] 0.7921890\n",
       "[15,] 0.7864014"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "number_cl=15\n",
    "ind <- 0\n",
    "JI_final <- matrix(data=NA, nrow=number_cl, ncol=1)\n",
    "#cat(JI_final,\"\\n\")\n",
    "# Read clusters imposed on simulated data \n",
    "cl  <- as.matrix(read.table(\"../data/simulations_20210329212141/equal/15/clusters.txt\", \n",
    "                            sep=\"\\t\", row.names=1, header=TRUE))\n",
    "#cat(\"cl:\",cl,\"\\t\")\n",
    "cl2 <- as.matrix(as.numeric(cl[,2]))\n",
    "cat(\"cl2:\",cl2[,1],\"\\n\")\n",
    "rownames(cl2) <- cl[,1]\n",
    "\n",
    "#factorization=read.table(\"../data/simulations_20210329212141/equal/15/AE_FAETC_EM.txt\", sep=\" \", row.names=cl[,1],header=FALSE)\n",
    "#factorization=read.table(\"../data/simulations_20210329212141/equal/15/AE_FCTAE_EM.txt\", sep=\" \", row.names=cl[,1],header=FALSE)\n",
    "#factorization=read.table(\"../data/simulations_20210329212141/equal/15/DAE_FAETC_EM.txt\", sep=\" \", row.names=cl[,1],header=FALSE)\n",
    "factorization=read.table(\"../data/simulations_20210329212141/equal/15/DAE_FCTAE_EM.txt\", sep=\" \", row.names=cl[,1],header=FALSE)\n",
    "#factorization=read.table(\"../data/simulations_20210329212141/equal/15/VAE_FCTAE_EM.txt\", sep=\" \", row.names=cl[,1],header=FALSE)\n",
    "#factorization=read.table(\"../data/simulations_20210329212141/equal/15/LSTMVAE_FCTAE_EM.txt\", sep=\" \", row.names=cl[,1],header=FALSE)\n",
    "\n",
    "\n",
    "\n",
    "factors <- factorization\n",
    "#factors <- factorizations[[i]][[1]]\n",
    "\n",
    "#print(factors)\n",
    "# Clustering by Kmeans\n",
    "JI_good <- numeric(0)\n",
    "for (run in 1:1000) {\n",
    "kmeans.out <- kmeans(factors, centers=number_cl) \n",
    "clust_iCluster <- as.matrix(kmeans.out$cluster)\n",
    "cat(\"clust_iCluster:\",clust_iCluster,\"\\n\")\n",
    "######creation sets of samples\n",
    "JI_mat <- numeric(0)\n",
    "for (p in 1:number_cl) {\n",
    "    x1  <- rownames(clust_iCluster)[which(clust_iCluster[,1]==p)]\n",
    "    print(x1)\n",
    "\n",
    "    row <- numeric(0)\n",
    "    for(j in 1:number_cl) {\n",
    "        x2  <- rownames(cl2)[which(cl2[,1]==j)]\n",
    "        cat(\"x2:\",x2,\"\\n\")\n",
    "        I   <- length(intersect(x1,x2))#交集\n",
    "        cat(\"I:\",I,\"\\n\")\n",
    "        S   <- I/(length(x1)+length(x2)-I)\n",
    "        cat(\"S:\",S,\"\\n\")\n",
    "        row <- cbind(row,S)\n",
    "        cat(\"row:\",row,\"\\n\")\n",
    "     }\n",
    "     JI_mat <- rbind(JI_mat,row)\n",
    "     cat(\"JI_mat:\",JI_mat,\"\\n\")\n",
    "     print(JI_mat)\n",
    "\n",
    "\n",
    " }\n",
    " JI_good <- rbind(JI_good,apply(JI_mat,1,max))\n",
    " cat(\"JI_good:\",JI_good,\"\\n\")\n",
    "}\n",
    "JI_final[1:number_cl] <- apply(JI_good,2,mean)\n",
    "JI_final"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "cl2: 7 7 12 2 5 15 7 10 15 8 13 4 3 7 15 10 2 2 9 14 2 13 10 10 13 8 1 9 10 11 12 15 9 2 12 14 6 11 3 1 5 8 6 2 13 11 5 4 8 7 5 1 1 12 14 15 3 9 5 10 1 13 11 6 5 3 4 6 6 8 3 9 11 6 14 14 7 13 6 4 9 15 13 11 12 11 2 5 3 9 15 14 4 1 1 7 8 12 4 3 \n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "IOPub data rate exceeded.\n",
      "The notebook server will temporarily stop sending output\n",
      "to the client in order to avoid crashing it.\n",
      "To change this limit, set the config variable\n",
      "`--NotebookApp.iopub_data_rate_limit`.\n",
      "\n",
      "Current values:\n",
      "NotebookApp.iopub_data_rate_limit=1000000.0 (bytes/sec)\n",
      "NotebookApp.rate_limit_window=3.0 (secs)\n",
      "\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<caption>A matrix: 15 × 1 of type dbl</caption>\n",
       "<tbody>\n",
       "\t<tr><td>0.7365600</td></tr>\n",
       "\t<tr><td>0.7399893</td></tr>\n",
       "\t<tr><td>0.7380597</td></tr>\n",
       "\t<tr><td>0.7495614</td></tr>\n",
       "\t<tr><td>0.7558608</td></tr>\n",
       "\t<tr><td>0.7513054</td></tr>\n",
       "\t<tr><td>0.7519942</td></tr>\n",
       "\t<tr><td>0.7433741</td></tr>\n",
       "\t<tr><td>0.7291959</td></tr>\n",
       "\t<tr><td>0.7450379</td></tr>\n",
       "\t<tr><td>0.7317692</td></tr>\n",
       "\t<tr><td>0.7382499</td></tr>\n",
       "\t<tr><td>0.7398166</td></tr>\n",
       "\t<tr><td>0.7516091</td></tr>\n",
       "\t<tr><td>0.7268284</td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "A matrix: 15 × 1 of type dbl\n",
       "\\begin{tabular}{l}\n",
       "\t 0.7365600\\\\\n",
       "\t 0.7399893\\\\\n",
       "\t 0.7380597\\\\\n",
       "\t 0.7495614\\\\\n",
       "\t 0.7558608\\\\\n",
       "\t 0.7513054\\\\\n",
       "\t 0.7519942\\\\\n",
       "\t 0.7433741\\\\\n",
       "\t 0.7291959\\\\\n",
       "\t 0.7450379\\\\\n",
       "\t 0.7317692\\\\\n",
       "\t 0.7382499\\\\\n",
       "\t 0.7398166\\\\\n",
       "\t 0.7516091\\\\\n",
       "\t 0.7268284\\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "A matrix: 15 × 1 of type dbl\n",
       "\n",
       "| 0.7365600 |\n",
       "| 0.7399893 |\n",
       "| 0.7380597 |\n",
       "| 0.7495614 |\n",
       "| 0.7558608 |\n",
       "| 0.7513054 |\n",
       "| 0.7519942 |\n",
       "| 0.7433741 |\n",
       "| 0.7291959 |\n",
       "| 0.7450379 |\n",
       "| 0.7317692 |\n",
       "| 0.7382499 |\n",
       "| 0.7398166 |\n",
       "| 0.7516091 |\n",
       "| 0.7268284 |\n",
       "\n"
      ],
      "text/plain": [
       "      [,1]     \n",
       " [1,] 0.7365600\n",
       " [2,] 0.7399893\n",
       " [3,] 0.7380597\n",
       " [4,] 0.7495614\n",
       " [5,] 0.7558608\n",
       " [6,] 0.7513054\n",
       " [7,] 0.7519942\n",
       " [8,] 0.7433741\n",
       " [9,] 0.7291959\n",
       "[10,] 0.7450379\n",
       "[11,] 0.7317692\n",
       "[12,] 0.7382499\n",
       "[13,] 0.7398166\n",
       "[14,] 0.7516091\n",
       "[15,] 0.7268284"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "number_cl=15\n",
    "ind <- 0\n",
    "JI_final <- matrix(data=NA, nrow=number_cl, ncol=1)\n",
    "#cat(JI_final,\"\\n\")\n",
    "# Read clusters imposed on simulated data \n",
    "cl  <- as.matrix(read.table(\"../data/simulations_20210329212141/equal/15/clusters.txt\", \n",
    "                            sep=\"\\t\", row.names=1, header=TRUE))\n",
    "#cat(\"cl:\",cl,\"\\t\")\n",
    "cl2 <- as.matrix(as.numeric(cl[,2]))\n",
    "cat(\"cl2:\",cl2[,1],\"\\n\")\n",
    "rownames(cl2) <- cl[,1]\n",
    "\n",
    "#factorization=read.table(\"../data/simulations_20210329212141/equal/15/AE_FAETC_EM.txt\", sep=\" \", row.names=cl[,1],header=FALSE)\n",
    "#factorization=read.table(\"../data/simulations_20210329212141/equal/15/AE_FCTAE_EM.txt\", sep=\" \", row.names=cl[,1],header=FALSE)\n",
    "#factorization=read.table(\"../data/simulations_20210329212141/equal/15/DAE_FAETC_EM.txt\", sep=\" \", row.names=cl[,1],header=FALSE)\n",
    "#factorization=read.table(\"../data/simulations_20210329212141/equal/15/DAE_FCTAE_EM.txt\", sep=\" \", row.names=cl[,1],header=FALSE)\n",
    "factorization=read.table(\"../data/simulations_20210329212141/equal/15/VAE_FCTAE_EM.txt\", sep=\" \", row.names=cl[,1],header=FALSE)\n",
    "#factorization=read.table(\"../data/simulations_20210329212141/equal/15/LSTMVAE_FCTAE_EM.txt\", sep=\" \", row.names=cl[,1],header=FALSE)\n",
    "\n",
    "\n",
    "\n",
    "factors <- factorization\n",
    "#factors <- factorizations[[i]][[1]]\n",
    "\n",
    "#print(factors)\n",
    "# Clustering by Kmeans\n",
    "JI_good <- numeric(0)\n",
    "for (run in 1:1000) {\n",
    "kmeans.out <- kmeans(factors, centers=number_cl) \n",
    "clust_iCluster <- as.matrix(kmeans.out$cluster)\n",
    "cat(\"clust_iCluster:\",clust_iCluster,\"\\n\")\n",
    "######creation sets of samples\n",
    "JI_mat <- numeric(0)\n",
    "for (p in 1:number_cl) {\n",
    "    x1  <- rownames(clust_iCluster)[which(clust_iCluster[,1]==p)]\n",
    "    print(x1)\n",
    "\n",
    "    row <- numeric(0)\n",
    "    for(j in 1:number_cl) {\n",
    "        x2  <- rownames(cl2)[which(cl2[,1]==j)]\n",
    "        cat(\"x2:\",x2,\"\\n\")\n",
    "        I   <- length(intersect(x1,x2))#交集\n",
    "        cat(\"I:\",I,\"\\n\")\n",
    "        S   <- I/(length(x1)+length(x2)-I)\n",
    "        cat(\"S:\",S,\"\\n\")\n",
    "        row <- cbind(row,S)\n",
    "        cat(\"row:\",row,\"\\n\")\n",
    "     }\n",
    "     JI_mat <- rbind(JI_mat,row)\n",
    "     cat(\"JI_mat:\",JI_mat,\"\\n\")\n",
    "     print(JI_mat)\n",
    "\n",
    "\n",
    " }\n",
    " JI_good <- rbind(JI_good,apply(JI_mat,1,max))\n",
    " cat(\"JI_good:\",JI_good,\"\\n\")\n",
    "}\n",
    "JI_final[1:number_cl] <- apply(JI_good,2,mean)\n",
    "JI_final"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "cl2: 7 7 12 2 5 15 7 10 15 8 13 4 3 7 15 10 2 2 9 14 2 13 10 10 13 8 1 9 10 11 12 15 9 2 12 14 6 11 3 1 5 8 6 2 13 11 5 4 8 7 5 1 1 12 14 15 3 9 5 10 1 13 11 6 5 3 4 6 6 8 3 9 11 6 14 14 7 13 6 4 9 15 13 11 12 11 2 5 3 9 15 14 4 1 1 7 8 12 4 3 \n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "IOPub data rate exceeded.\n",
      "The notebook server will temporarily stop sending output\n",
      "to the client in order to avoid crashing it.\n",
      "To change this limit, set the config variable\n",
      "`--NotebookApp.iopub_data_rate_limit`.\n",
      "\n",
      "Current values:\n",
      "NotebookApp.iopub_data_rate_limit=1000000.0 (bytes/sec)\n",
      "NotebookApp.rate_limit_window=3.0 (secs)\n",
      "\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<caption>A matrix: 15 × 1 of type dbl</caption>\n",
       "<tbody>\n",
       "\t<tr><td>0.4727026</td></tr>\n",
       "\t<tr><td>0.4756525</td></tr>\n",
       "\t<tr><td>0.4718643</td></tr>\n",
       "\t<tr><td>0.4635589</td></tr>\n",
       "\t<tr><td>0.4793765</td></tr>\n",
       "\t<tr><td>0.4613873</td></tr>\n",
       "\t<tr><td>0.4629963</td></tr>\n",
       "\t<tr><td>0.4653092</td></tr>\n",
       "\t<tr><td>0.4717958</td></tr>\n",
       "\t<tr><td>0.4745232</td></tr>\n",
       "\t<tr><td>0.4752839</td></tr>\n",
       "\t<tr><td>0.4738429</td></tr>\n",
       "\t<tr><td>0.4763239</td></tr>\n",
       "\t<tr><td>0.4642153</td></tr>\n",
       "\t<tr><td>0.4669012</td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "A matrix: 15 × 1 of type dbl\n",
       "\\begin{tabular}{l}\n",
       "\t 0.4727026\\\\\n",
       "\t 0.4756525\\\\\n",
       "\t 0.4718643\\\\\n",
       "\t 0.4635589\\\\\n",
       "\t 0.4793765\\\\\n",
       "\t 0.4613873\\\\\n",
       "\t 0.4629963\\\\\n",
       "\t 0.4653092\\\\\n",
       "\t 0.4717958\\\\\n",
       "\t 0.4745232\\\\\n",
       "\t 0.4752839\\\\\n",
       "\t 0.4738429\\\\\n",
       "\t 0.4763239\\\\\n",
       "\t 0.4642153\\\\\n",
       "\t 0.4669012\\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "A matrix: 15 × 1 of type dbl\n",
       "\n",
       "| 0.4727026 |\n",
       "| 0.4756525 |\n",
       "| 0.4718643 |\n",
       "| 0.4635589 |\n",
       "| 0.4793765 |\n",
       "| 0.4613873 |\n",
       "| 0.4629963 |\n",
       "| 0.4653092 |\n",
       "| 0.4717958 |\n",
       "| 0.4745232 |\n",
       "| 0.4752839 |\n",
       "| 0.4738429 |\n",
       "| 0.4763239 |\n",
       "| 0.4642153 |\n",
       "| 0.4669012 |\n",
       "\n"
      ],
      "text/plain": [
       "      [,1]     \n",
       " [1,] 0.4727026\n",
       " [2,] 0.4756525\n",
       " [3,] 0.4718643\n",
       " [4,] 0.4635589\n",
       " [5,] 0.4793765\n",
       " [6,] 0.4613873\n",
       " [7,] 0.4629963\n",
       " [8,] 0.4653092\n",
       " [9,] 0.4717958\n",
       "[10,] 0.4745232\n",
       "[11,] 0.4752839\n",
       "[12,] 0.4738429\n",
       "[13,] 0.4763239\n",
       "[14,] 0.4642153\n",
       "[15,] 0.4669012"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "number_cl=15\n",
    "ind <- 0\n",
    "JI_final <- matrix(data=NA, nrow=number_cl, ncol=1)\n",
    "#cat(JI_final,\"\\n\")\n",
    "# Read clusters imposed on simulated data \n",
    "cl  <- as.matrix(read.table(\"../data/simulations_20210329212141/equal/15/clusters.txt\", \n",
    "                            sep=\"\\t\", row.names=1, header=TRUE))\n",
    "#cat(\"cl:\",cl,\"\\t\")\n",
    "cl2 <- as.matrix(as.numeric(cl[,2]))\n",
    "cat(\"cl2:\",cl2[,1],\"\\n\")\n",
    "rownames(cl2) <- cl[,1]\n",
    "\n",
    "#factorization=read.table(\"../data/simulations_20210329212141/equal/15/AE_FAETC_EM.txt\", sep=\" \", row.names=cl[,1],header=FALSE)\n",
    "#factorization=read.table(\"../data/simulations_20210329212141/equal/15/AE_FCTAE_EM.txt\", sep=\" \", row.names=cl[,1],header=FALSE)\n",
    "#factorization=read.table(\"../data/simulations_20210329212141/equal/15/DAE_FAETC_EM.txt\", sep=\" \", row.names=cl[,1],header=FALSE)\n",
    "#factorization=read.table(\"../data/simulations_20210329212141/equal/15/DAE_FCTAE_EM.txt\", sep=\" \", row.names=cl[,1],header=FALSE)\n",
    "#factorization=read.table(\"../data/simulations_20210329212141/equal/15/VAE_FCTAE_EM.txt\", sep=\" \", row.names=cl[,1],header=FALSE)\n",
    "factorization=read.table(\"../data/simulations_20210329212141/equal/15/LSTMVAE_FCTAE_EM.txt\", sep=\" \", row.names=cl[,1],header=FALSE)\n",
    "\n",
    "\n",
    "\n",
    "factors <- factorization\n",
    "#factors <- factorizations[[i]][[1]]\n",
    "\n",
    "#print(factors)\n",
    "# Clustering by Kmeans\n",
    "JI_good <- numeric(0)\n",
    "for (run in 1:1000) {\n",
    "kmeans.out <- kmeans(factors, centers=number_cl) \n",
    "clust_iCluster <- as.matrix(kmeans.out$cluster)\n",
    "cat(\"clust_iCluster:\",clust_iCluster,\"\\n\")\n",
    "######creation sets of samples\n",
    "JI_mat <- numeric(0)\n",
    "for (p in 1:number_cl) {\n",
    "    x1  <- rownames(clust_iCluster)[which(clust_iCluster[,1]==p)]\n",
    "    print(x1)\n",
    "\n",
    "    row <- numeric(0)\n",
    "    for(j in 1:number_cl) {\n",
    "        x2  <- rownames(cl2)[which(cl2[,1]==j)]\n",
    "        cat(\"x2:\",x2,\"\\n\")\n",
    "        I   <- length(intersect(x1,x2))#交集\n",
    "        cat(\"I:\",I,\"\\n\")\n",
    "        S   <- I/(length(x1)+length(x2)-I)\n",
    "        cat(\"S:\",S,\"\\n\")\n",
    "        row <- cbind(row,S)\n",
    "        cat(\"row:\",row,\"\\n\")\n",
    "     }\n",
    "     JI_mat <- rbind(JI_mat,row)\n",
    "     cat(\"JI_mat:\",JI_mat,\"\\n\")\n",
    "     print(JI_mat)\n",
    "\n",
    "\n",
    " }\n",
    " JI_good <- rbind(JI_good,apply(JI_mat,1,max))\n",
    " cat(\"JI_good:\",JI_good,\"\\n\")\n",
    "}\n",
    "JI_final[1:number_cl] <- apply(JI_good,2,mean)\n",
    "JI_final"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "R",
   "language": "R",
   "name": "ir"
  },
  "language_info": {
   "codemirror_mode": "r",
   "file_extension": ".r",
   "mimetype": "text/x-r-source",
   "name": "R",
   "pygments_lexer": "r",
   "version": "3.5.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}