Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- "cells": [
- {
- "metadata": {
- "ExecuteTime": {
- "start_time": "2019-06-14T10:13:38.716038Z",
- "end_time": "2019-06-14T10:16:04.317510Z"
- },
- "trusted": true
- },
- "cell_type": "code",
- "source": "#Manager function\n\nimport joblib\nfrom joblib import Parallel,delayed\n\nimport importlib\nimport MCTS2\nimportlib.reload(MCTS2)\n\n\nimport numpy as np\n#protein = \"hhppppphhppphppphp\" #Best score -4 length 18\n#protein,maxValue = \"hphphhhppphhhhpphh\",8 #Best score -8 length 18\nprotein, maxValue = \"BWBWWBBWBWWBWBBWWBWB\",9 #Best score -9 length = 20 #B = H\n#protein,maxValue = \"WWWBBWWBBWWWWWBBBBBBBWWBBWWWWBBWWBWW\",14 #Best score -14 length 36\n#protein,maxValue = \"WWBWWBBWWWWBBWWWWBBWWWWBB\",8 #Best score -8 length 25\n#protein,maxValue = \"pphpphhpphhppppphhhhhhhhhhpppppphhpphhpphpphhhhh\",23 #Best score -23 length 48\nprotein,maxValue = \"PPPHHPPHHHHPPHHHPHHPHHPHHHHPPPPPPPPHHHHHHPPHHHHHHPPPPPPPPPHPHHPHHHHHHHHHHHPPHHHPHHPHPPHPHHHPPPPPPHHH\" ,50 #length 100, score-50\n#protein,maxValue = \"HHPHPHPHPHHHHPHPPPHPPPHPPPPHPPPHPPPHPHHHHPHPHPHPHH\",21 #Length 50, score -21\nl = []\nfor char in protein:\n if char == \"H\":\n l.append(2)\n else:\n l.append(1)\n\nproteinArray = np.array(l)\nprint(\"Length of protein\", proteinArray.shape[0])\n\n\nparams = MCTS2.params(alpha=0.04,\n nRuns = 100_000,\n maxValue = maxValue,\n selectionAlgorithm=MCTS2.MCTS,\n updateAlgorithm= MCTS2.UpdateNodesMCTS)\n\n#---------------------------------------------------------\n# Serial runs\n#---------------------------------------------------------\n#maxScore,foundRun,maxRun,board,nIllegalRuns ,alpha= MCTS2.MainLoop(proteinArray,maxValue,MCTS2.GreedyEpsilon,MCTS2.UpdateNodesEpsilon,.95)\nmaxScore,foundRun,maxRun,board,nIllegalRuns ,alpha, nRepeated,analysisNodes = MCTS2.MainLoop(proteinArray,params)\nprint(f\"Score {maxScore} run {foundRun} repeated routes {nRepeated} incomplete {nIllegalRuns}\")\n#MCTS2.ShowMolecule1(maxRun,board)\n\n#---------------------------------------------------------\n# Parallel runs\n#---------------------------------------------------------\n#results = Parallel(n_jobs=8)(delayed(MCTS2.MainLoop)(proteinArray,params) for i in range(8))\n# #results = Parallel(n_jobs=8)(delayed(MainLoop)(proteinArray,maxValue,GreedyEpsilon,UpdateNodesEpsilon,.9) for i in range(10))\n#formattedResults = [f\"Alpha {results[i][5]:.2f} Max found {results[i][0]} on iteration {results[i][1]}\" for i in range(len(results))]\n#print(*formattedResults,sep=\"\\n\")\n#MCTS2.ShowMolecule1(results[0][2],board)\n\n ",
- "execution_count": 17,
- "outputs": [
- {
- "output_type": "stream",
- "text": "Length of protein 100\n",
- "name": "stdout"
- },
- {
- "output_type": "stream",
- "text": "Max score 39: 100%|████████████████████████████████████████| 100000/100000 [02:25<00:00, 687.10it/s]\n",
- "name": "stderr"
- },
- {
- "output_type": "stream",
- "text": "Score 39 run 36549 repeated routes 42967 incomplete 0\n",
- "name": "stdout"
- }
- ]
- },
- {
- "metadata": {
- "ExecuteTime": {
- "end_time": "2019-06-12T08:54:15.749544Z",
- "start_time": "2019-06-12T08:54:15.706530Z"
- },
- "trusted": true
- },
- "cell_type": "code",
- "source": "import pandas as pd\nimport qgrid\nqgrid.set_grid_option('forceFitColumns',False)\nqgrid.set_grid_option('filterable',False)\nqgrid.enable()\ndf = pd.DataFrame(analysisNodes[1:15,6:9],columns=['Left','Forwards','Right'])\ndf",
- "execution_count": null,
- "outputs": []
- },
- {
- "metadata": {
- "ExecuteTime": {
- "end_time": "2019-06-12T09:12:43.726256Z",
- "start_time": "2019-06-12T09:12:43.460747Z"
- },
- "trusted": true
- },
- "cell_type": "code",
- "source": "MCTS2.ShowMolecule1(maxRun,board)",
- "execution_count": null,
- "outputs": []
- },
- {
- "metadata": {
- "ExecuteTime": {
- "end_time": "2019-06-12T09:21:16.477131Z",
- "start_time": "2019-06-12T09:21:13.019113Z"
- },
- "trusted": true
- },
- "cell_type": "code",
- "source": "MCTS2.drawTree()",
- "execution_count": null,
- "outputs": []
- },
- {
- "metadata": {
- "ExecuteTime": {
- "end_time": "2019-06-12T09:26:15.543294Z",
- "start_time": "2019-06-12T09:26:15.499794Z"
- },
- "trusted": true
- },
- "cell_type": "code",
- "source": "df = pd.DataFrame(analysisNodes)\ndf[1:100]",
- "execution_count": null,
- "outputs": []
- },
- {
- "metadata": {
- "ExecuteTime": {
- "end_time": "2019-06-12T13:16:49.416532Z",
- "start_time": "2019-06-12T13:16:49.238036Z"
- },
- "trusted": true
- },
- "cell_type": "code",
- "source": "print(analysisNodes[-100:])\nprint(np.sum(analysisNodes[:,9]))",
- "execution_count": null,
- "outputs": []
- },
- {
- "metadata": {
- "trusted": true
- },
- "cell_type": "code",
- "source": "",
- "execution_count": null,
- "outputs": []
- }
- ],
- "metadata": {
- "hide_input": false,
- "kernelspec": {
- "name": "python3",
- "display_name": "Python 3",
- "language": "python"
- },
- "language_info": {
- "name": "python",
- "version": "3.7.3",
- "mimetype": "text/x-python",
- "codemirror_mode": {
- "name": "ipython",
- "version": 3
- },
- "pygments_lexer": "ipython3",
- "nbconvert_exporter": "python",
- "file_extension": ".py"
- },
- "toc": {
- "nav_menu": {},
- "number_sections": true,
- "sideBar": false,
- "skip_h1_title": true,
- "base_numbering": 1,
- "title_cell": "Table of Contents",
- "title_sidebar": "Contents",
- "toc_cell": false,
- "toc_position": {
- "height": "47px",
- "left": "1117px",
- "top": "257px",
- "width": "161px"
- },
- "toc_section_display": false,
- "toc_window_display": true
- },
- "varInspector": {
- "window_display": false,
- "cols": {
- "lenName": 16,
- "lenType": 16,
- "lenVar": 40
- },
- "kernels_config": {
- "python": {
- "library": "var_list.py",
- "delete_cmd_prefix": "del ",
- "delete_cmd_postfix": "",
- "varRefreshCmd": "print(var_dic_list())"
- },
- "r": {
- "library": "var_list.r",
- "delete_cmd_prefix": "rm(",
- "delete_cmd_postfix": ") ",
- "varRefreshCmd": "cat(var_dic_list()) "
- }
- },
- "types_to_exclude": [
- "module",
- "function",
- "builtin_function_or_method",
- "instance",
- "_Feature"
- ]
- },
- "gist": {
- "id": "",
- "data": {
- "description": "Protein Folding/Protein Folding - Management function.ipynb",
- "public": true
- }
- }
- },
- "nbformat": 4,
- "nbformat_minor": 2
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement