[0b32b6]: / R-scripts / scripts / .ipynb_checkpoints / 聚类结果画盒型图-checkpoint.ipynb

Download this file

296 lines (295 with data), 13.8 kB

{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1] \"../data/simulations_20210329212141/equal/5/JI.txt\"\n",
      "   AE_FAETC X.AE_FCTAE X.DAE_FAETC X.DAE_FCTAE X.VAE_FCTAE X.LSTMVAE_FCTAE\n",
      "1 0.7864754  0.8555881   0.7650096   0.8729629   0.5151694       0.5910766\n",
      "2 0.7930283  0.8557713   0.7663618   0.8816597   0.5152971       0.5982880\n",
      "3 0.7815983  0.8519293   0.7703164   0.8696588   0.5112708       0.5954603\n",
      "4 0.7874296  0.8380773   0.7777636   0.8815903   0.5303783       0.6026711\n",
      "5 0.7998520  0.8593818   0.7718466   0.8699363   0.5228915       0.5959956\n",
      " [1] \"AE_FAETC_HET\"        \"AE_FAETC_EQ\"         \"X.AE_FCTAE_HET\"     \n",
      " [4] \"X.AE_FCTAE_EQ\"       \"X.DAE_FAETC_HET\"     \"X.DAE_FAETC_EQ\"     \n",
      " [7] \"X.DAE_FCTAE_HET\"     \"X.DAE_FCTAE_EQ\"      \"X.VAE_FCTAE_HET\"    \n",
      "[10] \"X.VAE_FCTAE_EQ\"      \"X.LSTMVAE_FCTAE_HET\" \"X.LSTMVAE_FCTAE_EQ\" \n",
      "[1] \"../data/simulations_20210329212141/equal/10/JI.txt\"\n",
      "    AE_FAETC X.AE_FCTAE X.DAE_FAETC X.DAE_FCTAE X.VAE_FCTAE X.LSTMVAE_FCTAE\n",
      "1  0.7686000  0.7753077   0.7860100   0.8219333   0.7515000       0.4608212\n",
      "2  0.7666667  0.7911071   0.7826930   0.8166000   0.7611857       0.4539229\n",
      "3  0.7535500  0.7876333   0.7880110   0.8121667   0.7651143       0.4404087\n",
      "4  0.7576000  0.7868333   0.7756981   0.8264000   0.7584012       0.4448950\n",
      "5  0.7420833  0.7930950   0.7764907   0.8163333   0.7577496       0.4528135\n",
      "6  0.7601000  0.7917452   0.7704681   0.8122667   0.7632258       0.4485148\n",
      "7  0.7503833  0.7896333   0.7619731   0.8235000   0.7605238       0.4548279\n",
      "8  0.7638190  0.7692190   0.7753311   0.8115667   0.7674000       0.4511056\n",
      "9  0.7649667  0.7795667   0.7807456   0.8183000   0.7581286       0.4587046\n",
      "10 0.7444429  0.7947190   0.7599756   0.8188286   0.7734583       0.4514359\n",
      " [1] \"AE_FAETC_HET\"        \"AE_FAETC_EQ\"         \"X.AE_FCTAE_HET\"     \n",
      " [4] \"X.AE_FCTAE_EQ\"       \"X.DAE_FAETC_HET\"     \"X.DAE_FAETC_EQ\"     \n",
      " [7] \"X.DAE_FCTAE_HET\"     \"X.DAE_FCTAE_EQ\"      \"X.VAE_FCTAE_HET\"    \n",
      "[10] \"X.VAE_FCTAE_EQ\"      \"X.LSTMVAE_FCTAE_HET\" \"X.LSTMVAE_FCTAE_EQ\" \n",
      "[1] \"../data/simulations_20210329212141/equal/15/JI.txt\"\n",
      "    AE_FAETC X.AE_FCTAE X.DAE_FAETC X.DAE_FCTAE X.VAE_FCTAE X.LSTMVAE_FCTAE\n",
      "1  0.7663878  0.7989517   0.7532231   0.7940330   0.7365600       0.4727026\n",
      "2  0.7676835  0.8052115   0.7563619   0.8056647   0.7399893       0.4756525\n",
      "3  0.7621207  0.8019024   0.7594553   0.7995865   0.7380597       0.4718643\n",
      "4  0.7733462  0.8157678   0.7525584   0.7820629   0.7495614       0.4635589\n",
      "5  0.7675834  0.7945885   0.7487293   0.7863840   0.7558608       0.4793765\n",
      "6  0.7461658  0.8191150   0.7492135   0.7954261   0.7513054       0.4613873\n",
      "7  0.7597422  0.8043023   0.7440258   0.7985005   0.7519942       0.4629963\n",
      "8  0.7563764  0.8144615   0.7524720   0.7922929   0.7433741       0.4653092\n",
      "9  0.7619438  0.8061806   0.7362969   0.7948400   0.7291959       0.4717958\n",
      "10 0.7697440  0.8206591   0.7606681   0.8013052   0.7450379       0.4745232\n",
      "11 0.7601137  0.8057421   0.7808652   0.8022179   0.7317692       0.4752839\n",
      "12 0.7770244  0.7979146   0.7486006   0.7860330   0.7382499       0.4738429\n",
      "13 0.7786453  0.8153197   0.7620518   0.8102876   0.7398166       0.4763239\n",
      "14 0.7430794  0.8033851   0.7535825   0.7921890   0.7516091       0.4642153\n",
      "15 0.7454310  0.8177235   0.7502729   0.7864014   0.7268284       0.4669012\n",
      " [1] \"AE_FAETC_HET\"        \"AE_FAETC_EQ\"         \"X.AE_FCTAE_HET\"     \n",
      " [4] \"X.AE_FCTAE_EQ\"       \"X.DAE_FAETC_HET\"     \"X.DAE_FAETC_EQ\"     \n",
      " [7] \"X.DAE_FCTAE_HET\"     \"X.DAE_FCTAE_EQ\"      \"X.VAE_FCTAE_HET\"    \n",
      "[10] \"X.VAE_FCTAE_EQ\"      \"X.LSTMVAE_FCTAE_HET\" \"X.LSTMVAE_FCTAE_EQ\" \n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<strong>png:</strong> 2"
      ],
      "text/latex": [
       "\\textbf{png:} 2"
      ],
      "text/markdown": [
       "**png:** 2"
      ],
      "text/plain": [
       "png \n",
       "  2 "
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "list_clusters <- seq(5,15,5)\n",
    "list_distrib <-  c(\"heterogeneous\",\"equal\")\n",
    "# Save all boxplots in a single PDF output file\n",
    "results_folder<-\"../data/simulations_20210329212141/\"\n",
    "pdf(file=paste0(results_folder, \"AE_simulated_boxplots.pdf\"), width = 15, height = 15, onefile = TRUE)\n",
    "\n",
    "# For each chosen number of clusters\n",
    "for (i in list_clusters) {\n",
    "    \n",
    "    # Output files for each distribution\n",
    "    eq_file <- paste0(results_folder,  \"equal/\", i,\"/JI.txt\")\n",
    "    het_file <- paste0(results_folder,  \"heterogeneous/\",i, \"/JI.txt\")\n",
    "    print(eq_file)\n",
    "    if(exists(\"JI.final\")) rm(JI.final)\n",
    "    \n",
    "    # Load clusters (equal distribution)\n",
    "    if(file.exists(eq_file)) {\n",
    "        JI.final  <- read.table(eq_file, sep=\"\\t\", header=TRUE)\n",
    "        print(JI.final)\n",
    "        names(JI.final) <- paste0(names(JI.final), \"_EQ\")        \n",
    "    }\n",
    "    #Load clusters (heterogeneous distribution)\n",
    "    if(file.exists(het_file)) {\n",
    "        JI.het <- read.table(het_file, sep=\"\\t\", header=TRUE)\n",
    "        names_methods <- names(JI.het)\n",
    "        names(JI.het) <- paste0(names(JI.het), \"_HET\")\n",
    "\n",
    "        # Aggregate results\n",
    "        if(exists(\"JI.final\")) {\n",
    "            JI.final <- data.frame(JI.het, JI.final)\n",
    "            new_order <- apply(expand.grid(c(\"_HET\", \"_EQ\"), names_methods)[, c(2,1)], 1, paste, collapse=\"\")\n",
    "            JI.final <- JI.final[, new_order]\n",
    "        }\n",
    "        else {\n",
    "            JI.final <- JI.het\n",
    "        }\n",
    "    }\n",
    "    print(names(JI.final))\n",
    "    \n",
    "    labels<-list(\"AE_FAETC_HET\",\"AE_FAETC_EQ\",\"AE_FCTAE_HET\",\"AE_FCTAE_EQ\",\"DAE_FAETC_HET\",\"DAE_FAETC_EQ\",\"DAE_FCTAE_HET\",\"DAE_FCTAE_EQ\",\"VAE_FCTAE_HET\"    \n",
    ",\"VAE_FCTAE_EQ\",\"LSTMVAE_FCTAE_HET\",\"LSTMVAE_FCTAE_EQ\" )\n",
    "    # Plot results\n",
    "    par(mar=c(25,4,2,2)+.1)\n",
    "    boxplot(JI.final, xaxt=\"none\", cex.axis=3.5, \n",
    "                 col=c('gray','gray','red','red','blue','blue','blueviolet','blueviolet','deeppink','deeppink','chocolate1','chocolate1'), \n",
    "                 ann=FALSE, outline=FALSE)\n",
    "    matplot(1:ncol(JI.final), t(JI.final), col=\"black\", pch=16, xaxt=\"none\", cex=0.8, add=TRUE)\n",
    "    axis(1, at=1:ncol(JI.final), labels=labels, \n",
    "         las=2, srt=45, cex=0.5, cex.lab=2, cex.axis=2, cex.main=1.5, cex.sub=1.5) \n",
    "    title(main=paste(i,\"clusters\",sep=\" \"), \n",
    "          cex.lab=0.75, line = -2.5, adj=0, cex.main=3.5)\n",
    "}\n",
    "dev.off()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<strong>png:</strong> 2"
      ],
      "text/latex": [
       "\\textbf{png:} 2"
      ],
      "text/markdown": [
       "**png:** 2"
      ],
      "text/plain": [
       "png \n",
       "  2 "
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "list_clusters <- seq(5,15,5)\n",
    "\n",
    "# Save all boxplots in a single PDF output file\n",
    "results_folder<-\"../results20210115154327/\"\n",
    "# Save all boxplots in a single PDF output file\n",
    "pdf(file=paste0(results_folder, \"simulated_boxplots.pdf\"), width = 15, height = 15, onefile = TRUE)\n",
    "\n",
    "# For each chosen number of clusters\n",
    "for (i in list_clusters) {\n",
    "    \n",
    "    # Output files for each distribution\n",
    "    eq_file <- paste0(results_folder, i, \"_equal/\", \"JI.txt\")\n",
    "    het_file <- paste0(results_folder, i, \"_heterogeneous/\", \"JI.txt\")\n",
    "    if(exists(\"JI.final\")) rm(JI.final)\n",
    "    \n",
    "    # Load clusters (equal distribution)\n",
    "    if(file.exists(eq_file)) {\n",
    "        JI.final  <- read.table(eq_file, sep=\"\\t\", header=TRUE)\n",
    "        names(JI.final) <- paste0(names(JI.final), \"_EQ\")        \n",
    "    }\n",
    "    cat\n",
    "    # Load clusters (heterogeneous distribution)\n",
    "    if(file.exists(het_file)) {\n",
    "        JI.het <- read.table(het_file, sep=\"\\t\", header=TRUE)\n",
    "        names_methods <- names(JI.het)\n",
    "        names(JI.het) <- paste0(names(JI.het), \"_HET\")\n",
    "\n",
    "        # Aggregate results\n",
    "        if(exists(\"JI.final\")) {\n",
    "            JI.final <- data.frame(JI.het, JI.final)\n",
    "            new_order <- apply(expand.grid(c(\"_HET\", \"_EQ\"), names_methods)[, c(2,1)], 1, paste, collapse=\"\")\n",
    "            JI.final <- JI.final[, new_order]\n",
    "        }\n",
    "        else {\n",
    "            JI.final <- JI.het\n",
    "        }\n",
    "    }\n",
    "    \n",
    "    # Plot results\n",
    "    par(mar=c(25,4,2,2)+.1)\n",
    "    boxplot(JI.final, xaxt=\"none\", cex.axis=3.5, \n",
    "                 col=c('gray','gray','red','red','blue','blue','blueviolet','blueviolet','deeppink','deeppink','chocolate1','chocolate1','darkgoldenrod','darkgoldenrod','green','green','darkturquoise','darkturquoise'), \n",
    "                 ann=FALSE, outline=FALSE)\n",
    "    matplot(1:ncol(JI.final), t(JI.final), col=\"black\", pch=16, xaxt=\"none\", cex=0.8, add=TRUE)\n",
    "    axis(1, at=1:ncol(JI.final), labels=names(JI.final), \n",
    "         las=2, srt=45, cex=0.8, cex.lab=3.5, cex.axis=3.5, cex.main=1.5, cex.sub=1.5) \n",
    "    title(main=paste(i,\"clusters\",sep=\" \"), \n",
    "          cex.lab=0.75, line = -2.5, adj=0, cex.main=3.5)\n",
    "}\n",
    "dev.off()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "list_clusters <- seq(5,15,5)\n",
    "list_distrib <-  c(\"heterogeneous\",\"equal\")\n",
    "# Save all boxplots in a single PDF output file\n",
    "results_folder<-\"../data/simulations_20210329212141/\"\n",
    "pdf(file=paste0(results_folder, \"AE_simulated_boxplots2.pdf\"), width = 15, height = 15, onefile = TRUE)\n",
    "\n",
    "# For each chosen number of clusters\n",
    "for (i in list_clusters) {\n",
    "    \n",
    "    # Output files for each distribution\n",
    "    eq_file <- paste0(results_folder,  \"equal/\", i,\"/JI2.txt\")\n",
    "    het_file <- paste0(results_folder,  \"heterogeneous/\",i, \"/JI2.txt\")\n",
    "    print(eq_file)\n",
    "    if(exists(\"JI.final\")) rm(JI.final)\n",
    "    \n",
    "    # Load clusters (equal distribution)\n",
    "    if(file.exists(eq_file)) {\n",
    "        JI.final  <- read.table(eq_file, sep=\"\\t\", header=TRUE)\n",
    "        print(JI.final)\n",
    "        names(JI.final) <- paste0(names(JI.final), \"_EQ\")        \n",
    "    }\n",
    "    #Load clusters (heterogeneous distribution)\n",
    "    if(file.exists(het_file)) {\n",
    "        JI.het <- read.table(het_file, sep=\"\\t\", header=TRUE)\n",
    "        names_methods <- names(JI.het)\n",
    "        names(JI.het) <- paste0(names(JI.het), \"_HET\")\n",
    "\n",
    "        # Aggregate results\n",
    "        if(exists(\"JI.final\")) {\n",
    "            JI.final <- data.frame(JI.het, JI.final)\n",
    "            new_order <- apply(expand.grid(c(\"_HET\", \"_EQ\"), names_methods)[, c(2,1)], 1, paste, collapse=\"\")\n",
    "            JI.final <- JI.final[, new_order]\n",
    "        }\n",
    "        else {\n",
    "            JI.final <- JI.het\n",
    "        }\n",
    "    }\n",
    "    print(names(JI.final))\n",
    "    \n",
    "    labels<-list(\"AE_FAETC_HET\",\"AE_FAETC_EQ\",\"AE_FCTAE_HET\",\"AE_FCTAE_EQ\",\"DAE_FAETC_HET\",\"DAE_FAETC_EQ\",\"DAE_FCTAE_HET\",\"DAE_FCTAE_EQ\",\"VAE_FCTAE_HET\"    \n",
    ",\"VAE_FCTAE_EQ\",\"SVAE_FCTAE_HET\",\"SVAE_FCTAE_EQ\",\"MMDVAE_HET\",\"MMDVAE_EQ\" )\n",
    "    # Plot results\n",
    "    par(mar=c(25,4,2,2)+.1)\n",
    "    boxplot(JI.final, xaxt=\"none\", cex.axis=3.5, \n",
    "                 col=c('gray','gray','red','red','blue','blue','blueviolet','blueviolet','deeppink','deeppink','chocolate1','chocolate1'), \n",
    "                 ann=FALSE, outline=FALSE)\n",
    "    matplot(1:ncol(JI.final), t(JI.final), col=\"black\", pch=16, xaxt=\"none\", cex=0.8, add=TRUE)\n",
    "    axis(1, at=1:ncol(JI.final), labels=labels, \n",
    "         las=2, srt=45, cex=0.5, cex.lab=2, cex.axis=2, cex.main=1.5, cex.sub=1.5) \n",
    "    title(main=paste(i,\"clusters\",sep=\" \"), \n",
    "          cex.lab=0.75, line = -2.5, adj=0, cex.main=3.5)\n",
    "}\n",
    "dev.off()"
   ]
  }
 ],
 "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
}