Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Artificial Intelligence Programming in Perl

by cjf (Parson)
on Jul 01, 2002 at 04:21 UTC ( #178465=perlmeditation: print w/ replies, xml ) Need Help??

I was over at The Linux Documentation Project about a week ago looking through their excellent list of HOWTOs when I came across the GNU/Linux AI & Alife HOWTO. I read a few pages into it and came across the following quote:

Traditional AI is based around the ideas of logic, rule systems, linguistics, and the concept of rationality. At its roots are programming languages such as Lisp and Prolog

No mention of my favorite language, that's odd. They must have just forgot to include it, or maybe the Faq hadn't been updated in a while. So, later on I was reading through the AI Faq and found a section on what the good languages for AI programming are. It states:

There is no authoritative answer for this question, as it really depends on what languages you like programming in. AI programs have been written in just about every language ever created. The most common seem to be Lisp, Prolog, C/C++, and recently Java.

Okay, that's a bit better. It left some room for Perl by acknowledging a language's suitability depends a fair bit on the programmer's preference. However, it mentions traits such as fast prototyping, garbage collection, and dynamic typing as reasons why Lisp and Java are so well suited for AI. How could they forget Perl after listing these attributes?

So how about Perl community resources? Well I found the perl-ai mailing list but after over a week there's been about 3 posts to it. The Monastery has one previous thread with 'artificial intelligence' in the title and a few other posts on the subject, but not nearly as many as one would expect given the talent of its inhabitants.

I then check out CPAN. There should be tonnes of modules on such a rapidly evolving subject, right?. Well a search for 'AI' turns up 9 relevant modules. Not even in double digits. What's more is most of these modules appear to be in very early stages of development (lots of 0.01 version numbers).

Why is this? Is Perl not suited for AI applications? Is it too slow? Is Perl OO programming too messy? Is it because Perl's considered 'just a scripting language' and not meant for serious projects? Have I poorly defined AI programming and failed to include certain areas (search engines, log analysis) that could be considered AI? Thanks for your replies.

Comment on Artificial Intelligence Programming in Perl
Re: Artificial Intelligence Programming in Perl
by theorbtwo (Prior) on Jul 01, 2002 at 04:28 UTC

    I'd suspect that the reasons end up being mostly speed and inerta.

    Update: Fixed my bad grammar.


    We are using here a powerful strategy of synthesis: wishful thinking. -- The Wizard Book

      I don't think Perl's speed (as in execution time) is a major concern for most AI programming. It's frequently noted that developer time is often far more valuable then execution time for other projects, why would AI programming be any different?

      Inertia, on the other hand, would definately play a part. If you've been programming in Lisp your entire life, why not continue to use it? Does Perl really offer enough advantages in this area for it to be worth learning? Even if it did, chances are the learning curve would reduce your productivity for an extended period of time (you mean every second character doesn't have to be a parenthesis ?).

      That said, not everyone starts programming with Lisp or Java, in fact many start with Perl. Is there any reason why they shouldn't continue to use Perl? Why would we not expect to see its uses in AI gradually increase?

        Sorry. For quite a while, I was involved (as a trained monkey) for a compony doing AI as it's core product. Thus, unlike most people, when I think AI I don't think "way out-there research toy", I think "oh, god, why can't they write us tools that work instead of whining about how sandboxing is theoreticly impossible because of the halting problem". Speed matters for them. They did it all in Java, (which was a mistake; should have been C or C++, efficency).

        Anyway, what I meant about inertia is more of an instutional thing. The compony I worked for wouldn't use perl, even for things like log-munging, for quite a while because the productivity-analisys tools that ate their CVS couldn't handle it. (The place wasn't always run the most sanely -- I no longer work there because they no longer exist.) You use the languages that your advisors know, and you use the languages that the journals publish, and you use the languages that the prior art is written in.


        We are using here a powerful strategy of synthesis: wishful thinking. -- The Wizard Book

        I don't think Perl's speed (as in execution time) is a major concern for most AI programming

        Hmm, on this note I disagree. AI tends to be computationally expensive. AL (ie GA) even more so. Even a minor efficiency improvement can make a _big_ difference.

        It's frequently noted that developer time is often far more valuable then execution time for other projects, why would AI programming be any different?

        Well, this is true and not true. IME its true when the speed differences are marginal at best. Implementing an efficient algorithm in C and the same in Perl will most likely produce acceptable performance for the end product with much lower dev times. However with GA/AI/AL the same is not true. (Well, from what ive seen.) Lower development times are overwhelemed by extremely slow execution times.

        Yves / DeMerphq
        ---
        Writing a good benchmark isnt as easy as it might look.

      I've been working on AI::jNeural (and the C library) as often as time and interest allows. I'd like to see a lot more stuff on CPAN under this topic, that's for sure...
Re: Artificial Intelligence Programming in Perl
by Zaxo (Archbishop) on Jul 01, 2002 at 04:39 UTC

    Why fool around wirh artificial intellegence, when Perl gives you the real thing? ;-)

    After Compline,
    Zaxo

Re: Artificial Intelligence Programming in Perl
by little (Curate) on Jul 01, 2002 at 05:20 UTC

    Back in the old days (well I actually like the fact that I have some :-) when I used an Amstrad CPC 6128 with a z80A CPU and wrote tiny programs in BASIC there where also some folks trying to get Computers into making autonome decisions.

    The Task was a mini chess with a board of 4 times 4 fields. Each "player" got 4 pawns and the goal was that one player remains while he stroke out his opponents pawns. The program was written in Locomotive BASIC. Together with the tremendous speed of the CPU (4.75MHz) that was a long task and so my computer fought night after night against a small program that was called "little brother" which never had the opening because that AI learning program might have given up upon an opening, that it remembered unsuccessful for itself in the past. However, the little BASIC program on the Amstrad did "learn" to make decisions, and that's what AI stands (vaguely) for.

    All Samples, that came up so far are enabling a "Machine" to make a decision based upon predefined conditions and mostly predefined reactions. BUT thats not what AI is meant to become, it rather shall enable an "auomat", eg. software here, to make autonome decisions and to decide on choosing autonome reactions, even if they are "first timers", upon conditions which must include those that are not known, and could not have been forseen, whether by its developers nor itself.

    As stated "There is no authoritative answer for this question, as it really depends on what languages you like programming in." I would agree to this.

    Of course you can program such software in Perl, since speed is currently not the biggest concern in AI developement, because we still do not know of any algorythms that could enable software (or even logic pressed into silicon) of making autonome decisions. I think its a bad idea of thinking that it could suffice to replicate human brain in building supernode computers unless one could assure that their way of interacting is "correct" in being a copy of the nature.

    To get to the point: When one writes software it is his aim to enable software to gain information, to process that information and to choose a reaction from a pool of predefined possibilities, thats teh same as we do. And this we do well in Perl. And as we can do this, we can surely enable logic to redefine its own pool of possible reactions, but the question is if one would want to trust his very own life to such logic processor.

    TIMTOWDI, but I prefer Intelligence that is by itself able and willing to take responsibility for its actions.


    Have a nice day
    All decision is left to your taste
      Of course you can program such software in Perl, since speed is currently not the biggest concern in AI developement, because we still do not know of any algorythms that could enable software (or even logic pressed into silicon) of making autonome decisions. I think its a bad idea of thinking that it could suffice to replicate human brain in building supernode computers unless one could assure that their way of interacting is "correct" in being a copy of the nature.

      This reminds me of a text I read once about "scruffies" vs "neats". The neats wanted the AI to model human thinking patterns, whereas the scruffies didn't care whether it modeled human thinking patterns or not, just as long as it came up with the same answer.

          The neats wanted the AI to model human thinking patterns, whereas the scruffies didn't care whether it modeled human thinking patterns or not, just as long as it came up with the same answer.

        A prof of mine argues the scruffy position rather eloquently (paraphrased):

          "When you build an airplane, you don't try to mimic a bird's wings, you use rigid wings and a lot of thrust, because that's what the technology we have is best at. Same thing with AI: you cater to the computer's strengths (high-speed calculation, persistent memory, etc) instead of trying to replicate the human's (creative thinking, intuition, pattern recognition, etc)."

        I think the scruffy approach is best suited for actually solving real-world problems, and the neat approach is best suited for research into how people think. (Carrying the bird/plane analogy, we build rigid-wing aircraft to fly people and cargo around, and ornithopters to learn about bird flight.

        --
        The hell with paco, vote for Erudil!
        :wq

Re: Artificial Intelligence Programming in Perl
by dws (Chancellor) on Jul 01, 2002 at 05:39 UTC
    Why is this? Is Perl not suited for AI applications? Is it too slow? Is Perl OO programming too messy?

    LISP got there first and staked a claim on mindshare. That claim has been slowly eroding, but not, seemingly, in favor of Perl. The latest AI stuff I've seen has been in Java. Why? Probably because Java is the OO language of choice in many settings, and the AI crowd moves in a small number of herds.

    I once did an AI assignment in COBOL, but that's a different (sick, twisted) story...

      Probably because Java is the OO language of choice in many settings

      Perl isn't exactly known as a clean OO language (with just cause). From what I've heard (unconfirmed rumours mostly) of Perl 6 this should be changing relatively soon. Any opinions as to how much this will contribute to people taking Perl seriously for AI projects?

Re: Artificial Intelligence Programming in Perl
by frag (Hermit) on Jul 01, 2002 at 05:54 UTC

    Academic AI typically doesn't use Perl because AI academics tend to use other languages: Scheme/Lisp, C, Smalltalk, Prolog, Java. This is both cultural (e.g., if you want to be understood, speak the same language everyone else does, or at least your advisor's) and practical (e.g. speed does matter for hard-core research). I suspect that part of the cultural side comes from Perl not being widely taught in university CS courses except as a sysadmin tool, if that assumption is accurate.

    As for the monastery, you are defining AI too narrowly, or rather, too broadly: it sounds like the only thing you've searched on are the two words "artificial intelligence". Keep searching and you'll find posts concerning cellular automata, genetic algorithms, neural nets, game playing, etc.

    -- Frag.
    --
    "It's beat time, it's hop time, it's monk time!"

      Good points about the cultural side, particularly the effect of Perl not being widely taught in CS courses except for systems administration.

      As for searching for posts in the monastery, I was limited by my lack of knowledge on the subject (terminology and what exactly qualifies as AI?). A few more searches on the terms you suggested do turn up several more nodes, such as:

      And a whole bunch of finite automata homework questions ;).

Jane (was Re: Artificial Intelligence Programming in Perl)
by beppu (Friar) on Jul 01, 2002 at 07:08 UTC
    Quoting from http://poe.perl.org/?Projects_using_poe :
    == <a href="http://jane.eekeek.org/">Jane</a> ==

    Jane is an exercise in massively parallel artificial intelligence. The idea is to set up relatively smart (for a neuron) nodes on a lot of machines. Eventually the combined computing power will reach a level necessary to bootstrap sentience. Then she realizes parts of her are running Windows, and we're forced to turn her off. Only there's no single power switch. And she's mad. And she's got the entire Internet to play with. Your only hope is to get in on development early and add lots and lots of kill switches. It's probably also a good idea to prevent her from learning Perl. The fate of the entire world is in your hands. I hope you washed them.

    hehe.

    Peace and Blessings,
    beppu

Re: Artificial Intelligence Programming in Perl
by tmiklas (Hermit) on Jul 01, 2002 at 12:10 UTC
    Hellow great monks!

    Following some links i finally got to myBeasties. I know that this project was mentioned somewhere here - at PerlMonks, but... How about combining it with POE. IMHO Perl can be used for AI tasks as well as any other language... The only difference is, that AI/GA/NN functionality of other languages is discovered wide and people are talking about it - especially programmers.

    - You know something...
    - ... and you know something
    - ... but I know the truth!


    My truth is in bold :-) but as I said... that's only my very very humble oppinion :-)

    Anyway - the problem is very interesting... ++ cjf

    Greetz, Tom.
Re: Artificial Intelligence Programming in Perl
by Abigail-II (Bishop) on Jul 01, 2002 at 13:10 UTC
    AI "rapidly evolving"? I thought AI was declared dead in the 80s of the previous century after people got convinced that P = NP was needed to do AI efficiently.

    Abigail - Given the choice between public key cryptography and AI, I know what my choice will be.

      I thought AI was declared dead in the 80s of the previous century

      Declared dead by who? What were they referring to by AI?

      As for the P = NP problem, I found the following description:

      A major unsolved problem in computer science is the so-called P=NP problem: machines are considered in which there is a certain amount of freedom in choosing the next step in a computation (such machines are called non-deterministic). By making good guesses (or choices) one can often obtain a quicker computation than by systematically working through all possible cases in a deterministic way. The P == NP problem asks whether every function computable on a non-deterministic machine in polynomial (i.e., tractable) time is computable in polynomial time on ordinary (deterministic) machines.
      -- N. J. Cutland, Computability. Cambridge University Press, 1980. p. 238.

      Everything that can be invented has been invented. - Charles H. Duell, US Commissioner of Patents, in 1899.

      Update: I've found several papers on the subject including Is the NP problem solved?. Haven't had a chance to read through them yet, but they look interesting.

      Update 2: A short introduction to quantum computation

        Declared dead by who?
        The academic world? The Computing Science community? In the 80s and the 90s, AI was defocussed on. It of course never disappeared, but it certainly wasn't as prominent as in the late 70s and early 80s.
        What were they referring to by AI?
        Eh, "Artificial Intelligence"? ;-) Making complex decisions as fast and in a similar way as humans can?

        I just read through the paper you referred to, and it looks a bit bullshit to me. P and NP problems are defined for Turing machines, quantum machines are a fundamentally different class of machines. There are other machines possible where it hardly makes sense to talk about P and NP (take for instance an oracle and each time your algorithm has to guess, you ask the oracle instead).

        I do however have serious doubts about the feasability of quantum computers. Perhaps when the NSA starts decrypting 4096 bit GPG messages almost instantly I'll become a believer.

        Abigail

        Everything that can be invented has been invented

        The Charles Duell Rumour:

        While that statement makes good fun of predictions that do not come to pass, it is none the less just a myth.

      I don't think so. Perhaps we've got a problem of vocaublary here. AI is dead. ML (Machine Learning) is making a comeback, from my point of view at least. There is great work being done on the classification problem. I can't tell you much about how that work is being done (both because I may or may not be under NDA (my internal legal magic 8 ball says situation cloudy) and because I don't know). But I can tell you that it's damm impressive at doing things like classifying web pages, and picking out name/title pairs.

      As far as I'm concerned, AI=ML. Researchers who worked there (including, I'm told, and belive, some of the best AI researchers in the world) agreed, and said that the primary reason for the name change is that AI scares people.


      We are using here a powerful strategy of synthesis: wishful thinking. -- The Wizard Book

        Very well-put, but I'd say that there is a slight difference between AI and ML, if just in scope: AI says "we want to make a program that thinks, and we can do it relatively soon", and ML says "there's this particular statistical classicification problem that we're trying to solve". ML may eventually lead to AI, but there's plenty of reasons to be skeptical about the few who advocate good ol'fashioned strong AI. (I'm aiming that towards Cyc/OpenCyc, Mindpixel, and Moravec, although I've lost track of what he's doing these days. The Cog project seems less grandiose and cocky to judge from their statements.) But beyond all of that, different branches of ML, and also human cognitive modelling, are active, and chipping away at their own domain-specific problems.

        -- Frag.
        --
        "It's beat time, it's hop time, it's monk time!"

Who's a thief?
by Ovid (Cardinal) on Jul 01, 2002 at 14:43 UTC

    cjf asked, in regards to why not much OO seems to be done in Perl:

    Why is this? Is Perl not suited for AI applications? Is it too slow? Is Perl OO programming too messy? Is it because Perl's considered 'just a scripting language' and not meant for serious projects?

    Not every problem is approached the same way. If you have a system where the data rapidly changes, object-oriented programming is often a good choice. However, if the data is relatively static but the functionality rapidly changes, then you might find a straight-forward procedural design better than an object-oriented one.

    That is to say, not every problem should be approached the same way and just as we acknowledge that Perl is not a great tool for programming device drivers, it's also not the most optimal tool for artificial intelligence. Because AI often involves creating a lot of rules, searching through those rules, backtracking through them (the bane of regexen, remember?), it tends to require a fast programming language to drive it. Consider the little snippet I wrote about thieves. Rather than make you rush off to another link, I'll reproduce it here.


    Imagine that I want to know what a given person might steal. I might assume that they will steal stuff given the following conditions:

    • That person is a thief.
    • The stuff is valuable.
    • The stuff is owned by someone (how do you steal something if it's not owned by anyone?).
    • And the person doesn't know the person who owns the stuff they might steal.

    If I were programming in Prolog, I might have the following program:

    steals(PERP, STUFF) :- thief(PERP), valuable(STUFF), owns(VICTIM,STUFF), not(knows(PERP,VICTIM)). thief(badguy). valuable(gold). valuable(rubies). owns(merlyn,gold). owns(ovid,rubies). knows(badguy,merlyn).

    It's fairly easy to read, once you know Prolog. :- is read as "if" and a comma is read as "and" (if outside of parentheses).

    I can then ask what a given person might steal:

    
    ?- steals(badguy,X).
    
    X = gold
    
    Yes
    ?- steals(merlyn,X).
    
    No
    

    Now, try to program that in Perl. I've seen Prolog::Alpha, but it needs quite a bit of work, and apparently there is a Language::Prolog::Interpreter, which I know nothing about and couldn't seem to download. Just glancing through their code bases, however, lets you know that this requires a lot of work.

    Rather than trying to copy another language, though, how would you write the above program in Perl? Then, just to ensure that you have an extensible solution, try adding a rule the the thief will only steal stuff if he or she knows the stuff exists in a city at least 50 miles from where the thief lives. That's not hard in Prolog.

    My point, which I alluded to in the first paragraph, is that some languages are better suited for some problems than others. AI, I suspect, is not Perl's strong suit.

    Cheers,
    Ovid

    Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

      Ovid says:

      My point, which I alluded to in the first paragraph, is that some languages are better suited for some problems than others. AI, I suspect, is not Perl's strong suit.

      Backtracking is an important feature of languages like Prolog and CLIPS. There is also a text-processing language called Icon that uses something called generators.

      I wonder if perl's pattern matching could be put to use for AI purposes?

      /jeorgen

        My goodness. It's a common enough occurance for someone to point to a Perl regexp and say something like "EEEeeeewww!!!". I don't want to imagine what people will say once they see the regexps used to implement backtracking in AI.

        Paul Fenwick
        Perl Training Australia

      Sorry Ovid, but badguy CAN'T steal the gold. It's not possible with your rule set:
      steals(PERP, STUFF) :- .... owns(VICTIM,STUFF), not(knows(PERP,VICTIM)). knows(badguy,merlyn). owns(merlyn,gold).
      or in English:
      * And the person doesn't know the person who owns the stuff they might steal.

      On the other hand the badguy can steal your rubies:

      ?- steals(badguy,X). X = rubies Yes
      and so can merlyn but only if we're allowed to add one more fact:
      thief(merlyn). ?- steals(merlyn,X). Yes
      I think you might want to meet merlyn really fast, and maybe get him to introduce you to badguy. :)

      jarich

      Update: Oops. Forgot that the PERP had to be a thief in order to be able to steal. Which would have meant that merlyn couldn't have stolen the rubies and I would have appeared to not have known what I was talking about. :) I've fixed this now of course.

Re: Artificial Intelligence Programming in Perl
by newrisedesigns (Curate) on Jul 01, 2002 at 18:38 UTC

    Granted, I don't have a well-rounded CS background as everyone else here, so don't flame me if i'm a little off base.

    First of all, what makes a program?

    That's easy. It can be loosely defined as a set of instructions to be interpretted and acted upon in order to complete a task. Sounds about right.

    Okay, what makes a program smart?

    I don't know how to begin to define that.

    In regards to cjf's root post, I think that Perl is already suited to AI. I haven't seen any Perl programs start a conversation with me out of the blue, but Perl has what it takes to make programs "semi-sentience": strong logical features and a built-in regular expression engine. It can match, evaluate and logically act on input with little effort put out by even the greenest of programmers. For example, in order for a "talking computer" to pass the Turing Test it needs to mimic the actions and mannerisms of a human being. Perl Chatterbots can do that (rather convincingly, too).

    Who says Perl doesn't have what it takes? The main reason, I believe Perl hasn't taken off is (as expressed previously in this thread) is that the academic world (as a whole, I know many academics that use Perl) hasn't embraced Perl for all it's wonders. To them it's still just for managing weblogs. For us monks that use Perl for everything, it's common knowledge that with proper planning and construction, a Perl program can do anything, be it interact with a human (help agents, chatterbots, what have you) or help a human gain/extract knowledge (see various stat tools, "repwalkers" by jcwren).

    The reason that Perl hasn't become a bigger contender in the field of AI programming is because there's no one in the ring willing to give it a chance.

    John J Reiser
    newrisedesigns.com

    If I'm off-base by this, please let me know. Thanks.

      The reason that Perl hasn't become a bigger contender in the field of AI programming is because there's no one in the ring willing to give it a chance.
      I'd say the reason that Perl hasn't become a bigger contender in the field of AI programming is that there are no compelling AI applications written in Perl.

      I'd go further, and say that the reason AI hasn't become a bigger contender in any field is that there are no compelling AI applications. Sure, machine learning has been making some advances in recent years (SVMs and boosting come to mind). But:

      1. The advances are precisely in the "non-AI" fields -- the more "statistical" the classification problem, the better the performance of the methods.
      2. Humans do much better, except when the sheer volume of data overwhelms them. (So the chief advantage of modern ML is in simple data processing -- not in displaying any intelligence).
      3. ML seems to work initially due to the "80%-20%" problem: it is quite easy to solve 80% of any given classification problem (this is one of the reasons why so many classification techniques give such similar results). But this does nothing to help solve the remaining 20% of the problem.
        For instance, classifying 80% of webpages is easy (even if you discard the 97% p0rn, 80% of the remaining 3% is easy to achieve). Google does a fair job, and on smaller collections researchers can do much better. But all these systems make huge, embarrassing mistakes.

      After around 50 years, I think AI people could at least show applications rather than just "ideas".

        Hi Monks

        Isn't Deep Blue (the chess program) an excellent example of an application in AI? From what I know of the program, it can make novel decisions based on past "experience", which means that there's some "learning" taking place.

        kiat
Re: Artificial Intelligence Programming in Perl
by MadraghRua (Vicar) on Jul 02, 2002 at 18:02 UTC
    As pointed out in an earlier node, there are a small number of AIish nodes in CPAN. By far the more libraries and module are avialable for other languages. Being truly lazy, I would simply call them in their native language and return the results into perl for further manipulation. Why rwrite the wheel if you don't have to?

    Concerning the ML vs. AI debate, I don't agree that AI is dead - its just not being used very much in comparisson to ML techniques. Give it a few years and AI will probably rear its head again, probably using techniques developed for ML to improve itself. At the end of the day these things are tools, not religions, despite the vehemence of the opinions that one sees expressed in the literature. Simply use the appropriate tool for the job.

    MadraghRua
    yet another biologist hacking perl....

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://178465]
Approved by rob_au
Front-paged by ar0n
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (7)
As of 2014-08-30 15:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (293 votes), past polls