aboutsummaryrefslogtreecommitdiff
path: root/LSN_Exercises_02.ipynb
blob: e51b0c0a7aa59468a819aa4caebdc238a7a38bfb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Exercise 02.1\n",
    "- Compute the following 1D integral via Monte Carlo \n",
    "$$I = \\int_0^1 \\frac{\\pi}{2}\\cos(\\pi x/2) dx = 1$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1. sampling a uniform distribution in $[0,1]$\n",
    "2. using importance sampling (i.e. sampling a non-uniform probability in $[0,1]$)\n",
    "\n",
    "<span style=\"color:red\">Show a picture of both your estimations of $I$</span> and their uncertainties with a large number of *throws* $M$ (e.g. $M\\ge 10^4$) as a function of the number of blocks, $N$</font>."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The taylor Expansion of the cosine is:\n",
    "\n",
    "$$\\cos(x) = 1 - \\frac{x^2}{2} + O(x^3).$$\n",
    "\n",
    "So I choose to sample the integral with distribution:\n",
    "$$d(x) = 1 - x^2.$$\n",
    "This must be normalized so that $\\int_0^1 d(x) \\,dx = 1$:\n",
    "$$\\int_0^1 \\left(1 - x^2\\right) \\,dx = \\left(x - \\frac{x^3}{3}\\right)\\bigg|_0^1 = \\frac{2}{3} \\quad \\implies \\quad d(x) = \\frac{3}{2}\\left(1 - x^2\\right).$$\n",
    "Inverting the cumulative distribution requires solving a cubic equation, so I resort to accept-reject to sample $d(x)$.\n",
    "$$y = F(x) = \\int_0^x dx' d(x') \\rightarrow x = F^{-1}(y)$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[<matplotlib.lines.Line2D at 0x7f16e1d37f40>]"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYUAAAEGCAYAAACKB4k+AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjguMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8g+/7EAAAACXBIWXMAAAsTAAALEwEAmpwYAAAka0lEQVR4nO3deXRV9b3+8ffnZCQkEIaEOYAQwMhMAEVUnAEHtAUFVERtFRSttbba3lvbXvvrcLXWolJEBGepCiq1Vto64MCYMI8SQCAyzyQhCUm+vz+S5qYYJEDO3uecPK+1shb77J3k2SvhPNnT92vOOURERAACfgcQEZHQoVIQEZFKKgUREamkUhARkUoqBRERqRTtd4Az0bRpU9euXTu/Y4iIhJXs7Oy9zrmU6taFdSm0a9eOrKwsv2OIiIQVM9tyonU6fSQiIpVUCiIiUkmlICIilVQKIiJSSaUgIiKVPCkFM5tmZrvNbNUJ1puZTTSzHDNbYWa9vcglIiL/yasjhReAwd+yfgiQXvFxJ/BnDzKJiMhxPHlOwTn3qZm1+5ZNhgEvufJxvBeYWbKZtXDO7QhGnvU7j/C3Fds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axexmJc6518wsCphnZpc45z7yO5tITehIQUREKumagoiIVFIpiIhIJZWCiIhUUimIiEgllYKIiFRSKYiISCWVgoiIVPr/AsrsC+Z951IAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "x = np.linspace(0, 1,100)\n",
    "y = 1 - x**2\n",
    "plt.xlabel('x')\n",
    "plt.ylabel('$d(x)$')\n",
    "plt.plot(x, y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Text(0.5, 1.0, 'Monte Carlo integration (uniform sampling)')"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYgAAAEWCAYAAAB8LwAVAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjguMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8g+/7EAAAACXBIWXMAAAsTAAALEwEAmpwYAAAiHElEQVR4nO3de5hdVX3/8feHhABBINGMGJKYgcotIAKmSKVqLKgQqVi0mDQKRDDqD6naVuTSClJTaUUFnlrSQBGRyEUqldpYL2jIo5XLJIRICIFwzZiQDBeTaLgFvr8/1ho5OVlnkpnMnpOZ+bye5zxz9lr78t1r79nffTt7KyIwMzOrt0OzAzAzs+2TE4SZmRU5QZiZWZEThJmZFTlBmJlZkROEmZkVOUFYJSQ9KumYHgw3TdKPq4ipL1QZv6SdJN0n6XW9MK5N4pR0lKQHJf1O0vu3dfz9Ue06K+lcSVf20njvlHRQb4yrrzlBVCyvdC9IGlVXvkhSSGrthWnMk3T6No7jPZLmS1ovqUPSbZLet62xdVdEzImId29Nv5JOlfSLqmPqYvqteRkO7SzrTvw9MAOYHxFPbOuICnFeCPxrRLwqIv5rW8ff30XEP0XEN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jO62rtgLOy+vgMuC4JsS2nHReunO9m5X7/UBe3vcAC4E/b0JsDZdjs9stl18NfKKu3z5rty62G5Wvb37UhpmZFQ30U0xmZtZDThBmZlbkBGFmZkVOEGZmVuQEYWZmRU4QZhWRFJK+WtP9d5IuaGJIZt3iBGFWneeBEyWNanYgZj3hBGFWnY2kdwV/ttmBmPWEE4RZtb4BTJO0R7MDMesuJwizCkV66uY1wF83Oxaz7nKCMKveJaRnDu3a5DjMusUJwqxiEfE0cCMpSZj1G04QZn3jq4DvZrJ+xU9zNTOzIh9BmJlZkROEmZkVOUGYmVmRE4SZmRU5QZiZWZEThJmZFTlBmJlZ0f8HzIt4XEj+BtkAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "uniform = np.loadtxt('data/exercise-02.1-uniform.dat')\n",
    "plt.errorbar(uniform[:,0], uniform[:,1], yerr=uniform[:,2], fmt='bo')\n",
    "plt.axhline(y = 1, color = 'red', linestyle = '-')\n",
    "plt.text(60, 1+0.005, 'Exact value', color='red')\n",
    "plt.xlabel('N')\n",
    "plt.ylabel('I')\n",
    "plt.title('Monte Carlo integration (uniform sampling)')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Text(0.5, 1.0, 'Monte Carlo integration (importance sampling)')"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAZUAAAEWCAYAAACufwpNAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjguMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8g+/7EAAAACXBIWXMAAAsTAAALEwEAmpwYAAAkgUlEQ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8/R/BbAiIn6d0z8kBZlm6f9RwGMRsToiXgF+BLyH5ul/h1r9XQHsVZhvCOnwYLc4qDQBSSIdT38wIv5voWg2cGp+firwk55uW0+IiIsiYkhEtJBOSP4iIj5B8/T/aWC5pHfkrCOBB2iS/pMOex0mqV/+LBxJOq/YLP3vUKu/s4HxkvpKGg6MAO7t7kr8i/omIOl9wH8C/8Pr5xQuJp1XmQUMJX3wPh4RlSf3tiuSxgCfi4jjJO1Gk/Rf0ijSRQp9gEeB00lfKpul/18BTiZdCXkfcBbwZrbT/kuaAYwh3d5+FXAp8GNq9FfSJcAZpNfngoi4o9vrdlAxM7Oy+PCXmZmVxkHFzMxK46BiZmalcVAxM7PSOKiYmVlpHFTMtiGSQtKVhfTnJF3WwCaZdYmDitm2ZT1woqTdG90Qs+5wUDHbtrST/jv8bxvdELPucFAx2/ZcD0yUtGujG2LWVQ4qZtuYfAfpW0h/LGX2huKgYrZtuho4E9ipwe0w6xIHFbNtUL7R3yxSYDF7w3BQMdt2XUm6y6zZG4bvUmxmZqXxSMXMzErjoGJmZqVxUDEzs9I4qJiZWWkcVMzMrDQOKmZmVhoHFTMzK83/B5cuTsDj/XxjAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "importance = np.loadtxt('data/exercise-02.1-importance.dat')\n",
    "plt.errorbar(importance[:5,0], importance[:5,1], yerr=importance[:5,2], fmt='bo')\n",
    "plt.axhline(y = 1, color = 'red', linestyle = '-')\n",
    "plt.text(60, 1+0.0005, 'Exact value', color='red')\n",
    "plt.xlabel('N')\n",
    "plt.ylabel('I')\n",
    "plt.title('Monte Carlo integration (importance sampling)')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Exercise 02.2\n",
    "- <span style=\"color:red\">3D Random Walks (RW) on a cubic lattice and in the continuum:</span> Repeat many times (e.g. say $10^4$) the simulation of a random walk in 3D always starting at the origin"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1. on a cubic lattice with lattice constant $a=1$; at each discrete time the walker makes a forward or backward step of length equal to $a$ in one of the 3 principal directions of the lattice: $x$, $y$ or $z$\n",
    "2. in the continuum; at each discrete time the walker makes a step of length equal to $a(=1)$ along a **random direction** obtained by sampling **uniformly** the solid angle: $\\theta \\in [0,\\pi]$ and $\\phi \\in [0,2\\pi]$\n",
    "\n",
    "<span style=\"color:red\">Show a picture of $\\sqrt{\\langle |\\vec{r}_N|^2 \\rangle_{RW}}$ for both RWs</span>, with their statistical uncertainties, as function of the step $i\\in [0,10^2]$.\n",
    "\n",
    "Suggestion: divide your $M$ throws into a reasonable number of blocks, compute $\\sqrt{\\langle |\\vec{r}_N|^2 \\rangle_{RW}}$ as function of the step $i\\in [0,10^2]$ in each block and use these values (for fixed $i$) to obtain the average value and its statistical uncertainty.\n",
    "\n",
    "Note that you could try to fit both results with a function like $f(N)=k\\sqrt{N}$. Do your results indicate a diffusive behavior?"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "/gnu/store/3lxr2xg3yscdb3979blgjg0h7xd1n9la-python-3.10.7/bin/python3",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}