开发者

Generating Random Numbers in Incanter

How 开发者_StackOverflow中文版do I use the random number generators in Parallel Colt from incanter?

I've listed these dependencies in my project.clj file:

:dependencies [
                 [org.clojure/clojure "1.2.0"]
                 [org.clojure/clojure-contrib "1.2.0"]
                 [incanter/core "1.2.3"]
                 [incanter/parallelcolt "0.9.4"]
              ]

And then I tried (import cern.jet.random.tdouble Normal) and I get a class java.lang.ClassNotFoundException.

What am I doing wrong here?


You don't need to call Parallel Colt directly to generate random numbers in Incanter. There are two different methods.

First, there is the original random number generator functions in incanter.stats:

sample-normal
sample-poisson
sample-uniform
sample-t
sample-net-binomial
sample-binomial
etc..

Each function takes the number of values to generate, as its first argument, as well as optional args for setting the parameters of the distribution to draw from. For instance, to draw 100 values from a normal distribution with a mean of -2 and a standard deviation of sqrt of 0.5, do this:

(use '[incanter core stats])
(sample-normal 100 :mean -2 :sd (sqrt 0.5))

The second method for generating random numbers is to use functions in the incanter.distributions namespace.

(require '[incanter.distributions :as dist])
(dist/draw (dist/normal-distribution -2 (sqrt 0.5)))


liebke may have addressed your domain-specific need here but re importing:

1) Make sure you run lein deps

2) The syntax for import is (import [cern.jet.random.tdouble Normal]) or (import cern.jet.random.tdouble.Normal)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜