Guest User

Untitled

a guest
Jul 16th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.56 KB | None | 0 0
  1. {
  2. "cells": [
  3. {
  4. "cell_type": "code",
  5. "execution_count": 1,
  6. "metadata": {},
  7. "outputs": [
  8. {
  9. "name": "stdout",
  10. "output_type": "stream",
  11. "text": [
  12. "env: MKL_THREADING_LAYER=GNU\n"
  13. ]
  14. }
  15. ],
  16. "source": [
  17. "%env MKL_THREADING_LAYER GNU"
  18. ]
  19. },
  20. {
  21. "cell_type": "code",
  22. "execution_count": 2,
  23. "metadata": {
  24. "scrolled": false
  25. },
  26. "outputs": [],
  27. "source": [
  28. "import numpy as np\n",
  29. "import arviz as az\n",
  30. "from arviz.tests.helpers import load_cached_models"
  31. ]
  32. },
  33. {
  34. "cell_type": "code",
  35. "execution_count": 3,
  36. "metadata": {},
  37. "outputs": [],
  38. "source": [
  39. "models = load_cached_models(500, 2)\n",
  40. "stan_model, stan_fit = models['pystan']\n",
  41. "\n",
  42. "# this is the OrderedDict\n",
  43. "sample_dict = stan_fit.extract(stan_fit.model_pars, permuted=False)\n",
  44. "\n",
  45. "# this is an example of the API being used carefully\n",
  46. "stan_xarray = az.convert_to_xarray(stan_fit, {'school': np.arange(8)}, dims={'theta': ['school'], 'theta_tilde': ['school']})"
  47. ]
  48. },
  49. {
  50. "cell_type": "code",
  51. "execution_count": 4,
  52. "metadata": {},
  53. "outputs": [],
  54. "source": [
  55. "dict_xarray = az.convert_to_xarray(sample_dict, {'chains': 2, 'school': np.arange(8)}, dims={'theta': ['school'], 'theta_tilde': ['school']})"
  56. ]
  57. },
  58. {
  59. "cell_type": "code",
  60. "execution_count": 5,
  61. "metadata": {},
  62. "outputs": [
  63. {
  64. "data": {
  65. "text/plain": [
  66. "<xarray.Dataset>\n",
  67. "Dimensions: (chain: 2, draw: 500, school: 8)\n",
  68. "Coordinates:\n",
  69. " * school (school) int64 0 1 2 3 4 5 6 7\n",
  70. " * draw (draw) int64 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 ...\n",
  71. " * chain (chain) int64 0 1\n",
  72. "Data variables:\n",
  73. " mu (chain, draw) float64 7.671 7.671 8.908 8.525 8.152 5.315 ...\n",
  74. " tau (chain, draw) float64 6.842 6.842 0.8769 1.08 0.1644 0.5318 ...\n",
  75. " theta_tilde (chain, draw, school) float64 0.5065 0.9721 0.7126 1.597 ...\n",
  76. " theta (chain, draw, school) float64 11.14 14.32 12.55 18.6 3.667 ..."
  77. ]
  78. },
  79. "execution_count": 5,
  80. "metadata": {},
  81. "output_type": "execute_result"
  82. }
  83. ],
  84. "source": [
  85. "stan_xarray"
  86. ]
  87. },
  88. {
  89. "cell_type": "code",
  90. "execution_count": 6,
  91. "metadata": {},
  92. "outputs": [
  93. {
  94. "data": {
  95. "text/plain": [
  96. "<xarray.Dataset>\n",
  97. "Dimensions: (chain: 2, draw: 500, school: 8)\n",
  98. "Coordinates:\n",
  99. " * school (school) int64 0 1 2 3 4 5 6 7\n",
  100. " * draw (draw) int64 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 ...\n",
  101. " * chain (chain) int64 0 1\n",
  102. "Data variables:\n",
  103. " mu (chain, draw) float64 7.671 7.671 8.908 8.525 8.152 5.315 ...\n",
  104. " tau (chain, draw) float64 6.842 6.842 0.8769 1.08 0.1644 0.5318 ...\n",
  105. " theta_tilde (chain, draw, school) float64 0.5065 0.9721 0.7126 1.597 ...\n",
  106. " theta (chain, draw, school) float64 11.14 14.32 12.55 18.6 3.667 ..."
  107. ]
  108. },
  109. "execution_count": 6,
  110. "metadata": {},
  111. "output_type": "execute_result"
  112. }
  113. ],
  114. "source": [
  115. "dict_xarray"
  116. ]
  117. },
  118. {
  119. "cell_type": "code",
  120. "execution_count": 7,
  121. "metadata": {},
  122. "outputs": [
  123. {
  124. "name": "stderr",
  125. "output_type": "stream",
  126. "text": [
  127. "/opt/conda/lib/python3.6/site-packages/ipykernel_launcher.py:1: FutureWarning: iteration over an xarray.Dataset will change in xarray v0.11 to only include data variables, not coordinates. Iterate over the Dataset.variables property instead to preserve existing behavior in a forwards compatible manner.\n",
  128. " \"\"\"Entry point for launching an IPython kernel.\n"
  129. ]
  130. },
  131. {
  132. "data": {
  133. "text/plain": [
  134. "True"
  135. ]
  136. },
  137. "execution_count": 7,
  138. "metadata": {},
  139. "output_type": "execute_result"
  140. }
  141. ],
  142. "source": [
  143. "all((stan_xarray == dict_xarray).all())"
  144. ]
  145. },
  146. {
  147. "cell_type": "code",
  148. "execution_count": null,
  149. "metadata": {},
  150. "outputs": [],
  151. "source": []
  152. }
  153. ],
  154. "metadata": {
  155. "kernelspec": {
  156. "display_name": "Python 3",
  157. "language": "python",
  158. "name": "python3"
  159. },
  160. "language_info": {
  161. "codemirror_mode": {
  162. "name": "ipython",
  163. "version": 3
  164. },
  165. "file_extension": ".py",
  166. "mimetype": "text/x-python",
  167. "name": "python",
  168. "nbconvert_exporter": "python",
  169. "pygments_lexer": "ipython3",
  170. "version": "3.6.5"
  171. }
  172. },
  173. "nbformat": 4,
  174. "nbformat_minor": 2
  175. }
Add Comment
Please, Sign In to add comment