e.g. I might have sample counts and corresponding population counts and
want to sum over the ratios where the population frequency is non-zero.
e.g. Using Python syntax; assume the sample and population counts are in
the lists f and F respectively,
res = sum([f[i] / F[i] for i in range(len(F)) if F[i]!=0])
I'm just seeking a clean mathematical notation for this. Also, in some
cases I want e.g. the number of sample counts equal to 2,
res = sum([1 for freq in f if freq==2])
At the moment I'm using a form of syntax I've seen before. But I'm
beginning to think it might be an abuse of the indicator function. e.g.
for the first example,
sum from {i} {f_i over F_i} I(F_i <> 0)
I'd be grateful for any hints. TIA.
Duncan
This is discussed by Knuth in the Amer. Math. Monthly article cited
here:
http://en.wikipedia.org/wiki/Iverson_bracket
> Hello,
> Just looking for some advice on notation when I'm summing over elements
> subject to a condition.
>
> e.g. I might have sample counts and corresponding population counts and
> want to sum over the ratios where the population frequency is non-zero.
> e.g. Using Python syntax; assume the sample and population counts are in
> the lists f and F respectively,
>
> res = sum([f[i] / F[i] for i in range(len(F)) if F[i]!=0])
>
sum(i in range(len F) & F(i) /= 0) f(i)/F(i)
sum[i in range(len F) & F(i) /= 0] f(i)/F(i)
> I'm just seeking a clean mathematical notation for this. Also, in some
> cases I want e.g. the number of sample counts equal to 2,
>
> res = sum([1 for freq in f if freq==2])
>
= 1 if freq = 2 in f
= 0 otherwise
> At the moment I'm using a form of syntax I've seen before. But I'm
> beginning to think it might be an abuse of the indicator function. e.g.
> for the first example,
>
> sum from {i} {f_i over F_i} I(F_i <> 0)
>
Is that an infinite sum?
No, a sum over a finite number of categories indexed i = 1, ..., N. I
forgot to make that clear. It looks like I might go with Knuth's
notation suggested by Butch, which isn't that far from what I was using.
The idea of "strong" zeroes also gets round the issue of division by
zero. e.g. (0/0)[false] = 0. Thus the 2 examples become (in OpenOffice
syntax),
sum from {i} {f_i over F_i} [F_i <> 0]
sum from {i} [f_i = 2]
Thanks.
Duncan
Excellent! I thought there must be a neat way of doing it. Love the
strong zeroes.
Duncan