Overview

clj-sample-utils

Description

A Clojure library for probability sampling. Inspired by the functions sample and sample.int in the R language. See: http://bitbucket.org/mnacamura/clj-sample-utils/

Example

user=> (use 'sample-utils)
nil
user=> (take 10 (sample [:a :b :c]))
(:c :c :a :b :c :c :a :a :a :b)
user=> (take 10 (sample [:a :b :c] :prob [0 1 2]))
(:c :c :c :c :c :b :c :c :b :b)
user=> (frequencies (take 100000 (sample [:a :b :c] :prob [0 1 2])))
{:b 33238, :c 66762}
user=> (take 10 (sample [:a :b :c] :prob {:b 2 :c 1}))
(:c :c :b :b :b :b :b :c :b :c)
user=> (take 10 (sample [:a :b :c] :replace? false))
(:b :a :c)

You can also use a Mersenne Twister random number generator provided by Sean Luke.

user=> (use '[ec.util.mtf :only (make-mtf-gen)])
nil
user=> (require '[sample-utils.mtf :as mtf])
nil
user=> (def g (make-mtf-gen))
#'user/g
user=> (take 10 (mtf/sample g [:a :b :c]))
(:a :b :c :b :a :c :a :c :b :a)

Installation

Add the dependency to your project.clj (in case you use Leiningen or Cake):

[clj-sample-utils "0.0.1"]

Then,

(use 'sample-utils)

or,

;; This contains the high-performance but unsafe version.
(use 'sample-utils.unsafe)

;; With a Mersenne Twister random number generator.
(use 'sample-utils.mtf)

;; The unsafe version with a Mersenne Twister random number generator.
(use 'sample-utils.mtf.unsafe)

Build from source

  1. Download MersenneTwisterFast.java from Sean Luke's website.

  2. Put MersenneTwisterFast.java into src/jvm/ec/util/.

  3. Execute:

    cake jar ; in case you use Cake

    lein jar ; in case you use Leiningen

Contact

Mitsuhiro Nakamura m.nacamura@gmail.com

License

Eclipse Public License - v 1.0, see LICENSE.

Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.