Skip to content

Instantly share code, notes, and snippets.

@ktsujister
Created September 6, 2014 13:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ktsujister/27ed7f216de20e13a8f7 to your computer and use it in GitHub Desktop.
Save ktsujister/27ed7f216de20e13a8f7 to your computer and use it in GitHub Desktop.
(ns more-distributions.triangular
(:require [incanter-contrib.distributions :as icd]
[incanter.charts :as c]
[incanter.core :as i]
[incanter.distributions :as d]
[incanter.stats :as s]))
(defn show-triangular-distribution []
(let [dist (icd/triangular-distribution 0.0 0.3 1.0)
n 100000
x (repeatedly n #(d/draw dist))
pdf-fn #(d/pdf dist %)]
(let [nbins 50
series-label "triangular"
[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 "triangular-pdf")
i/view))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment