Skip to content
/ MJr Public

A probabilistic programming language based on pattern-rewriting

License

Notifications You must be signed in to change notification settings

kaya3/MJr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

73 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MJr-compiler

MJr is a probabilistic programming language based on pattern-rewriting, heavily inspired by MarkovJunior by Maxim Gumin. This project provides a compiler for the MJr programming language, which compiles MJr programs to JavaScript, TypeScript or Python 3.

image

Examples

More examples can be found in the models folder.

Usage

MJr programs can be compiled to JavaScript, TypeScript or Python 3. To use the compiled output in your project, you must also include the MJr runtime library:

  • JavaScript/TypeScript: MJr.js
  • TypeScript type declarations: MJr.d.ts
  • Python 3: MJr.py (requires Python 3.10+)

The MJr program can then be used by calling its main function, which has the following signature:

function main(width: int, height: int, rng?: PRNG): Grid;

The return value is a Grid object with the following properties:

  • width and height: the grid dimensions
  • data: the grid cells, as a flat array of unsigned integers in row-major order.
  • alphabet: a string mapping the values in data to the alphabet symbols used in the MJr source code.

For convenience, Grid objects can also be converted to strings for display.

The rng parameter is optional; if provided, it must be an object with a nextDouble method returning a random floating-point value in the half-open interval [0, 1), and a nextInt method accepting a positive integer n and returning a random integer in the half-open interval [0, n). If not provided, a default unseeded algorithm is used.

Documentation

See the documentation and implementation notes for more information.

About

A probabilistic programming language based on pattern-rewriting

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

No packages published