1 | initial version |
First off, the var('x')
is not useful; the lambda functions will ignore that, I think.
Secondly, your first syntax was right; entropy was a property of the whole probability space. There isn't any room in the syntax for your variable, though, so this isn't possible in exactly this way.
Is this sufficient?
sage: S=[-1,0,1]
sage: P = [(1,lambda x:x)]
sage: P.append((0,lambda x:1.-2.*x))
sage: P.append((-1,lambda x:x))
sage: Sp = lambda x: DiscreteProbabilitySpace(S,dict([(a,b(x)) for (a,b) in P ]))
sage: Sp(0)
Discrete probability space defined by {0: 1.00000000000000, 1: 0, -1: 0}
sage: Sp(0).entropy()
0.000000000000000
sage: Sp(.5).entropy()
1.00000000000000
sage: Sp(.3).entropy()
1.57095059445467
I assume that this one doesn't make sense since it's not actually a probability distribution - maybe we should look for that in this code...
sage: Sp(1).entropy()
4.53236014182719*I