mcmtroffaes / improb

A Python module for working with imprecise probabilities.
http://packages.python.org/improb/
GNU General Public License v2.0
10 stars 3 forks source link

empty Prob (other classes as well?) not digested cleanly #4

Closed equaeghe closed 13 years ago

equaeghe commented 13 years ago

I'm not exactly sure whether this is an issue or a "we can't deal with every stupid corner case"; anyhow:

prob = Prob(PSpace('abc'), number_type='fraction')

print(prob)

Traceback (most recent call last): File "", line 1, in File "improb/lowprev/prob.py", line 49, in str [self[{omega: 1}, True][0] for omega in self.pspace])) File "improb/lowprev/lowpoly.py", line 278, in getitem return self._mapping[self._make_key(key)] KeyError: (Gamble(pspace=PSpace(['a', 'b', 'c']), mapping={'a': 1, 'b': 0, 'c': 0}), Event(pspace=PSpace(['a', 'b', 'c']), elements=set(['a', 'c', 'b'])))

prob.extend()

Traceback (most recent call last): File "", line 1, in File "improb/lowprev/lowprob.py", line 208, in extend algorithm=algorithm) File "improb/lowprev/lowpoly.py", line 736, in extend lprev, uprev = self[gamble, event] File "improb/lowprev/lowpoly.py", line 278, in getitem return self._mapping[self._make_key(key)] File "improb/lowprev/linvac.py", line 57, in _make_key raise ValueError('not a singleton') ValueError: not a singleton

mcmtroffaes commented 13 years ago

Currently, a Prob is taken to be a LowProb defined on singletons, and whose natural extension is calculated via expectation.

So:

In other words, with the current design, this is expected behaviour. I've updated the documentation to make this more clear:

https://github.com/mcmtroffaes/improb/commit/0a23d7cc8df9bd85056fd09d26e5ecb39ddfb7a7

Suggestions?

mcmtroffaes commented 13 years ago

I've just done another commit which I think addresses the extend problems in an elegant way:

https://github.com/mcmtroffaes/improb/commit/cd7f7c4853a7f1a51bcdc802e2f2a32459c55094

You can now do prob.extend(algorithm='linprog') without having an exception raised. Of course the resulting probability will generally not be valid (unless we implement another extend method specifically for probabilities, e.g. 'uniform', which distributes the remaining mass uniformly?).

mcmtroffaes commented 13 years ago

Printing of incompletely specified probability measures:

https://github.com/mcmtroffaes/improb/commit/08fbdaa8e204a0e873f6d37b033b285ab291df17

mcmtroffaes commented 13 years ago

Linear extension for Prob:

https://github.com/mcmtroffaes/improb/commit/1bb3b872e9396fc80741c5ba4ed8a2e9218266c6

I think this now addresses everything, so closing.

equaeghe commented 13 years ago

Hmm, I'm afraid I wasn't clear about what I meant exactly:

mcmtroffaes commented 13 years ago

Yes to all: