gprof2dot is an excellent tool to plot valgrind/callgrind data

See the project page for more details. This post is to remind myself the name of this tool.

https://github.com/jrfonseca/gprof2dot

Advertisements

Smoldyn packages

Following is from website.

Smoldyn is a computer program for cell-scale biochemical simulations. It simulates each molecule of interest individually to capture natural stochasticity and to yield nanometer-scale spatial resolution. It treats other molecules implicitly, enabling it to simulate hundreds of thousands of molecules over several minutes of real time. Simulated molecules diffuse, react, are confined by surfaces, and bind to membranes much as they would in a real biological system.

Its packages for various linux flavors can be found here. Current version is 2.54. Please let me know if there is any problem with the package.

Why Python’s `random.choice` is bad when number of choices are smalls

Consider two snippets. Both pick 0 or 1 with equal probabilities.

a = random.choice([0,1])

Or,

a = 1 if random.random() < 0.5 else 0

Later is much faster roughly 10 times faster.

In [4]: %timeit random.choice([0,1])
834 ns ± 2.19 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)

In [5]: %timeit 1 if random.random() < 0.5 else 0
101 ns ± 0.25 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)

How about when choices are large. Writing so many if else are waste of time. One can use the following approximation.

a = int(random.random()*100)

For 100 choices, it will generate number between 0 and 100. Its performance is slightly better than choice.

In [15]: %timeit random.choice( range(100) )
1 µs ± 1.38 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)

In [16]: %timeit int(random.random()*100)
224 ns ± 1.23 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)

Surprise:

I thought if my choices are always in list; probably choice will be faster but I was wrong.

In [20]: choices = list(range(100))

In [21]: %timeit random.choice( choices )
752 ns ± 1.56 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)

More importantly, DO NOT do this.

In [17]: choices = range(100)

In [18]: %timeit random.choice( choices )
798 ns ± 6.09 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)

Color alternate row in latex table

The often mentioned solution is the following:

\usepackage[table]{xcolor} % loads also colortbl
\rowcolors{1}{gray!10}{white} % color rows with gray!10 then white and so on starting with row 1

This works when when it doesn’t it is not very straightforward to figure out why.

If you have run into ‘xcolor’ related issue something like xcolor is already loaded etc. etc., Then do the following: At the very top of document, even before \documentclass [2].

\PassOptionsToPackage{table}{xcolor}

And do not \usepackage[table]{xcolor}; and then somewhere in your document — before the table — use the rowcolors statement.

\rowcolors{1}{gray!10}{white}

The package xcolor is heavily used by many other packages and it is very likely that some of package you have loaded before are already using xcolor therefore this error.

References:

  1. https://tex.stackexchange.com/a/5365/8087
  2. https://tex.stackexchange.com/a/5375/8087 (see comment by Bertram)

Sampling uniformly on unit simplex

The script is available here https://github.com/dilawar/Scripts/blob/master/simplex_generate.py

sage: simplex_generate.py [-h] [--dimension DIMENSION] [--number NUMBER]
[--output OUTPUT] [--method METHOD]
Generate x1,x2,...,xk such that sum(x1,x2,...,xk)=1

optional arguments:
-h, --help show this help message and exit
--dimension DIMENSION, -d DIMENSION
Dimention of vector (default 3)
--number NUMBER, -N NUMBER
Total number of vectors to generate (-1 for infinity).
--output OUTPUT, -o OUTPUT
Output file
--method METHOD, -m METHOD
Method (uniform sampling|TODO)

It writes the sampled numbers to stdout. By default, it samples from 3d space.