<?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>Lokah Samastha Sughino Bhavantu</title>
	<atom:link href="http://sureshamrita.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://sureshamrita.wordpress.com</link>
	<description>A blog for research students</description>
	<lastBuildDate>Mon, 26 Sep 2011 20:09:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='sureshamrita.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Lokah Samastha Sughino Bhavantu</title>
		<link>http://sureshamrita.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://sureshamrita.wordpress.com/osd.xml" title="Lokah Samastha Sughino Bhavantu" />
	<atom:link rel='hub' href='http://sureshamrita.wordpress.com/?pushpress=hub'/>
		<item>
		<title>2D array from boost::multi_array</title>
		<link>http://sureshamrita.wordpress.com/2011/09/26/2d-array-from-boostmulti_array/</link>
		<comments>http://sureshamrita.wordpress.com/2011/09/26/2d-array-from-boostmulti_array/#comments</comments>
		<pubDate>Mon, 26 Sep 2011 20:09:39 +0000</pubDate>
		<dc:creator>sureshamrita</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[2d array]]></category>
		<category><![CDATA[boost]]></category>
		<category><![CDATA[multi_array]]></category>

		<guid isPermaLink="false">http://sureshamrita.wordpress.com/?p=526</guid>
		<description><![CDATA[The following gives the code for a 2D array based on boost::multi_array. The code supports retrieval of arbitrary rows and columns. The code uses some features of C++ 11x. So use the appropriate compiler flag to compile the code. Application Code: The array class definition is given below:<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sureshamrita.wordpress.com&amp;blog=5849255&amp;post=526&amp;subd=sureshamrita&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The following gives the code for a 2D array based on boost::multi_array. The code supports retrieval of arbitrary rows and columns. The code uses some features of C++ 11x. So use the appropriate compiler flag to compile the code.</p>
<p>Application Code:</p>
<pre class="brush: cpp;">
#include &quot;array2d.h&quot;
#include &lt;vector&gt;
#include &lt;iterator&gt;
#include &lt;iostream&gt;
using namespace std;

int main(){
	//defining the array
        Array2d&lt;int&gt; array(2,5);
        //populating it
	Array2d&lt;int&gt;::element * itr = array.data();
	for(int i = 0; i &lt; 10; i++){
		*itr++ = i;
	}

        //getting an arbitrary row
	vector&lt;int&gt;r;
	array.row&lt;1&gt;(back_inserter(r));
	copy(r.begin(),r.end(),ostream_iterator&lt;int&gt;(cout,&quot; &quot;));

	cout &lt;&lt; endl;

        //getting an arbitrary column
	vector&lt;int&gt;c;
	array.col&lt;2&gt;(back_inserter(c));

	copy(c.begin(),c.end(),ostream_iterator&lt;int&gt;(cout,&quot; &quot;));
	return 0;
}
</pre>
<p>The array class definition is given below:</p>
<pre class="brush: cpp;">

#ifndef ARRAY_H_
#define ARRAY_H_

#include &lt;boost/multi_array.hpp&gt;
#include &lt;algorithm&gt;
#include &lt;iostream&gt;
#include &quot;mystrcat.h&quot;
#include &lt;stdexcept&gt;

using namespace std;

template &lt;class T&gt;
class Array2d{
public:
	typedef typename boost::multi_array&lt;T,2&gt; array_type;
	typedef typename array_type::element element;
	typedef boost::multi_array_types::index_range range;

	Array2d(uint rows, uint cols);
	element * data();

	void display();

	template&lt;int c, class Itr&gt;
	void col(Itr itr); //dumps the cth column to the container pointed to by itr

	template&lt;int r, class Itr&gt;
	void row(Itr itr); //dumps the rth row to the container pointed to by itr

private:
	array_type array;

	uint rows;
	uint cols;
};

template &lt;class T&gt;
Array2d&lt;T&gt;::Array2d(uint _rows, uint _cols):rows(_rows),cols(_cols){
	array.resize(boost::extents[rows][cols]);
}

template &lt;class T&gt;
typename Array2d&lt;T&gt;::element* Array2d&lt; T &gt;::data(){
	return array.data();
}

template&lt;class T&gt;
template&lt;int c, class Itr&gt;
void Array2d&lt;T&gt;::col(Itr itr) {
	//copies column c to the given container

	if (c &lt; 0 || c &gt;= cols) throw runtime_error(Mystrcat(&quot;Only&quot;, cols, &quot;columns available and you asked for column&quot;,c));
	typename array_type::template array_view&lt;1&gt;::type myview =
			array[boost::indices[range()][c]];
	std::copy(myview.begin(), myview.end(), itr);
}
template&lt;class T&gt;
template&lt;int r, class Itr&gt;
void Array2d&lt;T&gt;::row(Itr itr) {
	//copies row r to the given container
	if (r &lt; 0 || r &gt;= rows) throw runtime_error(Mystrcat(&quot;Only&quot;, rows, &quot;rows available and you asked for row&quot;,r));
	typename array_type::template array_view&lt;1&gt;::type myview =
			array[boost::indices[r][range()]];
	std::copy(myview.begin(), myview.end(), itr);
}

template &lt;class T&gt;
void Array2d&lt;T&gt;::display(){
	for (auto i = array.data(); i &lt; array.data()+array.num_elements(); i++)
		cout &lt;&lt; *i &lt;&lt; endl;
}

#endif /* 2DARRAY_H_ */
</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sureshamrita.wordpress.com/526/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sureshamrita.wordpress.com/526/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sureshamrita.wordpress.com/526/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sureshamrita.wordpress.com/526/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sureshamrita.wordpress.com/526/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sureshamrita.wordpress.com/526/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sureshamrita.wordpress.com/526/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sureshamrita.wordpress.com/526/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sureshamrita.wordpress.com/526/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sureshamrita.wordpress.com/526/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sureshamrita.wordpress.com/526/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sureshamrita.wordpress.com/526/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sureshamrita.wordpress.com/526/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sureshamrita.wordpress.com/526/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sureshamrita.wordpress.com&amp;blog=5849255&amp;post=526&amp;subd=sureshamrita&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sureshamrita.wordpress.com/2011/09/26/2d-array-from-boostmulti_array/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/bc57c719b5ac41697a435424d87ecb65?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sureshamrita</media:title>
		</media:content>
	</item>
		<item>
		<title>Current day and time using Boost</title>
		<link>http://sureshamrita.wordpress.com/2011/08/30/current-day-and-time-using-boost/</link>
		<comments>http://sureshamrita.wordpress.com/2011/08/30/current-day-and-time-using-boost/#comments</comments>
		<pubDate>Tue, 30 Aug 2011 22:13:52 +0000</pubDate>
		<dc:creator>sureshamrita</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[boost]]></category>
		<category><![CDATA[day]]></category>
		<category><![CDATA[time]]></category>

		<guid isPermaLink="false">http://sureshamrita.wordpress.com/?p=520</guid>
		<description><![CDATA[Tested with Boost version 1.41<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sureshamrita.wordpress.com&amp;blog=5849255&amp;post=520&amp;subd=sureshamrita&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<pre class="brush: cpp;">
#include &lt;iostream&gt;
#include &quot;boost/date_time/local_time/local_time.hpp&quot;
using namespace std;

int main(){
  boost::posix_time::ptime now = boost::posix_time::second_clock::local_time();
  cout &lt;&lt; now &lt;&lt; endl;
}
</pre>
<p>Tested with Boost version 1.41</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sureshamrita.wordpress.com/520/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sureshamrita.wordpress.com/520/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sureshamrita.wordpress.com/520/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sureshamrita.wordpress.com/520/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sureshamrita.wordpress.com/520/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sureshamrita.wordpress.com/520/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sureshamrita.wordpress.com/520/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sureshamrita.wordpress.com/520/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sureshamrita.wordpress.com/520/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sureshamrita.wordpress.com/520/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sureshamrita.wordpress.com/520/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sureshamrita.wordpress.com/520/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sureshamrita.wordpress.com/520/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sureshamrita.wordpress.com/520/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sureshamrita.wordpress.com&amp;blog=5849255&amp;post=520&amp;subd=sureshamrita&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sureshamrita.wordpress.com/2011/08/30/current-day-and-time-using-boost/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/bc57c719b5ac41697a435424d87ecb65?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sureshamrita</media:title>
		</media:content>
	</item>
		<item>
		<title>Extending the python configparser</title>
		<link>http://sureshamrita.wordpress.com/2011/08/28/extending-python-configparser/</link>
		<comments>http://sureshamrita.wordpress.com/2011/08/28/extending-python-configparser/#comments</comments>
		<pubDate>Sun, 28 Aug 2011 06:43:07 +0000</pubDate>
		<dc:creator>sureshamrita</dc:creator>
				<category><![CDATA[python]]></category>
		<category><![CDATA[configparser]]></category>

		<guid isPermaLink="false">http://sureshamrita.wordpress.com/?p=514</guid>
		<description><![CDATA[The existing configparser module of python, does not provide the following operations. If you are reading a directory/file name from a config file, it does not check if the directory/file exist It does not even check if the config file itself is existing or not in its read() method. It does not provide any specific methods [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sureshamrita.wordpress.com&amp;blog=5849255&amp;post=514&amp;subd=sureshamrita&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The existing <a href="http://docs.python.org/release/3.1.4/library/configparser.html?highlight=configparser#module-configparser" target="_blank">configparser module</a> of python, does not provide the following operations.</p>
<ul>
<li>If you are reading a directory/file name from a config file, it does not check if the directory/file exist</li>
<li>It does not even check if the config file itself is existing or not in its read() method.</li>
<li>It does not provide any specific methods to read and process multiple valued options, say comma separated. In such a situation the user would like to get the items as a list after removing the leading and trailing white space etc.</li>
</ul>
<div>My guess is that such refined processing is left to the user of the <a href="http://docs.python.org/release/3.1.4/library/configparser.html?highlight=configparser#module-configparser" target="_blank">configparser module</a>. The following code defines a new class <code>AmritaConfigParser</code> which is derived from the <code>SafeConfigParser</code> class which is defined in the <a href="http://docs.python.org/release/3.1.4/library/configparser.html?highlight=configparser#module-configparser" target="_blank">configparser module</a>. The <code>AmritaConfigParser</code> class redefines/adds the following methods to remedy the above mentioned shortcomings.</div>
<div>
<ol>
<li><code>read()</code>: It checks if the file is present and if it is present calls the base class read(). If the file is not present, raises an exception.</li>
<li><code>getFile(section,option,check = True,dir='False')</code> : Reads a dir or file name. If the<code> check</code> option is <code>True</code>, the existence of the read file is checked and an exception raised if it does not exist. If the <code>dir</code> option is made true, the read value is appended with <code>'/'</code> if it does not exist already. For windows the character appended would be <code>'\'</code>.</li>
<li><code>getFileList(self,section,option,sep = ',' , check = True)</code>: It is same as <code>getFile()</code> method but separates the string at the sep character and removes the leading/trailing space and returns the list. Had python permitted function overloading, these two methods could have been made into one. Or is there any other tricks to combine these two methods into one?</li>
</ol>
<div>The code is given below:</div>
<pre class="brush: python;">
#!/usr/bin/python3.1
from configparser import  SafeConfigParser
import os

class AmritaConfigParser(SafeConfigParser):
    def __init__(self):
        super().__init__()

    def read(self,file):
        if not os.path.exists(file):
            raise OSError(file + ' does not exist')
        return super().read(file)

    def getFile(self,section,option,check = True,dir='False'):
        &quot;&quot;&quot;gets the filename, checks if it is present (if check
        boolean is True)  or else gives an error
        message, and appends a / at the end if it does not exist already
        in case the retrieved file is a directory &quot;&quot;&quot;

        file = super().get(section,option)
        if check:
            if not os.path.exists(file):
                raise OSError(file + ' does not exist')

        if dir:
            if not file.endswith(os.sep):
                file = file + os.sep

        return file

    def getFileList(self,section,option,sep = ',',check = True):
        &quot;&quot;&quot;reads a string which contain 'sep' separated files.
        removes the trailing space between them
        checks for their presence if the check bool variable is True
        Finally returns a list &quot;&quot;&quot;
        fileList = super().get(section,option)
        if fileList:
            fileList = fileList.split(',')
            fileList = [x.strip() for x in fileList]

            if check:
                for f in fileList:
                    if not os.path.exists(f):
                        raise IOError(f + ': File cannot be openend')
        return fileList
</pre>
</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sureshamrita.wordpress.com/514/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sureshamrita.wordpress.com/514/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sureshamrita.wordpress.com/514/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sureshamrita.wordpress.com/514/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sureshamrita.wordpress.com/514/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sureshamrita.wordpress.com/514/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sureshamrita.wordpress.com/514/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sureshamrita.wordpress.com/514/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sureshamrita.wordpress.com/514/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sureshamrita.wordpress.com/514/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sureshamrita.wordpress.com/514/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sureshamrita.wordpress.com/514/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sureshamrita.wordpress.com/514/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sureshamrita.wordpress.com/514/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sureshamrita.wordpress.com&amp;blog=5849255&amp;post=514&amp;subd=sureshamrita&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sureshamrita.wordpress.com/2011/08/28/extending-python-configparser/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/bc57c719b5ac41697a435424d87ecb65?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sureshamrita</media:title>
		</media:content>
	</item>
		<item>
		<title>random_shuffle with Boost generator</title>
		<link>http://sureshamrita.wordpress.com/2011/08/27/random_shuffle-boost-generator/</link>
		<comments>http://sureshamrita.wordpress.com/2011/08/27/random_shuffle-boost-generator/#comments</comments>
		<pubDate>Sat, 27 Aug 2011 04:56:03 +0000</pubDate>
		<dc:creator>sureshamrita</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[boost]]></category>
		<category><![CDATA[generator]]></category>
		<category><![CDATA[random number]]></category>
		<category><![CDATA[random_shuffle]]></category>

		<guid isPermaLink="false">http://sureshamrita.wordpress.com/?p=503</guid>
		<description><![CDATA[The C++ algorithm random_shuffle accepts a random number generator as the third argument. One advantage of using your own random number generator is that  you can seed it the way you want. The following code segment demonstrates how it can be done with boost random number generator. The function currentTimeNS() gives the current time in [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sureshamrita.wordpress.com&amp;blog=5849255&amp;post=503&amp;subd=sureshamrita&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The C++ algorithm <code>random_shuffle</code> accepts a random number generator as the third argument. One advantage of using your own random number generator is that  you can seed it the way you want. The following code segment demonstrates how it can be done with boost random number generator.</p>
<pre class="brush: cpp;">
#include &lt;boost/random/mersenne_twister.hpp&gt;
#include &lt;boost/random/uniform_int.hpp&gt;
#include &lt;boost/random/variate_generator.hpp&gt;

boost::mt19937 generator(currentTimeNS());
boost::uniform_int&lt;&gt; uni_dist;
boost::variate_generator&lt;boost::mt19937&amp;, boost::uniform_int&lt;&gt; &gt; randomNumber(generator, uni_dist);

vector&lt;int&gt; v = {1,2,3,4,5,6,7,8,9,10};
random_shuffle(v.begin(), v.end(),randomNumber);
</pre>
<p>The function <code>currentTimeNS()</code> gives the current time in nanoseconds which is used as a seed. For an implementation of  <code>currentTimeNS()</code> function see <a href="http://sureshamrita.wordpress.com/2010/08/19/current-time-in-nano-seconds/" target="_blank">this</a> link.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sureshamrita.wordpress.com/503/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sureshamrita.wordpress.com/503/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sureshamrita.wordpress.com/503/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sureshamrita.wordpress.com/503/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sureshamrita.wordpress.com/503/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sureshamrita.wordpress.com/503/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sureshamrita.wordpress.com/503/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sureshamrita.wordpress.com/503/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sureshamrita.wordpress.com/503/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sureshamrita.wordpress.com/503/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sureshamrita.wordpress.com/503/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sureshamrita.wordpress.com/503/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sureshamrita.wordpress.com/503/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sureshamrita.wordpress.com/503/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sureshamrita.wordpress.com&amp;blog=5849255&amp;post=503&amp;subd=sureshamrita&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sureshamrita.wordpress.com/2011/08/27/random_shuffle-boost-generator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/bc57c719b5ac41697a435424d87ecb65?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sureshamrita</media:title>
		</media:content>
	</item>
		<item>
		<title>A C++ implementation of k-fold cross validation</title>
		<link>http://sureshamrita.wordpress.com/2011/08/24/c-implementation-of-k-fold-cross-validation/</link>
		<comments>http://sureshamrita.wordpress.com/2011/08/24/c-implementation-of-k-fold-cross-validation/#comments</comments>
		<pubDate>Wed, 24 Aug 2011 22:24:04 +0000</pubDate>
		<dc:creator>sureshamrita</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[cross validation]]></category>
		<category><![CDATA[kfold]]></category>

		<guid isPermaLink="false">http://sureshamrita.wordpress.com/?p=486</guid>
		<description><![CDATA[In K-fold cross validation, the given data is randomly divided into k disjoint sets of equal size n/k, where n is the total number of patters present in the given data. The classifier is trained k times, each time with a different set held out as a validation set. The estimated performance is the mean [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sureshamrita.wordpress.com&amp;blog=5849255&amp;post=486&amp;subd=sureshamrita&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In K-fold cross validation, the given data is randomly divided into k disjoint sets of equal size n/k, where n is the total number of patters present in the given data. The classifier is trained k times, each time with a different set held out as a validation set. The estimated performance is the mean of these k errors. (Taken from Duda, Hart, and Stork &#8211; Pattern Classification, 2006, page 483.</p>
<p>The given code implements a k-fold cross validation with the following features.</p>
<ul>
<li>The code is independent of the container in which the given data is stored.</li>
<li>The code just expects an iterator pointing to the beginning of the container and one pointing to the end (to be precise, one past the end) of the container.</li>
<li>The partitioned data can be stored in any container.</li>
<li>The code expects only an output iterator pointing to the destination containers (one for training data and the other for testing data)</li>
</ul>
<p>The header file &#8220;mystrcat.h&#8221; included in the following code is described <a href="http://sureshamrita.wordpress.com/2011/08/24/concatenating-arbitrary-number-types-of-arguments-into-a-string/" target="_blank">here</a></p>
<pre class="brush: cpp;">
#ifndef _kfoldh_
#define _kfoldh_
#include &lt;vector&gt;
#include &quot;/home/suresh/C++/myCodes/mystrcat.h&quot;
#include &lt;stdexcept&gt;
#include &lt;algorithm&gt;
#include &lt;iterator&gt;
#include &lt;boost/foreach.hpp&gt;

using namespace std;

#define foreach BOOST_FOREACH

template&lt;class In&gt;
class Kfold {
public:
	Kfold(int k, In _beg, In _end);
	template&lt;class Out&gt;
	void getFold(int foldNo, Out training, Out testing);

private:
	In beg;
	In end;
	int K; //how many folds in this
	vector&lt;int&gt; whichFoldToGo;

};

template&lt;class In&gt;
Kfold&lt;In&gt;::Kfold(int _k, In _beg, In _end) :
		beg(_beg), end(_end), K(_k) {
	if (K &lt;= 0)
		throw runtime_error(Mystrcat(&quot;The supplied value of K is =&quot;, K,&quot;. One cannot create &quot;,k, &quot;no of folds&quot;));

	//create the vector of integers
	int foldNo = 0;
	for (In i = beg; i != end; i++) {
		whichFoldToGo.push_back(++foldNo);
		if (foldNo == K)
			foldNo = 0;
	}
	if (!K)
		throw runtime_error(Mystrcat(&quot;With this value of k (=&quot;, k ,&quot;)Equal division of the data is not possible&quot;));
	random_shuffle(whichFoldToGo.begin(), whichFoldToGo.end());
}

template&lt;class In&gt;
template&lt;class Out&gt;
void Kfold&lt;In&gt;::getFold(int foldNo, Out training, Out testing) {

	int k = 0;
	In i = beg;
	while (i != end) {
		if (whichFoldToGo[k++] == foldNo) {
			*testing++ = *i++;
		} else
			*training++ = *i++;
	}
}

#endif
//******************************Application Code
#include &quot;kfold.h&quot;
#include &lt;vector&gt;
using namespace std;

int main() {
	vector&lt;int&gt; v = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

	const int folds = 5;
	Kfold&lt;vector&lt;int&gt;::const_iterator&gt; kf(folds, v.begin(), v.end());

	vector&lt;int&gt; test, train;

	for (int i = 0; i != folds; i++) {
		kf.getFold(i + 1, back_inserter(train), back_inserter(test));
		cout &lt;&lt; &quot;Fold &quot; &lt;&lt; i + 1 &lt;&lt; &quot; Training Data&quot; &lt;&lt; endl;
		foreach(auto x,train)
					cout &lt;&lt; x &lt;&lt; &quot; &quot;;
		cout &lt;&lt; endl;
		cout &lt;&lt; &quot;Fold &quot; &lt;&lt; i + 1 &lt;&lt; &quot; Testing Data&quot; &lt;&lt; endl;
		foreach(auto x,test)
					cout &lt;&lt; x &lt;&lt; &quot; &quot;;
		cout &lt;&lt; endl;

		train.clear();
		test.clear();
	}

	return 0;
}
 </pre>
<p>The code uses the auto keyword from C++ 0x. So please  select the appropriate compiler flag to include C++0x features. In the case of linux, the compiler flag is: <code>-std=c++0x</code></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sureshamrita.wordpress.com/486/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sureshamrita.wordpress.com/486/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sureshamrita.wordpress.com/486/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sureshamrita.wordpress.com/486/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sureshamrita.wordpress.com/486/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sureshamrita.wordpress.com/486/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sureshamrita.wordpress.com/486/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sureshamrita.wordpress.com/486/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sureshamrita.wordpress.com/486/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sureshamrita.wordpress.com/486/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sureshamrita.wordpress.com/486/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sureshamrita.wordpress.com/486/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sureshamrita.wordpress.com/486/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sureshamrita.wordpress.com/486/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sureshamrita.wordpress.com&amp;blog=5849255&amp;post=486&amp;subd=sureshamrita&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sureshamrita.wordpress.com/2011/08/24/c-implementation-of-k-fold-cross-validation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/bc57c719b5ac41697a435424d87ecb65?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sureshamrita</media:title>
		</media:content>
	</item>
		<item>
		<title>Concatenating arbitrary number/types of arguments into a string</title>
		<link>http://sureshamrita.wordpress.com/2011/08/24/concatenating-arbitrary-number-types-of-arguments-into-a-string/</link>
		<comments>http://sureshamrita.wordpress.com/2011/08/24/concatenating-arbitrary-number-types-of-arguments-into-a-string/#comments</comments>
		<pubDate>Wed, 24 Aug 2011 21:50:46 +0000</pubDate>
		<dc:creator>sureshamrita</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[exception]]></category>
		<category><![CDATA[variadic templates]]></category>

		<guid isPermaLink="false">http://sureshamrita.wordpress.com/?p=476</guid>
		<description><![CDATA[When exceptions are thrown from code, to make the received message meaningful, many a time one would like to combine variable values and strings into a const string. For example, if an exception is thrown because an argument is negative, one would like the message thrown to look like,  &#8221;expecting positive arguments, but the current [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sureshamrita.wordpress.com&amp;blog=5849255&amp;post=476&amp;subd=sureshamrita&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>When exceptions are thrown from code, to make the received message meaningful, many a time one would like to combine variable values and strings into a const string. For example, if an exception is thrown because an argument is negative, one would like the message thrown to look like,  &#8221;expecting positive arguments, but the current value of the argument is  10&#8243;.   In order to create such strings, we need a function which can accept arbitrary number of arguments of arbitrary types and then concatenate all of them into a string. The following code does just that.</p>
<pre class="brush: cpp;">
#include &lt;sstream&gt;
#include &lt;iostream&gt;
#include &lt;string&gt;

using namespace std;

class Mystrcat{
public:
  template&lt;typename T, typename ...P&gt;
  explicit Mystrcat(T t, P... p){init(t,p...);}

  operator const string(){return o.str();}

private:
  ostringstream o;
  void init(){}
  template&lt;typename T, typename ...P&gt;
  void init(T t, P... p);
};

template&lt;typename T, typename ...P&gt;
void Mystrcat::init(T t, P ...p){
  o &lt;&lt; t &lt;&lt; ' ';
  init(p...);
}
int main(){
  int x;
  cin &gt;&gt; x;
  if (!x) throw runtime_error(Mystrcat(&quot;The value you entered is&quot;, x, &quot;but non zero value expected&quot;, &quot;error from file:&quot;, __FILE__, &quot;line no:&quot;,__LINE__));
}
</pre>
<div>The above code uses variadic templates, which is a feature of C++0x. Hence to use the above code, one should select the appropriate compiler flag to include C++0x features. In the case linux, the compiler flag is: <code>-std=c++0x</code></div>
<div>To see an implementation of the above without using classes, look at this <a href="https://groups.google.com/forum/#!topic/comp.lang.c++/iljNZaVxn6s" target="_blank">usenet post</a>. A similar implementation is available <a href="http://stackoverflow.com/questions/7116025/variadic-templates-compile-error" target="_blank">here</a>.</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sureshamrita.wordpress.com/476/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sureshamrita.wordpress.com/476/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sureshamrita.wordpress.com/476/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sureshamrita.wordpress.com/476/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sureshamrita.wordpress.com/476/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sureshamrita.wordpress.com/476/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sureshamrita.wordpress.com/476/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sureshamrita.wordpress.com/476/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sureshamrita.wordpress.com/476/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sureshamrita.wordpress.com/476/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sureshamrita.wordpress.com/476/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sureshamrita.wordpress.com/476/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sureshamrita.wordpress.com/476/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sureshamrita.wordpress.com/476/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sureshamrita.wordpress.com&amp;blog=5849255&amp;post=476&amp;subd=sureshamrita&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sureshamrita.wordpress.com/2011/08/24/concatenating-arbitrary-number-types-of-arguments-into-a-string/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/bc57c719b5ac41697a435424d87ecb65?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sureshamrita</media:title>
		</media:content>
	</item>
		<item>
		<title>LaTeX + new fonts = XeLaTeX</title>
		<link>http://sureshamrita.wordpress.com/2011/03/19/latex-new-fonts-xelatex/</link>
		<comments>http://sureshamrita.wordpress.com/2011/03/19/latex-new-fonts-xelatex/#comments</comments>
		<pubDate>Sat, 19 Mar 2011 02:10:07 +0000</pubDate>
		<dc:creator>sureshamrita</dc:creator>
				<category><![CDATA[latex]]></category>
		<category><![CDATA[fontspec]]></category>
		<category><![CDATA[microsoft fonts]]></category>
		<category><![CDATA[texlive]]></category>
		<category><![CDATA[unicode-math]]></category>
		<category><![CDATA[xelatex]]></category>
		<category><![CDATA[xetex]]></category>

		<guid isPermaLink="false">http://sureshamrita.wordpress.com/?p=450</guid>
		<description><![CDATA[I was fascinated when I saw that xelatex can use all the new fonts like Asana Math, Cambria (for text and math), Calibri etc, and I need not learn anything new apart from my existing latex understanding. This blog is the summary of my efforts in installing xelatex and the new fonts and making them [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sureshamrita.wordpress.com&amp;blog=5849255&amp;post=450&amp;subd=sureshamrita&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I was fascinated when I saw that xelatex can use all the new fonts like Asana Math, Cambria (for text and math), Calibri etc, and I need not learn anything new apart from my existing latex understanding. This blog is the summary of my efforts in installing xelatex and the new fonts and making them work on my Ubuntu 10.04 machine!</p>
<p>First of all, for xelatex and the new fonts to work, one should have the latest tex distribution. Unfortunately Ubuntu 10.04 still have only texlive 2009. So the first step would be to acquire texlive 2010 and install it. Once it is done, the rest is trivial. Again installing texlive 2010 is also very easy &#8211; straightforward for at least Ubuntu.</p>
<h2>1 (a). Installing TeXLive 2010 from a CD</h2>
<h3><span style="font-size:13px;font-weight:normal;">One can get an iso image of TeXLive 2010 from the <a href="http://www.tug.org/texlive/" target="_blank">TeXLive Site</a>. Once the iso image is burned into a DVD, you can do the following for installation.</span></h3>
<ul>
<li>You may need the ﻿perl-tk package before you start. You can install this on ubuntu by the command <code>sudo aptitude install perl-tk </code>. I got this information from the blog ﻿﻿<a rel="bookmark" href="http://ubuntuguide.net/how-to-install-texlive-2010-on-ubuntu-10-10">How to install TeXLive 2010 on Ubuntu 10.10</a></li>
<li>Once  you have installed perl-tk, and the DVD ready, you can follow the detailed instructions on the blog <a href="http://sajangyang.blogspot.com/2010/09/ubuntu-1004-and-vanilla-texlive2010.html" target="_blank">How to install Vanilla TexLive 2010 on Ubuntu 10.04</a>.</li>
<li>Make sure to rename your local texmf tree if you have one. I forgot to do this and it created lot of difficulties for me.</li>
</ul>
<h2>1﻿﻿(b) Installing TeXLive 2010 from Internet</h2>
<p>Go to this <a href="http://www.tug.org/texlive/acquire-netinstall.html" target="_blank">site</a>.</p>
<h2>2. Updating TeXLive 2010</h2>
<ul>
<li>First you have change the repository from which <code>tlmgr</code> would do the updates. It is done by the command,</li>
</ul>
<p><span style="font-family:monospace;"> ﻿tlmgr option repository http://mirror.ctan.org/systems/texlive/tlnet</span></p>
<ul>
<li>Now you have to update <code>tlmgr</code> itself, if needed. Run the command <code>﻿tlmgr update --self</code> to update the<code> tlmgr </code>itself.</li>
<li>Once<code> tlmgr</code> is updated, you can run <code>tlmgr update -all</code> to install all updates. Beware, it will take some time, even to start dumping messages on the screen.</li>
</ul>
<h2>3. Where to put microsoft/other fonts in texlive?</h2>
<p>If your platform is windows, you can skip this step and go to section 4. If you are on a Ubuntu machine, you will not have access to the Microsoft fonts in the machine. You need to have the ttf files of the microsoft windows if you want to use them with latex.  Once  you get the font files, this is how you would install them. Getting the font files is described in the next section.</p>
<ul>
<li>TeXlive will have a ﻿﻿<code>texmf-local</code> folder inside your texlive installation. Inside that a <code>fonts</code> directory is present. Whatever ttf files you get hold of, you can create a directory inside the <code>texmf-local/fonts/</code> and store the ttf files. For example I have the following directories there: <code>texlive/texmf-local/fonts/vista, ﻿texlive/texmf-local/fonts/comic, texlive/texmf-local/fonts/Bergamo, texlive/texmf-local/fonts/sorts-mill-goudy, texlive/texmf-local/fonts/sorts-mill-goudy, texlive/texmf-local/fonts/STIXv1.0.0</code> etc.</li>
<li>After installing new fonts, you have to run the command <code>fc-cache -fv</code> from your home directory.</li>
</ul>
<h2>4. How to get the microsoft fonts for use in Ubuntu/LaTeX?</h2>
<p>You may use any of the method described below:</p>
<ul>
<li>Using your flash drive, copy the font files from windows and follow the steps in section 3.</li>
<li>Read <a href="http://www.oooninja.com/2008/01/calibri-linux-vista-fonts-download.html" target="_blank">Install Free Office 2007 Fonts for Linux and XP</a>.</li>
</ul>
<h2>5. You are done! Ready to test the comic font now</h2>
<p>\documentclass[12pt]{article}<br />
\usepackage{fontspec}<br />
\usepackage{amsmath}<br />
\usepackage{unicode-math}<br />
\usepackage{lipsum}<br />
\setromanfont{Comic Sans MS}<br />
\setmathfont{XITS}<br />
\begin{document}<br />
\begin{equation}<br />
x = \frac{-b \pm \sqrt{b^2 &#8211; 4ac}}{2a}<br />
\end{equation}<br />
\lipsum[1]<br />
\end{document}</p>
<p>You can copy the above code from here</p>
<pre class="brush: bash; collapse: true; light: false; toolbar: true;">
\documentclass[12pt]{article}
\usepackage{fontspec}
\usepackage{amsmath}
\usepackage{unicode-math}
\usepackage{lipsum}
\setromanfont{Comic Sans MS}
\setmathfont{XITS}
\begin{document}
\begin{equation}
    x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}
\end{equation}
\lipsum[1]
\end{document}
</pre>
<h3>﻿This is the output on my machine!<a href="http://sureshamrita.files.wordpress.com/2011/03/xelatex.png"><img class="aligncenter size-full wp-image-461" title="xelatex" src="http://sureshamrita.files.wordpress.com/2011/03/xelatex.png?w=482&#038;h=304" alt="" width="482" height="304" /></a></h3>
<h2>6. How to compile the above code?</h2>
<ul>
<li>Save the above file as test.tex</li>
<li>xelatex test.tex</li>
<li>View the pdf file in your favourite pdf viewer!</li>
</ul>
<h2>7. Some Explanations for the LaTeX code</h2>
<ul>
<li><code>﻿\usepackage{fontspec}</code>: Allows  you to put arbitrary fonts using the command <code>\setromanfont{font family name} </code>. For example<code> \setromanfont{Comic Sans MS}</code></li>
<li><code>\usepackage{unicode-math}</code>: Allows you to put arbitrary math font using the command, for example,<code>\setmathfont{XITS}</code></li>
</ul>
<h2>8. How to find the Font Family name?</h2>
<p>In windows, this is easy, but in Ubuntu, you can use the command <code>otfinfo</code>. For example, <code>﻿otfinfo --family STIXVarBol.otf</code> gave me the family name as <code>STIXVariants</code> which I can use in the <code>setromanfont </code>or <code>setmathfont</code> commands.</p>
<h2>9. Acknowledgement</h2>
<p>When I got stuck, many in the comp.text.tex and xetex mailing list helped me. I want to particularly thank, <a href="http://personal.mecheng.adelaide.edu.au/~will/" target="_blank">Will Robertson</a>, who is the author of the fontspec and unicode-math packages.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sureshamrita.wordpress.com/450/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sureshamrita.wordpress.com/450/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sureshamrita.wordpress.com/450/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sureshamrita.wordpress.com/450/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sureshamrita.wordpress.com/450/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sureshamrita.wordpress.com/450/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sureshamrita.wordpress.com/450/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sureshamrita.wordpress.com/450/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sureshamrita.wordpress.com/450/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sureshamrita.wordpress.com/450/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sureshamrita.wordpress.com/450/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sureshamrita.wordpress.com/450/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sureshamrita.wordpress.com/450/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sureshamrita.wordpress.com/450/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sureshamrita.wordpress.com&amp;blog=5849255&amp;post=450&amp;subd=sureshamrita&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sureshamrita.wordpress.com/2011/03/19/latex-new-fonts-xelatex/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/bc57c719b5ac41697a435424d87ecb65?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sureshamrita</media:title>
		</media:content>

		<media:content url="http://sureshamrita.files.wordpress.com/2011/03/xelatex.png" medium="image">
			<media:title type="html">xelatex</media:title>
		</media:content>
	</item>
		<item>
		<title>Reducing page count in a latex document</title>
		<link>http://sureshamrita.wordpress.com/2011/03/14/reducing-page-count-in-a-latex-document/</link>
		<comments>http://sureshamrita.wordpress.com/2011/03/14/reducing-page-count-in-a-latex-document/#comments</comments>
		<pubDate>Mon, 14 Mar 2011 17:30:28 +0000</pubDate>
		<dc:creator>sureshamrita</dc:creator>
				<category><![CDATA[latex]]></category>

		<guid isPermaLink="false">http://sureshamrita.wordpress.com/?p=437</guid>
		<description><![CDATA[Many a time it becomes necessary to reduce the page size of your document. I face this challenge when I submit a paper for a conference where the typical maximum page size is 8. This blog describes some of the techniques that I found useful. A good summary is available on http://www.eng.cam.ac.uk/help/tpl/textprocessing/squeeze.html Images scaling of images: [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sureshamrita.wordpress.com&amp;blog=5849255&amp;post=437&amp;subd=sureshamrita&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Many a time it becomes necessary to reduce the page size of your document. I face this challenge when I submit a paper for a conference where the typical maximum page size is 8. This blog describes some of the techniques that I found useful. A good summary is available on <a href="http://www.eng.cam.ac.uk/help/tpl/textprocessing/squeeze.html">http://www.eng.cam.ac.uk/help/tpl/textprocessing/squeeze.html</a></p>
<h4>Images</h4>
<ul>
<li>scaling of images: \includegraphics command has a scale option. eg. \includegraphics[scale=.5]. This reduced the overall size of the figure.</li>
<li>Another way to use this command is \includegraphics[width=\columnwidth]. This will scale the width exactly to column width and trial and error approach is not needed. Basic idea from <a href="http://visionlab.uta.edu/~ninad/" target="_blank">Dr Ninad</a>.</li>
<li>\includegraphics command has a trim option which allows one to trim whitespace from the 4 sides of the image. Example: \includegraphics[trim = 1in 2in 3in 4in]. This command removes 1in, 2in, 3in, and 4in of space from the left, bottom, right, and top of the image.</li>
<li><code>\usepackage[belowskip=-15pt,aboveskip=0pt]{caption}</code> will allow you to reduce the skip above and below the caption.</li>
<li><code>\setlength{\intextsep}{10pt plus 2pt minus 2pt}</code>. This command will let you change the space left on top and bottom of an in-text float.</li>
</ul>
<h4>Enumerations</h4>
<ul>
<li>Use paralist package and use compactenum/compactitem instead of enumerate. This will reduce the space between items.</li>
<li>Use inparaenum of the paralist package to convert an ordinary enumeration to paragraphy style enumeration.</li>
</ul>
<h4>Section/Subsection Titles</h4>
<ul>
<li>Look for section/subsection titles that take up more than one line and reduce their length.</li>
</ul>
<h4>Mathematics</h4>
<ul>
<li>Look for equations that are typeset in its own lines but are not referred to, in the document else where. Such equations can be merged with text and at least 3 lines can be saved.</li>
</ul>
<h4>References</h4>
<ul>
<li>Look for the bibliography listing. In my last paper, I replaced &#8220;IEEE Transactions on Pattern Analysis and Machine Intelligence&#8221; with &#8220;IEEE Tr. PAMI&#8221; and saved at least 10 lines.! This idea is from <a href="http://vislab.ucr.edu/PEOPLE/BIR_BHANU/index.php" target="_blank">Professor Bir Bhanu</a> (my PhD supervisor)</li>
</ul>
<h4>Page Length</h4>
<ul>
<li>The page length of one specific page may be increased by one or two lines without affecting the overall appearance by using: \enlargethispage{2\baselineskip}  will increase the page size by 2 lines.</li>
</ul>
<h4>Linespacing</h4>
<ul>
<li>This is the ultimate page size controlling command. \renewcommand{\baselinestretch}{.97} In this example, I have reduced  the baselinestretch  to 97% of the normal value. Its normal value is 100%. By changing this, the total page count of the document can be changed drastically, but <em>at the cost of the documents visual quality</em> . This idea is from <a href="http://vislab.ucr.edu/PEOPLE/BIR_BHANU/index.php" target="_blank">Professor Bir Bhanu</a> (my PhD supervisor)</li>
</ul>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sureshamrita.wordpress.com/437/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sureshamrita.wordpress.com/437/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sureshamrita.wordpress.com/437/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sureshamrita.wordpress.com/437/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sureshamrita.wordpress.com/437/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sureshamrita.wordpress.com/437/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sureshamrita.wordpress.com/437/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sureshamrita.wordpress.com/437/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sureshamrita.wordpress.com/437/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sureshamrita.wordpress.com/437/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sureshamrita.wordpress.com/437/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sureshamrita.wordpress.com/437/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sureshamrita.wordpress.com/437/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sureshamrita.wordpress.com/437/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sureshamrita.wordpress.com&amp;blog=5849255&amp;post=437&amp;subd=sureshamrita&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sureshamrita.wordpress.com/2011/03/14/reducing-page-count-in-a-latex-document/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/bc57c719b5ac41697a435424d87ecb65?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sureshamrita</media:title>
		</media:content>
	</item>
		<item>
		<title>Nearest neighbour in C++</title>
		<link>http://sureshamrita.wordpress.com/2011/03/08/nearest-neighbour-in-c/</link>
		<comments>http://sureshamrita.wordpress.com/2011/03/08/nearest-neighbour-in-c/#comments</comments>
		<pubDate>Tue, 08 Mar 2011 04:59:07 +0000</pubDate>
		<dc:creator>sureshamrita</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[min_element]]></category>

		<guid isPermaLink="false">http://sureshamrita.wordpress.com/?p=208</guid>
		<description><![CDATA[Using the min_element algorithm of the standard library, it is possible to write a nearest neighbor code as shown below. ﻿﻿<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sureshamrita.wordpress.com&amp;blog=5849255&amp;post=208&amp;subd=sureshamrita&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Using the min_element algorithm of the standard library, it is possible to write a nearest neighbor code as shown below.<br />
﻿﻿
<pre class="brush: cpp;">
#include&lt;iostream&gt;
#include&lt;vector&gt;
#include&lt;algorithm&gt;
using namespace std;
class NN{
  public:
  NN(int x):data(x){}
  bool operator()(int a, int b){
    return abs(a-data) &lt; abs(b-data);
  }
private:
  int data;
};
using namespace std;
int main(){
vector&lt;int&gt; data(10);
for(int i = 0; i &lt; 10; i++)data[i] = i;
NN n(4);
cout &lt;&lt; *min_element(data.begin(),data.end(),n);
}
</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sureshamrita.wordpress.com/208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sureshamrita.wordpress.com/208/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sureshamrita.wordpress.com/208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sureshamrita.wordpress.com/208/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sureshamrita.wordpress.com/208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sureshamrita.wordpress.com/208/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sureshamrita.wordpress.com/208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sureshamrita.wordpress.com/208/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sureshamrita.wordpress.com/208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sureshamrita.wordpress.com/208/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sureshamrita.wordpress.com/208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sureshamrita.wordpress.com/208/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sureshamrita.wordpress.com/208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sureshamrita.wordpress.com/208/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sureshamrita.wordpress.com&amp;blog=5849255&amp;post=208&amp;subd=sureshamrita&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sureshamrita.wordpress.com/2011/03/08/nearest-neighbour-in-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/bc57c719b5ac41697a435424d87ecb65?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sureshamrita</media:title>
		</media:content>
	</item>
		<item>
		<title>Simulation &#8211; some lessons</title>
		<link>http://sureshamrita.wordpress.com/2010/12/12/simulation-some-lessons/</link>
		<comments>http://sureshamrita.wordpress.com/2010/12/12/simulation-some-lessons/#comments</comments>
		<pubDate>Sun, 12 Dec 2010 04:21:40 +0000</pubDate>
		<dc:creator>sureshamrita</dc:creator>
				<category><![CDATA[Research]]></category>

		<guid isPermaLink="false">http://sureshamrita.wordpress.com/?p=405</guid>
		<description><![CDATA[Recently I had to write a Recognition system simulator.  It was a medium sized code with around 4000 lines of C++. This is the first time I was writing a simulator and at the end of it, I felt I could have done it better. Basically my code was monolithic. Just one executable at the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sureshamrita.wordpress.com&amp;blog=5849255&amp;post=405&amp;subd=sureshamrita&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Recently I had to write a Recognition system simulator.  It was a medium sized code with around 4000 lines of C++. This is the first time I was writing a simulator and at the end of it, I felt I could have done it better.</p>
<p>Basically my code was monolithic. Just one executable at the end. I realized that this approach has the following difficulties:</p>
<ul>
<li>When an error comes it is very difficult to know form which part of the code it came. We get an exception but which part of the code triggered the error in the first place?</li>
<li>We may later realize that some portion of the code is better written in another language, for example like matlab or python. But that would be impossible if we write a monolithic C++ code.</li>
</ul>
<p>A simulation system has the following logical components:</p>
<ul>
<li>The data generating unit.</li>
<li>Data processing unit.</li>
<li>Result display unit &#8211;  usually in the form of plots.</li>
</ul>
<p>My experience is that each of these units should be written as different executables &#8211; in a language most suited to the job at hand. Finally all the binaries could be bundled by a shell script or python script.</p>
<p>It is also better that each of the above components output is stored in  a file. It may be a good idea to create filenames which  reflect the parameter values used for generating data. This approach has the advantage that it is easy to fix a bug. Ourself or a code segment can look at the output file and quickly find out if the file is in order.</p>
<p>I have more comment to add regarding presentation of the final result. When I first wrote the code, all the data processing was done using C++ and the plots were generated using gnuplot. But it is much easier to do some kind of data manipulation using matlab and also generate plots using matlab or excel. Such an approach is possible only if we make our code hybrid instead of monolithic.</p>
<p>I would like to acknowledge the inputs given by my lab mate, <a href="http://visionlab.uta.edu/~ninad/" target="_blank">Dr Ninad Thakoor</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sureshamrita.wordpress.com/405/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sureshamrita.wordpress.com/405/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sureshamrita.wordpress.com/405/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sureshamrita.wordpress.com/405/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sureshamrita.wordpress.com/405/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sureshamrita.wordpress.com/405/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sureshamrita.wordpress.com/405/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sureshamrita.wordpress.com/405/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sureshamrita.wordpress.com/405/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sureshamrita.wordpress.com/405/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sureshamrita.wordpress.com/405/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sureshamrita.wordpress.com/405/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sureshamrita.wordpress.com/405/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sureshamrita.wordpress.com/405/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sureshamrita.wordpress.com&amp;blog=5849255&amp;post=405&amp;subd=sureshamrita&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sureshamrita.wordpress.com/2010/12/12/simulation-some-lessons/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/bc57c719b5ac41697a435424d87ecb65?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sureshamrita</media:title>
		</media:content>
	</item>
	</channel>
</rss>
