Showing posts with label Programming. Show all posts
Showing posts with label Programming. Show all posts
Wednesday, April 24, 2013
Generating n-Dimensional Lattice Coordinates
It comes up sometimes in my research that I need to generate coordinates along a lattice. For example, when generating an initial structure for a molecular dynamics simulation. I thought I share my code for this. The code works by recursively enumerating each dimension in a lattice and calling a given function each time it reaches a point. So, it could be used to execute any function along a lattice. Here's what it looks like for a 2D and 3D example. In the 3D example I didn't choose a cubic number of points on the lattice, so that it sort of stops in the middle.
Friday, April 12, 2013
Approximate Restricted Integer Partition With Exact Part Number
I'm interested in a certain type of mathematical structure this week: integer partitions. An integer partition,
p(n)
, is the set of sets of integers that add up to n
. For example,p(3) = 1 + 1 + 1, 1 + 2, 3
p(4) = 1 + 1 + 1 + 1, 1 + 1 + 2, 2 + 2, ...
Thursday, April 11, 2013
Speeding up R
I've been programming in R for a while now. Whenever I've had performance problems, it almost always is due to
data.frame
usage. To check what's slowing down your R code, just use the Rprof
command like so:Thursday, February 28, 2013
Markov Chains in JS — Part 1
I'm in the process of writing a new post or two on working with Markov Chains in javascrtipt. I created the javascript files already and I've decided to post them below for now. I'll write up more about it and hopefully use the code for something interesting in a future post. See below for the javascript Markov Chain Simulator! See the code here.
Saturday, December 29, 2012
Recovering Android Photos with Linux
As noticed by others on the Internet, it is possible to recover photos from an Android phone that were deleted. It is impossible, as far as I know, to recover the full resolution photos. You may, however, recover the thumbnails and those are often large. This also allows you to recover photos which weren't saved, like those from text messages. The problem though is that methods I found while googling require you to edit the image files in a hex editor. For example, as demonstrated in this video. I've instead written a python script which automates this greatly simplifying the fact that you need to recover all the pictures to find one in particular.
Thursday, August 23, 2012
A server job dispatcher using SQL in C
OK, imagine this: you would like to execute some jobs on your server,
but you don't want a fancy job dispatcher. You just want to put some
parameters into a SQL table and have the table updated when the job is
done. Perhaps you have trouble imagining that. However, that was my
fantasy while writing a webapp in codeigniter, a lovely php
framework. I had some statistics to calculate and I didn't want to
calculate them in codeigniter, so I wrote some R scripts. The scripts
are time consuming, so you can't just call them from the server
process. If you do, the webpage will stop loading and wait for the
scripts to finish. Well, just run them in the background and update
the page with javascript when the scripts are finished, right? Not if
there are one hundred people using the server at once. You need to control
the number of simultaneous jobs. Hence the need for a job dispatcher.
Friday, July 15, 2011
Latex to PNG to Blogger
I just wanted to put at the top what you need to follow along with this post. Everything below is written assuming you're using a Unix terminal and you have pdflatex and imagemagick installed. For Ubunu, the de facto linux distribution, type this into your terminal window to get these programs:
Due to my failure in making nice looking equations in my last posts, I worked on discovering a solution. Naturally, I tried to google Latex and Blogger. Latex is what I usually use for formatting equations, so that is what I was hoping to find. Unfortunately, most of the ideas I found for inserting equations into Blogger relied on hosted scripts and random people providing image hosting. I tried two solutions described in blogs and both didn't work, due to the site hosting the rendering engine being down. If you would like to convert LaTeX code directly into PNGs on the web, you can try codecogs, but I find the website to appear pretty Spammy and you cannot have very much control over your results. But, hey, it works.
Next idea: use Latex to write equations, use pdflatex to turn them into PDFs, and then use ImageMagick to convert the PDFs into PNGs. Easy, right? Well, here are the results:
sudo apt-get install imagemagick sudo apt-get install pdflatex
Due to my failure in making nice looking equations in my last posts, I worked on discovering a solution. Naturally, I tried to google Latex and Blogger. Latex is what I usually use for formatting equations, so that is what I was hoping to find. Unfortunately, most of the ideas I found for inserting equations into Blogger relied on hosted scripts and random people providing image hosting. I tried two solutions described in blogs and both didn't work, due to the site hosting the rendering engine being down. If you would like to convert LaTeX code directly into PNGs on the web, you can try codecogs, but I find the website to appear pretty Spammy and you cannot have very much control over your results. But, hey, it works.
Next idea: use Latex to write equations, use pdflatex to turn them into PDFs, and then use ImageMagick to convert the PDFs into PNGs. Easy, right? Well, here are the results:
Thursday, July 14, 2011
Predator-Prey Models and Global Warming Followup
I thought I'd follow up my last post with some information on some of the tools I used. I'm not going to talk about how I made the equations, because they came out terrible and I'm trying to come up with a new way. I guess if anyone is curious: I made them in LaTeX and used gimp to convert them to PNGs.
Ok, so let's see how I made the graphics. Here's the first graphic, in case anyone forgot.
Ok, so let's see how I made the graphics. Here's the first graphic, in case anyone forgot.
Subscribe to:
Posts (Atom)