Possible issue with Lea constructor

Issue #52 closed
Former user created an issue

Hi Pierre, working with Lea I found this situation using revised_prob, and I can't figure out why. Is possibly an issue with lea constructors? Maybe an issue on my Windows/Python? Please let me know what you think about it. Many thanks, Matthew.

mutuating from your example:

die = lea.interval(1,6) die 1 : 0.16666666666666666 2 : 0.16666666666666666 3 : 0.16666666666666666 4 : 0.16666666666666666 5 : 0.16666666666666666 6 : 0.16666666666666666 rev_die=die.given_prob(die==1,0.07) rev_die 1 : 0.07 2 : 0.186 3 : 0.186 4 : 0.186 5 : 0.186 6 : 0.186

neat! Now, the same interval but from a different source:

let's say np is numpy:

die=None # same with new shell die = lea.vals(*tuple(np.arange(1,7))) # omitting tuple() call leads to same result die 1 : 0.16666666666666666 2 : 0.16666666666666666 3 : 0.16666666666666666 4 : 0.16666666666666666 5 : 0.16666666666666666 6 : 0.16666666666666666

rev_die=die.given_prob(die==1,0.07) i get Traceback (most recent call last): File "<pyshell#48>", line 1, in <module> rev_die=die.given_prob(die==1,0.07) File "C:\Users\test:lea\AppData\Local\Programs\Python\Python37-32\lib\site-packages\lea\lea.py", line 337, in given_prob return Lea.if_(req_cond_lea,self.given(cur_cond_lea).get_alea(sorting=False),self.given(~cur_cond_lea).get_alea(sorting=False)) File "C:\Users\test:lea\AppData\Local\Programs\Python\Python37-32\lib\site-packages\lea\lea.py", line 1288, in get_alea new_alea = self.new(sorting=sorting) File "C:\Users\test:lea\AppData\Local\Programs\Python\Python37-32\lib\site-packages\lea\lea.py", line 1358, in new new_alea = Alea.pmf(self._calc(),prob_type=prob_type,sorting=sorting) File "C:\Users\test:lea\AppData\Local\Programs\Python\Python37-32\lib\site-packages\lea\lea.py", line 1399, in _calc return tuple(self.gen_vp()) File "C:\Users\test:lea\AppData\Local\Programs\Python\Python37-32\lib\site-packages\lea\ilea.py", line 78, in _gen_vp for cp in Ilea._gen_true_p(self._cond_leas): File "C:\Users\test:lea\AppData\Local\Programs\Python\Python37-32\lib\site-packages\lea\ilea.py", line 75, in _gen_true_p raise Lea.Error("boolean expression expected") lea.lea.Lea.Error: boolean expression expected

Comments (7)

  1. Pierre Denis repo owner

    Hi Matthew,

    Thank you for reporting this issue. Let me explain what happens. In the die built up using numpy construct, the values 1, 2, 3, 4, 5, 6 are numpy.int32. Then, expressions like die==1 produces numpy.bool_ objects. The issue is that Lea is expecting a native Python boolean, being unware of any numpy types.

    I understand that this is annoying and weird. I've found a simple way to fix this without refering to numpy (see next commit). I will probably release a new "bug fix" version for this, in the next days.

    In the meantime, the best is to convert all numpy array's element to Python native type (int, float, ...) before creating a Lea instance.

    See also #42 for a very similar problem.

  2. Log in to comment