<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Wojciech Jamrozy blog &#187; AI</title>
	<atom:link href="http://www.wojtekrj.net/category/ai/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.wojtekrj.net</link>
	<description>Blog about computer science, programming and linux</description>
	<lastBuildDate>Sun, 23 Oct 2011 21:57:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>[Matlab] Generating random numbers with given covariance matrix</title>
		<link>http://www.wojtekrj.net/2010/11/matlab-generating-random-numbers-with-given-covariance-matrix/</link>
		<comments>http://www.wojtekrj.net/2010/11/matlab-generating-random-numbers-with-given-covariance-matrix/#comments</comments>
		<pubDate>Sat, 20 Nov 2010 12:04:54 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[AI]]></category>
		<category><![CDATA[Matlab]]></category>

		<guid isPermaLink="false">http://www.wojtekrj.net/?p=594</guid>
		<description><![CDATA[We are given a covariance matrix, and we&#8217;d like to generate n vectors, whose coordinates&#8217; covariance matrix is equal to given. We also like each coordinate to have given mean. Here is a code: function numbers = randomcov&#40;n, covMatrix, offset&#41; x=randn&#40;n,length&#40;covMatrix&#40;1,:&#41;&#41;&#41;; numbers = x*inv&#40;chol&#40;cov&#40;x&#41;&#41;&#41;*chol&#40;covMatrix&#41;; for i=1:length&#40;offset&#41; numbers&#40;:,i&#41; = offset&#40;i&#41;+numbers&#40;:,i&#41;-mean&#40;numbers&#40;:,i&#41;&#41;; end end Usage: n &#8211; number [...]]]></description>
			<content:encoded><![CDATA[<p>We are given a covariance matrix, and we&#8217;d like to generate n vectors, whose coordinates&#8217; covariance matrix is equal to given. We also like each coordinate to have given mean.<br />
Here is a code:</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #0000FF;">function</span> numbers = randomcov<span style="color: #080;">&#40;</span>n, covMatrix, offset<span style="color: #080;">&#41;</span>
    x=<span style="color: #0000FF;">randn</span><span style="color: #080;">&#40;</span>n,<span style="color: #0000FF;">length</span><span style="color: #080;">&#40;</span>covMatrix<span style="color: #080;">&#40;</span><span style="color: #33f;">1</span>,:<span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>;
    numbers = x*<span style="color: #0000FF;">inv</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">chol</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">cov</span><span style="color: #080;">&#40;</span>x<span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>*<span style="color: #0000FF;">chol</span><span style="color: #080;">&#40;</span>covMatrix<span style="color: #080;">&#41;</span>;
    <span style="color: #0000FF;">for</span> <span style="color: #0000FF;"><span style="color: #33f;">i</span></span>=<span style="color: #33f;">1</span>:<span style="color: #0000FF;">length</span><span style="color: #080;">&#40;</span>offset<span style="color: #080;">&#41;</span>
        numbers<span style="color: #080;">&#40;</span>:,<span style="color: #0000FF;"><span style="color: #33f;">i</span></span><span style="color: #080;">&#41;</span> = offset<span style="color: #080;">&#40;</span><span style="color: #0000FF;"><span style="color: #33f;">i</span></span><span style="color: #080;">&#41;</span>+numbers<span style="color: #080;">&#40;</span>:,<span style="color: #0000FF;"><span style="color: #33f;">i</span></span><span style="color: #080;">&#41;</span>-<span style="color: #0000FF;">mean</span><span style="color: #080;">&#40;</span>numbers<span style="color: #080;">&#40;</span>:,<span style="color: #0000FF;"><span style="color: #33f;">i</span></span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>;
    <span style="color: #0000FF;">end</span>
<span style="color: #0000FF;">end</span></pre></div></div>

<p>Usage:<br />
<em>n</em> &#8211; number of vectors to generate<br />
<em>covMatrix</em> &#8211; given covariance matrix<br />
<em>offset</em> &#8211; vector of means of each coordinate</p>
<p>Example:</p>
<p><span id="more-594"></span></p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;">&gt;&gt; n = <span style="color: #33f;">1000</span>
&nbsp;
n =
&nbsp;
        <span style="color: #33f;">1000</span>
&nbsp;
&gt;&gt; covMatrix = <span style="color: #080;">&#91;</span><span style="color: #33f;">1</span> <span style="color: #33f;">0.6</span> <span style="color: #33f;">0.3</span>; <span style="color: #33f;">0.6</span> <span style="color: #33f;">4</span> <span style="color: #33f;">0.5</span>; <span style="color: #33f;">0.3</span> <span style="color: #33f;">0.5</span> <span style="color: #33f;">9</span><span style="color: #080;">&#93;</span>
&nbsp;
covMatrix =
&nbsp;
    <span style="color: #33f;">1.0000</span>    <span style="color: #33f;">0.6000</span>    <span style="color: #33f;">0.3000</span>
    <span style="color: #33f;">0.6000</span>    <span style="color: #33f;">4.0000</span>    <span style="color: #33f;">0.5000</span>
    <span style="color: #33f;">0.3000</span>    <span style="color: #33f;">0.5000</span>    <span style="color: #33f;">9.0000</span>
&nbsp;
&gt;&gt; offset=  <span style="color: #080;">&#91;</span><span style="color: #33f;">4</span>, <span style="color: #33f;">7</span>, <span style="color: #33f;">5</span><span style="color: #080;">&#93;</span>
&nbsp;
offset =
&nbsp;
     <span style="color: #33f;">4</span>     <span style="color: #33f;">7</span>     <span style="color: #33f;">5</span>
&nbsp;
&gt;&gt; res = randomcov<span style="color: #080;">&#40;</span><span style="color: #33f;">1000</span>, <span style="color: #080;">&#91;</span><span style="color: #33f;">1</span> <span style="color: #33f;">0.6</span> <span style="color: #33f;">0.3</span>; <span style="color: #33f;">0.6</span> <span style="color: #33f;">1</span> <span style="color: #33f;">0.5</span>; <span style="color: #33f;">0.3</span> <span style="color: #33f;">0.5</span> <span style="color: #33f;">9</span><span style="color: #080;">&#93;</span>, <span style="color: #080;">&#91;</span><span style="color: #33f;">4</span>, <span style="color: #33f;">7</span>, <span style="color: #33f;">5</span><span style="color: #080;">&#93;</span><span style="color: #080;">&#41;</span>;
&gt;&gt; <span style="color: #0000FF;">length</span><span style="color: #080;">&#40;</span>res<span style="color: #080;">&#41;</span>
&nbsp;
<span style="color: #0000FF;">ans</span> =
&nbsp;
        <span style="color: #33f;">1000</span>
&nbsp;
&gt;&gt; res<span style="color: #080;">&#40;</span><span style="color: #33f;">1</span>:<span style="color: #33f;">10</span>,:<span style="color: #080;">&#41;</span>
&nbsp;
<span style="color: #0000FF;">ans</span> =
&nbsp;
    <span style="color: #33f;">5.4045</span>    <span style="color: #33f;">6.7922</span>   <span style="color: #33f;">13.7702</span>
    <span style="color: #33f;">3.2959</span>    <span style="color: #33f;">7.8065</span>    <span style="color: #33f;">4.1698</span>
    <span style="color: #33f;">4.4234</span>    <span style="color: #33f;">7.5814</span>    <span style="color: #33f;">8.2764</span>
    <span style="color: #33f;">5.1770</span>    <span style="color: #33f;">9.1141</span>    <span style="color: #33f;">7.6232</span>
    <span style="color: #33f;">3.0880</span>    <span style="color: #33f;">5.7971</span>    <span style="color: #33f;">6.7749</span>
    <span style="color: #33f;">2.8736</span>    <span style="color: #33f;">6.6350</span>    <span style="color: #33f;">7.4795</span>
    <span style="color: #33f;">4.1235</span>    <span style="color: #33f;">7.1429</span>    <span style="color: #33f;">4.4354</span>
    <span style="color: #33f;">4.2488</span>    <span style="color: #33f;">7.5810</span>    <span style="color: #33f;">2.4269</span>
    <span style="color: #33f;">2.7958</span>    <span style="color: #33f;">7.3045</span>    <span style="color: #33f;">8.3019</span>
    <span style="color: #33f;">3.7704</span>    <span style="color: #33f;">6.5484</span>    <span style="color: #33f;">7.3827</span>
&nbsp;
&gt;&gt; <span style="color: #0000FF;">cov</span><span style="color: #080;">&#40;</span>res<span style="color: #080;">&#41;</span>
&nbsp;
<span style="color: #0000FF;">ans</span> =
&nbsp;
    <span style="color: #33f;">1.0000</span>    <span style="color: #33f;">0.6000</span>    <span style="color: #33f;">0.3000</span>
    <span style="color: #33f;">0.6000</span>    <span style="color: #33f;">1.0000</span>    <span style="color: #33f;">0.5000</span>
    <span style="color: #33f;">0.3000</span>    <span style="color: #33f;">0.5000</span>    <span style="color: #33f;">9.0000</span>
&nbsp;
&gt;&gt; <span style="color: #0000FF;">mean</span><span style="color: #080;">&#40;</span>res<span style="color: #080;">&#41;</span>
&nbsp;
<span style="color: #0000FF;">ans</span> =
&nbsp;
    <span style="color: #33f;">4.0000</span>    <span style="color: #33f;">7.0000</span>    <span style="color: #33f;">5.0000</span></pre></div></div>

<p><a class="a2a_button_wykop" href="http://www.addtoany.com/add_to/wykop?linkurl=http%3A%2F%2Fwww.wojtekrj.net%2F2010%2F11%2Fmatlab-generating-random-numbers-with-given-covariance-matrix%2F&amp;linkname=%5BMatlab%5D%20Generating%20random%20numbers%20with%20given%20covariance%20matrix" title="Wykop" rel="nofollow" target="_blank"><img src="http://www.wojtekrj.net/wp-content/plugins/add-to-any/icons/wykop.png" width="16" height="16" alt="Wykop"/></a><a class="a2a_button_delicious" href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fwww.wojtekrj.net%2F2010%2F11%2Fmatlab-generating-random-numbers-with-given-covariance-matrix%2F&amp;linkname=%5BMatlab%5D%20Generating%20random%20numbers%20with%20given%20covariance%20matrix" title="Delicious" rel="nofollow" target="_blank"><img src="http://www.wojtekrj.net/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a><a class="a2a_button_facebook" href="http://www.addtoany.com/add_to/facebook?linkurl=http%3A%2F%2Fwww.wojtekrj.net%2F2010%2F11%2Fmatlab-generating-random-numbers-with-given-covariance-matrix%2F&amp;linkname=%5BMatlab%5D%20Generating%20random%20numbers%20with%20given%20covariance%20matrix" title="Facebook" rel="nofollow" target="_blank"><img src="http://www.wojtekrj.net/wp-content/plugins/add-to-any/icons/facebook.png" width="16" height="16" alt="Facebook"/></a><a class="a2a_button_technorati_favorites" href="http://www.addtoany.com/add_to/technorati_favorites?linkurl=http%3A%2F%2Fwww.wojtekrj.net%2F2010%2F11%2Fmatlab-generating-random-numbers-with-given-covariance-matrix%2F&amp;linkname=%5BMatlab%5D%20Generating%20random%20numbers%20with%20given%20covariance%20matrix" title="Technorati Favorites" rel="nofollow" target="_blank"><img src="http://www.wojtekrj.net/wp-content/plugins/add-to-any/icons/technorati.png" width="16" height="16" alt="Technorati Favorites"/></a><a class="a2a_button_digg" href="http://www.addtoany.com/add_to/digg?linkurl=http%3A%2F%2Fwww.wojtekrj.net%2F2010%2F11%2Fmatlab-generating-random-numbers-with-given-covariance-matrix%2F&amp;linkname=%5BMatlab%5D%20Generating%20random%20numbers%20with%20given%20covariance%20matrix" title="Digg" rel="nofollow" target="_blank"><img src="http://www.wojtekrj.net/wp-content/plugins/add-to-any/icons/digg.png" width="16" height="16" alt="Digg"/></a><a class="a2a_button_google_bookmarks" href="http://www.addtoany.com/add_to/google_bookmarks?linkurl=http%3A%2F%2Fwww.wojtekrj.net%2F2010%2F11%2Fmatlab-generating-random-numbers-with-given-covariance-matrix%2F&amp;linkname=%5BMatlab%5D%20Generating%20random%20numbers%20with%20given%20covariance%20matrix" title="Google Bookmarks" rel="nofollow" target="_blank"><img src="http://www.wojtekrj.net/wp-content/plugins/add-to-any/icons/google.png" width="16" height="16" alt="Google Bookmarks"/></a><a class="a2a_button_msdn" href="http://www.addtoany.com/add_to/msdn?linkurl=http%3A%2F%2Fwww.wojtekrj.net%2F2010%2F11%2Fmatlab-generating-random-numbers-with-given-covariance-matrix%2F&amp;linkname=%5BMatlab%5D%20Generating%20random%20numbers%20with%20given%20covariance%20matrix" title="MSDN" rel="nofollow" target="_blank"><img src="http://www.wojtekrj.net/wp-content/plugins/add-to-any/icons/msdn.png" width="16" height="16" alt="MSDN"/></a><a class="a2a_button_twitter" href="http://www.addtoany.com/add_to/twitter?linkurl=http%3A%2F%2Fwww.wojtekrj.net%2F2010%2F11%2Fmatlab-generating-random-numbers-with-given-covariance-matrix%2F&amp;linkname=%5BMatlab%5D%20Generating%20random%20numbers%20with%20given%20covariance%20matrix" title="Twitter" rel="nofollow" target="_blank"><img src="http://www.wojtekrj.net/wp-content/plugins/add-to-any/icons/twitter.png" width="16" height="16" alt="Twitter"/></a><a class="a2a_button_technotizie" href="http://www.addtoany.com/add_to/technotizie?linkurl=http%3A%2F%2Fwww.wojtekrj.net%2F2010%2F11%2Fmatlab-generating-random-numbers-with-given-covariance-matrix%2F&amp;linkname=%5BMatlab%5D%20Generating%20random%20numbers%20with%20given%20covariance%20matrix" title="Technotizie" rel="nofollow" target="_blank"><img src="http://www.wojtekrj.net/wp-content/plugins/add-to-any/icons/technotizie.png" width="16" height="16" alt="Technotizie"/></a><a class="a2a_button_technet" href="http://www.addtoany.com/add_to/technet?linkurl=http%3A%2F%2Fwww.wojtekrj.net%2F2010%2F11%2Fmatlab-generating-random-numbers-with-given-covariance-matrix%2F&amp;linkname=%5BMatlab%5D%20Generating%20random%20numbers%20with%20given%20covariance%20matrix" title="TechNet" rel="nofollow" target="_blank"><img src="http://www.wojtekrj.net/wp-content/plugins/add-to-any/icons/technet.png" width="16" height="16" alt="TechNet"/></a><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.wojtekrj.net%2F2010%2F11%2Fmatlab-generating-random-numbers-with-given-covariance-matrix%2F&amp;title=%5BMatlab%5D%20Generating%20random%20numbers%20with%20given%20covariance%20matrix" id="wpa2a_2">Share/Save</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.wojtekrj.net/2010/11/matlab-generating-random-numbers-with-given-covariance-matrix/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Free on-line materials</title>
		<link>http://www.wojtekrj.net/2010/05/free-on-line-materials/</link>
		<comments>http://www.wojtekrj.net/2010/05/free-on-line-materials/#comments</comments>
		<pubDate>Mon, 10 May 2010 18:32:13 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[AI]]></category>

		<guid isPermaLink="false">http://www.wojtekrj.net/?p=495</guid>
		<description><![CDATA[Internet is a really great thing! I&#8217;m able to watch lectures from such great universities as Stanford or MIT. Here is Machine learning course from Stanford: And Introduction to algorithms course conducted by Charles Leiserson (coauthor of &#8220;Cormen&#8217;s book&#8221;). and MIT OpenCourseWare &#8211; nearly 2000 courses from MIT.]]></description>
			<content:encoded><![CDATA[<p>Internet is a really great thing! I&#8217;m able to watch lectures from such great universities as Stanford or MIT.</p>
<p>Here is Machine learning course from Stanford:<br />
<object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/UzxYlbK2c7E&#038;hl=pl_PL&#038;fs=1&#038;"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/UzxYlbK2c7E&#038;hl=pl_PL&#038;fs=1&#038;" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object></p>
<p>And Introduction to algorithms course conducted by Charles Leiserson (coauthor of &#8220;Cormen&#8217;s book&#8221;).<br />
<object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/JPyuH4qXLZ0&#038;hl=pl_PL&#038;fs=1&#038;"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/JPyuH4qXLZ0&#038;hl=pl_PL&#038;fs=1&#038;" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object></p>
<p>and <a href="http://ocw.mit.edu/OcwWeb/web/courses/courses/index.htm" target="_blank">MIT OpenCourseWare</a> &#8211; nearly 2000 courses from MIT.</p>
<p><a class="a2a_button_wykop" href="http://www.addtoany.com/add_to/wykop?linkurl=http%3A%2F%2Fwww.wojtekrj.net%2F2010%2F05%2Ffree-on-line-materials%2F&amp;linkname=Free%20on-line%20materials" title="Wykop" rel="nofollow" target="_blank"><img src="http://www.wojtekrj.net/wp-content/plugins/add-to-any/icons/wykop.png" width="16" height="16" alt="Wykop"/></a><a class="a2a_button_delicious" href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fwww.wojtekrj.net%2F2010%2F05%2Ffree-on-line-materials%2F&amp;linkname=Free%20on-line%20materials" title="Delicious" rel="nofollow" target="_blank"><img src="http://www.wojtekrj.net/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a><a class="a2a_button_facebook" href="http://www.addtoany.com/add_to/facebook?linkurl=http%3A%2F%2Fwww.wojtekrj.net%2F2010%2F05%2Ffree-on-line-materials%2F&amp;linkname=Free%20on-line%20materials" title="Facebook" rel="nofollow" target="_blank"><img src="http://www.wojtekrj.net/wp-content/plugins/add-to-any/icons/facebook.png" width="16" height="16" alt="Facebook"/></a><a class="a2a_button_technorati_favorites" href="http://www.addtoany.com/add_to/technorati_favorites?linkurl=http%3A%2F%2Fwww.wojtekrj.net%2F2010%2F05%2Ffree-on-line-materials%2F&amp;linkname=Free%20on-line%20materials" title="Technorati Favorites" rel="nofollow" target="_blank"><img src="http://www.wojtekrj.net/wp-content/plugins/add-to-any/icons/technorati.png" width="16" height="16" alt="Technorati Favorites"/></a><a class="a2a_button_digg" href="http://www.addtoany.com/add_to/digg?linkurl=http%3A%2F%2Fwww.wojtekrj.net%2F2010%2F05%2Ffree-on-line-materials%2F&amp;linkname=Free%20on-line%20materials" title="Digg" rel="nofollow" target="_blank"><img src="http://www.wojtekrj.net/wp-content/plugins/add-to-any/icons/digg.png" width="16" height="16" alt="Digg"/></a><a class="a2a_button_google_bookmarks" href="http://www.addtoany.com/add_to/google_bookmarks?linkurl=http%3A%2F%2Fwww.wojtekrj.net%2F2010%2F05%2Ffree-on-line-materials%2F&amp;linkname=Free%20on-line%20materials" title="Google Bookmarks" rel="nofollow" target="_blank"><img src="http://www.wojtekrj.net/wp-content/plugins/add-to-any/icons/google.png" width="16" height="16" alt="Google Bookmarks"/></a><a class="a2a_button_msdn" href="http://www.addtoany.com/add_to/msdn?linkurl=http%3A%2F%2Fwww.wojtekrj.net%2F2010%2F05%2Ffree-on-line-materials%2F&amp;linkname=Free%20on-line%20materials" title="MSDN" rel="nofollow" target="_blank"><img src="http://www.wojtekrj.net/wp-content/plugins/add-to-any/icons/msdn.png" width="16" height="16" alt="MSDN"/></a><a class="a2a_button_twitter" href="http://www.addtoany.com/add_to/twitter?linkurl=http%3A%2F%2Fwww.wojtekrj.net%2F2010%2F05%2Ffree-on-line-materials%2F&amp;linkname=Free%20on-line%20materials" title="Twitter" rel="nofollow" target="_blank"><img src="http://www.wojtekrj.net/wp-content/plugins/add-to-any/icons/twitter.png" width="16" height="16" alt="Twitter"/></a><a class="a2a_button_technotizie" href="http://www.addtoany.com/add_to/technotizie?linkurl=http%3A%2F%2Fwww.wojtekrj.net%2F2010%2F05%2Ffree-on-line-materials%2F&amp;linkname=Free%20on-line%20materials" title="Technotizie" rel="nofollow" target="_blank"><img src="http://www.wojtekrj.net/wp-content/plugins/add-to-any/icons/technotizie.png" width="16" height="16" alt="Technotizie"/></a><a class="a2a_button_technet" href="http://www.addtoany.com/add_to/technet?linkurl=http%3A%2F%2Fwww.wojtekrj.net%2F2010%2F05%2Ffree-on-line-materials%2F&amp;linkname=Free%20on-line%20materials" title="TechNet" rel="nofollow" target="_blank"><img src="http://www.wojtekrj.net/wp-content/plugins/add-to-any/icons/technet.png" width="16" height="16" alt="TechNet"/></a><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.wojtekrj.net%2F2010%2F05%2Ffree-on-line-materials%2F&amp;title=Free%20on-line%20materials" id="wpa2a_4">Share/Save</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.wojtekrj.net/2010/05/free-on-line-materials/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

