Home
   Journal    Friends    Archive    User Info    Memories
  Technorati Profile | Syndicate this weblog (RSS/XML) |

Autonomous Agent

Oct. 17th, 2005 09:23 pm YAP Prolog — Fast!

I tried YAP Prolog today, a Edinburgh-style Prolog implementation written entirely in C (as opposed to SWI-Prolog, for example, which is itself partially in Prolog). The website claims that YAP exhibits exceptional performance and is at least as fast as, if not faster than, other well-known implementations of the language. I tried testing this by running my version of the Porter Stemming Algorithm through it. It took only .6 seconds to process a megabyte of text, compared to 3.4 in SWI-Prolog (both using an Athlon64 3200+ in 32-bit Windows XP)! This only tests basic rule matching and list manipulation capabilities, but that's still an impressive difference. I'll still stick with SWI for most things because I find it more featureful and user-friendly, and I usually work with small enough data sets that I don't notice the processing time, but the YAP developers deserve a pat on the back.

Tags:

Current Mood: impressed

Leave a comment

Oct. 12th, 2005 04:02 pm C is BAD

As part of a homework assignment a few years ago, I needed to be able to use Prolog to generate random numbers from a Gaussian (bell curve) distribution with a given mean and standard deviation. A friend found the code that does this in the Python standard library, so I translated it into Prolog.

When SWI Prolog 5.2.10 decompiles a compiled program, it names the first variable to occur A, the second B, and so on. Part of my translation of the Python looked like this in the source file:

gaussian(SD,Mean,R) :-
	gaussian_z(Z),
	!,
	retractall(gaussian_z(_)),
	R is Mean + SD * Z.
When compiled and displayed, it reads:
gaussian(A, B, C) :-
        gaussian_z(D), !,
        retractall(gaussian_z(E)),
        C is B+A*D.
In spite of its apparent dislike of the language, I've since translated this from Prolog into C (really, C++) for a quick and dirty Gaussian random number generator for use in SAGA.
Tags: ,

2 comments - Leave a comment

Oct. 12th, 2005 01:10 am The Porter Stemmer in Prolog

I recently completed a project to implement in Prolog the Porter Stemming algorithm, which uses a rough model of English morphology to quickly estimate the stem of a word for Information Retrieval (IR) purposes. The code is available here. I first attempted to do this a few years ago with Jon McClain, who has since graduated. Our original approach was flawed, and we soon abandoned it as we became distracted by other things. I came across our code a few days ago and decided to rewrite it with a better method in mind. It seems to comply with the algorithm specification, correctly stemming the sample vocabulary on the website. Unfortunately, probably largely because Prolog most naturally handles data as linked lists with poor random access time, it does not compare very favorably to the implementations in other languages as far as speed is concerned. On my computer, it takes 3.4 seconds to process a megabyte of text, compared to the Perl version's 2.8.

Update: It is now posted on Martin Porter's website.

Leave a comment

 

Advertisement