Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
language: clojure
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
# Anglican

[![Build Status](https://travis-ci.org/LSaldyt/anglican.svg?branch=master)](https://travis-ci.org/LSaldyt/anglican)

Anglican is a probabilistic programming system
implemented in Clojure, both the programming environment and
the language. [Introduction to anglican](doc/intro.md) explains
the language.
To include Anglican in your Clojure project, add `[anglican "1.0.0"]` to your `project.clj` `:dependencies`.
*This* version of anglican (the LSaldyt fork) can be used with `[org.clojars.lsaldyt/anglican "1.0.1"]`.
[Introduction to Anglican](doc/intro.md) explains
how to write and run programs in anglican.

Everyone is welcome to write programs which call inference,
Expand Down Expand Up @@ -33,3 +38,7 @@ GNU General Public License for more details.
You should have received a copy of the [GNU General Public
License](gpl-3.0.txt) along with Anglican. If not, see
<http://www.gnu.org/licenses/>.

## Continuous Integration

Adds TravisCI
6 changes: 3 additions & 3 deletions project.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(defproject anglican "1.0.0-SNAPSHOT"
(defproject org.clojars.lsaldyt/anglican "1.0.1"
:description "Anglican, a probabilistic programming system"
:url "http://bitbucket.org/probprog/anglican"
:url "https://github.com/LSaldyt/anglican"
:license {:name "GNU General Public License Version 3"
:url "http://www.gnu.org/licenses/gpl.html"}
:dependencies [[org.clojure/clojure "1.8.0"]
Expand All @@ -14,7 +14,7 @@
[net.mikera/vectorz-clj "0.44.0"]]
:plugins [[codox "0.8.11"]]
:scm {:name "git"
:url "https://bitbucket.org/probprog/anglican"}
:url "https://github.com/LSaldyt/anglican"}
:repl-options {:timeout 600000}
:main ^:skip-aot anglican.core
:target-path "target/%s"
Expand Down
20 changes: 18 additions & 2 deletions src/anglican/runtime.clj
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
(sample* [this]
"draws a sample from the distribution")
(observe* [this value]
"return the probability [density] of the value"))
"return the log (using Math/log) probability [density] of the value"))

;; Log probabilities are used pervasively. A precision-preserving
;; way to add probabilities (e.g. for computing union probability)
Expand Down Expand Up @@ -175,7 +175,8 @@
(loop [[weight & weights] weights
acc 0. value 0]
(let [acc (+ acc weight)]
(if (< x acc) value
(if (< x acc)
value
(recur weights acc (inc value)))))))
(observe* [this value]
(Math/log
Expand All @@ -184,6 +185,18 @@
;; any value not in the support has zero probability.
(catch IndexOutOfBoundsException _ 0.)))))

(declare uniform-discrete)
(defdist uniform-draw
"Uniformly take a value from a vector"
[items] [n-items (count items)
dist (uniform-discrete 0 n-items)]
(sample* [this]
(let [i (sample* dist)]
(get items i)))
(observe* [this value]
(Math/log (/ 1 n-items))))


(declare gamma)
(defdist dirichlet
"Dirichlet distribution"
Expand Down Expand Up @@ -237,6 +250,9 @@
(from-apache uniform-discrete [min max] :discrete
(UniformInteger (int min) (dec (int max))))

;(defn )
;(uniform-discrete 0 10)

(defprotocol multivariate-distribution
"additional methods for multivariate distributions"
(transform-sample [this samples]
Expand Down