tag:blogger.com,1999:blog-73791109607960141702024-03-06T00:31:32.443-05:00Clueless FundatmaA random walk through a subset of things I care about. Science, math, computing, higher education, open source software, economics, food etc.Sachin Shanbhaghttp://www.blogger.com/profile/08932887228149182854noreply@blogger.comBlogger807125tag:blogger.com,1999:blog-7379110960796014170.post-47487452871296656902024-02-22T07:47:00.005-05:002024-02-22T07:47:25.732-05:00Large PDFs with MatplotlibVector graphics (SVG/PDF) outputs of scatterplots with thousands of points lead to bloated files, unlike say raster formats like PNG. This makes scrolling PDF documents that include such bloated files a painful affair.<div><div><br /></div><div>The reason is fairly obvious: vector files scale with the number of data-points, while raster files scale with the number of pixels.<br /><div><br /></div><div><div>There are many potential solutions. The simplest is to rasterize only the large dataset of scatter points using the <b>rasterized=True</b> flag. Thus,</div></div></div></div><br /><span style="font-family: courier;"><b>plt.plot(x, y, 'o', alpha=0.1, rasterized=True)</b></span><br /><div><span style="font-family: courier;"><b><br /></b></span></div><div>The resulting PDF is much lighter.</div>Sachin Shanbhaghttp://www.blogger.com/profile/08932887228149182854noreply@blogger.com0tag:blogger.com,1999:blog-7379110960796014170.post-3351716186293902292023-09-08T14:11:00.001-04:002023-09-08T14:11:13.217-04:00Merging BibTeX bibliography files<p>Suppose you want to merge two bib files (f1.bib and f2.bib) that have considerable overlap. One easy solution using Jabref works as described below.</p><p>Suppose the target bibliography file without duplicates is merge.bib.</p><p>1. Copy f1.bib to merge.bib [cp f1.bib merge.bib]</p><p>2. Open merge.bib with Jabref</p><p>3. Then click File > Import into current database and select the other file [f2.bib]</p><p>4. You get a dialog box which allows you to manually decide what entries/versions you want to retain. If both f1.bib and f2.bib are of comparable quality, you can select "Deselect all duplicates" which automatically unselects duplicated entries.</p><p>5. Hit "OK" and save the modfied database [Ctrl-S]</p>Sachin Shanbhaghttp://www.blogger.com/profile/08932887228149182854noreply@blogger.com0tag:blogger.com,1999:blog-7379110960796014170.post-33403174229816572942023-07-09T11:47:00.001-04:002023-07-09T11:47:15.883-04:00Two useful Matplotlib utilities<p> 1. <a href="https://github.com/google/latexify_py">Latexify_py</a></p>latexify is a Python package to compile a fragment of Python source code to a corresponding expression.<div><br /></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjkvhaOt-w2nCi3Gg1-miCH7dG_M_x9tduaZpxEYSW5qBvWcVYjjbiCuRnOFxhXcfSXjjBIehNgcY1TB4OGE9HfM0r0BnTM2V9aXP4tYxHDY6hKRatXmuen1Uvj0def7QphVjD3h4hDZvvjVL2_KtTSrs4gGeEn1pHrHscawuPpMRZBN7TAHhjkTbsJZgx5/s637/example.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="183" data-original-width="637" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjkvhaOt-w2nCi3Gg1-miCH7dG_M_x9tduaZpxEYSW5qBvWcVYjjbiCuRnOFxhXcfSXjjBIehNgcY1TB4OGE9HfM0r0BnTM2V9aXP4tYxHDY6hKRatXmuen1Uvj0def7QphVjD3h4hDZvvjVL2_KtTSrs4gGeEn1pHrHscawuPpMRZBN7TAHhjkTbsJZgx5/s16000/example.jpg" /></a></div><br /><div><div><br /></div><div><div>2. <a href="https://pylustrator.readthedocs.io/en/latest/">Pylustrator</a></div></div></div><div><br /></div>Pylustrator offers an interactive interface to find the best way to present your data in a figure for publication. Added formatting an styling can be saved by automatically generated code. To compose multiple figures to panels, pylustrator can compose different subfigures to a single figure.<div><br /></div><div>See <a href="https://www.youtube.com/watch?v=xXPI4LLrNuM&t=134s">Youtube</a> demo.<br /><br /><div><br /></div></div>Sachin Shanbhaghttp://www.blogger.com/profile/08932887228149182854noreply@blogger.com0tag:blogger.com,1999:blog-7379110960796014170.post-41701638086843882642022-11-08T15:36:00.003-05:002022-11-08T15:36:25.711-05:00LaTeX to Word<p>Often I have a document in LaTeX, and somebody else needs an editable copy in Word. Here is a list of hacks I have learnt to use:</p><p>1. If the document is relatively free of math and figures then the simplest course is often to compile a PDF, and "import" the PDF into MS Word. This works out remarkably well in many cases.</p><p>2. The same thing above applies to figures. You can now directly drop PDF images into a Word doc.</p><p>3. If you have lots of equations, then it is worthwhile to use pandoc</p><p><span style="background-color: #f2f2f2; color: #292929; font-family: Menlo, Monaco, "Courier New", Courier, monospace; font-size: 16px; letter-spacing: -0.352px; white-space: pre-wrap;">pandoc mydoc.tex -o mydoc.docx</span></p><p>More <a href="https://medium.com/@zhelinchen91/how-to-convert-from-latex-to-ms-word-with-pandoc-f2045a762293">sophisticated options</a> to copy cross-references, and bibliography exist. See <a href="https://ja01.chem.buffalo.edu/tutorials/latex-pandoc-word.html">this</a> as well.</p><p>4. Many journals accept PDF figures. If they need TIFF, then you can use <a href="https://www.adobe.com/acrobat/online/pdf-to-jpg.html">Adobe Acrobat online</a> to do this conversion. In my experience, this produces smaller files compared to other automatic converters including ImageMagick.</p>Sachin Shanbhaghttp://www.blogger.com/profile/08932887228149182854noreply@blogger.com0tag:blogger.com,1999:blog-7379110960796014170.post-72826801058884636692022-08-17T08:15:00.005-04:002022-08-17T08:15:43.437-04:00Recursively Clean LaTeX Debris in all Sub-Folders<p> Often, I have a big folder like Lectures/ which may have sub-folders based on topics, and each topic might have additional folders. To clean auxillary LaTeX files in one fell swoop use,</p><p>find ./ \( -iname "*.bbl" -o -iname "*.aux" -o -iname "*.log" -o -iname "*.blg" -o -iname "*.nav" -o -iname "*.snm" -o -iname "*.toc" -o -iname "*.vrb" -o -iname "*.out" -o -iname "*.synctex.gz" -o -iname _minted*" \) -delete</p><p><br /></p>Sachin Shanbhaghttp://www.blogger.com/profile/08932887228149182854noreply@blogger.com0tag:blogger.com,1999:blog-7379110960796014170.post-39838722377318865992022-07-18T11:22:00.006-04:002022-07-18T11:22:48.646-04:00RegEx Help<p>This ML based regex generator is quite handy! </p><p>https://www.autoregex.xyz/home</p>Sachin Shanbhaghttp://www.blogger.com/profile/08932887228149182854noreply@blogger.com0tag:blogger.com,1999:blog-7379110960796014170.post-52737626684742031952022-06-22T14:30:00.000-04:002022-06-22T14:30:02.649-04:00Lectures on Graphical Models<p>Christopher Bishop has an excellent set (<a href="https://www.youtube.com/watch?v=ju1Grt2hdko" target="_blank">1</a>, <a href="https://www.youtube.com/watch?v=c0AWH5UFyOk">2</a>, and <a href="https://www.youtube.com/watch?v=QJSEQeH40hM">3</a>) of introductory lectures on "Probabilistic Graphical Models". They are well-motivated and cover topics that include:</p><p></p><ul style="text-align: left;"><li>directed and undirected graphs</li><li>conditional independence</li><li>factor graphs</li><li>inference using factor graphs and sum/product rules</li></ul><div><br /></div><p></p>Sachin Shanbhaghttp://www.blogger.com/profile/08932887228149182854noreply@blogger.com0tag:blogger.com,1999:blog-7379110960796014170.post-15630239559864803932022-03-22T10:21:00.001-04:002022-03-22T10:39:24.916-04:00QuickTip: Extracting pages from PDF on Linux<p>On a Mac OSX system, the default app Preview allows you to cut and paste pages from a PDF.</p><p>On Linux you can use <a href="https://pdfchain.sourceforge.io/">PDFChain</a> to manipulate PDFs. If you simply want to extract a certain range, then <a href="https://qpdf.sourceforge.io/">qpdf</a> is quite handy.</p><p>A CLI solution is to use ghostscript as described <a href="https://www.linuxjournal.com/content/tech-tip-extract-pages-pdf">here</a>:</p><p><span style="font-family: courier;">gs -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dSAFER \</span></p><p><span style="font-family: courier;"> -dFirstPage=1 -dLastPage=15 -sOutputFile=outfile.pdf inpfile.pdf</span></p><p>You can make the interface friendlier by saving a function in your bashrc as described in the article.</p><p><br /></p>Sachin Shanbhaghttp://www.blogger.com/profile/08932887228149182854noreply@blogger.com0tag:blogger.com,1999:blog-7379110960796014170.post-71807031473244765522021-04-02T15:01:00.005-04:002021-04-02T15:01:53.338-04:00Matplotlib: Lines Connecting Points and Boxes<p>This <a href="https://gist.github.com/shane5ul/bd7e12b6bc0c7a8915f11e638bef5195">gist</a> has python functions that help Matplotlib draw lines connecting points, and to draw boxes.</p><span style="font-family: courier;">def drawBox(xlim, ylim):<br /><span> </span>pts = [[xlim[0], ylim[0]], [xlim[1], ylim[0]], </span><div><span style="font-family: courier;"> [xlim[1], ylim[1]], [xlim[0], ylim[1]], </span></div><div><span style="font-family: courier;"> [xlim[0], ylim[0]]]<br /> <span> </span>x, y = zip(*pts)<br /> <span> </span>return x, y<br /> <br /> def connectPoints(pts):<br /><span> </span>x, y = zip(*pts)<br /> <span> </span>return x, y</span><br /></div>Sachin Shanbhaghttp://www.blogger.com/profile/08932887228149182854noreply@blogger.com0tag:blogger.com,1999:blog-7379110960796014170.post-16277539468516458122021-03-30T08:51:00.005-04:002021-03-30T08:51:59.812-04:00Quicktip: Batch convert LibreOffice documents to PDF<p>To convert all the DOCX files the current working directory to PDF</p><p><span style="font-family: courier;"> lowriter --headless --convert-to pdf *.docx</span></p><p>Similarly, to convert ODT files,</p><p><span style="font-family: courier;"> lowriter --headless --convert-to pdf *.docx</span></p>Sachin Shanbhaghttp://www.blogger.com/profile/08932887228149182854noreply@blogger.com0tag:blogger.com,1999:blog-7379110960796014170.post-91448086588383994082021-02-03T21:03:00.001-05:002021-02-03T21:03:02.836-05:00QuickTip: LaTeX multiline equations with explanations<p>Sometimes you want to write a sequence of steps, and write the explanation for each step next to it.</p><p><span style="font-family: courier;">abc = xyz </span><span style="font-family: inherit;">pythagoras rule</span></p><p><span style="font-family: courier;"> </span><span style="font-family: courier;">= uvw </span><span style="font-family: inherit;">triangle inequality</span></p><p><span style="font-family: courier;"> </span><span style="font-family: courier;">= ABC </span></p><div>It is easy to do this with the amsmath package as detailed in <a href="https://tex.stackexchange.com/questions/12621/multi-line-equations-with-explanations-on-some-lines">this StackOverflow question</a>.</div><div><pre class="lang-tex s-code-block hljs latex" style="border-radius: 5px; border: 0px; box-sizing: inherit; color: var(--highlight-color); font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; line-height: 1.30769; margin-bottom: calc(var(--s-prose-spacing) + 0.4em); margin-top: 0px; max-height: 600px; overflow-wrap: normal; overflow: auto; padding: 12px; vertical-align: baseline; width: auto;"><code style="border: 0px; box-sizing: inherit; font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: 19.5px; margin: 0px; padding: 0px; vertical-align: baseline; white-space: inherit;"><span class="hljs-keyword" style="border: 0px; box-sizing: inherit; color: var(--highlight-keyword); font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">\usepackage</span>{amsmath}
<span class="hljs-keyword" style="border: 0px; box-sizing: inherit; color: var(--highlight-keyword); font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">\begin</span>{align*}
abc <span class="hljs-built_in" style="border: 0px; box-sizing: inherit; color: var(--highlight-literal); font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">&</span>= xyz <span class="hljs-keyword" style="border: 0px; box-sizing: inherit; color: var(--highlight-keyword); font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">\\</span>
<span class="hljs-built_in" style="border: 0px; box-sizing: inherit; color: var(--highlight-literal); font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;"><span> </span>&</span>= uvw <span class="hljs-built_in" style="border: 0px; box-sizing: inherit; color: var(--highlight-literal); font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">&</span><span class="hljs-built_in" style="border: 0px; box-sizing: inherit; color: var(--highlight-literal); font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">&</span> <span class="hljs-keyword" style="border: 0px; box-sizing: inherit; color: var(--highlight-keyword); font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">\text</span>{pythagoras rule} <span class="hljs-keyword" style="border: 0px; box-sizing: inherit; color: var(--highlight-keyword); font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">\\</span>
<span class="hljs-built_in" style="border: 0px; box-sizing: inherit; color: var(--highlight-literal); font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;"><span> </span>&</span>= D <span> </span><span class="hljs-built_in" style="border: 0px; box-sizing: inherit; color: var(--highlight-literal); font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">&</span><span class="hljs-built_in" style="border: 0px; box-sizing: inherit; color: var(--highlight-literal); font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">&</span> <span class="hljs-keyword" style="border: 0px; box-sizing: inherit; color: var(--highlight-keyword); font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">\text</span>{triangle inequality} <span class="hljs-keyword" style="border: 0px; box-sizing: inherit; color: var(--highlight-keyword); font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">\\</span>
<span class="hljs-built_in" style="border: 0px; box-sizing: inherit; color: var(--highlight-literal); font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;"><span> </span>&= ABC </span><span class="hljs-built_in" style="border: 0px; box-sizing: inherit; color: var(--highlight-literal); font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">&</span><span class="hljs-built_in" style="border: 0px; box-sizing: inherit; color: var(--highlight-literal); font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">&</span>
<span class="hljs-keyword" style="border: 0px; box-sizing: inherit; color: var(--highlight-keyword); font-family: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">\end</span>{align*}</code></pre></div><div><br /></div><div><br /></div><p><span style="font-family: inherit;"><br /></span></p>Sachin Shanbhaghttp://www.blogger.com/profile/08932887228149182854noreply@blogger.com0tag:blogger.com,1999:blog-7379110960796014170.post-69781172687178489342020-12-07T16:29:00.001-05:002020-12-07T16:29:10.007-05:00Smooth Transition Between Functions<p> Stitching together two functions is sometimes required as a way to transition from one dependence to another. The following schematic describes the idea pictorially:</p><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgtM0Yk_Xgs0s81QfCgXFXk2_SlkxosU-_O4me6GdBPJOzEUa7qLZORrm_Y0M4rpN2ZmUDhbbzC4kGLmP0oFR0ikXX0GWDOmiIYjsSOUKxZeULuQPhl2aDb7koSCo2c4HXaWddRsCxPI1Ak/s917/School+Work-3.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="859" data-original-width="917" height="188" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgtM0Yk_Xgs0s81QfCgXFXk2_SlkxosU-_O4me6GdBPJOzEUa7qLZORrm_Y0M4rpN2ZmUDhbbzC4kGLmP0oFR0ikXX0GWDOmiIYjsSOUKxZeULuQPhl2aDb7koSCo2c4HXaWddRsCxPI1Ak/w200-h188/School+Work-3.jpg" width="200" /></a></div><div class="separator" style="clear: both; text-align: center;"><br /></div>Two different approaches are considered in this <a href="https://drive.google.com/file/d/1-6o3FvJaRSHLp3hFvUtG-Q7jhZmoEYTZ/view">PDF</a> (or this <a href="https://drive.google.com/file/d/1dSf-806icmN1GQf0E_0P3ukj3NTaCRwx/view?usp=sharing">Jupyter Notebook</a>).<br /><p><br /></p>Sachin Shanbhaghttp://www.blogger.com/profile/08932887228149182854noreply@blogger.com1tag:blogger.com,1999:blog-7379110960796014170.post-85025724313104495632020-10-26T07:40:00.001-04:002020-10-26T07:40:14.482-04:00Trapezoidal rule in log-log spaceConsider the problem described in this <a href="https://scicomp.stackexchange.com/questions/20901/integral-in-log-log-space">StackOverFlow post</a>. You have a function with certain smoothness properties that are apparent on a log-log plot. This is often accompanied by a large domain of integration. It seems worthwhile to "integrate in logspace", whatever that means. <div><br /></div><div>This <a href="https://gist.github.com/shane5ul/06d000b066636dbaf111187bb4264a2f" target="_blank">Jupyter notebook</a> probes this question and makes some recommendations.</div><div><div style="text-align: left;"><span style="background-color: white; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 14px; text-align: justify;"><br /></span></div></div>Sachin Shanbhaghttp://www.blogger.com/profile/08932887228149182854noreply@blogger.com0tag:blogger.com,1999:blog-7379110960796014170.post-61476771370416792672020-05-20T17:37:00.003-04:002020-05-20T17:37:21.446-04:00Quicktip: Reindent Python Scripts<div dir="ltr" style="text-align: left;" trbidi="on">
Suppose part of a python file uses spaces for indentation, while another part uses tabs. This will throw up exceptions at runtime. So the <a href="https://stackoverflow.com/questions/1024435/how-to-fix-python-indentation">question</a> is how to fix it.<br />
<br />
One answer is to use the python script <a href="https://svn.python.org/projects/python/trunk/Tools/scripts/reindent.py">reindent.py</a>. Stick it in some folder (~/bin/) in the default path and make it executable (<span style="font-family: Courier New, Courier, monospace;">chmod +x reindent.py</span>).<br />
<br />
The <a href="https://stackoverflow.com/questions/27031912/howto-use-reindent-py-for-dummies">usage</a> is straightforward:<br />
<br />
<span style="font-family: Courier New, Courier, monospace;">reindent -n file.py</span><br />
<br />
modifies the original file in place.</div>
Sachin Shanbhaghttp://www.blogger.com/profile/08932887228149182854noreply@blogger.com0tag:blogger.com,1999:blog-7379110960796014170.post-90371550082021180862020-05-17T21:54:00.004-04:002020-05-17T21:54:30.489-04:00Matplotlib: Saving TIFF and JPG formats<div dir="ltr" style="text-align: left;" trbidi="on">
With pillow installed, on my LinuxMint installation:<br />
<br />
import matplotlib<br />
matplotlib.use('TkAgg') # backend<br />
<br />
x = np.linspace(0,1)<br />
plt.plot(x, x**2)<br />
plt.savefig('test.tiff', dpi=300, fmt="tiff", pil_kwargs={"compression": "tiff_lzw"})<br />
<br />
<br /></div>
Sachin Shanbhaghttp://www.blogger.com/profile/08932887228149182854noreply@blogger.com0tag:blogger.com,1999:blog-7379110960796014170.post-59388185581350562862020-01-20T12:31:00.001-05:002020-01-20T12:31:15.246-05:00QuickTip: Catching array bounds violations in Fortran 90<div dir="ltr" style="text-align: left;" trbidi="on">
With gfortran, you can check <a href="https://jblevins.org/log/double-free">if array bounds are violated</a> during runtime by,<br />
<br />
gfortran -fbounds-check myProg.f90<br />
<br />
<br />
<div>
<br /></div>
</div>
Sachin Shanbhaghttp://www.blogger.com/profile/08932887228149182854noreply@blogger.com0tag:blogger.com,1999:blog-7379110960796014170.post-80024008685110694812019-10-18T16:36:00.002-04:002019-10-18T16:36:30.301-04:00LaTeX: Cross-referencing between Different Documents<div dir="ltr" style="text-align: left;" trbidi="on">
<b>Problem</b>: I have a manuscript TeX file (main.tex), and an independent supporting information file (si.tex). I was to cross-reference (using \label and \ref) items across the two files.<br />
<br />
For example, I might want to reference figure 1 from si.tex in main.tex.<br />
<br />
<b>Solution</b>: As this <a href="https://tex.stackexchange.com/questions/14364/cross-referencing-between-different-files">SO answer</a> suggests, the answer lies in the CTAN package <a href="https://ctan.org/pkg/xr?lang=en">xr</a>.<br />
<br />
In main.tex, just include "si.tex" as an external documents, and all its labels become visible!<br />
<br />
\usepackage{xr}<br />
\externaldocument{si}</div>
Sachin Shanbhaghttp://www.blogger.com/profile/08932887228149182854noreply@blogger.com0tag:blogger.com,1999:blog-7379110960796014170.post-90760016937449058702019-10-17T08:14:00.003-04:002019-10-17T08:14:59.636-04:00Parameter Uncertainty in Numpy Polyfit<div dir="ltr" style="text-align: left;" trbidi="on">
Say you want to fit a line to (x,y) data. With <a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.polyfit.html">polyfit</a>, you can say,<div>
<br /></div>
<div>
coeff = np.polyfit(x, y, 1)</div>
<div>
<br /></div>
<div>
With numpy 1.7 and greater, you can also <a href="https://stackoverflow.com/questions/27757732/find-uncertainty-from-polyfit">request the estimated covariance matrix</a>,</div>
<div>
<br /></div>
<div>
coeff, cov = np.polyfit(x, y, 1, cov=True)</div>
<div>
<br /></div>
<div>
The standard error on the parameters is the square-root of the diagonal elements</div>
<div>
<br /></div>
<div>
print(np.sqrt(np.diag(cov)))</div>
<div>
<br /></div>
<div>
This <a href="https://ipnpr.jpl.nasa.gov/progress_report/42-122/122E.pdf">report</a> referenced in the SO page is quite useful!</div>
</div>
Sachin Shanbhaghttp://www.blogger.com/profile/08932887228149182854noreply@blogger.com0tag:blogger.com,1999:blog-7379110960796014170.post-77838017970547897192019-09-30T17:17:00.000-04:002019-09-30T17:17:01.178-04:00Learning Gaussian Processes<div dir="ltr" style="text-align: left;" trbidi="on">
I've been studying up Gaussian process modeling for machine learning.<br />
<br />
For someone seeing these concepts for the first time, I would recommend the following sequence based on my experience:<br />
<br />
1. <a href="https://distill.pub/2019/visual-exploration-gaussian-processes/">A Visual Exploration of Gaussian Processes</a><br />
<br />
It hits the key points of what makes multinormal distributions special (conditionals and marginals are normal too!), and the visuals help build intuition.<br />
<br />
1a. <a href="https://katbailey.github.io/post/gaussian-processes-for-dummies/">Gaussian Processes for Dummies</a><br />
<br />
You might not need this, but I like this essay because it is jargon-free, and focuses on how to get things going. There is python code at the end, which you can play with.<br />
<br />
2. Chapter 2 of <a href="http://www.gaussianprocess.org/gpml/chapters/RW.pdf">Gaussian Process for Machine Learning</a><br />
<br />
This "bible" is astonishingly well-written. If you are familiar with linear algebra and some statistics, this is a breezy read. Plus, all the important formulae and algorithms you see in different articles, are available here in one place!<br />
<br />
3. If you like videos, then <a href="https://www.youtube.com/watch?v=R-NUdqxKjos">this YouTube lecture</a> might be worth watching!</div>
Sachin Shanbhaghttp://www.blogger.com/profile/08932887228149182854noreply@blogger.com0tag:blogger.com,1999:blog-7379110960796014170.post-9155472802232161762019-08-22T14:14:00.003-04:002019-08-22T14:14:42.405-04:00QuickTip: Toggling to Previous View in PDF Readers:<div dir="ltr" style="text-align: left;" trbidi="on">
I use Preview (on my Mac laptop) and Foxit Reader (on my Linux Desktop) to read PDFs.<br />
<br />
While reading papers, I often find myself clicking on links to citations. This takes me to the reference section. After looking up the citation, I like to go back to the previous location on the paper (right before clicking on the link).<br />
<br />
How to go back to the "previous view" isn't well documented.<br />
<br />
In Preview, the short cut is "Cmd + [" and "Cmd + ]".<br />
<br />
In Foxit Reader for Linux (v2.4 and above) the short cut is "Alt + Left Arrow" and "Alt + Right Arrow", respectively. </div>
Sachin Shanbhaghttp://www.blogger.com/profile/08932887228149182854noreply@blogger.com0tag:blogger.com,1999:blog-7379110960796014170.post-52778525490219188342019-07-05T08:38:00.001-04:002019-07-05T08:38:12.147-04:00QuickTip: Math Font in Matplotlib<div dir="ltr" style="text-align: left;" trbidi="on">
Matplotlib (v2 and higher) uses "<a href="https://matplotlib.org/users/mathtext.html#mathtext-tutorial">mathtext</a>" to render math by default. It is quite capable, but I don't like the default font, and prefer the classic "Computer Modern" font.<br />
<br />
You can fix this globally by modifying the rc file in your custom-style file (use the command matplotlib.get_configdir() to find location) by adding the line:<br />
<br />
mathtext.fontset : cm<br />
<br />
If you want to render all text using LaTeX (this slows down rendering somewhat), then use:<br />
<br />
text.usetex : true<br />
<br />
<br /></div>
Sachin Shanbhaghttp://www.blogger.com/profile/08932887228149182854noreply@blogger.com0tag:blogger.com,1999:blog-7379110960796014170.post-87013909302657913432019-07-03T09:15:00.000-04:002019-07-03T09:15:06.051-04:00Snip Math<div dir="ltr" style="text-align: left;" trbidi="on">
<a href="https://mathpix.com/">Mathpix Snip</a> looks like an amazing tool.<br />
<br />
You take a screenshot of some math and get it rendered in LaTeX.<br />
<br />
The process as illustrated on their website:<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgKv5F4veekyuh8OMZzbBpvhGcDNxG0KHBRv4Sk7GxnSXzIdok6CI_IJPlmPHIVw_N9meQrl-M_w6dJO8YsoXAr7o1c-vym5h24F5T_Wltl4EKm1p7Y43I3qzp_2dTkk-FYXCfJBtVcuUDO/s1600/mathpix.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="894" data-original-width="1100" height="259" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgKv5F4veekyuh8OMZzbBpvhGcDNxG0KHBRv4Sk7GxnSXzIdok6CI_IJPlmPHIVw_N9meQrl-M_w6dJO8YsoXAr7o1c-vym5h24F5T_Wltl4EKm1p7Y43I3qzp_2dTkk-FYXCfJBtVcuUDO/s320/mathpix.png" width="320" /></a></div>
<br />
<br />
It is available for download on all major OS.</div>
Sachin Shanbhaghttp://www.blogger.com/profile/08932887228149182854noreply@blogger.com0tag:blogger.com,1999:blog-7379110960796014170.post-76027596577521262462019-06-26T09:24:00.000-04:002019-06-26T09:24:00.440-04:00Zero and Infinity<div dir="ltr" style="text-align: left;" trbidi="on">
A triangle has three corners.<br />
<br />
A pentagon has five. A decagon has ten.<br />
<br />
As the number of corners becomes large, the polygon becomes more "circular".<br />
<br />
When the number of corners is <b>infinity</b>, the polygon is a circle - a shape with <b>zero</b> corners!</div>
Sachin Shanbhaghttp://www.blogger.com/profile/08932887228149182854noreply@blogger.com0tag:blogger.com,1999:blog-7379110960796014170.post-11215025451388029832019-06-19T09:21:00.002-04:002019-06-19T09:21:25.038-04:00Links<div dir="ltr" style="text-align: left;" trbidi="on">
1. <a href="https://www.albertbridgecapital.com/drew-views/2019/6/17/stay-in-the-game">Stay in the Game</a>: There is hope in humanity!<br />
<br />
2. Kevin Simler's graphical essay on <a href="https://meltingasphalt.com/interactive/going-critical/">going critical</a><br />
<br />
3. The <a href="http://news.mit.edu/2019/gil-strang-still-going-strong-online-and-print-0508?fbclid=IwAR07UwAs87CQfRFRTSli6ulwZnpXMvlhENmJfAF9qNmikOPSaZLgU99FQPA">force of Gilbert Strang</a><br />
<br />
4. Strogatz's "<a href="https://frankeprogram.yale.edu/event/steven-strogatz-lecture-april-26-2019">Beauty of Calculus</a>" Lecture</div>
Sachin Shanbhaghttp://www.blogger.com/profile/08932887228149182854noreply@blogger.com0tag:blogger.com,1999:blog-7379110960796014170.post-6315320305419852742019-06-18T09:22:00.001-04:002019-06-18T09:22:26.048-04:00QuickTip: Linux Convert Color PDF to GrayScale<div dir="ltr" style="text-align: left;" trbidi="on">
Using GhostScript (<a href="https://superuser.com/questions/104656/convert-a-pdf-to-greyscale-on-the-command-line-in-floss">source</a>). The first line sets name of output file ("output.pdf" here)<br />
<br />
<div class="post-text" itemprop="text" style="border: 0px; box-sizing: inherit; font-family: Arial, "Helvetica Neue", Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: 1.3; margin: 0px 0px 5px; overflow-wrap: break-word; padding: 0px; vertical-align: baseline; width: 675px;">
<pre style="background-color: #eff0f1; border-radius: 3px; border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin-bottom: 1em; max-height: 600px; overflow-wrap: normal; overflow: auto; padding: 12px 8px; vertical-align: baseline; width: auto;"><code style="border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline; white-space: inherit;">gs \
-sOutputFile=output.pdf \
-sDEVICE=pdfwrite \
-sColorConversionStrategy=Gray \
-dProcessColorModel=/DeviceGray \
-dCompatibilityLevel=1.4 \
-dNOPAUSE \
-dBATCH \
input.pdf
</code></pre>
</div>
<div class="grid mb0 fw-wrap ai-start jc-end gs8 gsy" style="align-items: flex-start !important; border: 0px; box-sizing: inherit; display: flex; flex-wrap: wrap !important; font-family: inherit; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; justify-content: flex-end !important; line-height: inherit; margin-bottom: 0px !important; margin-left: 0px; margin-right: 0px; margin-top: -4px; padding: 0px; vertical-align: baseline;">
<br /><time datetime="2010-07-17T22:33:15" itemprop="dateCreated" style="background-color: white; border: 0px; box-sizing: inherit; color: #242729; font-family: Arial, "Helvetica Neue", Helvetica, sans-serif; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;"></time><div class="grid--cell mr16" style="background-color: white; border: 0px; box-sizing: inherit; color: #242729; flex: 1 1 100px; font-family: Arial, "Helvetica Neue", Helvetica, sans-serif; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; line-height: inherit; margin: 4px 0px; padding: 0px; vertical-align: baseline;">
</div>
</div>
</div>
Sachin Shanbhaghttp://www.blogger.com/profile/08932887228149182854noreply@blogger.com0