Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
JeanChristopheRohner opened this issue Mar 8, 2023 · 5 comments
Closed

Comments

@JeanChristopheRohner
Copy link

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
Copy link
Owner

friguzzi commented Mar 8, 2023

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
Copy link
Author

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

@JeanChristopheRohner
Copy link
Author

JeanChristopheRohner commented Mar 9, 2023

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
Copy link
Owner

friguzzi commented Mar 9, 2023

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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants