Wednesday 28 November 2007

Sample from Gamma distribution in Java

Back to the Java struggles.
Today I am giving away a piece of Java code which allows one to sample a random variable from Gamma distribution.
import java.util.Random;

public class Samplers {
private static Random rng = new Random(
Calendar.getInstance().getTimeInMillis() +
Thread.currentThread().getId());

public static double sampleGamma(double k, double theta) {
boolean accept = false;
if (k < 1) {
// Weibull algorithm
double c = (1 / k);
double d = ((1 - k) * Math.pow(k, (k / (1 - k))));
double u, v, z, e, x;
do {
u = rng.nextDouble();
v = rng.nextDouble();
z = -Math.log(u);
e = -Math.log(v);
x = Math.pow(z, c);
if ((z + e) >= (d + x)) {
accept = true;
}
} while (!accept);
return (x * theta);
} else {
// Cheng's algorithm
double b = (k - Math.log(4));
double c = (k + Math.sqrt(2 * k - 1));
double lam = Math.sqrt(2 * k - 1);
double cheng = (1 + Math.log(4.5));
double u, v, x, y, z, r;
do {
u = rng.nextDouble();
v = rng.nextDouble();
y = ((1 / lam) * Math.log(v / (1 - v)));
x = (k * Math.exp(y));
z = (u * v * v);
r = (b + (c * y) - x);
if ((r >= ((4.5 * z) - cheng)) ||
(r >= Math.log(z))) {
accept = true;
}
} while (!accept);
return (x * theta);
}
}
}

Wednesday 21 November 2007

The last hope for working with Exchange

Following on the topics of using iCal with the Exchange server. AppleInsider published a very interesting comparison of iCal and Mail.app to the coming Entourage 2008.

The AppleInsider Article left me very upset, as it is evident that there will be no improvement to synchronisation with iCal. Hopefully Office will become much faster, as it will be compiled as a universal binary...

The only remaining hope is for Snerdware's GroupCal. Guys from AppleInsider got it wrong, as GroupCal is not yet working with Leopard. We have to wait a little, and hope that the developers from Snerdware solve their problems and release a new version soon.

Forget my complaints about the price. I will buy the new GroupCal on the first day it is released.

Thursday 8 November 2007

Boeing CalDAV proxy for Microsoft Exchange

I concluded the previous post with a rumor that Boeing have developed a CalDAV proxy for Microsoft Exchange. This was my last hope for using iCal with my work Exchange account.

Unfortunately, this is the dead end. I have found what this software is and why it will never give me the functionality I want.

First of all, Boeing have developed a Free-Busy connector for Exchange, not a complete CalDAV proxy. This is a web application (an ASP by the way) which takes someones e-mail as an input and returns their Free-Busy information in a format compatible with some CalDAV servers. I have tried using it with Bedework CalDAV server and I found it absolutely useless. This is a very good first attempt, but there are the following shortfalls:
  1. You need to run this special connector service, and you need to run it on a Windows machine.
  2. This initial implementation does not have any built-in security. It just accesses the Exchange server through one preconfigured account. You canot use different users for different requests
  3. This will only allow you to see whether john@example.com is free or busy from 9am to 10am, but would not let John know if you are busy.
  4. This example service in not available in the wild.


On the other hand, this is a good first step towards integration with Exchange. If the community demonstrates any interest, there will be someone to make further road.