Skip to content

Instantly share code, notes, and snippets.

@ktsujister
Created August 30, 2014 12:23
Show Gist options
  • Save ktsujister/7ffee3319f15dfa42376 to your computer and use it in GitHub Desktop.
Save ktsujister/7ffee3319f15dfa42376 to your computer and use it in GitHub Desktop.
(ns various-distributions.exponential
(:require [incanter.charts :as c]
[incanter.core :as i]
[incanter.distributions :as d]
[incanter.stats :as s]))
(defn show-exponential-distribution []
(let [dist (d/exponential-distribution 1.0)
n 100000
x (repeatedly n #(d/draw dist))
pdf-fn #(d/pdf dist %)]
(let [nbins 50
series-label "exponential"
[x-min x-max] (s/quantile x :probs [0.01 0.99])]
(-> (c/histogram x :nbins nbins :density true :series-label series-label)
(c/set-x-range x-min x-max)
(c/add-function pdf-fn x-min x-max :series-label "exponential-pdf")
i/view))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment