Advertisement
Guest User

Untitled

a guest
Feb 16th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JSON 11.68 KB | None | 0 0
  1. {
  2.  "cells": [
  3.   {
  4.    "cell_type": "code",
  5.    "execution_count": 5,
  6.    "metadata": {
  7.     "ExecuteTime": {
  8.      "end_time": "2019-02-14T07:57+0000",
  9.      "start_time": "2019-02-14T07:57+0000"
  10.     }
  11.    },
  12.    "outputs": [
  13.     {
  14.      "data": {
  15.       "application/vnd.jupyter.widget-view+json": {
  16.        "model_id": "",
  17.        "version_major": 2,
  18.        "version_minor": 0
  19.       },
  20.       "method": "display_data"
  21.      },
  22.      "metadata": {},
  23.      "output_type": "display_data"
  24.     }
  25.    ],
  26.    "source": [
  27.     "%classpath add mvn org.apache.commons commons-math3 3.6.1"
  28.    ]
  29.   },
  30.   {
  31.    "cell_type": "code",
  32.    "execution_count": 59,
  33.    "metadata": {
  34.     "ExecuteTime": {
  35.      "end_time": "2019-02-14T08:36+0000",
  36.      "start_time": "2019-02-14T08:36+0000"
  37.     }
  38.    },
  39.    "outputs": [
  40.     {
  41.      "data": {
  42.       "text/plain": [
  43.        "#000b7e"
  44.       ]
  45.      },
  46.      "execution_count": 59,
  47.      "metadata": {},
  48.      "output_type": "execute_result"
  49.     }
  50.    ],
  51.    "source": [
  52.     "def randomRgbCode() {\n",
  53.     "    def rgb = new Random().nextInt(1 << 12) // A random 24-bit integer\n",
  54.     "    '#00' + Integer.toString(rgb, 16).padLeft(4, '0')\n",
  55.     "}\n",
  56.     "randomRgbCode()"
  57.    ]
  58.   },
  59.   {
  60.    "cell_type": "code",
  61.    "execution_count": 74,
  62.    "metadata": {
  63.     "ExecuteTime": {
  64.      "end_time": "2019-02-14T16:41+0000",
  65.      "start_time": "2019-02-14T16:41+0000"
  66.     },
  67.     "scrolled": true
  68.    },
  69.    "outputs": [
  70.     {
  71.      "data": {
  72.       "text/plain": [
  73.        "script1550162502672$_run_closure3@437165e5"
  74.       ]
  75.      },
  76.      "execution_count": 74,
  77.      "metadata": {},
  78.      "output_type": "execute_result"
  79.     }
  80.    ],
  81.    "source": [
  82.     "import org.apache.commons.math3.stat.regression.SimpleRegression\n",
  83.     "\n",
  84.     "/*\n",
  85.     "def randomRgbCode() {\n",
  86.     "    def rgb = new Random().nextInt(1 << 24) // A random 24-bit integer\n",
  87.     "    '#' + Integer.toString(rgb, 16).padLeft(6, '0')\n",
  88.     "}\n",
  89.     "*/\n",
  90.     "\n",
  91.     "def randomRgbCode() {\n",
  92.     "    def rgb = new Random().nextInt(1 << 12) // A random 24-bit integer\n",
  93.     "    '#00' + Integer.toString(rgb, 16).padLeft(4, '0')\n",
  94.     "}\n",
  95.     "\n",
  96.     "@Grab('com.xlson.groovycsv:groovycsv:1.3')\n",
  97.     "import static com.xlson.groovycsv.CsvParser.parseCsv\n",
  98.     "\n",
  99.     "add_data_points = { file_name,plot,runs,randomcolor -> \n",
  100.     "    \n",
  101.     "    for(num = 0; num<runs-1; num++){\n",
  102.     "        fh = new File(\"${file_name}${num}.tsv\")\n",
  103.     "        def csv_content = fh.getText('utf-8')\n",
  104.     "        data_iterator = parseCsv(csv_content, separator: ' ', readFirstLine: true)\n",
  105.     "        // println data_iterator.getClass()  // class com.xlson.groovycsv.CsvIterator\n",
  106.     "\n",
  107.     "        x = []\n",
  108.     "        y = []\n",
  109.     "\n",
  110.     "        for (line in data_iterator) {\n",
  111.     "            x_1 = Double.parseDouble(line[0])\n",
  112.     "            y_1 = Double.parseDouble(line[1])\n",
  113.     "\n",
  114.     "            x << x_1\n",
  115.     "            y << y_1\n",
  116.     "\n",
  117.     "            //regression.addData(x_1,y_1)\n",
  118.     "        }\n",
  119.     "\n",
  120.     "        def color = randomcolor ? Color.decode(randomRgbCode()) : Color.RED\n",
  121.     "        plot << new Points(x: x,y: y,color: color)\n",
  122.     "    }\n",
  123.     "}\n",
  124.     "\n",
  125.     "print_paretos = { exp_name,runs ->\n",
  126.     "\n",
  127.     "    plot = new Plot(title: \"Pareto Front\", initHeight: 200)\n",
  128.     "\n",
  129.     "    //regression = new SimpleRegression()\n",
  130.     "\n",
  131.     "    add_data_points(\"${exp_name}/FUN\",plot,runs,true)\n",
  132.     "\n",
  133.     "    //regression.regress()\n",
  134.     "\n",
  135.     "    intercept = regression.getIntercept()\n",
  136.     "    slope = regression.getSlope()\n",
  137.     "    \n",
  138.     "    println(\"Intercept: ${intercept}\")\n",
  139.     "    println(\"Slope: ${slope}\")\n",
  140.     "\n",
  141.     "    plot << new Line(x: [0,1],y: [regression.predict(0),regression.predict(1)], width: 3, color: Color.red)\n",
  142.     "\n",
  143.     "    return plot\n",
  144.     "}\n",
  145.     "\n",
  146.     "compare_single_multi = { single_file, multi_file, runs ->\n",
  147.     "\n",
  148.     "    plot = new Plot(title: \"Comparison\", initHeight: 200)\n",
  149.     "\n",
  150.     "    //regression = new SimpleRegression()\n",
  151.     "\n",
  152.     "    add_data_points(\"${single_file}/DEC\",plot,runs,false)\n",
  153.     "    add_data_points(\"${multi_file}/FUN\",plot,runs,true)\n",
  154.     "    \n",
  155.     "    //regression.regress()\n",
  156.     "\n",
  157.     "    //intercept = regression.getIntercept()\n",
  158.     "    //slope = regression.getSlope()\n",
  159.     "    \n",
  160.     "    //println(\"Intercept: ${intercept}\")\n",
  161.     "    //println(\"Slope: ${slope}\")\n",
  162.     "\n",
  163.     "    //plot << new Line(x: [0,1],y: [regression.predict(0),regression.predict(1)], width: 3, color: Color.red)\n",
  164.     "\n",
  165.     "    return plot\n",
  166.     "}"
  167.    ]
  168.   },
  169.   {
  170.    "cell_type": "code",
  171.    "execution_count": 5,
  172.    "metadata": {
  173.     "ExecuteTime": {
  174.      "end_time": "2019-02-11T22:54+0000",
  175.      "start_time": "2019-02-11T22:54+0000"
  176.     }
  177.    },
  178.    "outputs": [
  179.     {
  180.      "ename": "groovy.lang.MissingPropertyException",
  181.      "evalue": " No such property",
  182.      "output_type": "error",
  183.      "traceback": [
  184.       "\u001b[1;31mgroovy.lang.MissingPropertyException: No such property: x for class: script1549925654529\u001b[0;0m",
  185.       "\u001b[1;31m\tat this cell line 2\u001b[0;0m",
  186.       "\u001b[0;31m\tat com.twosigma.beakerx.groovy.evaluator.GroovyCodeRunner.runScript(GroovyCodeRunner.java:94)\u001b[0;0m",
  187.       "\u001b[0;31m\tat com.twosigma.beakerx.groovy.evaluator.GroovyCodeRunner.call(GroovyCodeRunner.java:59)\u001b[0;0m",
  188.       "\u001b[0;31m\tat com.twosigma.beakerx.groovy.evaluator.GroovyCodeRunner.call(GroovyCodeRunner.java:32)\u001b[0;0m"
  189.      ]
  190.     }
  191.    ],
  192.    "source": [
  193.     "plot = new Plot(title: \"Pareto Front\", initHeight: 200)\n",
  194.     "plot << new Points(x: x,y: y,color: Color.green)\n"
  195.    ]
  196.   },
  197.   {
  198.    "cell_type": "code",
  199.    "execution_count": 6,
  200.    "metadata": {
  201.     "ExecuteTime": {
  202.      "end_time": "2019-02-11T22:54+0000",
  203.      "start_time": "2019-02-11T22:54+0000"
  204.     },
  205.     "scrolled": false
  206.    },
  207.    "outputs": [
  208.     {
  209.      "name": "stdout",
  210.      "output_type": "stream",
  211.      "text": [
  212.       "Intercept: 0.7886246425446715\n",
  213.       "Slope: -0.21135806388698367\n",
  214.       "Intercept: 0.7389477566186027\n",
  215.       "Slope: -0.14569380154389486\n",
  216.       "Intercept: 0.6759963217641969\n",
  217.       "Slope: -0.06007280615199858\n"
  218.      ]
  219.     },
  220.     {
  221.      "data": {
  222.       "application/vnd.jupyter.widget-view+json": {
  223.        "model_id": "313d1a3d-2c1c-4c47-bd8b-8ada54f05905",
  224.        "version_major": 2,
  225.        "version_minor": 0
  226.       },
  227.       "method": "display_data"
  228.      },
  229.      "metadata": {},
  230.      "output_type": "display_data"
  231.     },
  232.     {
  233.      "data": {
  234.       "application/vnd.jupyter.widget-view+json": {
  235.        "model_id": "5665b593-0f52-4fa9-a12a-4d4338312556",
  236.        "version_major": 2,
  237.        "version_minor": 0
  238.       },
  239.       "method": "display_data"
  240.      },
  241.      "metadata": {},
  242.      "output_type": "display_data"
  243.     },
  244.     {
  245.      "data": {
  246.       "application/vnd.jupyter.widget-view+json": {
  247.        "model_id": "88f500a8-3fc1-48c6-9932-46fa4930ca49",
  248.        "version_major": 2,
  249.        "version_minor": 0
  250.       },
  251.       "method": "display_data"
  252.      },
  253.      "metadata": {},
  254.      "output_type": "display_data"
  255.     },
  256.     {
  257.      "data": {
  258.       "text/plain": [
  259.        "null"
  260.       ]
  261.      },
  262.      "execution_count": 6,
  263.      "metadata": {},
  264.      "output_type": "execute_result"
  265.     }
  266.    ],
  267.    "source": [
  268.     "plot1 = print_paretos(\"20_20_200_1549559439556\",20)\n",
  269.     "plot2 = print_paretos(\"20_20_200_1549559804878\",20)\n",
  270.     "plot3 = print_paretos(\"NONE\",200)\n",
  271.     "\n",
  272.     "display(plot1)\n",
  273.     "display(plot2)\n",
  274.     "display(plot3)"
  275.    ]
  276.   },
  277.   {
  278.    "cell_type": "code",
  279.    "execution_count": 28,
  280.    "metadata": {
  281.     "ExecuteTime": {
  282.      "end_time": "2019-02-14T08:26+0000",
  283.      "start_time": "2019-02-14T08:26+0000"
  284.     }
  285.    },
  286.    "outputs": [
  287.     {
  288.      "data": {
  289.       "application/vnd.jupyter.widget-view+json": {
  290.        "model_id": "ec116549-da43-4990-8e57-3a3589b7e7ba",
  291.        "version_major": 2,
  292.        "version_minor": 0
  293.       },
  294.       "method": "display_data"
  295.      },
  296.      "metadata": {},
  297.      "output_type": "display_data"
  298.     }
  299.    ],
  300.    "source": [
  301.     "compare_single_multi(\"Thing Study/data/Genetic_Algorithm_20_20_200_1550128953961/SingleObjectiveGrouping_20\",\"Thing Study/data/NSGAII_20_20_200_1550099845667/MultiObjectiveGrouping_20\",20)"
  302.    ]
  303.   },
  304.   {
  305.    "cell_type": "code",
  306.    "execution_count": 27,
  307.    "metadata": {
  308.     "ExecuteTime": {
  309.      "end_time": "2019-02-14T08:26+0000",
  310.      "start_time": "2019-02-14T08:26+0000"
  311.     }
  312.    },
  313.    "outputs": [
  314.     {
  315.      "data": {
  316.       "application/vnd.jupyter.widget-view+json": {
  317.        "model_id": "097ee876-2311-45d6-a198-71e1df28df6a",
  318.        "version_major": 2,
  319.        "version_minor": 0
  320.       },
  321.       "method": "display_data"
  322.      },
  323.      "metadata": {},
  324.      "output_type": "display_data"
  325.     }
  326.    ],
  327.    "source": [
  328.     "compare_single_multi(\"Thing Study/data/Genetic_Algorithm_20_20_200_1550128953961/SingleObjectiveGrouping_200\",\"Thing Study/data/NSGAII_20_20_200_1550099845667/MultiObjectiveGrouping_200\",20)"
  329.    ]
  330.   },
  331.   {
  332.    "cell_type": "code",
  333.    "execution_count": 75,
  334.    "metadata": {
  335.     "ExecuteTime": {
  336.      "end_time": "2019-02-14T16:41+0000",
  337.      "start_time": "2019-02-14T16:41+0000"
  338.     }
  339.    },
  340.    "outputs": [
  341.     {
  342.      "name": "stdout",
  343.      "output_type": "stream",
  344.      "text": [
  345.       "Intercept: NaN\n",
  346.       "Slope: NaN\n"
  347.      ]
  348.     },
  349.     {
  350.      "data": {
  351.       "application/vnd.jupyter.widget-view+json": {
  352.        "model_id": "8935f6b2-a173-420d-9bdf-53f8225e3fab",
  353.        "version_major": 2,
  354.        "version_minor": 0
  355.       },
  356.       "method": "display_data"
  357.      },
  358.      "metadata": {},
  359.      "output_type": "display_data"
  360.     }
  361.    ],
  362.    "source": [
  363.     "plot = print_paretos(\"Thing Study/data/NSGAII_200_20_200_1550132169095/MultiObjectiveGrouping_200\",200)\n",
  364.     "add_data_points(\"Thing Study/data/Genetic_Algorithm_20_20_200_1550128953961/SingleObjectiveGrouping_200/DEC\",plot,20,false)\n",
  365.     "\n",
  366.     "plot"
  367.    ]
  368.   },
  369.   {
  370.    "cell_type": "code",
  371.    "execution_count": 73,
  372.    "metadata": {
  373.     "ExecuteTime": {
  374.      "end_time": "2019-02-14T16:00+0000",
  375.      "start_time": "2019-02-14T16:00+0000"
  376.     },
  377.     "scrolled": true
  378.    },
  379.    "outputs": [
  380.     {
  381.      "data": {
  382.       "application/vnd.jupyter.widget-view+json": {
  383.        "model_id": "bb5c3ce5-ed83-4edc-8247-0d83e2c89ee8",
  384.        "version_major": 2,
  385.        "version_minor": 0
  386.       },
  387.       "method": "display_data"
  388.      },
  389.      "metadata": {},
  390.      "output_type": "display_data"
  391.     }
  392.    ],
  393.    "source": [
  394.     "new_plot = new Plot(title: \"Single points\", initHeight: 200)\n",
  395.     "add_data_points(\"Thing Study/data/Genetic_Algorithm_20_20_200_1550159784855/SingleObjectiveGrouping_200/DEC\",new_plot,20,false)\n",
  396.     "new_plot"
  397.    ]
  398.   }
  399.  ],
  400.  "metadata": {
  401.   "kernelspec": {
  402.    "display_name": "Groovy",
  403.    "language": "groovy",
  404.    "name": "groovy"
  405.   },
  406.   "language_info": {
  407.    "codemirror_mode": "groovy",
  408.    "file_extension": ".groovy",
  409.    "mimetype": "",
  410.    "name": "Groovy",
  411.    "nbconverter_exporter": "",
  412.    "version": "2.4.3"
  413.   },
  414.   "toc": {
  415.    "base_numbering": 1,
  416.    "nav_menu": {},
  417.    "number_sections": false,
  418.    "sideBar": false,
  419.    "skip_h1_title": false,
  420.    "title_cell": "Table of Contents",
  421.    "title_sidebar": "Contents",
  422.    "toc_cell": false,
  423.    "toc_position": {},
  424.    "toc_section_display": false,
  425.    "toc_window_display": false
  426.   }
  427.  },
  428.  "nbformat": 4,
  429.  "nbformat_minor": 2
  430. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement