<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Snippets. Code. Math.</title>
	<atom:link href="http://bellingthetech.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://bellingthetech.wordpress.com</link>
	<description>Technical Life. About Math, Programming and OR.</description>
	<lastBuildDate>Fri, 08 Apr 2011 18:47:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='bellingthetech.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Snippets. Code. Math.</title>
		<link>http://bellingthetech.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://bellingthetech.wordpress.com/osd.xml" title="Snippets. Code. Math." />
	<atom:link rel='hub' href='http://bellingthetech.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Cholesky&#8217;s Decomposition</title>
		<link>http://bellingthetech.wordpress.com/2011/04/08/cholesky-decomposition/</link>
		<comments>http://bellingthetech.wordpress.com/2011/04/08/cholesky-decomposition/#comments</comments>
		<pubDate>Fri, 08 Apr 2011 18:47:48 +0000</pubDate>
		<dc:creator>Shefali k.</dc:creator>
				<category><![CDATA[Linear Algebra]]></category>
		<category><![CDATA[Math]]></category>
		<category><![CDATA[Matrix Decomposition]]></category>
		<category><![CDATA[linear algebra]]></category>
		<category><![CDATA[matlab]]></category>

		<guid isPermaLink="false">http://bellingthetech.wordpress.com/?p=40</guid>
		<description><![CDATA[I love symmetric positive definite matrices. They are perfect. And so is Cholesky&#8217;s Decomposition on them. Here&#8217;s a quick short version in MatLab. function [G] = cholesky(A) %This code computes the cholesky decomposition of A. %A = given matrix. %G = Lower triangular cholesky decomposition %Written by: Shefali Kulkarni-Thaker epsilon = eps;%tolerance [row,col] = size(A); [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bellingthetech.wordpress.com&amp;blog=2037991&amp;post=40&amp;subd=bellingthetech&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I love symmetric positive definite matrices. They are perfect. And so is Cholesky&#8217;s Decomposition on them. Here&#8217;s a quick short version in MatLab.</p>
<pre style="color:#000000;background:#ffffff;"><span style="color:#800000;font-weight:bold;">function</span> <span style="color:#808030;">[</span>G<span style="color:#808030;">]</span> <span style="color:#808030;">=</span> cholesky<span style="color:#808030;">(</span>A<span style="color:#808030;">)</span>
<span style="color:#696969;">%This code computes the cholesky decomposition of A.</span>
<span style="color:#696969;">%A = given matrix.</span>
<span style="color:#696969;">%G = Lower triangular cholesky decomposition</span>
<span style="color:#696969;">%Written by: Shefali Kulkarni-Thaker</span>
epsilon <span style="color:#808030;">=</span> <span style="color:#bb7977;">eps</span><span style="color:#808030;">;</span><span style="color:#696969;">%tolerance</span>
<span style="color:#808030;">[</span>row<span style="color:#808030;">,</span>col<span style="color:#808030;">]</span> <span style="color:#808030;">=</span> <span style="color:#bb7977;">size</span><span style="color:#808030;">(</span>A<span style="color:#808030;">)</span><span style="color:#808030;">;</span>
<span style="color:#696969;">%check if matrix is square</span>
<span style="color:#800000;font-weight:bold;">if</span> row<span style="color:#808030;">~</span><span style="color:#808030;">=</span>col
    <span style="color:#bb7977;">error</span><span style="color:#808030;">(</span><span style="color:#800080;">'Matrix must be square'</span><span style="color:#808030;">)</span>
<span style="color:#800000;font-weight:bold;">end</span>
<span style="color:#696969;">%check that matrix is not singular - not the best way to do.</span>
<span style="color:#800000;font-weight:bold;">if</span> <span style="color:#bb7977;">abs</span><span style="color:#808030;">(</span><span style="color:#bb7977;">det</span><span style="color:#808030;">(</span>A<span style="color:#808030;">)</span><span style="color:#808030;">)</span> <span style="color:#808030;">&lt;</span> epsilon
    <span style="color:#bb7977;">error</span><span style="color:#808030;">(</span><span style="color:#800080;">'Matrix is singular to machine precision and cannot be solved'</span><span style="color:#808030;">)</span>
<span style="color:#800000;font-weight:bold;">end</span>
<span style="color:#696969;">%check is symmetric and positive definite. </span>
<span style="color:#696969;">%Implicitly checks for square matrices.</span>
<span style="color:#800000;font-weight:bold;">if</span> <span style="color:#808030;">~</span><span style="color:#808030;">(</span><span style="color:#bb7977;">all</span><span style="color:#808030;">(</span><span style="color:#bb7977;">all</span><span style="color:#808030;">(</span>A<span style="color:#808030;">=</span><span style="color:#808030;">=</span>A<span style="color:#808030;">'</span><span style="color:#808030;">)</span><span style="color:#808030;">)</span> <span style="color:#808030;">&amp;</span><span style="color:#808030;">&amp;</span> <span style="color:#bb7977;">min</span><span style="color:#808030;">(</span>eig<span style="color:#808030;">(</span>A<span style="color:#808030;">)</span><span style="color:#808030;">)</span><span style="color:#808030;">&gt;</span>0<span style="color:#808030;">)</span>
    <span style="color:#bb7977;">error</span><span style="color:#808030;">(</span><span style="color:#800080;">'Matrix is not SPD to perform Cholesky decomposition'</span><span style="color:#808030;">)</span><span style="color:#808030;">;</span>
<span style="color:#800000;font-weight:bold;">end</span>
n<span style="color:#808030;">=</span>row<span style="color:#808030;">;</span><span style="color:#696969;">%size of the matrix</span>
G <span style="color:#808030;">=</span> <span style="color:#bb7977;">zeros</span><span style="color:#808030;">(</span>n<span style="color:#808030;">,</span>n<span style="color:#808030;">)</span><span style="color:#808030;">;</span><span style="color:#696969;">%Lower triangular matrix</span>
<span style="color:#800000;font-weight:bold;">for</span> i <span style="color:#808030;">=</span> 1<span style="color:#808030;">:</span>n
    G<span style="color:#808030;">(</span>i<span style="color:#808030;">,</span>i<span style="color:#808030;">)</span> <span style="color:#808030;">=</span> <span style="color:#bb7977;">sqrt</span><span style="color:#808030;">(</span>A<span style="color:#808030;">(</span>i<span style="color:#808030;">,</span>i<span style="color:#808030;">)</span> <span style="color:#808030;">-</span> G<span style="color:#808030;">(</span>i<span style="color:#808030;">,</span><span style="color:#808030;">:</span><span style="color:#808030;">)</span><span style="color:#808030;">*</span>G<span style="color:#808030;">(</span>i<span style="color:#808030;">,</span><span style="color:#808030;">:</span><span style="color:#808030;">)</span><span style="color:#808030;">'</span><span style="color:#808030;">)</span><span style="color:#808030;">;</span><span style="color:#696969;">%Calculate diagonals.</span>
    <span style="color:#800000;font-weight:bold;">for</span> j <span style="color:#808030;">=</span> i<span style="color:#808030;">+</span>1<span style="color:#808030;">:</span>n
        G<span style="color:#808030;">(</span>j<span style="color:#808030;">,</span>i<span style="color:#808030;">)</span> <span style="color:#808030;">=</span> <span style="color:#808030;">(</span>A<span style="color:#808030;">(</span>j<span style="color:#808030;">,</span>i<span style="color:#808030;">)</span> <span style="color:#808030;">-</span> G<span style="color:#808030;">(</span>i<span style="color:#808030;">,</span><span style="color:#808030;">:</span><span style="color:#808030;">)</span><span style="color:#808030;">*</span>G<span style="color:#808030;">(</span>j<span style="color:#808030;">,</span><span style="color:#808030;">:</span><span style="color:#808030;">)</span><span style="color:#808030;">'</span><span style="color:#808030;">)</span><span style="color:#808030;">/</span>G<span style="color:#808030;">(</span>i<span style="color:#808030;">,</span>i<span style="color:#808030;">)</span><span style="color:#808030;">;</span><span style="color:#696969;">%column</span>
    <span style="color:#800000;font-weight:bold;">end</span>
<span style="color:#800000;font-weight:bold;">end</span>
<span style="color:#800000;font-weight:bold;">end</span></pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bellingthetech.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bellingthetech.wordpress.com/40/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bellingthetech.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bellingthetech.wordpress.com/40/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bellingthetech.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bellingthetech.wordpress.com/40/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bellingthetech.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bellingthetech.wordpress.com/40/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bellingthetech.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bellingthetech.wordpress.com/40/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bellingthetech.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bellingthetech.wordpress.com/40/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bellingthetech.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bellingthetech.wordpress.com/40/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bellingthetech.wordpress.com&amp;blog=2037991&amp;post=40&amp;subd=bellingthetech&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://bellingthetech.wordpress.com/2011/04/08/cholesky-decomposition/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a0ba2c7d11c8f06702ad5ccf7d76a84a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">S.K.</media:title>
		</media:content>
	</item>
		<item>
		<title>Single Table Inheritance using LINQ</title>
		<link>http://bellingthetech.wordpress.com/2009/02/11/single-table-inheritance-using-linq/</link>
		<comments>http://bellingthetech.wordpress.com/2009/02/11/single-table-inheritance-using-linq/#comments</comments>
		<pubDate>Wed, 11 Feb 2009 21:55:28 +0000</pubDate>
		<dc:creator>Shefali k.</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Linq]]></category>
		<category><![CDATA[ORM]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://bellingthetech.wordpress.com/2009/02/11/single-table-inheritance-using-linq/</guid>
		<description><![CDATA[My most recent venture in technical world has been learning MS technologies and eventually O/RM using LINQ. Language Integrated Query or LINQ is a Microsoft feature that allows you to map your relational database tables to objects. I will talk about mapping a single table to a class hierarchy &#8211; Single Table Inheritance &#8211; using [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bellingthetech.wordpress.com&amp;blog=2037991&amp;post=36&amp;subd=bellingthetech&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p align="justify">My most recent venture in technical world has been learning MS technologies and eventually O/RM using LINQ. Language Integrated Query or LINQ is a Microsoft feature that allows you to map your relational database tables to objects. I will talk about mapping a single table to a class hierarchy &#8211; <a href="http://www.martinfowler.com/eaaCatalog/singleTableInheritance.html">Single Table Inheritance</a> &#8211; using LINQ.</p>
<p><span id="more-36"></span>
<p align="justify">LINQ features are located in System.Linq, System.Data.Linq, and System.Data.Linq.Mapping namespaces. It&#8217;s mapping attribute [InheritanceMapping] does all the job for you.</p>
<p align="justify">Let us write a base class called Node and map it to a table in database using the TableAttribute.</p>
<blockquote><p align="left">&nbsp; [Table(Name = "MST_EQUIP")]<br /> [InheritanceMapping(Code = "SOURCE", Type = typeof(Source)]<br /> public class Node<br />&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [Column(Name = "EQUIP_TYPE", IsDiscriminator = true,IsPrimaryKey=true)]<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public string NodeType;<br />&nbsp; }</p>
</blockquote>
<p align="justify">The Attribute, Column maps the field, NodeType to a column, EQUIP_TYPE, in database. The parameter IsDiscriminator identifies whether this column is the basis of inheritance. </p>
<p align="justify">In the Attribute, InheritanceMapping the parameter Code identifies the value in the Discriminating column which results in child class for the node. The Type parameter identifies the class. </p>
<p align="justify">In simple English, if the column EQUIP_TYPE of the table MST_EQUIP has the string &#8220;SOURCE&#8221; in it,&nbsp; LINQ will create an Object of type Source for you. The class Source, of course, inherits the class Node.</p>
<p align="justify">That&#8217;s cool, isn&#8217;t it ?</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bellingthetech.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bellingthetech.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bellingthetech.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bellingthetech.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bellingthetech.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bellingthetech.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bellingthetech.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bellingthetech.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bellingthetech.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bellingthetech.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bellingthetech.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bellingthetech.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bellingthetech.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bellingthetech.wordpress.com/36/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bellingthetech.wordpress.com&amp;blog=2037991&amp;post=36&amp;subd=bellingthetech&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://bellingthetech.wordpress.com/2009/02/11/single-table-inheritance-using-linq/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a0ba2c7d11c8f06702ad5ccf7d76a84a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">S.K.</media:title>
		</media:content>
	</item>
		<item>
		<title>World Wide Telescope</title>
		<link>http://bellingthetech.wordpress.com/2008/05/13/world-wide-telescope/</link>
		<comments>http://bellingthetech.wordpress.com/2008/05/13/world-wide-telescope/#comments</comments>
		<pubDate>Tue, 13 May 2008 16:44:28 +0000</pubDate>
		<dc:creator>Shefali k.</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://bellingthetech.wordpress.com/2008/05/13/world-wide-telescope/</guid>
		<description><![CDATA[&#160; This is what I saw When I downloaded Microsoft Research&#8217;s World Wide Telescope.&#160; Can&#8217;t wait to connect it a Stellarscope Star Finder. Any buyers?<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bellingthetech.wordpress.com&amp;blog=2037991&amp;post=34&amp;subd=bellingthetech&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://bellingthetech.files.wordpress.com/2008/05/clip-image002.jpg"><img style="border-right:0;border-top:0;border-left:0;border-bottom:0;" height="153" alt="clip_image002" src="http://bellingthetech.files.wordpress.com/2008/05/clip-image002-thumb.jpg?w=244&#038;h=153" width="244" border="0"></a>&nbsp;</p>
<p>This is what I saw When I downloaded <a href="http://www.worldwidetelescope.org/">Microsoft Research&#8217;s World Wide Telescope.</a>&nbsp;</p>
<p>Can&#8217;t wait to connect it a <a href="http://shop.nationalgeographic.com/product/4098.html">Stellarscope Star Finder</a>.</p>
<p>Any buyers?</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/bellingthetech.wordpress.com/34/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/bellingthetech.wordpress.com/34/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bellingthetech.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bellingthetech.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bellingthetech.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bellingthetech.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bellingthetech.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bellingthetech.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bellingthetech.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bellingthetech.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bellingthetech.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bellingthetech.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bellingthetech.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bellingthetech.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bellingthetech.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bellingthetech.wordpress.com/34/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bellingthetech.wordpress.com&amp;blog=2037991&amp;post=34&amp;subd=bellingthetech&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://bellingthetech.wordpress.com/2008/05/13/world-wide-telescope/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a0ba2c7d11c8f06702ad5ccf7d76a84a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">S.K.</media:title>
		</media:content>

		<media:content url="http://bellingthetech.files.wordpress.com/2008/05/clip-image002-thumb.jpg" medium="image">
			<media:title type="html">clip_image002</media:title>
		</media:content>
	</item>
		<item>
		<title>Asymptotic Notation</title>
		<link>http://bellingthetech.wordpress.com/2008/05/08/asymptotic-notation/</link>
		<comments>http://bellingthetech.wordpress.com/2008/05/08/asymptotic-notation/#comments</comments>
		<pubDate>Thu, 08 May 2008 21:50:02 +0000</pubDate>
		<dc:creator>Shefali k.</dc:creator>
				<category><![CDATA[Algorithms]]></category>
		<category><![CDATA[Data Structure]]></category>

		<guid isPermaLink="false">http://bellingthetech.wordpress.com/2008/05/08/asymptotic-notation/</guid>
		<description><![CDATA[Most of us had a hard time learning asymptotic notation. I fairly skipped it, like my other classmates until recently I found that it was quite interesting to understand. Asymptote is a curve on a graph that is approached but not reached. Performance of algorithms is an important algorithmic study, only after it&#8217;s correctness. It [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bellingthetech.wordpress.com&amp;blog=2037991&amp;post=31&amp;subd=bellingthetech&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p align="justify">Most of us had a hard time learning asymptotic notation. I fairly skipped it, like my other classmates until recently I found that it was quite interesting to understand.</p>
<p align="justify">Asymptote is a curve on a graph that is approached but not reached. Performance of algorithms is an important algorithmic study, only after it&#8217;s correctness. It is measured in terms of size of the input. As the input size increases boundlessly how does the running time of the algorithm vary ? We plot the graph of the input size versus the running time of the algorithm. The curve of the graph essentially tells us the performance of the algorithm.</p>
<p align="justify">The first sorting procedure we learnt in school is insertion sort. The worst-case time of this algorithm is Θ(n<sup>2</sup>). So, what is this?</p>
<p align="justify">The mathematical definition of Θ is as follows: Given a function <em>g(n) , </em>Θ(<em>g(n) </em>) is defined as a set of functions:</p>
<blockquote>
<p align="justify">Θ(<em>g(n) </em>) = {<em>f(n):  there exist positive constants c<sub>1</sub> and c<sub>2,</sub></em> and n<sub>0</sub> such that <em>0 ≤ c<sub>1</sub>g(n) ≤ f(n) ≤ c<sub>2</sub>g(n) for all n ≥ n<sub>0</sub> }.</em></p>
</blockquote>
<p align="justify">So, we are trying to club <em>f(n)</em> between <em>c<sub>1</sub>g(n)</em> and <em>c<sub>2</sub>g(n)</em> for a large value of n. So, since  Θ(<em>g(n) </em>) is a set of function and <em>f(n) </em>belongs to it, it means <em>f(n)</em> <em>ε </em>Θ(<em>g(n) </em>). Instead we write <em>f(n)</em> <em>= </em>Θ(<em>g(n) </em>), to mean the same (and we shall stick to that). The graph for <em>f(n)</em> <em>= </em>Θ(<em>g(n) </em>) is:</p>
<p align="justify"><img style="border-right:0;border-top:0;border-left:0;border-bottom:0;" src="http://bellingthetech.files.wordpress.com/2008/05/theta-thumb.png?w=240&#038;h=181" border="0" alt="theta" width="240" height="181" align="left" />The figure says that the value of function f(n) lies between an upper bound , <em>c<sub>2</sub>g(n)</em> , and a lower bound <em>c<sub>1</sub>g(n)</em>. <em>f(n) </em>is hence a tightly bound by <em>g(n).</em></p>
<p align="justify">The asymptotic running time ignores machine constants and looks for the growth of running time. So, as <em>n</em> approaches infinity, a Θ(n<sup>2</sup>) algorithm beats a Θ(n<sup>3</sup>).  There will a point after which no matter how much step up you give to a Θ(n<sup>3</sup>) algorithm in terms of processing power &#8211; Θ(n<sup>2</sup>)  will beat it. This point is n<sub>0</sub> .</p>
<p align="justify">The <em>O-</em>notation gives an upper bound to the function. When it is used for bounding the worst running time of the algorithm, it gives a bound on <em>every </em>input to the algorithm. Ω-notation gives a lower bound to the function. When it is used to describe the best running time for an algorithm, it gives a bound to any <em>random</em> input.</p>
<p align="justify">For example, consider insertion sort on an array A.</p>
<blockquote>
<p align="justify"><span style="color:#808080;">1. for i = 2 to length(A)<br />
do k = A[ i ]<br />
j = i &#8211; 1;<br />
while j &gt; 0 and A[ j ] &gt; k<br />
do A[ j+1 ] = A[ j ]<br />
j = j &#8211; 1;<br />
A[ j+1 ] = k;</span></p>
</blockquote>
<p align="justify">The running time of insertion sort is Θ(n<sup>2</sup>), when the input is reverse sorted. However, if the input is already sorted, it gives a running time of Θ(n).</p>
<p align="justify">Saying that running time is <em>O</em>(n<sup>2</sup>), means that there is a function <em>f(n)=O(n<sup>2</sup>) </em>so that<em> </em>no matter how large the input is or what the input is, running time will never go beyond <em>f(n)</em>.</p>
<p align="justify">Saying that running time is <em>Ω(n),</em> means that there is a function<br />
<em>f(n)=Ω(n) </em>so that<em> </em>no matter how large the input is or what the input is , running time will never fall below <em>f(n)</em>.</p>
<p align="justify">To say running time (of insertion sort) is <em>Ω</em>(n<sup>2</sup>) means that there is a function <em>f(n) = Ω(n<sup>2</sup>), </em>such that no matter what size input is chosen it will never go below <em>f(n). </em>This is, of course, incorrect in case of insertion sort.</p>
<p align="justify">Thus, insertion sort  will take a minimum of Ω(n) and a maximum of <em>O</em>(n<sup>2</sup>).</p>
<p align="justify">Worst case running time is a guarantee of performance, while best-case can cheat since some algorithms work faster on some input.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/bellingthetech.wordpress.com/31/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/bellingthetech.wordpress.com/31/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bellingthetech.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bellingthetech.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bellingthetech.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bellingthetech.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bellingthetech.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bellingthetech.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bellingthetech.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bellingthetech.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bellingthetech.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bellingthetech.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bellingthetech.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bellingthetech.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bellingthetech.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bellingthetech.wordpress.com/31/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bellingthetech.wordpress.com&amp;blog=2037991&amp;post=31&amp;subd=bellingthetech&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://bellingthetech.wordpress.com/2008/05/08/asymptotic-notation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a0ba2c7d11c8f06702ad5ccf7d76a84a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">S.K.</media:title>
		</media:content>

		<media:content url="http://bellingthetech.files.wordpress.com/2008/05/theta-thumb.png" medium="image">
			<media:title type="html">theta</media:title>
		</media:content>
	</item>
		<item>
		<title>Parallel Expression Evaluation using Tree Contraction</title>
		<link>http://bellingthetech.wordpress.com/2008/05/07/parallel-expression-evaluation-using-tree-contraction/</link>
		<comments>http://bellingthetech.wordpress.com/2008/05/07/parallel-expression-evaluation-using-tree-contraction/#comments</comments>
		<pubDate>Wed, 07 May 2008 23:27:17 +0000</pubDate>
		<dc:creator>Shefali k.</dc:creator>
				<category><![CDATA[Algorithms]]></category>
		<category><![CDATA[Data Structure]]></category>
		<category><![CDATA[Expression evaluation]]></category>
		<category><![CDATA[OpenMP]]></category>
		<category><![CDATA[Parallel Computing]]></category>
		<category><![CDATA[Tree]]></category>

		<guid isPermaLink="false">http://bellingthetech.wordpress.com/2008/05/07/parallel-expression-evaluation-using-tree-contraction/</guid>
		<description><![CDATA[Recently I wrote on Sequential Expression Evaluation in its stack-based recursive form. As a part of my course work, I wrote a parallel version for it referencing this. My implementation was in OpenMP using shared memory on SHARCNET. Parallel implementation is done using Tree Contraction technique. The important operation of this technique is raking, that [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bellingthetech.wordpress.com&amp;blog=2037991&amp;post=25&amp;subd=bellingthetech&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p align="justify">Recently I wrote on <a href="http://bellingthetech.wordpress.com/2008/03/11/sequential-arithmetic-expression-evaluation/">Sequential Expression Evaluation</a> in its stack-based recursive form. As a part of my course work, I wrote a parallel version for it referencing <a href="http://www.cc.gatech.edu/~bader/papers/HiPC2002.html">this</a>. My implementation was in <a href="http://www.openmp.org">OpenMP</a> using shared memory on <a href="http://www.sharcnet.ca">SHARCNET</a>.</p>
<p><span id="more-25"></span></p>
<p align="justify">
<p align="justify">Parallel implementation is done using Tree Contraction technique. The important  operation of this technique is raking, that involves removing of many leaves of the binary expression tree in parallel.  Tree Contraction and Raking is explained as under:</p>
<p align="justify">For a vertex <em>u</em> in tree having <em>v</em> and <em>w</em> as its left and right children. The vertex <em>v</em> ( and every other node) is associated with label <img src='http://s0.wp.com/latex.php?latex=%28a_%7Bv%7D%2Cb_%7Bv%7D%29&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='(a_{v},b_{v})' title='(a_{v},b_{v})' class='latex' /><code>.</code>The initial value of this label id (1,0).  At every iteration new value for this labels are evaluated until the the tree is reduced to 3 vertices. The value of the parent node <em>v</em> is given by:</p>
<blockquote>
<p align="justify"><img src='http://s0.wp.com/latex.php?latex=val%28u%29+%3D+%28a_%7Bv%7D%2Aval%28v%29+%2B+b_%7Bv%7D%29+op%28u%29+%28a_%7Bw%7D%2Aval%28w%29%2Bb_%7Bw%7D%29&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='val(u) = (a_{v}*val(v) + b_{v}) op(u) (a_{w}*val(w)+b_{w})' title='val(u) = (a_{v}*val(v) + b_{v}) op(u) (a_{w}*val(w)+b_{w})' class='latex' /></p>
</blockquote>
<p>The value of the parent of <em>u, </em>denoted by <em>p(u) </em>is given by:</p>
<blockquote><p><img src='http://s0.wp.com/latex.php?latex=val%28p%28u%29%29+%3D+a_%7Bu%7D%2Aval%28u%29+%2B+b_%7Bu%7D&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='val(p(u)) = a_{u}*val(u) + b_{u}' title='val(p(u)) = a_{u}*val(u) + b_{u}' class='latex' /><br />
<img src='http://s0.wp.com/latex.php?latex=%3D+a_%7Bu%7D%2A%28%28a_%7Bv%7D%2Aval%28v%29+%2B+b_%7Bv%7D%29+op%28u%29+%28a_%7Bw%7D%2Aval%28v%29+%2B+b_%7Bw%7D%29%29+%2B+b_%7Bu%7D&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='= a_{u}*((a_{v}*val(v) + b_{v}) op(u) (a_{w}*val(v) + b_{w})) + b_{u}' title='= a_{u}*((a_{v}*val(v) + b_{v}) op(u) (a_{w}*val(v) + b_{w})) + b_{u}' class='latex' /></p></blockquote>
<p>When we rake <em>v</em>, labels of <em>w </em>are updated. Thus, on applying rake operation repeatedly we get a three-vertex tree T with root <em>r</em>, having the operator, and its children as <img src='http://s0.wp.com/latex.php?latex=v_%7B1%7D&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='v_{1}' title='v_{1}' class='latex' /> and <img src='http://s0.wp.com/latex.php?latex=v_%7B2%7D&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='v_{2}' title='v_{2}' class='latex' />.</p>
<p>The value at the root, and hence the expression is given by:</p>
<blockquote><p><img src='http://s0.wp.com/latex.php?latex=val%28T%29+%3D+val%28r%29+%3D+%28a_%7Bv_%7B1%7D%7D%2Aval%28v_%7B1%7D%29+%2B+b_%7Bv_%7B1%7D%7D%29+op%28r%29+%28a_%7Bv_%7B2%7D%7D%2Aval%28v_%7B2%7D%29+%2B+b_%7Bv_%7B2%7D%7D%29&amp;bg=ffffff&amp;fg=000000&amp;s=0' alt='val(T) = val(r) = (a_{v_{1}}*val(v_{1}) + b_{v_{1}}) op(r) (a_{v_{2}}*val(v_{2}) + b_{v_{2}})' title='val(T) = val(r) = (a_{v_{1}}*val(v_{1}) + b_{v_{1}}) op(r) (a_{v_{2}}*val(v_{2}) + b_{v_{2}})' class='latex' /></p></blockquote>
<p>Parallel Expression Evaluation is about applying raking operation in parallel.  Here is a glimpse of raking operation.</p>
<p><a href="http://bellingthetech.files.wordpress.com/2008/05/image5.png"><img style="border-right:0;border-top:0;border-left:0;border-bottom:0;" src="http://bellingthetech.files.wordpress.com/2008/05/image-thumb5.png?w=244&#038;h=123" border="0" alt="image" width="244" height="123" /></a></p>
<p>The raking operation has to be done with a small strategy. Consider this tree.</p>
<p align="justify"><a href="http://bellingthetech.files.wordpress.com/2008/05/image2.png"><img style="border-width:0;" src="http://bellingthetech.files.wordpress.com/2008/05/image-thumb2.png?w=244&#038;h=120" border="0" alt="image" width="244" height="120" align="left" /></a> We clearly cannot rake node 1 and 8, whose parents are consecutive, at the same time. So we apply raking to non-consecutive leaves as they appear from left to right.  The algorithm for the raking operation is as:</p>
<p align="justify">
<p align="justify">
<p align="justify">1. Label the leaves consecutively in order from left to right, excluding the left-most and right-most nodes (since we need then for final evaluation), and store this in an array A of size n. Create a subarray  A<sub>odd </sub>and A<sub>even</sub> that consist of odd- and even-indexed elements of A.</p>
<p align="justify">2.for(lg(n+1)) iteration do</p>
<blockquote>
<p align="justify"><span style="color:#808080;">1. Apply rake operation that modifies the siblings labels concurrently to all the elements of A<sub>odd </sub>that are left children,</span></p>
<p align="justify"><span style="color:#808080;">2. Apply rake operation that modifies the siblings labels concurrently to all the rest of the elements of A<sub>odd </sub>.</span></p>
<p align="justify"><span style="color:#808080;">3. Make A = A<sub>even</sub>.</span></p>
</blockquote>
<p align="justify">3.Compute the value of arithmetic expression from the three-vertex binary tree.</p>
<p align="justify">A glimpse of this operation in action is here:</p>
<p align="justify"><a href="http://bellingthetech.files.wordpress.com/2008/05/image3.png"><img style="border-width:0;" src="http://bellingthetech.files.wordpress.com/2008/05/image-thumb3.png?w=244&#038;h=234" border="0" alt="image" width="244" height="234" /></a></p>
<p>The OpenMP implementation of this algorithm gave significant results when applied on a <a href="http://www.nist.gov/dads/HTML/fullBinaryTree.html">Full Binary Tree</a> with height = 30.</p>
<p><a href="http://bellingthetech.files.wordpress.com/2008/05/image6.png"><img style="border-right:0;border-top:0;border-left:0;border-bottom:0;" src="http://bellingthetech.files.wordpress.com/2008/05/image-thumb6.png?w=244&#038;h=144" border="0" alt="image" width="244" height="144" /></a></p>
<p>The complexity of sequential arithmetic evaluation, for an n node tree is <em>O</em>(<em>n</em>), while for parallel version it is reduced to <em>O</em>(<em>lg(n)</em>).</p>
<p>All figures, excluding chart, are from <a href="http://ad.informatik.uni-freiburg.de/lehre/ss02/paa/vorlesung-uebungen/lektion6/index.html">here</a>.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/bellingthetech.wordpress.com/25/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/bellingthetech.wordpress.com/25/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bellingthetech.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bellingthetech.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bellingthetech.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bellingthetech.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bellingthetech.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bellingthetech.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bellingthetech.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bellingthetech.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bellingthetech.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bellingthetech.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bellingthetech.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bellingthetech.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bellingthetech.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bellingthetech.wordpress.com/25/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bellingthetech.wordpress.com&amp;blog=2037991&amp;post=25&amp;subd=bellingthetech&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://bellingthetech.wordpress.com/2008/05/07/parallel-expression-evaluation-using-tree-contraction/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a0ba2c7d11c8f06702ad5ccf7d76a84a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">S.K.</media:title>
		</media:content>

		<media:content url="http://bellingthetech.files.wordpress.com/2008/05/image-thumb5.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://bellingthetech.files.wordpress.com/2008/05/image-thumb2.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://bellingthetech.files.wordpress.com/2008/05/image-thumb3.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://bellingthetech.files.wordpress.com/2008/05/image-thumb6.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
		<item>
		<title>JDBC and MySQL</title>
		<link>http://bellingthetech.wordpress.com/2008/05/07/jdbc-and-mysql/</link>
		<comments>http://bellingthetech.wordpress.com/2008/05/07/jdbc-and-mysql/#comments</comments>
		<pubDate>Wed, 07 May 2008 22:03:22 +0000</pubDate>
		<dc:creator>Shefali k.</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://bellingthetech.wordpress.com/2008/05/07/jdbc-and-mysql/</guid>
		<description><![CDATA[I have to always connect to the database for some reason. My usual problem is &#8220;Access denied&#8221;. I thought I would document it once. The steps to start connecting to MySQL from a program are as: 1) Install MySQL server and download mysql-connector-java-3.0.17-ga. 2) Set the class path. ( could be C:\mysql-connector-java-3.0.17-ga ) 3) Grant [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bellingthetech.wordpress.com&amp;blog=2037991&amp;post=15&amp;subd=bellingthetech&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I have to always connect to the database for some reason. My usual problem is &#8220;Access denied&#8221;. I thought I would document it once. The steps to start connecting to MySQL from a program are as:</p>
<p><span id="more-15"></span></p>
<p><strong></strong></p>
<p><strong>1)</strong> Install MySQL server and download mysql-connector-java-3.0.17-ga.</p>
<p><strong>2) </strong>Set the class path. ( could be C:\mysql-connector-java-3.0.17-ga )</p>
<p>3) Grant permission on the SQL server as:<br />
GRANT ALL PRIVILEGES ON some_database.* TO <a href="mailto:'someuser'@'localhost'">&#8216;someuser&#8217;@'localhost&#8217;</a> IDENTIFIED BY &#8216;some_password&#8217; WITH GRANT OPTION;</p>
<p><strong>4)</strong> Load driver in JDBC as  com.mysql.jdbc.Driver</p>
<p><strong>5)</strong> Get the connection as  <em>jdbc:mysql://localhost:3306/&lt;db_name&gt;?user=some_user&amp;password=some_password&#8217;6</em></p>
<p><strong>6)</strong> Do you queries.</p>
<p><strong>7) </strong>Close your connection.</p>
<p>You are all set.</p>
<p>Here is a quick example of this.</p>
<pre style="width:575px;height:525px;">
import java.io.*;
import java.sql.*;

<span class="kwrd">public class SQLExample{
	public static void main(String args[])
	{
		Connection conn = null;
		Statement stmt = null;
		try{
	        //LOAD THE DRIVER
	       Class.forName("com.mysql.jdbc.Driver");
	       //GET THE CONNECTION STRING
	       conn = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/db_name?
user=someuser&amp;password=somepassword");
	       //GET A STATEMENT TO EXECUTE
	       stmt=conn.createStatement ();
	       String query="insert into newtable values('someName',10)";
	       ResultSet result = stmt.executeQuery(query);
               System.out.println("query executed");
               int row = result.getRow();
               if(row&gt;0)
               System.out.println("Row " +row+" Added");
	        }catch(Exception e){
	        	e.printStackTrace();
	        }
	        finally
	        {
	        	try {
	        			conn.close();
				}catch (SQLException e) {
					e.printStackTrace();
				}
	        }
	}
}
</span></pre>
<p>Good Luck connecting the database ! </p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/bellingthetech.wordpress.com/15/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/bellingthetech.wordpress.com/15/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bellingthetech.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bellingthetech.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bellingthetech.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bellingthetech.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bellingthetech.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bellingthetech.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bellingthetech.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bellingthetech.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bellingthetech.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bellingthetech.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bellingthetech.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bellingthetech.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bellingthetech.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bellingthetech.wordpress.com/15/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bellingthetech.wordpress.com&amp;blog=2037991&amp;post=15&amp;subd=bellingthetech&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://bellingthetech.wordpress.com/2008/05/07/jdbc-and-mysql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a0ba2c7d11c8f06702ad5ccf7d76a84a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">S.K.</media:title>
		</media:content>
	</item>
		<item>
		<title>Probing Agent Properties that are Objects: REPAST S</title>
		<link>http://bellingthetech.wordpress.com/2008/05/06/probing-objects-repast-s/</link>
		<comments>http://bellingthetech.wordpress.com/2008/05/06/probing-objects-repast-s/#comments</comments>
		<pubDate>Tue, 06 May 2008 14:49:59 +0000</pubDate>
		<dc:creator>Shefali k.</dc:creator>
				<category><![CDATA[Agent-Based Systems]]></category>
		<category><![CDATA[RePast S]]></category>

		<guid isPermaLink="false">http://bellingthetech.wordpress.com/2008/05/06/probing-objects-repast-s/</guid>
		<description><![CDATA[The way to probe agent properties that are user-defined objects in repast is through converters. For example, we have an agent with a parameter Volume, an object. package properties; /* @author Shefali Kulkarni */ public class Volume { private double vol; private double minVol; private double maxVol; public Volume() { this.vol = 100; this.minVol = [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bellingthetech.wordpress.com&amp;blog=2037991&amp;post=14&amp;subd=bellingthetech&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The way to probe agent properties that are user-defined objects in repast is through converters. For example, we have an agent with a parameter Volume, an object.</p>
<p><span id="more-14"></span></p>
<pre style="width:462px;height:355px;"><span class="rem">package properties;
</span><span class="rem">/* @author Shefali Kulkarni </span><span class="rem">*/</span>
<span class="kwrd">public</span> <span class="kwrd">class</span> Volume {
    <span class="kwrd">private</span> <span class="kwrd">double</span> vol;
    <span class="kwrd">private</span> <span class="kwrd">double</span> minVol;
    <span class="kwrd">private</span> <span class="kwrd">double</span> maxVol;
     <span class="kwrd">public</span> Volume()
    {
        <span class="kwrd">this</span>.vol = 100;
        <span class="kwrd">this</span>.minVol = 0;
        <span class="kwrd">this</span>.maxVol = 500;
    }
   // to define Accessor methods
   @Override
   <span class="kwrd">public</span> String toString() {
        <span class="kwrd">return</span> vol+<span class="str">" "</span>+minVol+<span class="str">" "</span>+maxVol;
    }
}
</pre>
<p>There is a need to write a Converter class for Volume, that converts Volume object to and from String. This is required since, the probe display is essentially String representation of Object. The definition for this Volume converter would be something as:</p>
<pre>package properties.converter;
import repast.simphony.parameter.StringConverter;
<span class="rem">/**</span>
<span class="rem"> * @author Shefali Kulkarni</span>
<span class="rem">  */</span>
<span class="kwrd">public</span> <span class="kwrd">class</span> VolumeConverter implements
StringConverter&lt;Volume&gt;
{

    <span class="kwrd">public</span> Volume fromString(String str) {
        <span class="kwrd">if</span>(str.equals(<span class="kwrd">null</span>)) <span class="kwrd">new</span> Volume();
        <span class="kwrd">int</span> index = str.indexOf(<span class="str">" "</span>);
        System.<span class="kwrd">out</span>.println(index);
        Double vol = Double.parseDouble
(str.substring(0,index));
        <span class="kwrd">int</span> next_index = str.indexOf(<span class="str">" "</span>,index+1);
        System.<span class="kwrd">out</span>.println(next_index);
        Double min = Double.parseDouble
(str.substring(index+1,next_index));
        <span class="kwrd">double</span> max = Double.parseDouble
(str.substring(next_index+1, str.length()));
        <span class="kwrd">return</span> <span class="kwrd">new</span> Volume(vol,min,max);
     }

    <span class="kwrd">public</span> String toString(Volume obj) {
        <span class="kwrd">if</span>(obj.equals(<span class="kwrd">null</span>))
 <span class="kwrd">return</span> <span class="str">"Volume of the Tank is Undefined."</span>;
       <span class="kwrd">return</span> obj.getVol()+<span class="str">" "</span>+obj.getMinVol()+
<span class="str">" "</span>+obj.getMaxVol();
    }
}</pre>
<p>The definition has to make sure that the object and string are convertible from each other.</p>
<p>The parameter annotation would then be as follows indicating the converter class.</p>
<pre>package somepackage;

<span class="kwrd">public</span> <span class="kwrd">class</span> SomeAgent{

@Parameter(displayName=<span class="str">"Volume"</span>, usageName=<span class="str">"volume"</span>,
  converter=<span class="str">" properties.converter.VolumeConverter"</span>)
<span class="kwrd">public</span> Volume getVolume()
{
<span class="kwrd">return</span> volume;
}
<span class="kwrd">public</span> <span class="kwrd">void</span> setVolume(Volume volume)
{
<span class="kwrd">this</span>.volume=volume;
}
<span class="kwrd">private</span> Volume volume = <span class="kwrd">null</span>;
}</pre>
<p>If Volume is a simulation parameter, then this has to be included in <em>extended_params.XML</em> in the <em>modelname.rs</em> directory.</p>
<pre>&lt;parameters&gt;
&lt;parameter name=<span class="str">"sim_vol"</span>
displayName = <span class="str">"Simulation Volume"</span>
type = <span class="str">"properties.Volume"</span>
converter = <span class="str">"properties.converter.VolumeConverter"</span>
defaultValue = <span class="str">"0 100 500"</span> /&gt;
&lt;/parameters&gt;</pre>
<p>It would be more exciting to probe Volume as a category, with its some or all instance variables as subcategory.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/bellingthetech.wordpress.com/14/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/bellingthetech.wordpress.com/14/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bellingthetech.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bellingthetech.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bellingthetech.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bellingthetech.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bellingthetech.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bellingthetech.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bellingthetech.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bellingthetech.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bellingthetech.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bellingthetech.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bellingthetech.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bellingthetech.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bellingthetech.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bellingthetech.wordpress.com/14/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bellingthetech.wordpress.com&amp;blog=2037991&amp;post=14&amp;subd=bellingthetech&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://bellingthetech.wordpress.com/2008/05/06/probing-objects-repast-s/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a0ba2c7d11c8f06702ad5ccf7d76a84a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">S.K.</media:title>
		</media:content>
	</item>
		<item>
		<title>Coding a RePast S model (Non-Groovy way)</title>
		<link>http://bellingthetech.wordpress.com/2008/05/06/coding-a-repast-s-model-non-groovy-way/</link>
		<comments>http://bellingthetech.wordpress.com/2008/05/06/coding-a-repast-s-model-non-groovy-way/#comments</comments>
		<pubDate>Tue, 06 May 2008 13:23:07 +0000</pubDate>
		<dc:creator>Shefali k.</dc:creator>
				<category><![CDATA[Agent-Based Systems]]></category>
		<category><![CDATA[RePast S]]></category>

		<guid isPermaLink="false">http://bellingthetech.wordpress.com/2008/05/06/coding-a-repast-s-model-non-groovy-way/</guid>
		<description><![CDATA[Before I write about how to write a RePast S model from scratch, the non-groovy way, let me write something that will lead to the details. Any model needs to know what is has &#8211; model descriptor, and how it is &#8211; scenario descriptor. Model descriptors consists of agent definition &#8211; java classes, networks, space, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bellingthetech.wordpress.com&amp;blog=2037991&amp;post=12&amp;subd=bellingthetech&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p align="justify">Before I write about how to write a RePast S model from scratch, the non-groovy way, let me write something that will lead to the details. Any model needs to know what is has &#8211; model descriptor, and how it is &#8211; scenario descriptor.</p>
<p><span id="more-12"></span></p>
<p align="justify">Model descriptors consists of agent definition &#8211; java classes, networks, space, grids etc., relation ships between them, watching and watcher triggers, schedule methods etc. Scenario descriptors tell you what the model has. It would say that the grid from the model descriptor is 2D or 3D. It would also tell you from where the agents are loaded &#8211; from the scenario loader or some class context loader. It also has charts etc i.e logging information for the model.</p>
<p align="justify">So what do you basically need to create a RePast S model ?</p>
<p align="justify">1. Define a Model &#8211; the Agents, the relationship between agents (which method to schedule when, which agent keeps an eyes on another etc.)</p>
<p align="justify">2. Define the Context. RePast S has a default context that spares you from writing a Context class but I will write here to illustrate. Define geometry of the model. Add the agents to that geometry. This is essentially the scenario part.</p>
<p align="justify">3. Load the model and run it.</p>
<p>Let us go through each of these steps.</p>
<p><strong><span style="font-size:medium;">1. Defining the model.</span></strong></p>
<p>Assuming familiarity with Eclipse, load the Eclipse and create RePast S project <a href="http://bellingthetech.files.wordpress.com/2008/05/image.png"><img style="border-width:0;" src="http://bellingthetech.files.wordpress.com/2008/05/image-thumb.png?w=244&#038;h=155" border="0" alt="image" width="244" height="155" align="right" /></a>and name it GasNodeModel. Create an Agent GasNodeAgent, GasNodeGrid, GasNetwork. The GasNodeGrid will tell the model where the Agent GasNode is going to reside and The GasNetwork will define the interconnection between these agents. Take a look at the Scenario.xml in the directory where model.score lies.</p>
<p>Let me write the agent GasNodeAgent with parameter Pressure and measuredPressure, much the same from the tutorial.</p>
<pre>package gasnodemodel;

import repast.simphony.engine.schedule.ScheduledMethod;
import repast.simphony.engine.watcher.Watch;
import repast.simphony.engine.watcher.WatcherTriggerSchedule;
import repast.simphony.parameter.Parameter;
import repast.simphony.ui.probe.ProbeID;

<span class="rem">/**</span>
<span class="rem"> * @author shefali</span>
<span class="rem"> *</span>
<span class="rem"> */</span>
<span class="kwrd">public</span> <span class="kwrd">class</span> GasNodeAgent {
  @Parameter (displayName = <span class="str">"Node Pressure"</span>, usageName = <span class="str">"pressure"</span>)
    <span class="kwrd">public</span> <span class="kwrd">double</span> getPressure() {
        <span class="kwrd">return</span> <span class="kwrd">this</span>.pressure;
    }
    <span class="kwrd">public</span> <span class="kwrd">void</span> setPressure(<span class="kwrd">double</span> pressure) {
        <span class="kwrd">this</span>.pressure = pressure;
    }
    <span class="kwrd">private</span> <span class="kwrd">double</span> pressure = 300;
    @Parameter (displayName = <span class="str">"Measured Pressure"</span>, usageName = <span class="str">"measuredPressure"</span>)
    <span class="kwrd">public</span> <span class="kwrd">double</span> getMeasuredPressure() {
        <span class="kwrd">return</span> <span class="kwrd">this</span>.measuredPressure;
    }
    <span class="kwrd">public</span> <span class="kwrd">void</span> setMeasuredPressure(<span class="kwrd">double</span> measuredPressure) {
        <span class="kwrd">this</span>.measuredPressure = measuredPressure;
    }
    <span class="kwrd">private</span> <span class="kwrd">double</span> measuredPressure = 0;
    @Watch(
        watcheeClassName = <span class="str">"gasnodemodel.GasNodeAgent"</span>,
        watcheeFieldNames = <span class="str">"pressure"</span>,
        query = <span class="str">"linked_from"</span>,
        whenToTrigger = WatcherTriggerSchedule.LATER,
        scheduleTriggerDelta = 10d,
        triggerCondition = <span class="str">"$watchee.getPressure()&lt;200"</span>)
     <span class="kwrd">public</span> <span class="kwrd">void</span> changePressure(gasnodemodel.GasNodeAgent watchedNode) {
               setPressure(watchedNode.getPressure());
    }

    @ScheduledMethod(
        start = 1d,
        interval = 1d,
        shuffle = <span class="kwrd">true</span>
    )
    <span class="kwrd">public</span> <span class="kwrd">void</span> measurePressure() {
            <span class="kwrd">double</span> x = 0;
            <span class="kwrd">int</span> num = 0;
            <span class="kwrd">for</span> (<span class="kwrd">int</span> i=0;i&lt;10;i++) {
            x = x+pressure + Math.random();
            num++;
            }
            setMeasuredPressure(x/num);
   }
  @ProbeID()
    <span class="kwrd">public</span> String toString() {
        <span class="kwrd">return</span> <span class="str">"GasNode"</span>;
 }
}</pre>
<p>Run your model. Build Displays. It goes all well! That&#8217;s all you need to make a non-groovy model.</p>
<p>But what if my model agents are fixed ? Yeap, lets create a context. Quite the one in SimpleHappy.</p>
<p><span style="font-size:medium;">2. Define the Context. </span></p>
<p>Let me write a GasNodeContext class.</p>
<pre>package gasnodemodel;

import repast.simphony.context.Context;
import repast.simphony.context.space.graph.NetworkFactoryFinder;
import repast.simphony.context.space.grid.GridFactoryFinder;
import repast.simphony.dataLoader.ContextBuilder;
import repast.simphony.space.grid.StickyBorders;
import repast.simphony.space.graph.Network;
import repast.simphony.space.grid.GridBuilderParameters;
import repast.simphony.space.grid.RandomGridAdder;

<span class="rem">/**</span>
<span class="rem"> * @author shefali</span>
<span class="rem"> */</span>
<span class="kwrd">public</span> <span class="kwrd">class</span> GasNodeContext implements ContextBuilder&lt;GasNodeAgent&gt; {

    <span class="kwrd">private</span> <span class="kwrd">int</span> gasNodes = 3;
    <span class="kwrd">public</span> Context&lt;GasNodeAgent&gt; build(Context&lt;GasNodeAgent&gt; context) {
    Network&lt;GasNodeAgent&gt; network = NetworkFactoryFinder.createNetworkFactory(<span class="kwrd">null</span>).createNetwork(<span class="str">"GasNetwork"</span>, context, <span class="kwrd">true</span>);
    GridFactoryFinder.createGridFactory(<span class="kwrd">null</span>).createGrid(<span class="str">"GasNodeGrid"</span>, context,
                GridBuilderParameters.singleOccupancy2D(<span class="kwrd">new</span> RandomGridAdder&lt;GasNodeAgent&gt;(), <span class="kwrd">new</span> StickyBorders(), 30, 30));
        GasNodeAgent gasnode = <span class="kwrd">new</span> GasNodeAgent();
        context.add(gasnode);
        GasNodeAgent prev = gasnode;
        GasNodeAgent  agent = <span class="kwrd">null</span>;
        <span class="kwrd">for</span> (<span class="kwrd">int</span> i = 0; i &lt; gasNodes - 1; i++) {
            agent = <span class="kwrd">new</span> GasNodeAgent();
            context.add(agent);
            network.addEdge(prev, agent);
            prev = agent;
        }
        network.addEdge(agent, gasnode);
        <span class="kwrd">return</span> context;
    }

    <span class="kwrd">public</span> <span class="kwrd">int</span> getNumNodes() {
        <span class="kwrd">return</span> gasNodes;
    }

    <span class="kwrd">public</span> <span class="kwrd">void</span> setNumNodes(<span class="kwrd">int</span> numNodes) {
        <span class="kwrd">this</span>.gasNodes = numNodes;
    }
}</pre>
<p>Lets run it. It wont work. If you look on the left pane the data loader is Score Context Builder, RePast`s default. It determines where to load data from, from scenario.xml. Let go back to this scenario.xml. It will have an element:</p>
<p><span class="kwrd"><br />
<span style="color:#00ffff;">&lt;</span></span><span style="color:#00ffff;"><span class="html">repast.simphony.dataLoader.engine.ScoreDataLoaderAction</span> context=&#8221;GasNodeModel&#8221; file=&#8221;repast.simphony.dataLoader.engine.ScoreDataLoaderAction_0.xml&#8221; <span class="kwrd">/&gt;</span><br />
</span><br />
You would need to change one last thing to get those &#8216;fixed&#8217; agents in your display. Change the above line to:</p>
<p><em><span style="color:#80ffff;">&lt;repast.simphony.dataLoader.engine.ClassNameDataLoaderAction context=<span class="str">&#8220;GasNodeModel&#8221;</span> file=<span class="str">&#8220;repast.simphony.dataLoader.engine.ClassNameDataLoaderAction_0.xml&#8221;</span> /&gt; </span></em></p>
<p>Create a file named repast.simphony.dataLoader.engine.ClassNameDataLoaderAction_0.xml in gasnodemodel.rs directory and add the line:</p>
<p><em><span style="color:#00ffff;"><span class="kwrd">&lt;</span><span class="html">string</span><span class="kwrd">&gt;</span>gasnodemodel.GasNodeContext<span class="kwrd">&lt;/</span><span class="html">string</span><span class="kwrd">&gt;</span></span></em></p>
<p><a href="http://bellingthetech.files.wordpress.com/2008/05/final.png"><img class="alignright size-medium wp-image-13" style="float:right;" src="http://bellingthetech.files.wordpress.com/2008/05/final.png?w=300&#038;h=187" alt="" width="300" height="187" /></a>That&#8217;s to it.</p>
<p>The RePast S runtime system needs to know from where to load agents, and in what to load agents. That&#8217;s what scenario.xml tells the model.</p>
<p>Happy creating POJO Agents !!</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/bellingthetech.wordpress.com/12/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/bellingthetech.wordpress.com/12/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bellingthetech.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bellingthetech.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bellingthetech.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bellingthetech.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bellingthetech.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bellingthetech.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bellingthetech.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bellingthetech.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bellingthetech.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bellingthetech.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bellingthetech.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bellingthetech.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bellingthetech.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bellingthetech.wordpress.com/12/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bellingthetech.wordpress.com&amp;blog=2037991&amp;post=12&amp;subd=bellingthetech&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://bellingthetech.wordpress.com/2008/05/06/coding-a-repast-s-model-non-groovy-way/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a0ba2c7d11c8f06702ad5ccf7d76a84a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">S.K.</media:title>
		</media:content>

		<media:content url="http://bellingthetech.files.wordpress.com/2008/05/image-thumb.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://bellingthetech.files.wordpress.com/2008/05/final.png?w=300" medium="image" />
	</item>
		<item>
		<title>Sequential Arithmetic Expression Evaluation</title>
		<link>http://bellingthetech.wordpress.com/2008/03/11/sequential-arithmetic-expression-evaluation/</link>
		<comments>http://bellingthetech.wordpress.com/2008/03/11/sequential-arithmetic-expression-evaluation/#comments</comments>
		<pubDate>Wed, 12 Mar 2008 00:35:07 +0000</pubDate>
		<dc:creator>Shefali k.</dc:creator>
				<category><![CDATA[Graphs]]></category>
		<category><![CDATA[Sequential]]></category>
		<category><![CDATA[Tree]]></category>

		<guid isPermaLink="false">http://bellingthetech.wordpress.com/2008/03/11/sequential-arithmetic-expression-evaluation/</guid>
		<description><![CDATA[Expression evaluation is probably the most common text book example, and a popular application of those tree walks. Recently, while writing a parallel version for the same I had to quickly jot down a sequential version using stack and post order walk. The tree is implemented as an array that has its index, and index [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bellingthetech.wordpress.com&amp;blog=2037991&amp;post=9&amp;subd=bellingthetech&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p align="justify">Expression evaluation is probably the most common text book example, and a popular application of those tree walks. Recently, while writing a parallel version for the same I had to quickly jot down a sequential version using stack and post order walk. The tree is implemented as an array that has its index, and index of left and right children. The reason to use it as an array is to facilitate parallel version for the same using multi-threading. Here is the code for the sequential version.</p>
<p><span id="more-9"></span></p>
<pre><span class="kwrd"></span><b>void</b> <font color="#2040a0">postorder</font><font color="#4444ff">(</font><font color="#2040a0">INFO</font> <font color="#2040a0">curr_index</font><font color="#4444ff">)</font>
<font color="#4444ff"><b>{</b></font>
<b>if</b><font color="#4444ff">(</font><font color="#2040a0">curr_index</font><font color="#4444ff">!</font><font color="#4444ff">=</font><font color="#4444ff">-</font><font color="#ff0000">1</font><font color="#4444ff">)</font>
<font color="#4444ff"><b>{</b></font>
  <font color="#2040a0">postorder</font><font color="#4444ff">(</font><font color="#2040a0">exp</font><font color="#4444ff">[</font><font color="#2040a0">curr_index</font><font color="#4444ff">]</font>.<font color="#2040a0">left</font><font color="#4444ff">)</font><font color="#4444ff">;</font>
  <font color="#2040a0">postorder</font><font color="#4444ff">(</font><font color="#2040a0">exp</font><font color="#4444ff">[</font><font color="#2040a0">curr_index</font><font color="#4444ff">]</font>.<font color="#2040a0">right</font><font color="#4444ff">)</font><font color="#4444ff">;</font>
  <b>if</b><font color="#4444ff">(</font><font color="#2040a0">exp</font><font color="#4444ff">[</font><font color="#2040a0">curr_index</font><font color="#4444ff">]</font>.<font color="#2040a0">op</font><font color="#4444ff">=</font><font color="#4444ff">=</font><font color="#2040a0">NIL</font><font color="#4444ff">)</font>
    <font color="#2040a0">s</font>.<font color="#2040a0">item</font><font color="#4444ff">[</font><font color="#4444ff">+</font><font color="#4444ff">+</font><font color="#2040a0">s</font>.<font color="#2040a0">top</font><font color="#4444ff">]</font><font color="#4444ff">=</font><font color="#2040a0">exp</font><font color="#4444ff">[</font><font color="#2040a0">curr_index</font><font color="#4444ff">]</font>.<font color="#2040a0">c</font><font color="#4444ff">;</font>
  <b>else</b><font color="#4444ff"><b>{</b></font>
       <b>switch</b><font color="#4444ff">(</font><font color="#2040a0">exp</font><font color="#4444ff">[</font><font color="#2040a0">curr_index</font><font color="#4444ff">]</font>.<font color="#2040a0">op</font><font color="#4444ff">)</font>
       <font color="#4444ff"><b>{</b></font>
 	<b>case</b> <font color="#2040a0">ADD</font><font color="#4444ff">:</font>
         <font color="#2040a0">result</font> <font color="#4444ff">=</font> <font color="#2040a0">s</font>.<font color="#2040a0">item</font><font color="#4444ff">[</font><font color="#2040a0">s</font>.<font color="#2040a0">top</font><font color="#4444ff">-</font><font color="#4444ff">-</font><font color="#4444ff">]</font> <font color="#4444ff">+</font> <font color="#2040a0">s</font>.<font color="#2040a0">item</font><font color="#4444ff">[</font><font color="#2040a0">s</font>.<font color="#2040a0">top</font><font color="#4444ff">-</font><font color="#4444ff">-</font><font color="#4444ff">]</font><font color="#4444ff">;</font>
         <font color="#2040a0">s</font>.<font color="#2040a0">item</font><font color="#4444ff">[</font><font color="#4444ff">+</font><font color="#4444ff">+</font><font color="#2040a0">s</font>.<font color="#2040a0">top</font><font color="#4444ff">]</font> <font color="#4444ff">=</font> <font color="#2040a0">result</font><font color="#4444ff">;</font>
         <b>break</b><font color="#4444ff">;</font>
        <b>case</b> <font color="#2040a0">SUB</font><font color="#4444ff">:</font>
         <font color="#2040a0">result</font> <font color="#4444ff">=</font> <font color="#4444ff">-</font> <font color="#2040a0">s</font>.<font color="#2040a0">item</font><font color="#4444ff">[</font><font color="#2040a0">s</font>.<font color="#2040a0">top</font><font color="#4444ff">-</font><font color="#4444ff">-</font><font color="#4444ff">]</font> <font color="#4444ff">+</font> <font color="#2040a0">s</font>.<font color="#2040a0">item</font><font color="#4444ff">[</font><font color="#2040a0">s</font>.<font color="#2040a0">top</font><font color="#4444ff">-</font><font color="#4444ff">-</font><font color="#4444ff">]</font><font color="#4444ff">;</font>
	 <font color="#2040a0">s</font>.<font color="#2040a0">item</font><font color="#4444ff">[</font><font color="#4444ff">+</font><font color="#4444ff">+</font><font color="#2040a0">s</font>.<font color="#2040a0">top</font><font color="#4444ff">]</font> <font color="#4444ff">=</font> <font color="#2040a0">result</font><font color="#4444ff">;</font>
         <b>break</b><font color="#4444ff">;</font>
        <b>case</b> <font color="#2040a0">MULT</font><font color="#4444ff">:</font>
         <font color="#2040a0">result</font> <font color="#4444ff">=</font> <font color="#2040a0">s</font>.<font color="#2040a0">item</font><font color="#4444ff">[</font><font color="#2040a0">s</font>.<font color="#2040a0">top</font><font color="#4444ff">-</font><font color="#4444ff">-</font><font color="#4444ff">]</font> <font color="#4444ff">*</font> <font color="#2040a0">s</font>.<font color="#2040a0">item</font><font color="#4444ff">[</font><font color="#2040a0">s</font>.<font color="#2040a0">top</font><font color="#4444ff">-</font><font color="#4444ff">-</font><font color="#4444ff">]</font><font color="#4444ff">;</font>
         <font color="#2040a0">s</font>.<font color="#2040a0">item</font><font color="#4444ff">[</font><font color="#4444ff">+</font><font color="#4444ff">+</font><font color="#2040a0">s</font>.<font color="#2040a0">top</font><font color="#4444ff">]</font> <font color="#4444ff">=</font> <font color="#2040a0">result</font><font color="#4444ff">;</font>
         <b>break</b><font color="#4444ff">;</font>
       <font color="#4444ff"><b>}</b></font><font color="#444444">/*switch*/</font> <font color="#444444">
      }/*else*/</font>
<font color="#4444ff"><b> }</b></font><font color="#444444">/*if*/</font>
<font color="#4444ff"><b>}</b></font><font color="#444444">/*postorder*/</font></pre>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/bellingthetech.wordpress.com/9/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/bellingthetech.wordpress.com/9/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bellingthetech.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bellingthetech.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bellingthetech.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bellingthetech.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bellingthetech.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bellingthetech.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bellingthetech.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bellingthetech.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bellingthetech.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bellingthetech.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bellingthetech.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bellingthetech.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bellingthetech.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bellingthetech.wordpress.com/9/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bellingthetech.wordpress.com&amp;blog=2037991&amp;post=9&amp;subd=bellingthetech&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://bellingthetech.wordpress.com/2008/03/11/sequential-arithmetic-expression-evaluation/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a0ba2c7d11c8f06702ad5ccf7d76a84a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">S.K.</media:title>
		</media:content>
	</item>
		<item>
		<title>OpenMP and MPI</title>
		<link>http://bellingthetech.wordpress.com/2008/01/25/openmp-and-mpi/</link>
		<comments>http://bellingthetech.wordpress.com/2008/01/25/openmp-and-mpi/#comments</comments>
		<pubDate>Fri, 25 Jan 2008 17:01:06 +0000</pubDate>
		<dc:creator>Shefali k.</dc:creator>
				<category><![CDATA[MPI]]></category>
		<category><![CDATA[OpenMP]]></category>
		<category><![CDATA[Parallel Computing]]></category>

		<guid isPermaLink="false">http://bellingthetech.wordpress.com/2008/01/25/openmp-and-mpi/</guid>
		<description><![CDATA[Parallel computing is use of multiple resources to solve a computational problem. The prime reason for using parallel computing is the need for speed. Dividing a problem and then distributing it on different processors definitely gives a boost towards solution. The motivation to use parallel computing is to reduce wall clock time and to make [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bellingthetech.wordpress.com&amp;blog=2037991&amp;post=7&amp;subd=bellingthetech&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Parallel computing is use of multiple resources to solve a computational problem. The prime reason for using parallel computing is the need for speed. Dividing a problem and then distributing it on different processors definitely gives a boost towards solution. The motivation to use parallel computing is to reduce wall clock time and to make solutions to large problems available in feasible time. Making efficient use of local and remote processors, overcoming memory considerations, concurrency are additional reasons for &quot;why parallel&quot;. </p>
<p><span id="more-7"></span></p>
<p>Of various parallel Programming model, the ones of particular interest in this post are: Thread Model and Message Passing Model.</p>
<p><strong>Thread Model</strong></p>
<ul>
<li>A single process has&#160; multiple execution paths.</li>
<li>Associated with shared memory architectures.</li>
<li>POSIX threads and OpenMP are implementation of threads.</li>
<p>&#160;</p>
<p>Talking about OpenMP &#8211; Open specifications for Multi Processing</p>
<p align="justify">It is based on existence of multiple threads in shared memory architecture. Single process consists of multiple threads. The Programming model is explicit and hence programmer has full control over the parallelism. It is an API to implement multi-threading, shared memory parallelism. Data sharing is implicit due to shared memory architecture. It follows a dynamic parallelism, meaning new threads can be spawned dynamically.</p>
</ul>
<p><strong>Message Passing Model &#8211; MPI &#8211; Message Passing Interface</strong></p>
<ul>
<li>MPI is specification targeted towards distributed memory architectures. </li>
<li>It consists of set of processes having their own memory space. </li>
<li>Communication is explicit and is done by sending messages using send and receive. </li>
<li>Programming model is explicit and programmer has to identify parallelism. </li>
<li>It does not have dynamic parallelism, i.e the number of processes created is static and new ones cannot be created at runtime.</li>
</ul>
<p><a href="http://www.sharcnet.ca/~jemmyhu/tutorials/mpi+smp.swf">Illustration</a> demonstrating the difference.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/bellingthetech.wordpress.com/7/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/bellingthetech.wordpress.com/7/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bellingthetech.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bellingthetech.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bellingthetech.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bellingthetech.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bellingthetech.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bellingthetech.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bellingthetech.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bellingthetech.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bellingthetech.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bellingthetech.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bellingthetech.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bellingthetech.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bellingthetech.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bellingthetech.wordpress.com/7/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bellingthetech.wordpress.com&amp;blog=2037991&amp;post=7&amp;subd=bellingthetech&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://bellingthetech.wordpress.com/2008/01/25/openmp-and-mpi/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a0ba2c7d11c8f06702ad5ccf7d76a84a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">S.K.</media:title>
		</media:content>
	</item>
	</channel>
</rss>
