These are miscellaneous notes and recipes.
2010-06-22
Calculation of Boltzmann factors in Google
A google search for (-6 kcal/mol) * -1 / (Avogadro constant)/ (Boltzmann constant) / (273.15 K + 42 K)) calculates the Boltzmann factor for a molecule being in a state with a free energy of -6 kcal / mol, at 42 degrees Celsius, 9.5805616.
2010-03-30
Logarithm of a sum of large numbers
When dealing with large numbers, it can be useful, as an approximation, not to deal with the numbers themselves, but with their logarithms. This has the added benefit that multiplication of two numbers corresponds to taking the sum of their logarithms. But what if you want to take the sum of the numbers,
and
, how can you avoid dealing with the possibly horrendously large numbers themselves? This problem is encountered for example when computing the total unnormalized probability (a Boltzmann factor or partition function) of mutually exclusive events. Here’s a way:
Presume that
,
, and
. If
you can always swap the two numbers.
.
If
is a very large negative number, then
.
For the logarithm of the difference of
and
, we would proceed similarly:
Presume that
,
, and
. These conditions are necessarily satisfied if
,
, and
can be calculated.
.
If
is a very large negative number, then
.
and
are called Gaussian logarithms, because Carl Friedrich Gauss was the first to publish printed tables of them.
2010-03-02
Newbie bug with C++ nested templates
Say, you want to create a map from stings to vectors of strings. Why does this (with the appropriate STL includes):
typedef std::vector<std::string> VectorOfStrings;
typedef std::map<std::string, VectorOfStrings> StringToVectorOfStrings;
work, while this doesn’t:
typedef std::map<std::string, std::vector<std::string>> StringToVectorOfStrings;
The latter works if you modify it a little bit, so that the consecutive >’s are not recognized as >>:
typedef std::map<std::string, std::vector<std::string> > StringToVectorOfStrings;
2009-10-15
Two IRC channels in different windows using EPIC IRC client
Start your IRC session like this:
/window new
/window show 1
/bind ^I parse_command {/window size 6} {/window last} {/window move 1}
Now you have two windows on top of each other, and you are doing things in the bottom one. You can switch between the windows by pressing tab.
The normal usage is to join on two different channels:
/join #firstchannel
Press tab.
/join #secondchannel
Whenever you want to view or talk on the other channel, press tab.
2009-09-12
Embedding a Java Applet in a WordPress 2.8.4 post
In the HTML editor:
<div id="dyemixer">APPLET HERE<script type="text/javascript">// <![CDATA[ document.getElementById('dyemixer').innerHTML = '<applet width="550" height="420" code="DyeMixer.class" archive="http://yehar.com/blog/wp-content/uploads/2009/09/DyeMixer.jar" alt="To use this applet, you need a Java virtual machine (Java plug-in) for your web browser.">'; // ]]></script></div>
This also survives editing the post in the visual editor. You can even center the applet like you would a normal paragraph. Note that the div’s id and the argument to getElementById must be identical. Using a similar JavaScript script, you should be able to put also other arbitrary HTML in a WordPress post or page.
2009-07-30
Generation of random numbers from a truncated exponential distribution
To generate a random number with a truncated exponential distribution:
- Generate a random number
from an exponential distribution with the rate parameter you want
- Calculate
modulo where-to-truncate. This would not be integer modulo but for example fmod() floating-point remainder.
Could be useful if you have exponentially distributed random numbers handy.
2002-11-25
Anti-imaged wavelet transform
This is an idea of a wavelet-type audio processing scheme, where you decompose the audio into octave bands, each octave sampled at half the sampling frequency compared to the one-up octave band. Then you process the bands in whatever way you wish, and reconstruct the signal from the bands. The benefit of the method compared to usual wavelets is the low level of imaging noise when bands are processed separately. The original music-dsp posting has the details:
http://aulos.calarts.edu/pipermail/music-dsp/2002-November/018600.html

The processing scheme ("/2" means decimation by 2, "*2" means dilution by zeros to 2x samplerate)

Frequency responses of filters that could be used in the scheme
2001-09-02
Frequency shifting (audio effect)
Frequency shifting can be an interesting audio effect, although it does not usually preserve harmonic relations. Here is how to do it the wrong and the right way:

Complex exponential modulation illustrated on z-plane unit circle

The ugly mixture. Complicated aliasing caused by discarding the imaginary part from a complex exponential modulated signal.

Anti-aliased frequency shifting illustrated on z-plane unit circle
2000-08-10
Daubechies wavelets 1-38 in a .h file
I copied some daubechies wavelets from a published database into this C header file, confirmed the data to be error-free and wrote a little introduction into wavelets in the comments.