Giter Site home page Giter Site logo

Comments (5)

friguzzi avatar friguzzi commented on June 27, 2024 1

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

from cplint.

JeanChristopheRohner avatar JeanChristopheRohner commented on June 27, 2024

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

from cplint.

JeanChristopheRohner avatar JeanChristopheRohner commented on June 27, 2024

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 :-)

from cplint.

friguzzi avatar friguzzi commented on June 27, 2024

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?".

from cplint.

JeanChristopheRohner avatar JeanChristopheRohner commented on June 27, 2024

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

from cplint.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.