Poisson Log-Normal Distributed Random Numbers

This post has moved to eklausmeier.goip.de/blog/2021/02-09-poisson-log-normal-distributed-random-numbers.

Task at hand: Generate random numbers which follow a lognormal distribution, but this drawing is governed by a Poisson distribution. I.e., the Poisson distribution governs how many lognormal random values are drawn. Input to the program are \lambda of the Poisson distribution, modal value and either 95% or 99% percentile of the lognormal distribution.

From Wikipedia’s entry on Log-normal distribution we find the formula for the quantile q for the p-percentage of the percentile (0<p<1), given mean \mu and standard deviation \sigma:

q = \exp\left( \mu + \sqrt{2}\,\sigma\, \hbox{erf}^{-1}(2p-1)\right)

and the modal value m as

m = \exp\left( \mu - \sigma^2 \right).

So if q and m are given, we can compute \mu and \sigma:

\mu = \log m + \sigma^2,

and \sigma is the solution of the quadratic equation:

\log q = \log m + \sigma^2 + \sqrt{2}\,\sigma\, \hbox{erf}^{-1}(2p-1),

hence

\sigma_{1/2} = -{\sqrt{2}\over2}\, \hbox{erf}^{-1}(2p-1) \pm\sqrt{ {1\over2}\left(\hbox{erf}^{-1}(2p-1)\right)^2 - \log(m/q) },

or more simple

\sigma_{1/2} = -R/2 \pm \sqrt{R^2/4 - \log(m/q) },

with

R = \sqrt{2}\,\hbox{erf}^{-1}(2p-1).

For quantiles 95% and 99% one gets R as 1.64485362695147 and 2.32634787404084 respectively. For computing the inverse error function I used erfinv.c from lakshayg.

Actual generation of random numbers according Poisson- and lognormal-distribution is done using GSL. My program is here: gslSoris.c.

Poisson distribution looks like this (from GSL documentation):
Poisson distribution

Lognormal distribution looks like this (from GSL):
Lognormal distribution

Set-Up Hiawatha Web-Server

This post has moved to eklausmeier.goip.de/blog/2018/03-06-set-up-hiawatha-web-server.

I stumbled upon Hiawatha web-server when I read about a web-server for a houseboat by Ronald Scheckelhoff, WB8LZR. I had used Apache, thttpd, Lighttp, NGINX, and others before. Now I use Hiawatha web-server.

Hiawatha has three objectives, which are nicely met:

  1. Security: Hiawatha resisted Heartbleed and Slowloris attacks
  2. Ease of use: use the man-pages for configuring the web-server, no extensive Googling
  3. Lightweight on resources

Also see Hiawatha – the best webserver you’ve never heard of, or see Why I use Hiawatha Webserver.

The following diagram shows the number of source code lines using

wc `find . -iname \*.c -o -iname \*.h -o -iname \*akefile\* `

for each web-server.

Below configuration mostly follows the example configuration and provides Perl and PHP as CGI:

ServerId = http
ConnectionsTotal = 1000
ConnectionsPerIP = 25
SystemLogfile = /var/log/hiawatha/system.log
GarbageLogfile = /var/log/hiawatha/garbage.log

Binding {
        Port = 80
        MaxRequestSize = 1572864
        MaxUploadSize = 2047
        TimeForRequest = 90,180
}

CGIhandler = /usr/bin/perl:pl
CGIhandler = /usr/bin/php-cgi:php

Directory {
        DirectoryID = DownloadArea
        Path = /Download
        ShowIndex = yes
}

Directory {
        DirectoryID = WebPresence
        Path = /
        ExecuteCGI = yes
}

Hostname = 127.0.0.1
WebsiteRoot = /srv/http

VirtualHost {
        Hostname = www.eklausmeier.tk, eklausmeier.tk, 192.168.178.24, klm.no-ip.org, klm.ddns.net, edh.no-ip.org, edh.ddns.net, klmport.no-ip.org, borussia.no-ip.org
        WebsiteRoot = /srv/http
        FollowSymlinks = yes
        UseDirectory = WebPresence, DownloadArea
}

So I have a directory where Hiawatha shows a graphical representation of some files I can download. And it has an ordinary directory where I serve HTML and PHP files. I had to change MaxRequestSize and MaxUploadSize as I sometimes upload large chunks of data.

Since the 2014 Microsoft shotgun attack on No-IP.org I have many different DNS names to better withstand this vandalism.

Enabling GD for PHP is described here: php-gd — just uncomment extension=gd.

On Differential Forms

This post has moved to eklausmeier.goip.de/blog/2015/03-15-on-differential-forms-2.

Abstract. This article will give a very simple definition of k-forms or differential forms. It just requires basic knowledge about matrices and determinants. Furthermore a very simple proof will be given for the proposition that the double outer differentiation of k-forms vanishes.

MSC 2010: 58A10

1. Basic definitions.

We denote the submatrix of A=(a_{ij})\in R^{m\times n} consisting of the rows i_1,\ldots,i_k and the columns j_1,\ldots,j_k with

\displaystyle{         [A]{\textstyle\!{\scriptstyle j_1\atop\scriptstyle i_1}         \!{\scriptstyle\ldots\atop\scriptstyle\ldots}         \!{\scriptstyle j_k\atop\scriptstyle i_k}} := \begin{pmatrix}                 a_{i_1j_1} & \ldots & a_{i_1j_k}\\                 \vdots     & \ddots & \vdots\\                 a_{i_kj_1} & \ldots & a_{i_kj_k}\\         \end{pmatrix} }

Continue reading

Re-installing Grub when MS Windows Destroyed It

This post has moved to eklausmeier.goip.de/blog/2013/09-29-re-installing-grub-when-ms-windows-destroyed-it.

I have now done it a couple of times, but always have to look it up. Here are the steps to re-install Grub from a live Ubuntu CD, when you have Windows and Linux on your hard disk. You must be root, or run these commands with sudo. Change /dev/sdaXY accordingly.

  1. mount /dev/sda2 /mnt
  2. mount /dev/sda3 /mnt/boot, if you have a separate boot partition
  3. mount -o bind /dev /mnt/dev
  4. mount -o bind /sys /mnt/sys
  5. mount -t proc /proc /mnt/proc
  6. chroot /mnt /bin/bash
  7. grub-install /dev/sda

Above commands are from method 3 in GRUB (in German).

inotify-tools: inotifywait

This post has moved to eklausmeier.goip.de/blog/2013/01-29-inotify-tools-inotifywait.

I wanted to see what files and when J-Pilot accesses its pdb and pc3 files. In my case strace produces much more output than actually needed. But inotifywait shows what and when files are accessed.

inotifywait -m .jpilot/

Continue reading

On Differential Forms

This post has moved to eklausmeier.goip.de/blog/2013/01-10-on-differential-forms.

A couple of years ago I went through Otto Forster’s Analysis 3 book for self study of differential forms. I thought the presentation could be leaned more towards matrices and determinants, which since Bourbaki’s time got a difficult stand in mathematics.

Here is the document: On Differential Forms.

See same text in blog format: On Differential Forms.