{"id":15400609,"url":"https://github.com/armanbilge/schrodinger","last_synced_at":"2025-05-07T13:06:50.699Z","repository":{"id":37156522,"uuid":"362762406","full_name":"armanbilge/schrodinger","owner":"armanbilge","description":"Give your cats a set of dice","archived":false,"fork":false,"pushed_at":"2025-04-21T19:18:13.000Z","size":920,"stargazers_count":38,"open_issues_count":19,"forks_count":4,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-05-07T13:06:42.805Z","etag":null,"topics":["cats","cats-effect","probabilistic-programming"],"latest_commit_sha":null,"homepage":"","language":"Scala","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/armanbilge.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-04-29T09:29:23.000Z","updated_at":"2025-05-06T20:22:48.000Z","dependencies_parsed_at":"2023-10-03T15:00:36.174Z","dependency_job_id":"a5c63c2b-f558-4042-a31f-ce2fedccc499","html_url":"https://github.com/armanbilge/schrodinger","commit_stats":{"total_commits":619,"total_committers":3,"mean_commits":"206.33333333333334","dds":"0.36187399030694667","last_synced_commit":"243d7659b581b4fed5940265468ed5985f3a79a0"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/armanbilge%2Fschrodinger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/armanbilge%2Fschrodinger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/armanbilge%2Fschrodinger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/armanbilge%2Fschrodinger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/armanbilge","download_url":"https://codeload.github.com/armanbilge/schrodinger/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252883204,"owners_count":21819160,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["cats","cats-effect","probabilistic-programming"],"created_at":"2024-10-01T15:54:21.218Z","updated_at":"2025-05-07T13:06:50.676Z","avatar_url":"https://github.com/armanbilge.png","language":"Scala","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Schrodinger\n\n[![Latest version](https://index.scala-lang.org/armanbilge/schrodinger/schrodinger/latest.svg?color=orange)](https://index.scala-lang.org/armanbilge/schrodinger/schrodinger)\n\n\u003cimg align=\"right\" width=\"384px\" src=\"https://user-images.githubusercontent.com/3119428/139197953-1abbf14c-0484-4a79-b6d0-927bd05a4546.png\"/\u003e\n\nSchrodinger is an (early-stage) project for probabilistic programming in Scala 3, built for the [Cats](https://github.com/typelevel/cats) ecosystem. At its heart is the `RVT` monad transformer for modeling pseudo-random effects that is designed to fully compose with asynchronous effects such as `IO`. The goal is that this construct will facilitate the implementation of high-performance, concurrent Monte Carlo algorithms for simulation and inference. \n\nFurthermore, Schrodinger encodes the foundational probability distributions as a set of typeclasses to be used to write \"universal\" probabilistic programs, for which simulators and inference algorithms can be automatically derived by implementing interpreters in terms of these same typeclasses.\n\n## Usage\n\n```scala\nlibraryDependencies += \"com.armanbilge\" %% \"schrodinger\" % \"0.3-193-ed9a8ba\"\n```\n\n## Modules\n\n* `kernel`: essential typeclasses for writing probabilistic programs.\n  - `Random[F[_]]` encodes the primitive of generating random bits in the form of `Int` and `Long`.\n  - `PseudoRandom[F[_], G[_], S]`: encodes the ability to pseudo-randomly simulate (\"compile\") a `Random` effect `F` to another effect `G` via a seed `S`. Extends `Random[F]`.\n  - `Distribution[F[_], P, X]`: the Kleisli `P =\u003e F[X]`, encoding the mapping from parameters `P` (e.g., the mean and standard deviation of a Gaussian) for a distribution on `X` (e.g., the reals represented as `Double`) to an instance of an effect `F[X]` (e.g., an effect implementing the `Random` typeclass).\n  - Various `case class`es parameterizing different distribution families, to be used as arguments for `P` above, as well as convenient aliases that can be used with the usual typeclass syntax.\n  - `Density[F[_], X, R]`: the Kleisli `X =\u003e F[R]`, encoding the probability density (or probability mass) function in some effect `F`.\n* `random`: samplers for the distribution families in `kernel`. These are implemented purely monadically, in terms of `Random[F]` or each other.\n* `schrodinger`: the core module, also brings in `random`.\n  - `RVT[F[_], S, A]`: a monad transformer for pseudo-random effects. Use this to simulate your probabilistic programs. Externally it is pure, although internally it is implemented with a mutable RNG for performance. Notably, it implements all the Cats Effect typeclasses up to `Async` (given that `F` is equally capable) by utilizing the underlying RNG's capability to deterministically [\"split\"](https://docs.oracle.com/javase/8/docs/api/java/util/SplittableRandom.html) itself, such that each fiber has its own source of randomness. Not only does this avoid contention and synchronization, it makes it possible to write pseudo-random programs that are concurrent yet _deterministic_, and thus reproducible. Anyone who has debugged a complex Monte Carlo algorithm knows this is a big deal.\n  - `Rng[S]`: a mutable and thus unsafe random number generator with state `S`.\n  - `RngDispatcher[F[_], S]`: \"dispatches\" a mutable RNG that can be used to run pseudo-random imperative programs, for interop with unsafe lands. This also relies on the splitting capability described above.\n* `stats`: `Density` implementations for the distribution families in `kernel`. \n* `monte-carlo`: algorithms and datastructures for Monte Carlo inference.\n  - `Weighted` and `WeightedT`: encodes a sample from a distribution along with its weight and probability density. This is useful for implementing importance sampling-based algorithms.\n  - `ImportanceSampler`: derives a sampler for a distribution `P` in terms of a sampler for a distribution `Q`.\n* `math`: assorted math stuff.\n  - `LogDouble` for [probability calculations in log space](https://en.wikipedia.org/wiki/Log_probability).\n* `laws`: currently empty besides a silly law for `PseudoRandom`. Still figuring this one out in [#2](https://github.com/armanbilge/schrodinger/issues/2).\n* `kernel-testkit`: currently mostly used to test `random`.\n  - the `PureRVT` monad, implemented in terms of Cats' `StateT`. It is completely pure, unlike `RVT` in core which is run with an unsafe mutable RNG.\n  - \\*waves hands\\* `Eq` for a pseudo-random effect `F`.\n* `testkit`: used to test `RVT`.\n\nIf not readily apparent, various aspects of the design are heavily influenced by [Cats Effect 3](https://github.com/typelevel/cats-effect).\n* `monte-carlo` is like a \"`std`\" lib, and so-called middlewares can ideally be implemented only in terms of that and `kernel`. The implementations provided by the `random` and `stats` modules and `RVT` itself are only needed at runtime and indeed can be substituted with (more performant!) alternatives.\n* The unsafe `Rng` that is used to simulate an `RVT` is kind of like the unsafe `IORuntime` that runs `IO`.\n* `RngDispatcher` facilitates interop with \"unsafe lands\" inspired by the `Dispatcher` in CE3.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farmanbilge%2Fschrodinger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farmanbilge%2Fschrodinger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farmanbilge%2Fschrodinger/lists"}