Dynamic programming utilities for webppl
JavaScript
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src expose cache variable so people can measure scaling Mar 11, 2016
.gitignore
README.md Update README.md Jan 24, 2016
package.json 0.1.1 Jan 24, 2016
test.wppl expose cache variable so people can measure scaling Mar 11, 2016

README.md

webppl-dp

This package provides a function dp.cache that memoizes functions in a way compatible with mutual recursion.

var even = dp.cache(function(x) {
  console.log('Called `even` with argument ' + x);
  if (x == 0) {
    return true;
  } else {
    return odd(x - 1);
  }
});

var odd = dp.cache(function(x) {
  console.log('Called `odd` with argument ' + x);
  if (x == 0) {
    return false;
  } else {
    return even(x - 1);
  }
});

console.log(odd(3));
console.log(odd(5));

returns

Called `odd` with argument 3
Called `even` with argument 2
Called `odd` with argument 1
Called `even` with argument 0
true
Called `odd` with argument 5
Called `even` with argument 4
true

Installation

To globally install webppl-dp, run:

mkdir -p ~/.webppl
npm install --prefix ~/.webppl webppl-dp

This may print warnings (npm WARN ENOENT...) which can be ignored.

To upgrade to the latest version, run:

npm install --prefix ~/.webppl webppl-dp --force

Usage

Once installed, you can make dp.cache available to program.wppl by running:

webppl program.wppl --require webppl-dp

License

MIT