Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
Dear Ovid,

I spent a good number of hours experimenting after reading your last post about thieves etc. Unfortunately since I had two deadlines I didn't have time to finish or to post my work in time. (and also it didn't work completely). This is great stuff, though everyone seems to be talking about databases all of a sudden.

I've looked around at reasoning code for use with Perl several times, though you probably know about the AI tool from NASA (CLIPS, thanks for the link John) and also CYC (also someone linked before I read the thread..). Perhaps you were prodded by a recent news story about Dr. Howard Cross' Problem Knowledge Coupler for medical diagnoses.

Anyway, some quick thoughts on what you've mentioned so far.

%actor = ( merlyn=>1, kudra=>1, ovid=>1, badguy=>1 ); %thing = ( gold=>50, pocketLint=>0.01, cheapWhiskey=>-20, dominationFund=>10E10 ); $actor{merlyn}{owns} = {gold=>1}; $actor{kudra}{owns} = {dominationFund=>1}; $actor{ovid}{owns} = {pocketLint=>1, cheapWhiskey=>1};
or maybe one day, &addfact qw(merlyn owns (gold of value 50));

What I first tried to do was implement the Who's a Thief problem using Damian Conway's Quantum Superpositions module, since it sounded like his any() and all() might be useful. Good for consciousness jokes too :) actually I had tried to apply it with an ingenious but only 80% implemented (too small to fit in this margin) solution to the question about filling a table with categories. The neat thing in both cases is that after setting up the data, the final answer usually is only one to three lines of what looks like very intuitive English-like phrasing.

I wanted to be able to say,

$x = any($actor); $y = any($thing); &rich($x) if (&owns($x,$y) and &isvaluable($y));
I had difficulty using it, for example I don't think any(actor)->owns{item} syntax worked. But it was seductive because it looked just like your prolog statements, except for all that punctuation. I played around with these kinds of statements:
if ($x{owns}{$y} && $thing{$y}{value}>20) { print "The badguy will ste +al $x\'s $y.\n"; } if ($item{value} > 20) { print "The badguy will steal from $potentialv +ictim\n"; } if ( $(any(@{$x->{owns}})){value} > 20) { print "badguy will steal fr +om $x\n"; } $isvaluable = sub ($) { my $x=shift; $x->{value} > 20 ? 0 : 1; };
Here $item and $potentialvictim were supposed to be simultaneously multivalued. But (unless I misunderstood) some of this did not work because you actually have to superimpose two multivalued objects to get the superimposition, I think. Otherwise a lot of what you think should happen doesn't.

Then I realized Quantum::Entanglement would be far more useful. This was also pretty difficult conceptually but I found it fascinating. In particular you might want to look at Entanglement's p_func which might be useful as a way to set rules operating on things. Also, the quantumlogic method looks extremely interesting and I haven't even barely looked in its general direction yet.

Well, I tried to say

$x = wave(keys %actor); $y = wave(keys %thing); $item = wave($actor{$x}{owns}->{$y});
where &wave would entangle its parameters like any(). (maybe this is how any() works, didn't check).
sub wave { # given an array, return entanglement of elements my @k = @_; my $n; foreach (@k) { push(@n,(1,$_)); } # every element is 100% probable return entangle @n; }
This would seem to let you easily change the probability of certain events happening. This module is extremely cool and brain bending, I recommend it.

However unless I am wrong (quite possible), since all possibilities need to be well-defined you end up with just a big matrix solver instead of an elegant logic engine. But the need for intersection, union, and probably a "such that" phrase (a pipe in math or haskell, like x|y=1) seem useful. Maybe for/foreach does it but there seems to be quite a lot more cool stuff in Haskell.

So I'd recommend checking out Set::Bag and Set::Scalar/Set::Scalar::Valued which seems pretty powerful and even overrides some symbols so you can take the intersection of sets which would help solve the thief problem. You can say things in Set::Bag like: $rich = owns(x,y) * valuable(y); # intersection

I think a Perl AI engine would be very useful in making interesting services, for example I did some looking around for one when I was planning a product recommendation engine that would help a customer find the right product given certain needs. I'd be much more interested now in being able to ask intelligent questions and get back statistically sorted answers, than to save a hundred thousand facts in a database just yet. Or to have just a little bit of intelligence added to my coding to save me time. Maybe something that knows all the functions I've written and could whip something up in response to a well-typed phrase?

By the way, about Cyc, if you haven't it might be interesting to read some of the messages in the forum in the sourceforge project page. A couple months ago I remember some very interesting questions.

And, have you looked at Haskell and what do you think?

Also, what if we had a project wiki for pm projects?

Finally a few thoughts about your questions, at the risk of stating the obvious..

- making a statement like you did about kudra and merlyn creates possible counterstatements (how many books does merlyn have) for example, which would seem to mean either doing a database search each time, or updating a hash of facts about each object every time you do anything. Perhaps you would like to simulate a universe of objects? It might make queries faster. Hence your pairs note, I'm sure.

- For some reason I think we operate more like the Entanglement routine above and less like SQL. Not subatomically speaking, but that some facts stand out, or your interest is piqued by certain words. Perhaps simulating a person listening to those facts and recording a story about them in a graph would be a viable approach. Plus you could graph it with DataViz! :)

- I like the ability to state questions in perl-friendly phrasing, like $kudra gives $book{learningperl} to $merlyn. And I'd like to have "such that" added to Perl. Looking back at Haskell and even Functional.pm it would seem that a hard mathematical approach is one way to do an interface, while another might be a more linguistic approach.

- I'd like to suggest a general purpose reasoning module that would emphasize useful interface and queries and not speed or volume of facts.

- Also as mentioned above, something which does some of the work for you in Perl development would be extremely useful.
For example, a repository of logic about Perl programming and other development issues, with knowledge about glueing modules together might be a killer. It could chat with you about what you want to build, and.. well you can finish this one yourself. But if a semantic repository is available, TMTOWTDI will reign supreme!

Anyway, something that greatly magnifies the strength of a Perl programmer, and makes perl itself more powerful even in a small way, would have a lot of applications. What are the one or two words you would like to see added to the language?

Hope this has helped stir the coals and not put you to sleep. Much luck!

Matt R.


In reply to Re: Choosing a data structure for AI applications by mattr
in thread Choosing a data structure for AI applications by Ovid

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others rifling through the Monastery: (12)
    As of 2014-11-28 08:48 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My preferred Perl binaries come from:














      Results (194 votes), past polls