Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.09 KB | None | 0 0
  1. {
  2. "cells": [
  3. {
  4. "metadata": {
  5. "ExecuteTime": {
  6. "start_time": "2019-06-14T10:13:38.716038Z",
  7. "end_time": "2019-06-14T10:16:04.317510Z"
  8. },
  9. "trusted": true
  10. },
  11. "cell_type": "code",
  12. "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 ",
  13. "execution_count": 17,
  14. "outputs": [
  15. {
  16. "output_type": "stream",
  17. "text": "Length of protein 100\n",
  18. "name": "stdout"
  19. },
  20. {
  21. "output_type": "stream",
  22. "text": "Max score 39: 100%|████████████████████████████████████████| 100000/100000 [02:25<00:00, 687.10it/s]\n",
  23. "name": "stderr"
  24. },
  25. {
  26. "output_type": "stream",
  27. "text": "Score 39 run 36549 repeated routes 42967 incomplete 0\n",
  28. "name": "stdout"
  29. }
  30. ]
  31. },
  32. {
  33. "metadata": {
  34. "ExecuteTime": {
  35. "end_time": "2019-06-12T08:54:15.749544Z",
  36. "start_time": "2019-06-12T08:54:15.706530Z"
  37. },
  38. "trusted": true
  39. },
  40. "cell_type": "code",
  41. "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",
  42. "execution_count": null,
  43. "outputs": []
  44. },
  45. {
  46. "metadata": {
  47. "ExecuteTime": {
  48. "end_time": "2019-06-12T09:12:43.726256Z",
  49. "start_time": "2019-06-12T09:12:43.460747Z"
  50. },
  51. "trusted": true
  52. },
  53. "cell_type": "code",
  54. "source": "MCTS2.ShowMolecule1(maxRun,board)",
  55. "execution_count": null,
  56. "outputs": []
  57. },
  58. {
  59. "metadata": {
  60. "ExecuteTime": {
  61. "end_time": "2019-06-12T09:21:16.477131Z",
  62. "start_time": "2019-06-12T09:21:13.019113Z"
  63. },
  64. "trusted": true
  65. },
  66. "cell_type": "code",
  67. "source": "MCTS2.drawTree()",
  68. "execution_count": null,
  69. "outputs": []
  70. },
  71. {
  72. "metadata": {
  73. "ExecuteTime": {
  74. "end_time": "2019-06-12T09:26:15.543294Z",
  75. "start_time": "2019-06-12T09:26:15.499794Z"
  76. },
  77. "trusted": true
  78. },
  79. "cell_type": "code",
  80. "source": "df = pd.DataFrame(analysisNodes)\ndf[1:100]",
  81. "execution_count": null,
  82. "outputs": []
  83. },
  84. {
  85. "metadata": {
  86. "ExecuteTime": {
  87. "end_time": "2019-06-12T13:16:49.416532Z",
  88. "start_time": "2019-06-12T13:16:49.238036Z"
  89. },
  90. "trusted": true
  91. },
  92. "cell_type": "code",
  93. "source": "print(analysisNodes[-100:])\nprint(np.sum(analysisNodes[:,9]))",
  94. "execution_count": null,
  95. "outputs": []
  96. },
  97. {
  98. "metadata": {
  99. "trusted": true
  100. },
  101. "cell_type": "code",
  102. "source": "",
  103. "execution_count": null,
  104. "outputs": []
  105. }
  106. ],
  107. "metadata": {
  108. "hide_input": false,
  109. "kernelspec": {
  110. "name": "python3",
  111. "display_name": "Python 3",
  112. "language": "python"
  113. },
  114. "language_info": {
  115. "name": "python",
  116. "version": "3.7.3",
  117. "mimetype": "text/x-python",
  118. "codemirror_mode": {
  119. "name": "ipython",
  120. "version": 3
  121. },
  122. "pygments_lexer": "ipython3",
  123. "nbconvert_exporter": "python",
  124. "file_extension": ".py"
  125. },
  126. "toc": {
  127. "nav_menu": {},
  128. "number_sections": true,
  129. "sideBar": false,
  130. "skip_h1_title": true,
  131. "base_numbering": 1,
  132. "title_cell": "Table of Contents",
  133. "title_sidebar": "Contents",
  134. "toc_cell": false,
  135. "toc_position": {
  136. "height": "47px",
  137. "left": "1117px",
  138. "top": "257px",
  139. "width": "161px"
  140. },
  141. "toc_section_display": false,
  142. "toc_window_display": true
  143. },
  144. "varInspector": {
  145. "window_display": false,
  146. "cols": {
  147. "lenName": 16,
  148. "lenType": 16,
  149. "lenVar": 40
  150. },
  151. "kernels_config": {
  152. "python": {
  153. "library": "var_list.py",
  154. "delete_cmd_prefix": "del ",
  155. "delete_cmd_postfix": "",
  156. "varRefreshCmd": "print(var_dic_list())"
  157. },
  158. "r": {
  159. "library": "var_list.r",
  160. "delete_cmd_prefix": "rm(",
  161. "delete_cmd_postfix": ") ",
  162. "varRefreshCmd": "cat(var_dic_list()) "
  163. }
  164. },
  165. "types_to_exclude": [
  166. "module",
  167. "function",
  168. "builtin_function_or_method",
  169. "instance",
  170. "_Feature"
  171. ]
  172. },
  173. "gist": {
  174. "id": "",
  175. "data": {
  176. "description": "Protein Folding/Protein Folding - Management function.ipynb",
  177. "public": true
  178. }
  179. }
  180. },
  181. "nbformat": 4,
  182. "nbformat_minor": 2
  183. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement