public double variance()
{
if (variance_ == null) {
int N = samples();
if (!(N > 1)) throw new ApplicationException("sample number <=1, unsufficient");
// Subtract the mean and square. Repeat on the whole range.
// Hopefully, the whole thing will be inlined in a single loop.
double s2 = expectationValue(x => Math.Pow(x.Key * x.Value - mean(), 2), x => true).Key;
//compose(square<Real>(), std::bind2nd(std::minus<Real>(), mean())), () => true).Key;
variance_ = s2 * N / (N - 1.0);
}
return variance_.GetValueOrDefault();
}