<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://nemenmanlab.org/~ilya/index.php?action=history&amp;feed=atom&amp;title=Physics_212%2C_2019%3A_Lecture_19</id>
	<title>Physics 212, 2019: Lecture 19 - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://nemenmanlab.org/~ilya/index.php?action=history&amp;feed=atom&amp;title=Physics_212%2C_2019%3A_Lecture_19"/>
	<link rel="alternate" type="text/html" href="https://nemenmanlab.org/~ilya/index.php?title=Physics_212,_2019:_Lecture_19&amp;action=history"/>
	<updated>2026-04-26T23:47:12Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.31.0</generator>
	<entry>
		<id>https://nemenmanlab.org/~ilya/index.php?title=Physics_212,_2019:_Lecture_19&amp;diff=3327&amp;oldid=prev</id>
		<title>Ilya at 13:06, 3 April 2019</title>
		<link rel="alternate" type="text/html" href="https://nemenmanlab.org/~ilya/index.php?title=Physics_212,_2019:_Lecture_19&amp;diff=3327&amp;oldid=prev"/>
		<updated>2019-04-03T13:06:04Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;Revision as of 13:06, 3 April 2019&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l44&quot; &gt;Line 44:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 44:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;While we will skip the details, the generation of a random variable on a circle hints how to generate such standard random variables easily. First, imagine that I generate not one, but a pair of standard random normal variables &amp;lt;math&amp;gt;(x,y)&amp;lt;/math&amp;gt;. Then &amp;lt;math&amp;gt;r^2=x^2+y^2&amp;lt;/math&amp;gt;, and &amp;lt;math&amp;gt;P(x,y)=&amp;#160; \frac{1}{2\pi}\exp \left(-\frac{x^2+y^2}{2}\right)=\frac{1}{2\pi}\exp \left(-\frac{r^2}{2}\right)&amp;lt;/math&amp;gt;. Thus the radius-squared is exponentially distributed. So maybe if one should generate a random angle &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt; between 0 and &amp;lt;math&amp;gt;2\pi&amp;lt;/math&amp;gt; and a random exponentially distributed variable, which one views as &amp;lt;math&amp;gt;r^2&amp;lt;/math&amp;gt;. Then taking it's square root and choosing &amp;lt;math&amp;gt;x=\sqrt{r^2}\cos \phi&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;y=\sqrt{r^2}\sin \phi&amp;lt;/math&amp;gt; generates a pair of random standard normal samples. The code uploaded with this module compares this method against the built-in ''nprnd.randn()'' function provided by Python for generation of Gaussian numbers.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;While we will skip the details, the generation of a random variable on a circle hints how to generate such standard random variables easily. First, imagine that I generate not one, but a pair of standard random normal variables &amp;lt;math&amp;gt;(x,y)&amp;lt;/math&amp;gt;. Then &amp;lt;math&amp;gt;r^2=x^2+y^2&amp;lt;/math&amp;gt;, and &amp;lt;math&amp;gt;P(x,y)=&amp;#160; \frac{1}{2\pi}\exp \left(-\frac{x^2+y^2}{2}\right)=\frac{1}{2\pi}\exp \left(-\frac{r^2}{2}\right)&amp;lt;/math&amp;gt;. Thus the radius-squared is exponentially distributed. So maybe if one should generate a random angle &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt; between 0 and &amp;lt;math&amp;gt;2\pi&amp;lt;/math&amp;gt; and a random exponentially distributed variable, which one views as &amp;lt;math&amp;gt;r^2&amp;lt;/math&amp;gt;. Then taking it's square root and choosing &amp;lt;math&amp;gt;x=\sqrt{r^2}\cos \phi&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;y=\sqrt{r^2}\sin \phi&amp;lt;/math&amp;gt; generates a pair of random standard normal samples. The code uploaded with this module compares this method against the built-in ''nprnd.randn()'' function provided by Python for generation of Gaussian numbers.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;==Uses of random numbers==&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;We use random numbers to perform computations that are fundamentally random, and we will focus on those in the upcoming weeks. However, there are computations that are fundamentally deterministic, but may be easier to perform with random numbers. Suppose we want to calculate an integral under a curve &amp;lt;math&amp;gt;y=y(x)&amp;lt;/math&amp;gt;, with the limits &amp;lt;math&amp;gt;x\in [a,b]&amp;lt;/math&amp;gt;. We can, of course, do it analytically for some functions &amp;lt;math&amp;gt;y&amp;lt;/math&amp;gt; or numerically by subdividing the interval of &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; into small segments &amp;lt;math&amp;gt;\Delta x&amp;lt;/math&amp;gt; and adding up the areas of all small rectangles, &amp;lt;math&amp;gt;y(x)\times \Delta x&amp;lt;/math&amp;gt;. An alternative way is as follows. Suppose we know that &amp;lt;math&amp;gt;y(x)&amp;lt;/math&amp;gt; is positive and smaller than &amp;lt;math&amp;gt;f_{\rm max}&amp;lt;/math&amp;gt;. Then the area under the curve can be written down as &amp;lt;math&amp;gt;(b-a)f_{\rm max}*\alpha&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;\alpha&amp;lt;/math&amp;gt; is the fraction of the square &amp;lt;math&amp;gt;b-a&amp;lt;/math&amp;gt; by &amp;lt;math&amp;gt;f_{\rm max}&amp;lt;/math&amp;gt; that is actually under the curve. How do we estimate this fraction? Suppose I generate random points (dart throws), uniformly distributed over the square &amp;lt;math&amp;gt;b-a&amp;lt;/math&amp;gt; by &amp;lt;math&amp;gt;f_{\rm max}&amp;lt;/math&amp;gt;. The fraction of those that end up under the curve (and it's easy to check which one does!) is an estimate of &amp;lt;math&amp;gt;\alpha&amp;lt;/math&amp;gt;. The provided script performs such calculation for an arbitrary &amp;lt;math&amp;gt;y=y(x)&amp;lt;/math&amp;gt;. This is called Monte-Carlo integration. Note that our implementation is incomplete -- we don't check if the function ever is below 0 or ever is above &amp;lt;math&amp;gt;f_{\rm max}&amp;lt;/math&amp;gt;, which a better implementation should do.&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;A problem, of course, is that such calculation is probabilistic -- every time we perform it, the results are different. But how different? We can verify, first of all, that our probabilistic estimate of the area converges to to true one, where true is known, e.g, when we integrate a function &amp;lt;math&amp;gt;x^2&amp;lt;/math&amp;gt;. We can also show the distribution of the estimates of the area when we perform the are estimate with &amp;lt;math&amp;gt;N&amp;lt;/math&amp;gt; dart throws. We see that the larger &amp;lt;math&amp;gt;N&amp;lt;/math&amp;gt; is, the more concentrated the estimates are. To quantify this, we use the provided script to calculate the standard deviation of the estimates as a function of &amp;lt;math&amp;gt;N&amp;lt;/math&amp;gt;. We find that &amp;lt;math&amp;gt;\sigma^2 = A/N&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; is some constant. The claim is that the general &amp;lt;math&amp;gt;1/N&amp;lt;/math&amp;gt; law holds true for essentially any function being integrated. It's only the constant that changes -- and we can verify this by integrating other functions.&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==Scripts==&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==Scripts==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[media:RandomNumbers.txt | Random Numbers]] -- the Random Numbers notebook, which we will be exploring over multiple lectures.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[media:RandomNumbers.txt | Random Numbers]] -- the Random Numbers notebook, which we will be exploring over multiple lectures.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Ilya</name></author>
		
	</entry>
	<entry>
		<id>https://nemenmanlab.org/~ilya/index.php?title=Physics_212,_2019:_Lecture_19&amp;diff=3321&amp;oldid=prev</id>
		<title>Ilya at 13:54, 1 April 2019</title>
		<link rel="alternate" type="text/html" href="https://nemenmanlab.org/~ilya/index.php?title=Physics_212,_2019:_Lecture_19&amp;diff=3321&amp;oldid=prev"/>
		<updated>2019-04-01T13:54:47Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;Revision as of 13:54, 1 April 2019&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l2&quot; &gt;Line 2:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 2:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;In today's lecture, we will study how to generate different types of random numbers using just a standard, uniformly distributed random number. If time permits, we will also study how random errors scale with the number of random trials.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;In today's lecture, we will study how to generate different types of random numbers using just a standard, uniformly distributed random number. If time permits, we will also study how random errors scale with the number of random trials.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Follow the [[media:RandomNumbers.txt | Random Numbers]] notebook in this lecture.&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==Different types of random numbers==&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==Different types of random numbers==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l47&quot; &gt;Line 47:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 49:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;A problem, of course, is that such calculation is probabilistic -- every time we perform it, the results are different. But how different? We can verify, first of all, that our probabilistic estimate of the area converges to to true one, where true is known, e.g, when we integrate a function &amp;lt;math&amp;gt;x^2&amp;lt;/math&amp;gt;. We can also show the distribution of the estimates of the area when we perform the are estimate with &amp;lt;math&amp;gt;N&amp;lt;/math&amp;gt; dart throws. We see that the larger &amp;lt;math&amp;gt;N&amp;lt;/math&amp;gt; is, the more concentrated the estimates are. To quantify this, we use the provided script to calculate the standard deviation of the estimates as a function of &amp;lt;math&amp;gt;N&amp;lt;/math&amp;gt;. We find that &amp;lt;math&amp;gt;\sigma^2 = A/N&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; is some constant. The claim is that the general &amp;lt;math&amp;gt;1/N&amp;lt;/math&amp;gt; law holds true for essentially any function being integrated. It's only the constant that changes -- and we can verify this by integrating other functions.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;A problem, of course, is that such calculation is probabilistic -- every time we perform it, the results are different. But how different? We can verify, first of all, that our probabilistic estimate of the area converges to to true one, where true is known, e.g, when we integrate a function &amp;lt;math&amp;gt;x^2&amp;lt;/math&amp;gt;. We can also show the distribution of the estimates of the area when we perform the are estimate with &amp;lt;math&amp;gt;N&amp;lt;/math&amp;gt; dart throws. We see that the larger &amp;lt;math&amp;gt;N&amp;lt;/math&amp;gt; is, the more concentrated the estimates are. To quantify this, we use the provided script to calculate the standard deviation of the estimates as a function of &amp;lt;math&amp;gt;N&amp;lt;/math&amp;gt;. We find that &amp;lt;math&amp;gt;\sigma^2 = A/N&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; is some constant. The claim is that the general &amp;lt;math&amp;gt;1/N&amp;lt;/math&amp;gt; law holds true for essentially any function being integrated. It's only the constant that changes -- and we can verify this by integrating other functions.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;==Scripts==&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;[[media:RandomNumbers.txt | Random Numbers]] -- the Random Numbers notebook, which we will be exploring over multiple lectures.&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Ilya</name></author>
		
	</entry>
	<entry>
		<id>https://nemenmanlab.org/~ilya/index.php?title=Physics_212,_2019:_Lecture_19&amp;diff=3317&amp;oldid=prev</id>
		<title>Ilya at 13:30, 1 April 2019</title>
		<link rel="alternate" type="text/html" href="https://nemenmanlab.org/~ilya/index.php?title=Physics_212,_2019:_Lecture_19&amp;diff=3317&amp;oldid=prev"/>
		<updated>2019-04-01T13:30:00Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;Revision as of 13:30, 1 April 2019&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l38&quot; &gt;Line 38:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 38:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;The notebook uploaded with this module demonstrate these methods. Which one of the ones that work would be the fastest? Why? Verify your guess yourself and explain what you see.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;The notebook uploaded with this module demonstrate these methods. Which one of the ones that work would be the fastest? Why? Verify your guess yourself and explain what you see.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;=&lt;/del&gt;==Gaussian random variables&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;=&lt;/del&gt;==&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==Gaussian random variables==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;A Gaussian (or normal) random variable is a variable with the probability density function &amp;lt;math&amp;gt;P(x) = \frac{1}{\sqrt{2\pi\sigma^2}}\exp \left[-\frac{(x-\mu)^2}{2\sigma^2}\right]&amp;lt;/math&amp;gt;. &amp;lt;math&amp;gt;\mu&amp;lt;/math&amp;gt; is called the mean, and &amp;lt;math&amp;gt;\sigma&amp;lt;/math&amp;gt; is called the standard deviation. This is the familiar bell-shaped distribution centered around &amp;lt;math&amp;gt;\mu&amp;lt;/math&amp;gt; with the width of &amp;lt;/math&amp;gt;\sigma&amp;lt;/math&amp;gt;. The standard normal distribution has &amp;lt;math&amp;gt;\mu=0&amp;lt;/math&amp;gt; and &amp;lt;\math&amp;gt;\sigma^2=1&amp;lt;/math&amp;gt;. Clearly, if one can generate a standard normal random variable, one can get a more general normal variable from it by multiplying by &amp;lt;math&amp;gt;\sigma&amp;lt;/math&amp;gt; and shifting by &amp;lt;math&amp;gt;\mu&amp;lt;/math&amp;gt;. So we only need to figure out how to generate a standard normal variable.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;A Gaussian (or normal) random variable is a variable with the probability density function &amp;lt;math&amp;gt;P(x) = \frac{1}{\sqrt{2\pi\sigma^2}}\exp \left[-\frac{(x-\mu)^2}{2\sigma^2}\right]&amp;lt;/math&amp;gt;. &amp;lt;math&amp;gt;\mu&amp;lt;/math&amp;gt; is called the mean, and &amp;lt;math&amp;gt;\sigma&amp;lt;/math&amp;gt; is called the standard deviation. This is the familiar bell-shaped distribution centered around &amp;lt;math&amp;gt;\mu&amp;lt;/math&amp;gt; with the width of &amp;lt;/math&amp;gt;\sigma&amp;lt;/math&amp;gt;. The standard normal distribution has &amp;lt;math&amp;gt;\mu=0&amp;lt;/math&amp;gt; and &amp;lt;\math&amp;gt;\sigma^2=1&amp;lt;/math&amp;gt;. Clearly, if one can generate a standard normal random variable, one can get a more general normal variable from it by multiplying by &amp;lt;math&amp;gt;\sigma&amp;lt;/math&amp;gt; and shifting by &amp;lt;math&amp;gt;\mu&amp;lt;/math&amp;gt;. So we only need to figure out how to generate a standard normal variable.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Ilya</name></author>
		
	</entry>
	<entry>
		<id>https://nemenmanlab.org/~ilya/index.php?title=Physics_212,_2019:_Lecture_19&amp;diff=3316&amp;oldid=prev</id>
		<title>Ilya: Created page with &quot;{{PHYS212-2019}}  In today's lecture, we will study how to generate different types of random numbers using just a standard, uniformly distributed random number. If time permi...&quot;</title>
		<link rel="alternate" type="text/html" href="https://nemenmanlab.org/~ilya/index.php?title=Physics_212,_2019:_Lecture_19&amp;diff=3316&amp;oldid=prev"/>
		<updated>2019-04-01T13:29:34Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;{{PHYS212-2019}}  In today&amp;#039;s lecture, we will study how to generate different types of random numbers using just a standard, uniformly distributed random number. If time permi...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{PHYS212-2019}}&lt;br /&gt;
&lt;br /&gt;
In today's lecture, we will study how to generate different types of random numbers using just a standard, uniformly distributed random number. If time permits, we will also study how random errors scale with the number of random trials.&lt;br /&gt;
&lt;br /&gt;
==Different types of random numbers==&lt;br /&gt;
In the previous lecture, we discussed how a computer would generate pseudorandom floating point numbers, uniformly distributed between zero and one. How do we use these random numbers to generate other random number types?&lt;br /&gt;
&lt;br /&gt;
===Uniform continuous random numbers===&lt;br /&gt;
The standard linear congruential generator allows us to generate a uniform pseudo-random floating point number between 0 and 1, called the ''standard'' uniform random number. How do we then generate a number between, say, &amp;lt;math&amp;gt;a&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;b&amp;lt;/math&amp;gt;? For this, we only need to scale and shift the standard number. That is, if we say that &amp;lt;math&amp;gt;y=a + (b-a)*x&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; is the standard uniform number, then &amp;lt;math&amp;gt;y&amp;lt;/math&amp;gt; is the uniform random number between the two required limits.&lt;br /&gt;
&lt;br /&gt;
===Multinomial random number===&lt;br /&gt;
A dice is an example of a multinomial random number with six equally probable outcomes. In general, a multinomial random variable is a random variable that can have a finite, discrete set of values, with a given probability of each of these values. We generate these random numbers by sub-dividing the interval between zero and one into subintervals. The number of the sub-intervals is equal to the number of possible outcomes of the multinomial variable, and the length of each sub-interval is equal to the probability of each outcome. We then generate a uniform floating point number between zero and one and check which of the sub-intervals it fell into. The index of the subinterval is then the generated multinomial number. See the code in the script uploaded for this module.&lt;br /&gt;
&lt;br /&gt;
===Exponential random number===&lt;br /&gt;
Real-valued variables that have an exponential distribution are also very common. For example, the time between two subsequent nuclear decays, or the time between two nearby spikes in the simplest models of neuronal dynamics is exponentially distributed. Why is that? Nuclear decay has a finite probability &amp;lt;math&amp;gt;\rho dt&amp;lt;/math&amp;gt; of happening in any interval of time &amp;lt;math&amp;gt;dt&amp;lt;/math&amp;gt;. For the next event to happen at time &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;, it must not happen in all of the &amp;lt;math&amp;gt;T/dt&amp;lt;/math&amp;gt; previous windows of the width &amp;lt;math&amp;gt;dt&amp;lt;/math&amp;gt;, and then it should happen in the window &amp;lt;math&amp;gt;(T,T+dt)&amp;lt;/math&amp;gt;. Combining this, we get &amp;lt;math&amp;gt;P(T,T+dt)=(1-\rho dt)^{T/dt}\rho dt\to e^{-\rho T}\rho dt&amp;lt;/math&amp;gt;, so that the probability density is &amp;lt;math&amp;gt;P(T)=e^{-\rho T} \rho&amp;lt;/math&amp;gt;. More generally, a random variable &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; is called exponentially distributed with the mean &amp;lt;math&amp;gt;x_0&amp;lt;/math&amp;gt; if the probability density function for this variable obeys &amp;lt;math&amp;gt;P(x)=1/x_0 \exp(-x/x_0)&amp;lt;/math&amp;gt;. The distribution with &amp;lt;math&amp;gt;x_0=1&amp;lt;/math&amp;gt; is called the ''standard'' exponential distribution. Generation of exponential random numbers illustrates a few important properties of probability distributions. First of all, if we have an access to a standard exponential pseudo-random number, then by just multiplying it by &amp;lt;math&amp;gt;x_0&amp;lt;/math&amp;gt; we will get the exponentially distributed number with a mean of &amp;lt;math&amp;gt;x_0&amp;lt;/math&amp;gt;. This means that we only need to figure out how to generate standard numbers. &lt;br /&gt;
&lt;br /&gt;
For this, let's go back to our definition of continuous random numbers as a limit of an ever-finer discretization of the real axis. Suppose we have a real valued variable &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;, which is distributed according to &amp;lt;math&amp;gt;P(x)&amp;lt;/math&amp;gt;. This means that the probability of having a sample land in the interval &amp;lt;math&amp;gt;[x,x+\Delta x)&amp;lt;/math&amp;gt; tends to &amp;lt;math&amp;gt;P(x)\Delta x&amp;lt;/math&amp;gt;. Suppose now we have defined a new variable &amp;lt;math&amp;gt;y=y(x)&amp;lt;/math&amp;gt;, or, alternatively, &amp;lt;math&amp;gt;x=x(y)&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;x(y)&amp;lt;/math&amp;gt; is the inverse function to &amp;lt;math&amp;gt;y(x)&amp;lt;/math&amp;gt; (note that we are now assuming that such inverse exists!) Of course, &amp;lt;math&amp;gt;y&amp;lt;/math&amp;gt; is also a random variable. How is it distributed? We note that the probability of a sample to land in our interval should not depend on whether we marked its end points as &amp;lt;math&amp;gt;[x,x+\Delta x)&amp;lt;/math&amp;gt;, or as &amp;lt;math&amp;gt;[y(x),y(x+\Delta x))\approx [y(x),y(x) + dy/dx \Delta x)&amp;lt;/math&amp;gt;. In other words, &amp;lt;math&amp;gt;P(x)|\Delta x|=P(y)|\Delta y|&amp;lt;/math&amp;gt;, where we added the absolute value signs to ensure that, even if an interval is negative (read from right to left), the probability is still positive. This gives, in the limit of small &amp;lt;math&amp;gt;\Delta x&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;P(y) = P(x(y))\left|\frac{dx}{dy}\right|&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
How does this help with generating exponential numbers? Suppose that &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; is a standard uniform number, so that &amp;lt;math&amp;gt;P(x)=1&amp;lt;/math&amp;gt;. Let's choose &amp;lt;math&amp;gt;y=-\log x&amp;lt;/math&amp;gt;, and then &amp;lt;math&amp;gt;x= e^{-y}&amp;lt;/math&amp;gt;. Then &amp;lt;math&amp;gt;P(y)=P(x(y))\left|\frac{d e^{-y}}{dy}\right|=e^{-y}&amp;lt;/math&amp;gt;. In other words, the variable &amp;lt;math&amp;gt;y&amp;lt;/math&amp;gt; is a pseudo-random standard exponential variable! So generating samples of such random variables is easy -- just generate standard uniform pseudo-random variables and take the negative log of them. The script that goes with this module shows that built-in functions for generation of exponential random samples (''nprnd.exponential()'') generate output that is indistinguishable from our approach of taking the negative log.&lt;br /&gt;
&lt;br /&gt;
===Uniform random number in a square===&lt;br /&gt;
I hope you see that this is easy -- just generate a random &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; and a random &amp;lt;math&amp;gt;y&amp;lt;/math&amp;gt; coordinates using the uniform pseudo-random number, and the job is done.&lt;br /&gt;
&lt;br /&gt;
==Your work==&lt;br /&gt;
===Uniform random number in a circle===&lt;br /&gt;
Let's suppose we need a uniform random number in a circle around &amp;lt;math&amp;gt;(0,0)&amp;lt;/math&amp;gt; with a radius of 1. '''You work: of the following methods that might seem to generate such a random number in a circle, choose the one that you think will be the most accurate and the fastest and implement it. Or create your own method and implement it. Generate a 1000 such random points and plot them. Do you see what you expected to see?'''&lt;br /&gt;
&lt;br /&gt;
;Random angle / random scale: Generate a random pair &amp;lt;math&amp;gt;(x,y)&amp;lt;/math&amp;gt; between -1 and 1. The pair defines a ray from zero to this point. Now generate a random distance between 0 and 1, and then scale the point to be this random distance from zero on the ray.&lt;br /&gt;
&lt;br /&gt;
;Random radius / random angle: Generate a random angle between 0 and &amp;lt;math&amp;gt;2\pi&amp;lt;/math&amp;gt; and a random radius between 0 and 1. The point will be at this angle and this radius.&lt;br /&gt;
&lt;br /&gt;
;Random radius-squared / random angle: Generate a random angle between 0 and &amp;lt;math&amp;gt;2\pi&amp;lt;/math&amp;gt; and a random radius-squared between 0 and 1. Take a square root of the second number to get the random radius. The point will be at this angle and this radius.&lt;br /&gt;
&lt;br /&gt;
;Rejection method: Generate a random pair &amp;lt;math&amp;gt;(x,y)&amp;lt;/math&amp;gt; between -1 and 1. Verify that the pair landed within a circle. Reject it if it's outside and accept otherwise. Note that you will need to generate more than &amp;lt;math&amp;gt;N&amp;lt;/math&amp;gt; such random pairs to generate &amp;lt;math&amp;gt;N&amp;lt;/math&amp;gt; points inside the circle.&lt;br /&gt;
&lt;br /&gt;
Once you do these, you will see that some of these methods will generate too many points at the center of the circle compared to the edges. Those of you who know multivariate calculus should extend the calculation we did for generation of exponential random numbers to the multivariate case and relate the higher density of points near the center of the circle to the Jacobian of the transformation we make when we generate such two-dimensional random numbers from uniform standard numbers. &lt;br /&gt;
&lt;br /&gt;
The notebook uploaded with this module demonstrate these methods. Which one of the ones that work would be the fastest? Why? Verify your guess yourself and explain what you see.&lt;br /&gt;
&lt;br /&gt;
===Gaussian random variables===&lt;br /&gt;
A Gaussian (or normal) random variable is a variable with the probability density function &amp;lt;math&amp;gt;P(x) = \frac{1}{\sqrt{2\pi\sigma^2}}\exp \left[-\frac{(x-\mu)^2}{2\sigma^2}\right]&amp;lt;/math&amp;gt;. &amp;lt;math&amp;gt;\mu&amp;lt;/math&amp;gt; is called the mean, and &amp;lt;math&amp;gt;\sigma&amp;lt;/math&amp;gt; is called the standard deviation. This is the familiar bell-shaped distribution centered around &amp;lt;math&amp;gt;\mu&amp;lt;/math&amp;gt; with the width of &amp;lt;/math&amp;gt;\sigma&amp;lt;/math&amp;gt;. The standard normal distribution has &amp;lt;math&amp;gt;\mu=0&amp;lt;/math&amp;gt; and &amp;lt;\math&amp;gt;\sigma^2=1&amp;lt;/math&amp;gt;. Clearly, if one can generate a standard normal random variable, one can get a more general normal variable from it by multiplying by &amp;lt;math&amp;gt;\sigma&amp;lt;/math&amp;gt; and shifting by &amp;lt;math&amp;gt;\mu&amp;lt;/math&amp;gt;. So we only need to figure out how to generate a standard normal variable.&lt;br /&gt;
&lt;br /&gt;
While we will skip the details, the generation of a random variable on a circle hints how to generate such standard random variables easily. First, imagine that I generate not one, but a pair of standard random normal variables &amp;lt;math&amp;gt;(x,y)&amp;lt;/math&amp;gt;. Then &amp;lt;math&amp;gt;r^2=x^2+y^2&amp;lt;/math&amp;gt;, and &amp;lt;math&amp;gt;P(x,y)=  \frac{1}{2\pi}\exp \left(-\frac{x^2+y^2}{2}\right)=\frac{1}{2\pi}\exp \left(-\frac{r^2}{2}\right)&amp;lt;/math&amp;gt;. Thus the radius-squared is exponentially distributed. So maybe if one should generate a random angle &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt; between 0 and &amp;lt;math&amp;gt;2\pi&amp;lt;/math&amp;gt; and a random exponentially distributed variable, which one views as &amp;lt;math&amp;gt;r^2&amp;lt;/math&amp;gt;. Then taking it's square root and choosing &amp;lt;math&amp;gt;x=\sqrt{r^2}\cos \phi&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;y=\sqrt{r^2}\sin \phi&amp;lt;/math&amp;gt; generates a pair of random standard normal samples. The code uploaded with this module compares this method against the built-in ''nprnd.randn()'' function provided by Python for generation of Gaussian numbers.&lt;br /&gt;
&lt;br /&gt;
==Uses of random numbers==&lt;br /&gt;
We use random numbers to perform computations that are fundamentally random, and we will focus on those in the upcoming weeks. However, there are computations that are fundamentally deterministic, but may be easier to perform with random numbers. Suppose we want to calculate an integral under a curve &amp;lt;math&amp;gt;y=y(x)&amp;lt;/math&amp;gt;, with the limits &amp;lt;math&amp;gt;x\in [a,b]&amp;lt;/math&amp;gt;. We can, of course, do it analytically for some functions &amp;lt;math&amp;gt;y&amp;lt;/math&amp;gt; or numerically by subdividing the interval of &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; into small segments &amp;lt;math&amp;gt;\Delta x&amp;lt;/math&amp;gt; and adding up the areas of all small rectangles, &amp;lt;math&amp;gt;y(x)\times \Delta x&amp;lt;/math&amp;gt;. An alternative way is as follows. Suppose we know that &amp;lt;math&amp;gt;y(x)&amp;lt;/math&amp;gt; is positive and smaller than &amp;lt;math&amp;gt;f_{\rm max}&amp;lt;/math&amp;gt;. Then the area under the curve can be written down as &amp;lt;math&amp;gt;(b-a)f_{\rm max}*\alpha&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;\alpha&amp;lt;/math&amp;gt; is the fraction of the square &amp;lt;math&amp;gt;b-a&amp;lt;/math&amp;gt; by &amp;lt;math&amp;gt;f_{\rm max}&amp;lt;/math&amp;gt; that is actually under the curve. How do we estimate this fraction? Suppose I generate random points (dart throws), uniformly distributed over the square &amp;lt;math&amp;gt;b-a&amp;lt;/math&amp;gt; by &amp;lt;math&amp;gt;f_{\rm max}&amp;lt;/math&amp;gt;. The fraction of those that end up under the curve (and it's easy to check which one does!) is an estimate of &amp;lt;math&amp;gt;\alpha&amp;lt;/math&amp;gt;. The provided script performs such calculation for an arbitrary &amp;lt;math&amp;gt;y=y(x)&amp;lt;/math&amp;gt;. This is called Monte-Carlo integration. Note that our implementation is incomplete -- we don't check if the function ever is below 0 or ever is above &amp;lt;math&amp;gt;f_{\rm max}&amp;lt;/math&amp;gt;, which a better implementation should do.&lt;br /&gt;
&lt;br /&gt;
A problem, of course, is that such calculation is probabilistic -- every time we perform it, the results are different. But how different? We can verify, first of all, that our probabilistic estimate of the area converges to to true one, where true is known, e.g, when we integrate a function &amp;lt;math&amp;gt;x^2&amp;lt;/math&amp;gt;. We can also show the distribution of the estimates of the area when we perform the are estimate with &amp;lt;math&amp;gt;N&amp;lt;/math&amp;gt; dart throws. We see that the larger &amp;lt;math&amp;gt;N&amp;lt;/math&amp;gt; is, the more concentrated the estimates are. To quantify this, we use the provided script to calculate the standard deviation of the estimates as a function of &amp;lt;math&amp;gt;N&amp;lt;/math&amp;gt;. We find that &amp;lt;math&amp;gt;\sigma^2 = A/N&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; is some constant. The claim is that the general &amp;lt;math&amp;gt;1/N&amp;lt;/math&amp;gt; law holds true for essentially any function being integrated. It's only the constant that changes -- and we can verify this by integrating other functions.&lt;/div&gt;</summary>
		<author><name>Ilya</name></author>
		
	</entry>
</feed>