Renke's blog

A blog.

Monaco Font in Sublime Text 3 on Linux Using Xfce

To make Monaco look good in Sublime Text 3 I came up with the following font configuration:

<?xml version='1.0'?>
<!DOCTYPE fontconfig SYSTEM 'fonts.dtd'>
<fontconfig>
 <match target="font">
  <edit mode="assign" name="rgba">
   <const>rgb</const>
  </edit>

  <edit mode="assign" name="hinting">
   <bool>false</bool>
  </edit>

  <edit mode="assign" name="hintstyle">
   <const>hintnone</const>
  </edit>

  <edit mode="assign" name="antialias">
   <bool>true</bool>
  </edit>

  <edit mode="assign" name="lcdfilter">
    <const>lcddefault</const>
  </edit>
 </match>
</fontconfig>

Paste this into the file ~/.config/fontconfig/fonts.conf and restart Sublime Text. Here is the result:

Monaco in Sublime Text 3

XCompose in Sublime Text and Other Applications

Since I am using the QWERTY keyboard layout (plus some small personal modifications) I am not able to type characters like ä, ö, ü or ß directly when writing text in German. To solve this problem I use the ~/.XCompose to compose the desired characters: e.g. pressing the compose key followed by “ue” becomes “ü” or “lambda” becomes “λ”. See my XCompose file for more combinations.

Now the problem with XCompose is that some application don’t recognize those combinations. Most prominently Sublime Text 3 failed to recognize them for me. But I’ve also seen other applications failing such as the XFCE file manager Thunar when renaming files.

While I can tolerate Thunar failing in a situation where I seldomly need special characters like umlauts I definitely require it to work in my text editor of choice. Trying to solve the problem I finally found this in the Sublime Text forum.

Just add the following to your “.profile” (or wherever you store your environment variables settings) export GTK_IM_MODULE=uim-scim and all combinations of your XCompose file should work in most (GTK?) applications. You may need to install the scim package in your distribution to make this work.

APT – Analysis of Petri Nets and Labeled Transition Systems

APT

We released our software APT (not to be confused with this APT) as free software (GPLv2 or later) over at GitHub. APT is project that was created by a group of computer science master students at the Carl von Ossietzky University of Oldenburg over the course of 2 semesters.

APT offers a collection of algorithms that work with Petri nets and labelled transition systems combined in an unified command-line interface. APT runs on all major operating systems including Linux, Mac OS X and Windows (anything that runs Java 1.7 really).

Check out the README to get further information.

Python Plot #2

The 68-95-99.7 rule states that for a normal distribution about 68%, 95% and 99.7% of the values lie within 1, 2 and 3 standard deviation of the mean. The plot in the Wikipedia article illustrates the rule quite nicely. I tried to create a similar plot with Python and matplotlib using the normal distribution with a mean of 0 and a variance of 2.

Illustration of the three-sigma rule

The Python code to create the plot is attached below. The only thing that annoys me about it (beside the fact that some things are hard-coded in a way) is that I had to pick colors for the curve and areas myself. The plot from Wikipedia (created in R) uses a library to do that. I guess I have to search for something similar that works in Python for the upcomming plots.

Illustration of the three-sigma rule (002-three-sigma-rule.py) download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import math
import matplotlib.pyplot as plt
import numpy

LINE_WIDTH = 3

MEAN = 0 # Don't change this since we assume a mean of 0
VAR = 2
SD = math.sqrt(VAR)

# In standard deviations
FROM_X = -4 # 
TO_X = 4

NUMBER_OF_SAMPLES = 1000 # The more samples the smoother :)

def pdf(x, mean, var):
  """Probability density function of the Normal distribution"""
  sd = math.sqrt(var)
  return 1 / (sd * (math.sqrt(2 * math.pi))) * (math.e ** -(((x - mean) ** 2) / (2 * var)))

# Highlight the x- and y-axis
plt.axvline(color=(0.75,0.75,0.75), linewidth=1)
plt.axhline(color=(0.75,0.75,0.75), linewidth=1)

# Take NUMBER_OF_SAMPLES numbers evenly from [FROM_X, TO_X]
xs = numpy.linspace(FROM_X * SD , TO_X * SD, NUMBER_OF_SAMPLES)
ys = [pdf(x, MEAN, VAR) for x in xs]
plt.plot(xs, ys, linewidth=LINE_WIDTH, color="Blue")

# Fill area under curver where x lies within some standard deviations of the mean
plt.fill_between(xs, 0, ys, where=numpy.logical_and(xs > 3 * -SD, xs < 3 * SD), color="LightSteelBlue")
plt.fill_between(xs, 0, ys, where=numpy.logical_and(xs > 2 * -SD, xs < 2 * SD), color="CornflowerBlue")
plt.fill_between(xs, 0, ys, where=numpy.logical_and(xs > -SD, xs < SD), color="RoyalBlue")

x_text = SD - SD / 2
y_text = pdf(x_text, MEAN, VAR) / 2

plt.text(x_text, y_text, "%.1f%%" % (68 / 2.0,), fontsize=14, ha="center")
plt.text(-x_text, y_text, "%.1f%%" % (68 / 2.0,), fontsize=14, ha="center")

# The used factors are basically arbitrary and used to position the text
x_text = 2 * SD - SD / 2
y_text = pdf(x_text, MEAN, VAR) / 4

plt.text(x_text, y_text, "%.1f%%" % ((95 - 68) / 2.0,), fontsize=14, ha="center")
plt.text(-x_text, y_text, "%.1f%%" % ((95 - 68) / 2.0,), fontsize=14, ha="center")

x_point = 3 * SD - SD / 2
y_point = pdf(x_point, MEAN, VAR) * 1.25

x_text = 3 * SD - SD / 2
y_text = pdf(x_text, MEAN, VAR) * 3

# The height of the area between the third and second standard deviation is too small
# We are use an arrow pointing to that area instead
text = "%.2f%%" % ((99.7 - 95) / 2.0,)
plt.annotate(text, (x_point, y_point), (x_text, y_text),
             ha="left", fontsize=14, arrowprops=dict(arrowstyle='-'), )

plt.annotate(text, (-x_point, y_point), (-x_text, y_text),
             ha="right", fontsize=14, arrowprops=dict(arrowstyle='-'), )

# Configure the x-axis size
plt.xlim((FROM_X, TO_X))

# Configure the y-axis size to capture the height of the curve
plt.ylim((-0.025, pdf(MEAN, MEAN, VAR) + 0.05))

# Configure the x-axis labels
xticks_locs = [SD * i for i in range(FROM_X, TO_X + 1)]

# Show the x values in numbers of standard deviation counted from the mean
xticks_labels = ["$%i\sigma$" % i if i != MEAN else "$\mu$ " for i in range(FROM_X, TO_X + 1)]

plt.xticks(xticks_locs, xticks_labels)

plt.title("The normal distribution $\mathcal{N}(%i, %i)$" % (MEAN, VAR))
plt.grid() # Toggle the axes grid

plt.gcf().set_size_inches(10, 6)
plt.savefig('002-three-sigma-rule.png',dpi=100)
plt.show() # Show the actual plot

Python Plot #1

A plot of the probability density function of the normal distribution with different means and variances created with Python and matplotlib. The green curve is the well-known standard normal distribution. The plot tries to mimic this plot from Wikpedia.

Probability densitity function of the normal distribution

I am quite pleased with the result but I don’t like that the parameters in the legend are not aligned on the σ like in the Wikipedia plot. Anyway, here is the Python code to produce the above plot.

Probability densitity function of the normal distribution (001-normal-distribution.py) download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import math
import matplotlib.pyplot as plt
import numpy

LINE_WIDTH = 3

FROM_X = -6
TO_X = 6

NUMBER_OF_SAMPLES = 1000 # The more samples the smoother :)

def pdf(x, mean, var):
  """Probability density function of the Normal distribution"""
  sd = math.sqrt(var)
  return 1 / (sd * (math.sqrt(2 * math.pi))) * (math.e ** -(((x - mean) ** 2) / (2 * var)))

def plot(mean, var):
  """Plot the probability density function of the Normal distribution for the given mean and variance"""
 # Take NUMBER_OF_SAMPLES numbers evenly from [FROM_X, TO_X]
  xs = numpy.linspace(FROM_X, TO_X, NUMBER_OF_SAMPLES)
  ys = [pdf(x, mean, var) for x in xs]

  # Show what mean and variance were used for this plot
  label = r"$\mu = %.1f,\, \sigma^2 = %.1f$" % (mean, var)

  plt.plot(xs, ys, label=label, linewidth=LINE_WIDTH)

# Plot the curves with different means and variances
plot(0, 0.2)
plot(0, 1)
plot(0, 5)
plot(-2, 0.5)

# Configure the x-axis size
plt.xlim((FROM_X, TO_X))

# Configure the y-axis size
plt.ylim((-0.1, 1.1)) # Extend the y axis a bit to the top and bottom

# Configure the x-axis labels
plt.xticks(range(FROM_X + 1, TO_X)) # 1 tick for each integer in [FROM_X - 1, TO_X + 1]

# Configure the y-axis labels to show values of [0, 1] with step size 0.1
plt.yticks([i * 0.1 for i in xrange(11)])

plt.grid() # Toggle the axes grid
plt.legend() # Show a legend
plt.show() # Show the actual plot

Inline Math in Ledger

I just noticed that Ledger supports inline math expressions. This is useful when you have a split transaction like in the following example where I have a receipt from a visit to a local grocery store.

Receipt

Only two items on the list (Weichspüler and Schampoo) belong to the account Expenses:Hygenie while the rest belongs to Expenses:Food.

Now for me the best way to split transaction is to use the sum as a negative amount for the account Assets:Cash (or the like) and compute the amount for either Expenses:Hygenie or Expenses:Food since Ledger will choose an appropriate amount to balance the transaction to zero for me.

To actually compute the amount I chose the account Expenses:Hygenie having only two items to consider. Instead of summing the amounts 0.99 EUR and 1.99 EUR to 2.98 EUR we can use Ledger’s inline math capabilities to make it clear that the amount stems from two individual items. The result is the following transaction.

2013/01/11 Grocery Store XY
  Expenses:Food
  Expenses:Hygiene  (0.99 EUR + 1.99 EUR)
  Assets:Cash  -15.19 EUR

I couldn’t find any hints regarding inline math expressions in the manual but Ledger seems to support the usual operators: +, -, / and *.

Update: I found the relevant section in the manual. It doesn’t contain that much information though.