🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.prolog
Article #3547

Re: Probabilistic 'or'?

#3547
From: Richard A. O'Keefe
Date: Sat, 06 Aug 1988 04:07
38 lines
1618 bytes
In article <613@etive.ed.ac.uk> jha@lfcs.ed.ac.uk (Jamie Andrews) writes:
>
>     Does anyone know of a Prolog or other LP system with a
>probabilistic 'or' or probabilistic clause selection?  What I mean by
>this is a clause selection rule or disjunct selection rule which
>randomly selects which branch to follow and which to put in the
>backtrack stack.  A weighting on the branches would be useful, too.

This doesn't need to be a language primitive.  For example, Quintus
Prolog comes with library(random), which includes things like

	random(Lower, Upper, Choice)
	random_permutation(List, Perm)

amongst others.  Suppose you have

	p(~args~) :- ~clause 1~.
	...
	p(~args~) :- ~clause 7~.

and you would like to try the clauses in random order.  Just do

	p(~args~) :-
		random_permutation([1,2,3,4,5,6,7], Perm),
		member(Index, Perm),
		p(Index, ~args~).

	p(1, ~args~) :- ~clause 1~.
	...
	p(7, ~args~) :- ~clause 7~.

If you want to pick a clause at random and stick to it, it's even easier:

	p(~args~) :-
		random(1, 7, Index),
		p(Index, ~args~).

Just use standard methods for generating and applying random numbers.
Technical Details
Message-ID: <256@quintus.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!lll-winken!lll-tis!helios.ee.lbl.gov!pasteur!ucbvax!decwrl!labrea!sri-unix!quintus!ok
References: <613@etive.ed.ac.uk>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!lll-winken!lll-tis!helios.ee.lbl.gov!pasteur!ucbvax!decwrl!labrea!sri-unix!quintus!ok
From: ok@quintus.uucp (Richard A. O'Keefe)
Newsgroups: comp.lang.prolog
Subject: Re: Probabilistic 'or'?
Message-ID: <256@quintus.UUCP>
Date: 6 Aug 88 04:07:48 GMT
References: <613@etive.ed.ac.uk>
Sender: news@quintus.UUCP
Reply-To: ok@quintus.UUCP (Richard A. O'Keefe)
Organization: Quintus Computer Systems, Inc.
Lines: 37