<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
   <title>David Gleich&apos;s Notebook</title>
   <link rel="alternate" type="text/html" href="http://www.stanford.edu/~dgleich/notebook/" />
   <link rel="self" type="application/atom+xml" href="http://www.stanford.edu/~dgleich/notebook/atom.xml" />
   <id>tag:www.stanford.edu,2010:/~dgleich/notebook//1</id>
   <updated>2009-09-17T22:40:13Z</updated>
   <subtitle>A small collection of helpful snippets I&apos;ve found.</subtitle>
   <generator uri="http://www.sixapart.com/movabletype/">Movable Type 3.34</generator>

<entry>
   <title>RMatlab - Using R from Matlab!</title>
   <link rel="alternate" type="text/html" href="http://www.stanford.edu/~dgleich/notebook/2009/09/rmatlab_using_r_from_matlab.html" />
   <id>tag:www.stanford.edu,2009:/~dgleich/notebook//1.38</id>
   
   <published>2009-09-17T22:39:54Z</published>
   <updated>2009-09-17T22:40:13Z</updated>
   
   <summary>RMatlab is a wonderful package I just discovered.&amp;#160; It interfaces R and Matlab.&amp;#160; I use it to make sexy figure from within Matlab.&amp;#160; (The alternative is to export data, import it to R, and make a figure.&amp;#160; It&apos;s possible, but...</summary>
   <author>
      <name></name>
      
   </author>
         <category term="compiling" scheme="http://www.sixapart.com/ns/types#category" />
   
   
   <content type="html" xml:lang="en" xml:base="http://www.stanford.edu/~dgleich/notebook/">
      <![CDATA[<p><a href="http://www.omegahat.org/RMatlab/">RMatlab</a> is a wonderful package I just discovered.&#160; It interfaces R and Matlab.&#160; I use it to make sexy figure from within Matlab.&#160; (The alternative is to export data, import it to R, and make a figure.&#160; It's possible, but a big pain.)&#160; The package works great, but I found it slightly difficult to get working.&#160; Here are the steps I took.</p> ]]>
      <![CDATA[  <h4>Prerequisites </h4>  <ul>   <li>A recent version of R; I'm using R 2.9.2 from the R debian repositories. </li>    <li>A working mex compiler. </li>    <li>A unix environment. </li> </ul>  <h4>Installation</h4>  <p>Download the file <code>RMatlab_0.2-5.tar.gz</code> from <a href="http://www.omegahat.org/RMatlab/">http://www.omegahat.org/RMatlab/</a></p>  <p>Unzip</p>  <pre><code>dgleich@icme-392-dgleich:~/devextern$ tar xzvf RMatlab_0.2-5.tar.gz </code></pre>

<p>Download apply the provided patch.&#160; Get it here: </p>

<div class="wlWriterEditableSmartContent" id="scid:fb3a1972-4489-4e52-abe7-25a00bb07fdf:184d1f7a-ac65-4713-9d20-d7db65c2878b" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px"><p> <a href="http://www.stanford.edu/~dgleich/notebook/WindowsLiveWriter/RMatlabUsingRfromMatlab_CD8A/RMatlab.patch" target="_blank">Rmatlab.patch</a></p></div>

<p></p>

<p></p>

<pre><code>dgleich@icme-392-dgleich:~/devextern$ cd RMatlab
dgleich@icme-392-dgleich:~/devextern/RMatlab$ patch -p1 &lt; ../RMatlab.patch 
patching file src/initializeR.c
patching file src/Makefile.in</code></pre>

<p>Configure — the two settings below are for Ubuntu 8.10 with R 2.9.2; to figure out the paths for yourself, check out the section below.</p>

<pre><code>dgleich@icme-392-dgleich:~/devextern/RMatlab$ export R_HOME=/usr/lib64/R
dgleich@icme-392-dgleich:~/devextern/RMatlab$ export R_INCLUDE_DIR=/usr/share/R/include
dgleich@icme-392-dgleich:~/devextern/RMatlab$ ./configure </code></pre>

<p>Install with R.</p>

<pre><code>dgleich@icme-392-dgleich:~/devextern/RMatlab$ cd ..
dgleich@icme-392-dgleich:~/devextern$ R CMD INSTALL RMatlab</code></pre>

<p>Hopefully, there aren’t any problems.</p>

<h4>Running</h4>

<p>There are quite a few paths you need to set to get RMatlab working properly. Here is the easiest way to do it.</p>

<p>Use the compiled directory to set all the paths. The following command depends on being in the <code>devextern</code> directory. You’ll need to adjust this path if you call the command from elsewhere.</p>

<pre><code>dgleich@icme-392-dgleich:~/devextern$ source RMatlab/inst/scripts/RMatlab.sh</code></pre>

<p>Run Matlab.</p>

<pre><code>dgleich@icme-392-dgleich:~/devextern$ matlab -nojvm -nodisplay

                            &lt; M A T L A B (R) &gt;
                  Copyright 1984-2008 The MathWorks, Inc.
                         Version 7.7.0.471 (R2008b)
                             September 17, 2008

 
  To get started, type one of these: helpwin, helpdesk, or demo.
  For product information, visit www.mathworks.com.
 

&gt;&gt; initializeR({'RMatlab'})    
&gt;&gt; x=callR('runif',10)

x =

    0.5233
    0.9075
    0.0258
    0.0107
    0.8787
    0.6178
    0.3865
    0.3492
    0.0195
    0.2071</code></pre>

<p>My preferred way is to set all the paths myself.</p>

<pre><code>dgleich@icme-392-dgleich:~/devextern$ export R_HOME=/usr/lib64/R
dgleich@icme-392-dgleich:~/devextern$ export R_SHARE_DIR=/usr/share/R/share
dgleich@icme-392-dgleich:~/devextern$ matlab -nojvm -nodisplay

                            &lt; M A T L A B (R) &gt;
                  Copyright 1984-2008 The MathWorks, Inc.
                         Version 7.7.0.471 (R2008b)
                             September 17, 2008

 
  To get started, type one of these: helpwin, helpdesk, or demo.
  For product information, visit www.mathworks.com.
 
&gt;&gt; addpath('~/R/x86_64-pc-linux-gnu-library/2.9/RMatlab/mex/');

&gt;&gt; initializeR({'RMatlab','--vanilla','--silent'})
&gt;&gt; x=callR('rpois',10,3)

x =

     5
     1
     1
     2
     2
     6
     2
     2
     2
     2</code></pre>

<p>Sophisticated users may find it convinent to wrap everything up</p>

<h4>Finding R paths</h4>

<p>To set <code>R_HOME</code> run</p>

<pre><code>$ locate libR.so</code></pre>

<p>and find an appropriate directory. For example, on my computer:</p>

<pre><code>dgleich@icme-392-dgleich:~/devextern$ locate libR.so
/home/dgleich/devextern/R-2.5.1/lib/libR.so
/home/dgleich/devextern/R-2.5.1/src/main/libR.so
/usr/lib/R/lib/libR.so</code></pre>

<p>This means I have two versions of R installed, but the one to use is the <code>/usr/lib/R</code> for <code>R_HOME</code>.</p>

<p>To set <code>R_INCLUDE_DIR</code>, use locate again.</p>

<pre><code>$ locate Rinternals.h</code></pre>

<p>On my computer:</p>

<pre><code>dgleich@icme-392-dgleich:~/devextern$ locate Rinternals.h
/home/dgleich/devextern/R-2.5.1/include/Rinternals.h
/home/dgleich/devextern/R-2.5.1/src/include/Rinternals.h
/usr/share/R/include/Rinternals.h</code></pre>

<p>So I set <code>R_INCLUDE_DIR</code> to <code>/usr/share/R/include</code></p>]]>
   </content>
</entry>
<entry>
   <title>Appendix Slides in Beamer: Controlling frame numbers</title>
   <link rel="alternate" type="text/html" href="http://www.stanford.edu/~dgleich/notebook/2009/05/appendix_slides_in_beamer_cont_1.html" />
   <id>tag:www.stanford.edu,2009:/~dgleich/notebook//1.37</id>
   
   <published>2009-05-05T05:43:53Z</published>
   <updated>2009-05-05T05:51:27Z</updated>
   
   <summary>A fellow student, Andrew Bradley, and I had a chat today about a feature missing from the beamer package in Latex: fine control over slide numbers.&amp;#160; We both subscribe to the philosophy that a each slide in a presentation should...</summary>
   <author>
      <name></name>
      
   </author>
   
   
   <content type="html" xml:lang="en" xml:base="http://www.stanford.edu/~dgleich/notebook/">
      <![CDATA[<p>A fellow student, <a href="http://www.stanford.edu/~ambrad">Andrew Bradley</a>, and I had a chat today about a feature missing from the beamer package in Latex: fine control over slide numbers.&#160; We both subscribe to the philosophy that a each slide in a presentation should have a slide number and the total number of slides.&#160; (An old professor strongly advocated this approach so that he could critique individual slides and had some idea of how much was left.)</p>  <p>Beamer makes it somewhat difficult to accommodate this system if you have backup slides in your presentation.&#160; You know, those things you are supposed to have prepared in case you get one of the &quot;hard&quot; questions?&#160; Anyway, these slides aren't a part of the standard presentation, and so they shouldn't count to the total slide number --- but they need to be there in your presentation file.</p>  <p>I had previously faced this issue and realized that you can just store and set the frame numbers in beamer at arbitrary points in the presentation.</p>  

<pre>% All your regular slides
% After your last numbered slide
\appendix
\newcounter{finalframe}
\setcounter{finalframe}{\value{framenumber}}
% Backup frames
\setcounter{framenumber}{\value{finalframe}}
\end{document}</pre>

<p>However, Andrew wanted to go beyond just skipping backup slides and &quot;uncount&quot; the outline slides that appear at the beginning of a section, as well as the title slide.&#160; He proposed using the trick above with the following adjustments.</p>

<pre>1. Add \addtocounter{framenumber}{-1} on the \AtBeginSubsection frame
2. Add \setcounter{framenumber}{0} or \setcounter{framenumber}{1}
   to the \titlepage frame and/or the \tableofcontents frame
   depending on taste.</pre>

<p>There you have it, all the tricks about frame counters in beamer that we know!</p>

<p>I suspect there is some way to accomplish the &quot;backup&quot; slides with a modification of the \appendix command and the \AtEndDocument directive.&#160; My brief attempt at making these changes ended in failure and frustration.&#160; Failure because it didn't work.&#160; Frustration because I forgot to write down that it didn't work and didn't remember it the next time I wanted to use this feature.&#160; (In fact, I really wish that beamer modified the \appendix command to implement precisely this feature.&#160; What else would an appendix do in a presentation?)</p>]]>
      
   </content>
</entry>
<entry>
   <title>Birthday distribution</title>
   <link rel="alternate" type="text/html" href="http://www.stanford.edu/~dgleich/notebook/2009/04/birthday_distribution.html" />
   <id>tag:www.stanford.edu,2009:/~dgleich/notebook//1.36</id>
   
   <published>2009-04-17T08:31:17Z</published>
   <updated>2009-04-17T08:31:26Z</updated>
   
   <summary>Many of my friends have birthdays in the next few weeks.&amp;#160; This fact prompted a discussion about the uniformity of birthdays.&amp;#160; In Outliers, Gladwell makes the case that birthdays of a group of individuals may appear skewed for subtle reasons;...</summary>
   <author>
      <name></name>
      
   </author>
         <category term="comments" scheme="http://www.sixapart.com/ns/types#category" />
   
   
   <content type="html" xml:lang="en" xml:base="http://www.stanford.edu/~dgleich/notebook/">
      <![CDATA[<p>Many of my friends have birthdays in the next few weeks.&#160; This fact prompted a discussion about the uniformity of birthdays.&#160; In <em>Outliers</em>, Gladwell makes the case that birthdays of a group of individuals may appear skewed for subtle reasons; however such results shouldn't hold for the populace.</p>  <p>This question is easy to answer with a bit of Googling.&#160; A Dartmouth professor has precisely the required data --- though only for a single year.</p>  <p><a title="http://www.dartmouth.edu/~chance/teaching_aids/data/birthday.txt" href="http://www.dartmouth.edu/~chance/teaching_aids/data/birthday.txt">http://www.dartmouth.edu/~chance/teaching_aids/data/birthday.txt</a></p>  <p>I used R to make a quick display of the data.</p> <script src="http://gist.github.com/96897.js"></script>  <div>Cutting and pasting this into R produces the following output for me.</div>  <div><a href="http://www.stanford.edu/~dgleich/notebook/WindowsLiveWriter/Birthdaydistribution_74C/dob-distribution_2.png" rel="lightbox"><img title="dob-distribution" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="294" alt="dob-distribution" src="http://www.stanford.edu/~dgleich/notebook/WindowsLiveWriter/Birthdaydistribution_74C/dob-distribution_thumb.png" width="420" border="0" /></a> </div>  <p></p>  <p>No, that isn't a data problem.&#160; There really are two groups of birthdays.</p>  <p>While looking for the overall date of birth data, I discovered another file from the CDC that explains the effect.</p>  <p><a title="http://www.cdc.gov/nchs/data/statab/t941x16.pdf" href="http://www.cdc.gov/nchs/data/statab/t941x16.pdf">http://www.cdc.gov/nchs/data/statab/t941x16.pdf</a></p>  <p>The data in that file show many fewer births on weekends compared with weekdays.&#160; This effect is precisely what we see in the plot, which R helps us validate.</p> <script src="http://gist.github.com/96902.js"></script>  <p><a href="http://www.stanford.edu/~dgleich/notebook/WindowsLiveWriter/Birthdaydistribution_74C/dob-dayofweek_2.png" rel="lightbox"><img title="dob-dayofweek" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="294" alt="dob-dayofweek" src="http://www.stanford.edu/~dgleich/notebook/WindowsLiveWriter/Birthdaydistribution_74C/dob-dayofweek_thumb.png" width="420" border="0" /></a> </p>  <p>This analysis was good enough for my own personal edification.&#160; There is still a bit of work left to make these claims statistically valid, but that isn't my point here.</p>]]>
      
   </content>
</entry>
<entry>
   <title>Easy software?</title>
   <link rel="alternate" type="text/html" href="http://www.stanford.edu/~dgleich/notebook/2009/03/easy_software.html" />
   <id>tag:www.stanford.edu,2009:/~dgleich/notebook//1.35</id>
   
   <published>2009-03-30T04:02:45Z</published>
   <updated>2009-03-30T04:32:49Z</updated>
   
   <summary><![CDATA[This afternoon, I added a &quot;recent links&quot; section to the left hand side of the main notebook index page.&#160; This section tracks links from my delicious account.&#160; After figuring out that I already had the Feeds App Lite plugin installed,...]]></summary>
   <author>
      <name></name>
      
   </author>
         <category term="comments" scheme="http://www.sixapart.com/ns/types#category" />
   
   
   <content type="html" xml:lang="en" xml:base="http://www.stanford.edu/~dgleich/notebook/">
      <![CDATA[<p>This afternoon, I added a &quot;recent links&quot; section to the left hand side of the main notebook index page.&#160; This section tracks links from my <a href="http://delicious.com/mithandor">delicious account</a>.&#160; After figuring out that I already had the Feeds App Lite plugin installed, it literally took about 5 minutes to get everything working.&#160; From my perspective, that is simply awesome --- <em>I didn't have to write a line of code!</em>&#160; Thanks to the authors of Movable Type and the Feeds App Lite for doing a great job.</p>  <p><em><strong>Update</strong></em> It turns out Live Writer decided to change the quote setting to insert gnarly &quot;curly&quot; quotes instead of the standard straight quotes.&#160; Ick, now I have to fix all these ugly quotes.&#160; I'm not sure what isn't working now. </p>]]>
      
   </content>
</entry>
<entry>
   <title>Paper: Improving the Presentation and Interpretation of Online Ratings Data with Model-Based Figures</title>
   <link rel="alternate" type="text/html" href="http://www.stanford.edu/~dgleich/notebook/2009/03/paper_improving_the_presentati.html" />
   <id>tag:www.stanford.edu,2009:/~dgleich/notebook//1.34</id>
   
   <published>2009-03-07T07:08:00Z</published>
   <updated>2009-03-30T04:30:39Z</updated>
   
   <summary>Every so often, I come across a paper I find really exciting. Presently, it&apos;s Daniel E. Ho and Kevin M. Quinn, Improving the Presentation and Interpretation of Online Ratings Data with Model-Based Figures, The American Statistician, November 2008(doi:10.1198/000313008X366145).&amp;#160; The paper...</summary>
   <author>
      <name></name>
      
   </author>
         <category term="papers" scheme="http://www.sixapart.com/ns/types#category" />
   
   
   <content type="html" xml:lang="en" xml:base="http://www.stanford.edu/~dgleich/notebook/">
      <![CDATA[<p>Every so often, I come across a paper I find really exciting. Presently, it's Daniel E. Ho and Kevin M. Quinn, <a href="http://pubs.amstat.org/doi/pdf/10.1198/000313008X366145">Improving the Presentation and Interpretation of Online Ratings Data with Model-Based Figures</a>, The American Statistician, November 2008(doi:10.1198/000313008X366145).&#160; </p>  <p>The paper tackles one problem that irritates me --- aggregating online ratings --- and uses a solution I've previously considered and wanted to investigate --- profiling the raters.&#160; (It's always nice to discover you don't have to do ALL the work yourself.)</p>  <p align="left">The problem is illustrated by the following snapshot from Amazon.</p>  <p align="left"><a href="http://www.stanford.edu/~dgleich/notebook/WindowsLiveWriter/PaperImprovingthePresentationandInterpre_14582/image_2.png"><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="36" alt="image" src="http://www.stanford.edu/~dgleich/notebook/WindowsLiveWriter/PaperImprovingthePresentationandInterpre_14582/image_thumb.png" width="479" border="0" /></a> </p>  <p align="left">With only three ratings, no product merits a 5-star rating.&#160; To Amazon's credit, they clearly note there are only three ratings aggregated into a single 5-star rating.&#160; They also show a histogram of the individual ratings elsewhere on the product page.</p>  <p align="left">A simple fix would be to apply well known statistical confidence intervals to the ratings and use the lower bound.&#160; Of these fixes, the most naive would be to add pseudo-counts for each possible rating.&#160; With three 5-stars, the pseudo-count score would be 3.75.&#160; <a href="http://www.evanmiller.org">Evan Miller</a> proposes <a href="http://www.evanmiller.org/how-not-to-sort-by-average-rating.html">a more sophisticated technique based on Wilson's score</a> in a recent blog post.</p>  <p align="left">Ho and Quinn do something different.&#160; They propose a model that incorporates the raters behavior on the site and thus, all ratings are not equal.&#160;&#160; The types of behavior captured are</p>  <ul>   <li>     <div align="left">Uncritical --- easy to please,</div>   </li>    <li>     <div align="left">Non-discriminating --- useless, and</div>   </li>    <li>     <div align="left">Discriminating --- a &quot;critic.&quot;</div>   </li> </ul>  <p align="left">Go read the paper for the details of the model.&#160; The punch line is that the aggregate rating depends on <em>all</em> ratings submitted to the site.</p>  <p align="left">After looking at lots of rating data from Netflix, LAUNCHcast, and even the smaller datasets from HelloMovies, incorporating this information seems critical to generate useful aggregate ratings.</p>  <p align="left">One issue with their techniques is the lack of transparency.&#160; As a user, I would <em>really</em> have to trust your site to take the ratings seriously.&#160; The Amazon approach with the histogram allows me to evaluate the data myself; though I lack the critical context that the Ho/Quinn ratings provide.&#160; A second issue is computation.&#160;&#160; I did not fully check their paper, but I don't think the model is trivial to fit and could be done in real time.&#160; </p>  <p align="left">These are just theoretical issues.&#160; They have an <a href="http://cran.r-project.org/web/packages/Ratings/index.html">R package: Ratings</a>, so go give it a try.</p>]]>
      
   </content>
</entry>
<entry>
   <title>CoinOr CLOP for Matlab</title>
   <link rel="alternate" type="text/html" href="http://www.stanford.edu/~dgleich/notebook/2009/03/coinor_clop_for_matlab.html" />
   <id>tag:www.stanford.edu,2009:/~dgleich/notebook//1.33</id>
   
   <published>2009-03-05T06:15:02Z</published>
   <updated>2009-03-05T06:16:32Z</updated>
   
   <summary>Johan Lofberg wrote a nice function to interface the Clp linear program solver from the CoinOR project with Matlab. He distributes a precompiled version of the Clp Matlab wrapper for windows, but doesn&apos;t include one for linux. Nor are there...</summary>
   <author>
      <name></name>
      
   </author>
   
   
   <content type="html" xml:lang="en" xml:base="http://www.stanford.edu/~dgleich/notebook/">
      <![CDATA[<p><a href="http://control.ee.ethz.ch/~joloef/">Johan Lofberg</a> wrote a nice function to interface the <a href="http://www.coin-or.org/Clp/">Clp linear program solver from the CoinOR project</a> with Matlab. He distributes a precompiled version of the <a href="http://control.ee.ethz.ch/~joloef/clp.php ">Clp Matlab wrapper</a> for windows, but doesn't include one for linux. Nor are there any directions on how to compile here. I managed to get it to compile with <a href="http://www.coin-or.org/download/source/Clp/">Clp-1.9.0</a>. My directions follow.&#160; Issue these commands </p>  <pre># Download Clp-1.9.0.tgz
wget http://www.coin-or.org/download/source/Clp/Clp-1.9.0.tgz

# untar
tar xzvf Clp-1.9.0.tgz

# configure and make
cd Clp-1.9.0
./configure
make
make install

# get mexclp
wget http://control.ee.ethz.ch/~joloef/mexclp.zip
unzip mexclp.zip

# compile in matlab
matlab -nojvm -nodesktop -nodisplay 
ldf=['LDFLAGS=&quot;\$LDFLAGS -Wl,--rpath -Wl,' pwd '/lib&quot;'];
mex(ldf,'-Iinclude/coin', '-Llib', '-lClp',  '-lCoinUtils', 'mexclp.cpp')</pre>

<p>After compiling (hopefully successfully!) </p>

<pre>&gt;&gt; clp([],[1 2 1],[1 1 1],-1,[],[])

ans = 

    0
   -1
    0</pre>

<p>For Matlab 2008b on Ubuntu 8.10, I found it necessary to install g++-4.1, setup mex with g++-4.1 and run </p>

<pre>./configure CXX=g++-4.1
make
make install</pre>

<p>before everything would work. </p>]]>
      
   </content>
</entry>
<entry>
   <title>Latex Presentation Fonts</title>
   <link rel="alternate" type="text/html" href="http://www.stanford.edu/~dgleich/notebook/2008/11/latex_presentation_fonts.html" />
   <id>tag:www.stanford.edu,2008:/~dgleich/notebook//1.31</id>
   
   <published>2008-11-09T20:19:25Z</published>
   <updated>2008-11-09T20:31:15Z</updated>
   
   <summary><![CDATA[I don't like the standard beamer fonts in LaTeX for linear algebra presentations.&#160; I find the &quot;I&quot; as a big vertical line quite annoying.&#160; Previously, I used the lxfonts set, which has gorgeous characters.&#160; However, lxfonts is too &quot;wide&quot; and...]]></summary>
   <author>
      <name></name>
      
   </author>
   
   
   <content type="html" xml:lang="en" xml:base="http://www.stanford.edu/~dgleich/notebook/">
      <![CDATA[<p>I don't like the standard beamer fonts in LaTeX for linear algebra presentations.&#160; I find the &quot;I&quot; as a big vertical line quite annoying.&#160; Previously, I used the <a href="http://www.ctan.org/tex-archive/fonts/lxfonts/doc/fonts/lxfonts/LXfonts-demo.pdf">lxfonts</a> set, which has gorgeous characters.&#160; However, lxfonts is too &quot;wide&quot; and makes long equations slightly challenging.</p>  <p>The <a href="http://www.ctan.org/tex-archive/fonts/arev/arevdoc.pdf">arev package</a> is a nice compromise: it has a nice I glyph.&#160; Continue reading for some screenshots.</p> ]]>
      <![CDATA[  <p>Let’s start with the new arev fonts.&#160; </p>  <p><a href="http://www.stanford.edu/~dgleich/notebook/WindowsLiveWriter/LatexPresentationFonts_9FB0/image_2.png" rel="lightbox[slide]"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="302" alt="image" src="http://www.stanford.edu/~dgleich/notebook/WindowsLiveWriter/LatexPresentationFonts_9FB0/image_thumb.png" width="404" border="0" /></a></p>  <p>&#160;</p>  <p>The next set is my old preference.&#160; It’s the lxfonts set for math, with Myriad Pro semi-bold for text.&#160; I think this makes a really nice presentation, but the equations are fairly wide.</p>  <p><a href="http://www.stanford.edu/~dgleich/notebook/WindowsLiveWriter/LatexPresentationFonts_9FB0/image_4.png" rel="lightbox[slide]"><img title="image" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="305" alt="image" src="http://www.stanford.edu/~dgleich/notebook/WindowsLiveWriter/LatexPresentationFonts_9FB0/image_thumb_1.png" width="404" border="0" /></a></p>]]>
   </content>
</entry>
<entry>
   <title>Old posts?</title>
   <link rel="alternate" type="text/html" href="http://www.stanford.edu/~dgleich/notebook/2008/11/old_posts.html" />
   <id>tag:www.stanford.edu,2008:/~dgleich/notebook//1.30</id>
   
   <published>2008-11-09T05:31:10Z</published>
   <updated>2008-11-09T05:31:13Z</updated>
   
   <summary><![CDATA[I moved a few posts from my old &quot;blog-like&quot; site to this notebook.&#160; That's why there are posts going back to 2006. Going forward, my goal is going to be a post a week.&#160;...]]></summary>
   <author>
      <name></name>
      
   </author>
   
   
   <content type="html" xml:lang="en" xml:base="http://www.stanford.edu/~dgleich/notebook/">
      <![CDATA[<p>I moved a few posts from my old &quot;blog-like&quot; site to this notebook.&#160; That's why there are posts going back to 2006.</p>  <p>Going forward, my goal is going to be a post a week.&#160; </p>]]>
      
   </content>
</entry>
<entry>
   <title>kvm vs kqemu</title>
   <link rel="alternate" type="text/html" href="http://www.stanford.edu/~dgleich/notebook/2008/11/kvm_vs_kqemu.html" />
   <id>tag:www.stanford.edu,2008:/~dgleich/notebook//1.25</id>
   
   <published>2008-11-09T05:10:12Z</published>
   <updated>2008-11-09T05:10:16Z</updated>
   
   <summary>After I updated my Ubuntu distribution to 8.04, I discovered that the virtualization software I used to compile MatlabBGL didn&apos;t work with a 64-bit version of Windows XP anymore.&amp;#160; No one seems to mention this next fact, but I simply...</summary>
   <author>
      <name></name>
      
   </author>
   
   
   <content type="html" xml:lang="en" xml:base="http://www.stanford.edu/~dgleich/notebook/">
      <![CDATA[<p>After I updated my Ubuntu distribution to 8.04, I discovered that the virtualization software I used to compile MatlabBGL didn't work with a 64-bit version of Windows XP anymore.&#160; No one seems to mention this next fact, but I simply couldn't get qemu/kqemu to work with Ubuntu 8.04 and XP64 with a network interface enabled.&#160; Instead, kvm --- the &quot;new&quot; and &quot;official&quot; kernel virtualization module --- worked instantly, it even uses the old qemu/kqemu images.</p>  <p>So don't bother with kqemu under Ubuntu 8.04 --- just use kvm.&#160; </p>]]>
      
   </content>
</entry>
<entry>
   <title>A fun LaTeX Command</title>
   <link rel="alternate" type="text/html" href="http://www.stanford.edu/~dgleich/notebook/2007/12/a_fun_latex_command.html" />
   <id>tag:www.stanford.edu,2007:/~dgleich/notebook//1.24</id>
   
   <published>2007-12-09T01:47:08Z</published>
   <updated>2007-12-09T02:19:40Z</updated>
   
   <summary><![CDATA[A while back, I wanted to write &quot;Google&quot; in a presentation.&#160; (Given that I do some research on the PageRank system they proposed, I guess this isn't too surprising.) I believe in making presentations fun and wanted to use the...]]></summary>
   <author>
      <name></name>
      
   </author>
   
   
   <content type="html" xml:lang="en" xml:base="http://www.stanford.edu/~dgleich/notebook/">
      <![CDATA[<p>A while back, I wanted to write &quot;Google&quot; in a presentation.&#160; (Given that I do some research on the PageRank system they proposed, I guess this isn't too surprising.)</p>  <p>I believe in making presentations fun and wanted to use the Google colored version of the term.&#160; After some googling, I found the RGB colors and painstakingly converted them to floating point values to use with the latex xcolor package.&#160; To make my life easier, I encoded everything into the following command.</p>  <pre>\newcommand{\Google}{{
  \color[rgb]{    0.2000 ,   0.3922  ,  0.7647}G%
  \color[rgb]{    0.9529  ,  0.0980  ,  0.0118}o%
  \color[rgb]{   0.9686  ,  0.8431  , 0.1529}o%
  \color[rgb]{    0.2000 ,   0.3922  ,  0.7647}g%
  \color[rgb]{    0.2667 ,   0.7686  ,  0.0235}l%
  \color[rgb]{   0.9529 ,   0.0980 ,   0.0118}e%
 }
}</pre>

<p>Later, I learned that I could have used the RGB values with the color package directly.&#160; Oh well, it would have saved a little bit of time.</p>]]>
      
   </content>
</entry>
<entry>
   <title>Getting a 64-bit copy of Windows XP</title>
   <link rel="alternate" type="text/html" href="http://www.stanford.edu/~dgleich/notebook/2007/12/getting_a_64bit_copy_of_window.html" />
   <id>tag:www.stanford.edu,2007:/~dgleich/notebook//1.23</id>
   
   <published>2007-12-06T21:12:07Z</published>
   <updated>2007-12-09T02:19:25Z</updated>
   
   <summary>I&apos;ve been getting a few emails about folks interested in using my MatlabBGL software on 64-bit installations of Windows.&amp;#160; Personally, I don&apos;t have a 64-bit installation of a Windows environment (XP, Server, or Vista) which always made testing a little...</summary>
   <author>
      <name></name>
      
   </author>
   
   
   <content type="html" xml:lang="en" xml:base="http://www.stanford.edu/~dgleich/notebook/">
      <![CDATA[<p>I've been getting a few emails about folks interested in using my MatlabBGL software on 64-bit installations of Windows.&#160; </p>  <p>Personally, I don't have a 64-bit installation of a Windows environment (XP, Server, or Vista) which always made testing a little difficult.&#160; A while back, the ICME sysadmin (a really huge help!) setup a machine with a 64-bit copy of XP to test for one person.&#160; I got the code compiled and everything tested.&#160; (Unfortunately, I couldn't reproduce the problem he identified.)&#160; </p>  <p>In theory, I thought it would work quite simply.&#160; I compile a 64-bit libmbgl, and they compile the .mexw64 files on their system.</p>  <p>Life is never that simple.</p> ]]>
      <![CDATA[  <p>Suffice it to say, I ran into tremendous problems on getting libmbgl and the mex files compiled on the other computer.</p>  <p>To attack the problem I set about getting a 64-bit copy of WinXP.</p>  <p>Sometimes, being at Stanford is great.&#160; I emailed our sysadmin.&#160; By the time I came back from my next class, a WinXP 64-bit edition CD was waiting for me.&#160; He need to run somewhere to get the volume license key, but in a short bit, I had my operating system.</p>  <p>I did not get another computer to install it on and instead, I setup QEMU on my ubuntu system.</p>  <pre>sudo apt-get install qemu</pre>

<p>Blah</p>

<p>To get things working, I created a 16GB image for the qemu virtual machine and an ISO of the winxp64 install disk.&#160; </p>

<pre>qemu-img create winxp64.img 16G # create the qemu image</pre>

<pre>dd if=/dev/cdrom of=winxp64.iso # create the iso (may need to change /dev/cdrom)</pre>

<pre>qemu -boot d -hda winxp64.img -cdrom winxp64.iso -m 512 -localtime</pre>

<p>At which point I got an error message about how I needed a 64-bit machine to install a 64-bit version of XP.</p>

<p>Blast.</p>

<p>Google quickly provided the answer and the following command ...</p>

<pre>qemu-system-x86_64 -boot d -hda winxp64.img -cdrom winxp64.iso -m 512 -localtime</pre>

<p>... gave me a working virtual machine with a running windows installation extolling the benefits of 64-bit computing.&#160; </p>

<p>The install took ages.&#160; When it finished, XP rebooted itself and qemu did not boot from the virtual CD-ROM again.&#160; Quickly thereafter, I logged into the XP system and tried Internet Explorer.</p>

<p>Nothing... there was no network!</p>

<p>Blast.</p>

<p>Google showed that I should be able to setup a NE2000 PCI network card with QEMU, but some quick checking showed that XP64 didn't have a NE2000 PCI driver.</p>

<p>Double blast.</p>

<p>A few hours past and I considered the possibility that my &quot;open-source&quot; QEMU idea wouldn't cut it.&#160; After reading the QEMU FAQ, they posted a note on how to get the network working with Windows Server 2003.&#160; Inspiration struck when I remembered that XP64 is based on the Windows Server 2003 source code.&#160; I clicked the &quot;howto&quot; from the QEMU FAQ and the link was dead!</p>

<p>BLAST!</p>

<p>But, the link was to a realtek site, whereas the NE2000 driver should have been a novell site.&#160; Maybe... there was something else I could do?&#160; Indeed there was: QEMU can also emulate a realtek card as I found out on another page.&#160; I tried this and still had problems, but Windows recognized the driver and virtual network card.&#160; Another google search showed that I had to add just one more command line option to make things work.&#160; </p>

<pre>qemu-system-x86_64 winxp64.img -m 512 -net nic,model=rtl8139,vlan=0 -net user,vlan=0</pre>

<p>... gave me a working virtual machine with a 64-bit copy of XP and access to the Internet.&#160; </p>

<p>Finally.</p>

<p>Maybe now I can do some much work.&#160; Just remember folks, &quot;I do these things so you don't have to.&quot;&#160; (I feel like someone famous said that sentence.&#160; Google turns up nothing, however.)</p>

<h3>References</h3>

<ul>
  <li><a title="https://help.ubuntu.com/community/WindowsXPUnderQemuHowTo" href="https://help.ubuntu.com/community/WindowsXPUnderQemuHowTo">https://help.ubuntu.com/community/WindowsXPUnderQemuHowTo</a> </li>

  <li><a title="http://209.85.173.104/search?q=cache:ZGTcXOggvscJ:qemu-forum.ipi.fi/viewtopic.php%3Fp%3D11341+qemu+windows+server+2003+network.&amp;hl=en&amp;ct=clnk&amp;cd=3&amp;gl=us&amp;client=firefox-a" href="http://209.85.173.104/search?q=cache:ZGTcXOggvscJ:qemu-forum.ipi.fi/viewtopic.php%3Fp%3D11341+qemu+windows+server+2003+network.&amp;hl=en&amp;ct=clnk&amp;cd=3&amp;gl=us&amp;client=firefox-a">http://209.85.173.104/search?q=cache:ZGTcXOggvscJ:qemu-forum.ipi.fi/viewtopic.php%3Fp%3D11341+qemu+windows+server+2003+network.&amp;hl=en&amp;ct=clnk&amp;cd=3&amp;gl=us&amp;client=firefox-a</a> </li>

  <li><a title="http://maconstuff.blogspot.com/2006/06/how-to-run-windows-xp-under-ubuntu.html" href="http://maconstuff.blogspot.com/2006/06/how-to-run-windows-xp-under-ubuntu.html">http://maconstuff.blogspot.com/2006/06/how-to-run-windows-xp-under-ubuntu.html</a> </li>
</ul>]]>
   </content>
</entry>
<entry>
   <title>Research Note 1</title>
   <link rel="alternate" type="text/html" href="http://www.stanford.edu/~dgleich/notebook/2007/11/research_note_1.html" />
   <id>tag:www.stanford.edu,2007:/~dgleich/notebook//1.2</id>
   
   <published>2007-11-04T21:28:26Z</published>
   <updated>2007-11-04T21:28:29Z</updated>
   
   <summary>I&apos;ve decided to try and setup an online research notebook to keep track of a few issues as I encounter them.&amp;#xA0; The first set of entries will revolve around Beamer used for a presentation....</summary>
   <author>
      <name></name>
      
   </author>
   
   
   <content type="html" xml:lang="en" xml:base="http://www.stanford.edu/~dgleich/notebook/">
      <![CDATA[<p>I've decided to try and setup an online research notebook to keep track of a few issues as I encounter them.&#xA0; The first set of entries will revolve around Beamer used for a presentation.</p>]]>
      
   </content>
</entry>
<entry>
   <title>Reading Cluto Files in Matlab (Part 1)</title>
   <link rel="alternate" type="text/html" href="http://www.stanford.edu/~dgleich/notebook/2006/04/reading_cluto_files_in_matlab.html" />
   <id>tag:www.stanford.edu,2006:/~dgleich/notebook//1.28</id>
   
   <published>2006-04-11T06:26:08Z</published>
   <updated>2008-11-09T05:26:44Z</updated>
   
   <summary>Update: I never completed this series, but I do have a Cluto sparse matrix reading for Matlab.&amp;#160; Contact me for information, or check out readCluto on Matlab central. Today, let&amp;#8217;s see a Matlab solution to reading and writing CLUTO data...</summary>
   <author>
      <name></name>
      
   </author>
   
   
   <content type="html" xml:lang="en" xml:base="http://www.stanford.edu/~dgleich/notebook/">
      <![CDATA[<p><strong>Update: I never completed this series, but I do have a Cluto sparse matrix reading for Matlab.&#160; Contact me for information, or check out <a href="http://www.mathworks.com/matlabcentral/fileexchange/10706">readCluto</a> on Matlab central.</strong></p>  <p>Today, let&#8217;s see a Matlab solution to reading and writing CLUTO data files. CLUTO is a clustering toolkit by George Karypis at U of Minn. There are FOUR possible input files CLUTO might see.</p>  <ul>   <li>Dense Graph </li>    <li>Sparse Graph </li>    <li>Dense Matrix </li>    <li>Sparse Matrix </li> </ul>  <p>The difference between the dense and sparse files is simply a matter of header information. Let&#8217;s describe a few CLUTO files.</p>  <ul>   <li>Suppose we have a 5-node line graph&#160; </li> </ul>  <p>v1 &lt;-&gt; v2 &lt;-&gt; v3 &lt;-&gt; v4 &lt;-&gt; v5</p>  <p>In dense graph format, this graph is</p>  <pre>5 0 1 0 0 0 1 0 1 0 0 0 1 0 1 0 0 0 1 0 1 0 0 0 1 0 </pre>

<p>In sparse graph format, this graph is</p>

<pre>5 8 2 1 1 1 3 1 2 1 4 1 3 1 5 1 4 1 </pre>

<p>To wit, the dense graph format is merely an explicit specification of the adjacency matrix for the graph with a single line specifying the number of vertices. The sparse graph format is a sparse adjacency representation. The sparse adjacency is somewhat strange in that it uses 1 based columns, and implicit rows.</p>

<p>More formally, the sparse adjacency structure has 1 line of header information: </p>

<p>&lt;number of vertices&gt; &lt;number of edges*2&gt;</p>

<p>and the <i>i+1</i>th line of the file contains </p>

<p>adj_1 weight_1 adj_2 weight_2 &#8230; adj_d weight_d</p>

<p>where adj_j is the <i>j</i>th adjacent vertex and weight_j is the weight of that edge and <i>d</i> is the degree of the <i>i</i>th vertex. The input must be symmetric.</p>

<p>The sparse and dense matrix file formats are similar. The difference is the matrices involved are not square which changes the header. </p>

<ul>
  <li>dense matrix header:&#160; <br />&lt;number of rows&gt; &lt;number of columns&gt;</li>

  <li>sparse matrix header:&#160; <br />&lt;number of rows&gt; &lt;number of columns&gt; &lt;number of nonzeros&gt;</li>
</ul>

<p>The dense matrix format is just a row-by-row listing of the elements of the matrix. The sparse matrix format is a sparse row-by-row listing. In the sparse matrix format, the <i>i+1</i>th line of the file contains information about the non-zeros in row <i>i</i>.

  <br />column_1 value_1 column_2 value_2 &#8230; column_d value_d</p>

<p>Coming next, we&#8217;ll see how to read these files in Matlab using a combination of mex files and scripts.</p>]]>
      
   </content>
</entry>
<entry>
   <title>Sorting two arrays simultaneously</title>
   <link rel="alternate" type="text/html" href="http://www.stanford.edu/~dgleich/notebook/2006/03/sorting_two_arrays_simultaneou.html" />
   <id>tag:www.stanford.edu,2006:/~dgleich/notebook//1.29</id>
   
   <published>2006-03-25T05:27:08Z</published>
   <updated>2008-11-09T05:27:23Z</updated>
   
   <summary>Suppose, for the sake of this article, that you have two arrays in C++ with the same number of element.&amp;#160; For example, int a1[] = {5, 8, 9, 1, 4, 3, 2}; double v[] = {3., 4., 5., 2., 1.,...</summary>
   <author>
      <name></name>
      
   </author>
   
   
   <content type="html" xml:lang="en" xml:base="http://www.stanford.edu/~dgleich/notebook/">
      <![CDATA[<p>Suppose, for the sake of this article, that you have two arrays in C++ with the same number of element.&#160; For example,    <br /></p>  <p><font face="courier new,monospace">int a1[] = {5, 8, 9, 1, 4, 3, 2};      <br />double v[] = {3., 4., 5., 2., 1., 9., 8.};</font></p>  <p>Now, for reasons that perhaps only I care about.&#160; I want to sort the array a1, and permute v in according to the same permutation.&#160; </p>  <p><font face="courier new,monospace">// a1 = {1,&#160; 2,&#160; 3,&#160; 4,&#160; 5,&#160; 8,&#160; 9}      <br />// v =&#160; {2., 8., 9., 1., 3., 4., 5.,}</font></p>  <p>(For those who care and who know what I'm talking about.&#160; I have a compressed sparse row matrix represented in the AIJ format and I want to sort the element of each row in increasing order so I can do O(log n) binary search to determine if an element exists.&#160; However, as always, the problem is more generic than the instance I care to solve.)</p>  <p>To wit, I wish to sort one array and &quot;take the other&quot; along for a ride.</p>  <p>This problem has a few trivial solutions:    <br /></p>  <p>1.&#160; Sort the array a1 implicitly by sorting a permutation vector that indexes into a1.&#160; Then permute a1, and v by this array.    <br /></p>  <p>2.&#160; Write a custom sorting routine that does the operation for this special case.</p>  <p>3.&#160; Try to shoehorn this problem into an existing sorting array.</p>  <p>In terms of performance, the fastest solution is probably 2.&#160; The second fastest is probably 1.&#160; Finally, 3. is likely the slowest.</p>  <p>Solution 3, however, has two huge advantages.&#160; First, I don't have to write my own sorting routine.&#160; This is important as writing a general purpose sort is somewhat non-trivial.&#160; Also, it is fairly likely that the input to the sort will be nearly sorted so I can't use a general purpose quicksort routine which has O(n^2) performance on a sorted array.&#160; The second advtange is that it does not require extra memory as solution 1 does.&#160; In fact, solution 1 requires quite a bit of extra memory.&#160; While it is a tractable amount, it is nonetheless superfluous.&#160; </p>  <p>Thus, I decided to look at solution 3.&#160; Between STL and Boost, there are quite robust and generic C++ sorting libraries.&#160; How hard could this be?&#160; Maybe 20, 30 minutes of work?</p>  <p>Quickly, I realized how such thoughts were hopelessly naive.&#160; </p>  <p>In a nutshell, the requirements are:</p>  <p>1.&#160; Use the C++ STL sorting routine (which has good O(n log n) worst case performance).</p>  <p>2.&#160; Do not create extra memory for the sort.</p>  <p>Thankfully, I did not impose any sort of &quot;performance&quot; requirement on myself.&#160; In fact, many of the arrays will be rather small; so performance for large arrays is not quite so important.&#160; <br /></p>  <p>First, C++ STL sort does not work on boost's zip_iterators, which would have been the natural solution. In fact, there seem to be a number of debates on this matter; and more generally on the requirements of iterators, zip_iterators, and the STL Sort function.</p>  <p><font face="courier new,monospace"><font face="arial,sans-serif"><a href="http://user.it.uu.se/%7Ekrister/Research/iterators.pdf%0A">http://user.it.uu.se/~krister/Research/iterators.pdf</a>         <br /><a href="http://lists.boost.org/Archives/boost/2004/07/68758.php">http://lists.boost.org/Archives/boost/2004/07/68758.php</a>         <br /><a href="http://web.onetel.com/%7Eanthony_w/cplusplus/pair_iterators.pdf">http://web.onetel.com/~anthony_w/cplusplus/pair_iterators.pdf</a>         <br /><a href="http://cplusplus.anthonyw.cjb.net/">http://cplusplus.anthonyw.cjb.net/</a></font></font></p>  <p>Second, the fundamental problem is that &quot;pairs&quot; of array references do not behave like they should for things to work nicely.&#160; That is, there are no clean generalizations of a set of pointers.&#160; The best that exists is the boost::tuple class with a set of reference.&#160; However, that class fails because references and values are quite strange and do not behave quite like you think.&#160; <font face="courier new,monospace"><font face="arial,sans-serif"></font></font>&#160; <br /></p>  <p>Instead, I simply decided to abuse the notation of an iterator and write something that works.</p>  <p>This involved writing, effectively, a non-conforming iterator where the reference of the value type is not the same as the reference type.</p>  <p>Here is the code for anyone who cares.&#160; (This is a slightly modified version from my code, so it may not compiler, but the fixes should be trivial.)    <br /></p>  <p><font face="courier new,monospace" size="1">template &lt;class SortIter, class PermuteIter&gt;      <br />struct sort_permute_iter_helper_type       <br />{       <br />&#160;&#160;&#160; typedef boost::tuple&lt;       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; typename std::iterator_traits&lt;SortIter&gt;::value_type,       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; typename std::iterator_traits&lt;PermuteIter&gt;::value_type &gt;       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; value_type;       <br />      <br />&#160;&#160;&#160; typedef boost::tuple&lt;       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; typename std::iterator_traits&lt;SortIter&gt;::value_type&amp;,       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; typename std::iterator_traits&lt;PermuteIter&gt;::value_type&amp; &gt;       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; ref_type;       <br />};       <br />&#160; <br />template &lt;class SortIter, class PermuteIter&gt;       <br />class sort_permute_iter       <br />&#160;&#160;&#160; : public boost::iterator_facade&lt;       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; sort_permute_iter&lt;SortIter, PermuteIter&gt;,       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; typename sort_permute_iter_helper_type&lt;       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; SortIter, PermuteIter&gt;::value_type,       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; std::random_access_iterator_tag,       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; typename sort_permute_iter_helper_type&lt;       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; SortIter, PermuteIter&gt;::ref_type,       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; typename std::iterator_traits&lt;SortIter&gt;::difference_type       <br />&#160;&#160;&#160; &gt;       <br />{       <br />public:       <br />&#160;&#160;&#160; sort_permute_iter()       <br />&#160;&#160;&#160; {}       <br />      <br />&#160;&#160;&#160; sort_permute_iter(SortIter ci, PermuteIter vi)       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; : _ci(ci), _vi(vi)       <br />&#160;&#160;&#160; {       <br />&#160;&#160;&#160; }       <br />      <br />&#160;&#160;&#160; SortIter _ci;       <br />&#160;&#160;&#160; PermuteIter _vi;       <br />      <br />      <br />private:       <br />&#160;&#160;&#160; friend class boost::iterator_core_access;       <br />      <br />&#160;&#160;&#160; void increment()       <br />&#160;&#160;&#160; {       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; ++_ci; ++_vi;       <br />&#160;&#160;&#160; }       <br />      <br />&#160;&#160;&#160; void decrement()       <br />&#160;&#160;&#160; {       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; --_ci; --_vi;       <br />&#160;&#160;&#160; }       <br />      <br />&#160;&#160;&#160; bool equal(sort_permute_iter const&amp; other) const       <br />&#160;&#160;&#160; {       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; return (_ci == other._ci);       <br />&#160;&#160;&#160; }       <br />      <br />&#160;&#160;&#160; typename       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; sort_permute_iter_helper_type&lt;       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; SortIter, PermuteIter&gt;::ref_type dereference() const       <br />&#160;&#160;&#160; {       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; return (typename       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; sort_permute_iter_helper_type&lt;       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ColIter, PermuteIter&gt;::ref_type(*_ci, *_vi));       <br />&#160;&#160;&#160; }       <br />      <br />&#160;&#160;&#160; void advance(difference_type n)       <br />&#160;&#160;&#160; {       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; _ci += n;       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; _vi += n;       <br />&#160;&#160;&#160; }       <br />      <br />&#160;&#160;&#160; difference_type distance_to(sort_permute_iter const&amp; other) const       <br />&#160;&#160;&#160; {       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; return ( other._ci - _ci);       <br />&#160;&#160;&#160; }       <br />}; </font></p>  <p><font face="courier new,monospace" size="1">     <br />template &lt;class SortIter, class PermuteIter&gt;       <br />struct sort_permute_iter_compare       <br />&#160;&#160;&#160; hehe: public std::binary_function&lt;       <br />&#160;&#160;&#160; typename sort_permute_iter_helper_type&lt;       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; SortIter, PermuteIter&gt;::value_type,       <br />&#160;&#160;&#160; typename sort_permute_iter_helper_type&lt;       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; SortIter, PermuteIter&gt;::value_type,       <br />&#160;&#160;&#160; bool&gt;       <br />{       <br />&#160;&#160;&#160; typedef       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; typename sort_permute_iter_helper_type&lt;       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; SortIter, PermuteIter&gt;::value_type T;       <br />&#160;&#160;&#160; bool operator()(const&#160; T&amp; t1, const T&amp; t2)       <br />&#160;&#160;&#160; {       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; return (boost::get&lt;0&gt;(t1) &lt; boost::get&lt;0&gt;(t2));       <br />&#160;&#160;&#160; }       <br />};       <br />      <br />template &lt;class SortIter, class PermuteIter&gt;       <br />sort_permute_iter&lt;SortIter, PermuteIter&gt;       <br />make_sort_permute_iter(SortIter ci, PermuteIter vi)       <br />{       <br />&#160;&#160;&#160; return sort_permute_iter&lt;SortIter, PermuteIter&gt;(ci, vi);       <br />}; </font></p>  <p><font face="courier new,monospace" size="1"><font face="arial,sans-serif" size="2">Finally, then, we can write the following sort routine for our two arrays and get the correct result:</font></font></p>  <p><font face="courier new,monospace" size="1">std::sort(make_sort_permute_iter(&amp;a1[0],&amp;v[0]),      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; make_sort_permute_iter(&amp;a1[0]+7,&amp;v[0]+7),       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; sort_permute_iter_compare());</font></p>  <p><font face="courier new,monospace" size="1"><font face="arial,sans-serif" size="2">Wow.&#160; That was a lot of work.&#160; I hope someone finds it useful.</font></font><font face="courier new,monospace" size="1"></font></p>]]>
      
   </content>
</entry>
<entry>
   <title>Paper of the Week</title>
   <link rel="alternate" type="text/html" href="http://www.stanford.edu/~dgleich/notebook/2006/03/paper_of_the_week.html" />
   <id>tag:www.stanford.edu,2006:/~dgleich/notebook//1.26</id>
   
   <published>2006-03-04T05:11:09Z</published>
   <updated>2008-11-09T05:11:50Z</updated>
   
   <summary><![CDATA[Quantum Computing as Geometry&#160; [http://www.sciencemag.org/cgi/content/full/311/5764/1133] This paper addresses an important aspect of quantum computing.&#160; The authors show that designing a quantum circuit is equivalent to minimizing the difference between two linear operators.&#160; Further, the &quot;cost&quot; of the circuit (in number...]]></summary>
   <author>
      <name></name>
      
   </author>
   
   
   <content type="html" xml:lang="en" xml:base="http://www.stanford.edu/~dgleich/notebook/">
      <![CDATA[<p>Quantum Computing as Geometry&#160; [<a href="http://www.sciencemag.org/cgi/content/full/311/5764/1133">http://www.sciencemag.org/cgi/content/full/311/5764/1133</a>]</p>  <p>This paper addresses an important aspect of quantum computing.&#160; The authors show that designing a quantum circuit is equivalent to minimizing the difference between two linear operators.&#160; Further, the &quot;cost&quot; of the circuit (in number of gates) is proportional to the minimum geodesic (shortest path) distance between the trivial operator and the desired quantum operator.</p>  <p>Intriguingly, the authors make the statement that we can use their results to find the initial point to begin a search for the quantum circuit; but (and this is an important but) we do not know the initial velocity along the shortest path.&#160; In all likelihood, this problem will be resolved in the future.&#160; Nevertheless, this statement harks to the uncertainty principle.&#160; Suppose a similar result is true for these Riemannian spaces?&#160; We cannot know both the initial search position and the initial velocity.&#160; Again, probably my na&#239;vet&#233;.</p>  <p>Still fantastically cool... enjoy reading!</p>]]>
      
   </content>
</entry>

</feed>
