diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..07913052 --- /dev/null +++ b/.travis.yml @@ -0,0 +1 @@ +language: clojure diff --git a/README.md b/README.md index 9829d4d0..4e798de7 100644 --- a/README.md +++ b/README.md @@ -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, @@ -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 . + +## Continuous Integration + +Adds TravisCI diff --git a/project.clj b/project.clj index f2ad6f34..51c92b9d 100644 --- a/project.clj +++ b/project.clj @@ -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"] @@ -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" diff --git a/src/anglican/runtime.clj b/src/anglican/runtime.clj index b33565c0..9ba2d032 100644 --- a/src/anglican/runtime.clj +++ b/src/anglican/runtime.clj @@ -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) @@ -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 @@ -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" @@ -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]