friguzzi / cplint

cplint is a suite of programs for reasoning with probabilistic logic programs
Other
67 stars 14 forks source link

Get proof trees for queries on probabilistic logic programs? #50

Closed JeanChristopheRohner closed 1 year ago

JeanChristopheRohner commented 1 year ago

Hi!

Is it possible to get proof trees for queries on probabilistic logic programs? I.e. like SLDNF draw or s(CASP) but with a PLP.

Kind regards, JC

friguzzi commented 1 year ago

Hi Jean Christophe, cplint uses tabling, so it is not possible to draw an SLDNF tree. One should draw an SLG forest but I don't know of any tool that can do it. However, you can draw the BDD.

Best Fabrizio

JeanChristopheRohner commented 1 year ago

Thanks for the information and the suggestion. Kind regards, JC

JeanChristopheRohner commented 1 year ago

I re-opened the issue because I started considering writing code that automatically converts an LPAD to a program with CLPR constraints. For example, given the LPAD:

0.9::happy(P):- 
    hasFriend(P, F), 
    nice(F).
0.3::happy(P):- 
    rich(P).

hasFriend(josh, mark).
0.8::nice(mark).
rich(josh).

Automatically generate (where the X's are probabilities):

:- use_module(library(clpr)).
happy(P, X1):- 
    niceFriend(P, X2), 
    rich(P, X3), 
    {X1 = 0.9 * X2 + 0.3 * X3 - 0.9 * X2 * 0.3 * X3}.
niceFriend(P, X1):- 
    hasFriend(P, F, X2), 
    nice(F, X3),
    {X1 = X2 * X3}.

hasFriend(josh, mark, 1).
nice(mark, 0.8).
rich(josh, 1).

One advantage could be to facilitate generating proof trees such as the following (in addition to the BDDs you suggested).

happy(josh,0.804) ⇐
     niceFriend(josh,0.800) ⇐
          hasFriend(josh,mark,1) ⇐ true
          nice(mark,0.800) ⇐ true
          {0.800=1*0.800} ⇐ true
     rich(josh,1) ⇐ true
     {0.804=0.900*0.800+0.300*1-0.900*0.800*0.300*1} ⇐ true

Another advantage is that it would be possible to reason bidirectionally (curtesy of CLPR), e.g. "Given that Josh is happy, that he is friends with mark who is nice, what is the probability that Josh is rich?"

And it would be cool be be able to go from a SLIPCOVER generated LPAD to a CLPR version.

On the other hand I am not sure if the semantics associated with CLPR adequately captures LPADS...

These are just some thoughts (not an issue with CPLINT per se)... I am curious about if you think that this is a good idea or not before I embark on such a project :-)

friguzzi commented 1 year ago

Hi, the approach you propose works only if the programs satisfy the independent-and and independent-or assumption. Moreover, even in that case, it does not work if josh has more than one friend. However, you can have a look at https://github.com/friguzzi/cplint/blob/master/prolog/pitaind.pl and modify these predicates

 * orc_ind(++A:float,++B:float,--AorB:float) is det
 *
 * Returns A + B - A*B in AorB (or in case of independence)
 */
orc_ind(A,B,C):-
        C is 1-(1-A)*(1-B).

/**
 * orc_exc(++A:float,++B:float,--AorB:float) is det
 *
 * Returns A + B in AorB (or in case of exclusion)
 */
orc_exc(A,B,C):-
        C is A+B.

/**
 * onec(--One:float) is det
 *
 * Returns 1.0
 */
onec(1.0).

/**
 * zeroc(--Zero:float) is det
 *
 * Returns 0.0
 */
zeroc(0.0).

/**
 * andc(++A:float,++B:float,--AandB:float) is det
 *
 * Returns A*B in AandB (and in case of idependence). Fails if either A or B is 0.0
 */
andc(A,B,C):-
  ((A=0.0;B=0.0)->
    %C=and(A,B)
    fail
  ;
    (A=1.0->
      C=B
    ;
      (B=1.0->
        C=A
      ;
        C is A*B
      )
    )
  ).

/**
 * andcnf(++A:float,++B:float,--AandB:float) is det
 *
 * Returns A*B in AandB (and in case of idependence).
 */
andcnf(A,B,C):-
  (A=1.0->
    C=B
  ;
    (B=1.0->
      C=A
    ;
      C is A*B
    )
  ).

/**
 * notc(++A:float,--NotA:float) is det
 *
 * Returns 1-A in NotA (negation)
 */
notc(A,B):-
  (A=0.0->
    B=1.0
  ;
    (A=1.0->
      B=0.0
    ;
      B is 1.0-A
    )
  ).

Replace and, or and not computations with CLPR computations and you would get what you want. Note that this is not necessary to answer queries like "Given that Josh is happy, that he is friends with mark who is nice, what is the probability that Josh is rich?" which is a regular conditional probability query P(q|e) that you can answer computing P(q,e) and P(e), but you can answer queries such as "what probability should the fact that Josh is rich have to make the he probability of Josh being happy being tot?".

JeanChristopheRohner commented 1 year ago

Aha I see. Maybe more tricky than I thought initially. Thank you for suggesting where to look in Pita!