Randomized aggregates

Author(s): Jose F. Morales.

This module implements randomized version of aggregates predicates.

Example 1:

?- random_findall(4, X, between(1,10000,X), Xs).

Xs = [6659,7135,7871,9864] ? 

yes

Example 2:

?- random_findall(4, X, member(X, [the,sequel,will,not,happen]), Xs).

Xs = [the,sequel,will,happen] ? 

yes

Usage and interface

  • Library usage:
    :- use_module(library(random_aggregates)).
  • Exports:

Documentation on exports

random_findall(K,X,Goal,Ys)

This predicate implements the reservoir sampling algorithm. It needs to evaluate all solutions to Goal but only need to keeps K of those solutions in memory simultaneously.

Usage:random_findall(K,X,Goal,Ys)

Obtains a list Ys of length K of random solutions uniformly distributed from X for all solutions to Goal. Fails if there are less than K solutions.

Meta-predicate with arguments: random_findall(?,?,goal,?).

Documentation on imports

This module has the following direct dependencies: