{"id":32191189,"url":"https://github.com/thomasathorne/clj-stan","last_synced_at":"2026-02-21T12:01:38.562Z","repository":{"id":62431521,"uuid":"99703565","full_name":"thomasathorne/clj-stan","owner":"thomasathorne","description":"A library to interface with STAN.","archived":false,"fork":false,"pushed_at":"2018-11-22T13:22:24.000Z","size":31,"stargazers_count":17,"open_issues_count":0,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2026-02-17T10:54:45.352Z","etag":null,"topics":["bayesian-inference","machine-learning","stan"],"latest_commit_sha":null,"homepage":null,"language":"Clojure","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/thomasathorne.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-08-08T14:44:21.000Z","updated_at":"2023-01-23T15:51:13.000Z","dependencies_parsed_at":"2022-11-01T21:01:05.318Z","dependency_job_id":null,"html_url":"https://github.com/thomasathorne/clj-stan","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/thomasathorne/clj-stan","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thomasathorne%2Fclj-stan","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thomasathorne%2Fclj-stan/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thomasathorne%2Fclj-stan/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thomasathorne%2Fclj-stan/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thomasathorne","download_url":"https://codeload.github.com/thomasathorne/clj-stan/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thomasathorne%2Fclj-stan/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29680147,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-21T11:29:27.227Z","status":"ssl_error","status_checked_at":"2026-02-21T11:29:20.292Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bayesian-inference","machine-learning","stan"],"created_at":"2025-10-22T01:34:19.843Z","updated_at":"2026-02-21T12:01:38.549Z","avatar_url":"https://github.com/thomasathorne.png","language":"Clojure","funding_links":[],"categories":[],"sub_categories":[],"readme":"# clj-stan\n\nA Clojure library that interfaces with the STAN statistical modeling\nplatform as an external process.\n\n## Setup\n\nThis project uses the `cmdstan` command line interface to STAN.\n\nUnfortunately, `clj-stan` is not very flexible in which version of\n`cmdstan` it can use. To install `cmdstan` version `2.18.0`, make sure\nyou have the necessary dependencies installed:\n\n    sudo apt-get install clang g++ libc++-dev\n\nand then download the tar file `cmdstan-2.18.0.tar.gz` from\nhttps://github.com/stan-dev/cmdstan/releases. Extract the archive, and\nthen run\n\n    make build -j4\n\nin the resulting directory. The `-j4` option parallelises the build,\nwhich is advisable since it takes 10+ minutes and is quite CPU\nintensive.\n\nYou must configure the environment variable `$STAN_HOME` to be the\npath to the directory extracted from the release tar.\n\nThis process is scripted in the `install` directory. There is also a\n`Dockerfile` there, which is intended to build a base image for\nclojure apps that use `clj-stan`.\n\nA simple way to check that things are correctly configured is to run\nthe (fairly minimal) test suite:\n\n    me@machine:~/projects/clj-stan$ lein test\n\n## Usage\n\nSuppose we have the following model written in the file\n`/models/bernoulli.stan`:\n\n```\ndata {\n  int\u003clower=0\u003e N;\n  int\u003clower=0,upper=1\u003e y[N];\n}\nparameters {\n  real\u003clower=0,upper=1\u003e theta;\n}\nmodel {\n  theta ~ beta(0.5,0.5);\n  for (n in 1:N)\n    y[n] ~ bernoulli(theta);\n}\n```\n\nwhich expresses a simple bernoulli trial model with the Jeffreys\nprior.\n\nThere are three core functions we will use:\n\n    (def bern (stan/make \"/models/bernoulli.stan\" \"bern\"))\n\nwill compile the model and return a record that wraps the resulting\nexecutable. This record implements two methods:\n\n    (stan/sample bern {:N 3 :y [0 1 1]})\n\nthe primary sampling method, returns a collection of samples from the\nposterior distribution of the model, and:\n\n    (stan/optimize bern {:N 3 :y [0 1 1]})\n\ncalls the optimization routine of the executable, which will find the\nMAP ('Maximum A Posteriori') estimate for the model.\n\nAlternatively, the variational bayes approach can be used for model\ntraining\n\n    (stan/variational bern {:N 3 :y [0 1 1]} \"fullrank\")\n\nThe third parameter specifies the variational algorithm to be used,\nwhich can be either `meanfield` (using a fully factored Gaussian for\nthe approximation) or `fullrank` (using a Gaussian with full-rank\ncovariance matrix for the optimization). The `variational` method\nreturns a map containing keys `:mode` and `:samples`.\n\n## Resources\n\nSee the cmdstan documentation at\nhttp://mc-stan.org/users/interfaces/cmdstan\n\n## License\n\n```\n  Copyright (c) Metail and Thomas Athorne\n\n  Licensed under the Apache License, Version 2.0 (the \"License\");\n  you may not use this file except in compliance with the License.\n  You may obtain a copy of the License at\n\n      http://www.apache.org/licenses/LICENSE-2.0\n\n  Unless required by applicable law or agreed to in writing, software\n  distributed under the License is distributed on an \"AS IS\" BASIS,\n  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n  See the License for the specific language governing permissions and\n  limitations under the License.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthomasathorne%2Fclj-stan","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthomasathorne%2Fclj-stan","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthomasathorne%2Fclj-stan/lists"}