probmods / webppl

Probabilistic programming for the web
http://webppl.org
Other
619 stars 86 forks source link

Use distribution types from Javascript #469

Closed stuhlmueller closed 8 years ago

stuhlmueller commented 8 years ago

I'm working on upgrading dippl to webppl 0.7. This requires that we use distributions directly from Javascript (since we're re-implementing some of the inference algorithms for educational purposes). However, the distribution constructors don't seem to work when called from Javascript:

> var webppl = require(".")
undefined

> dists
{ Uniform: [Function],
  UniformDrift: [Function],
  Bernoulli: [Function],
  RandomInteger: [Function],
  Gaussian: [Function],
  GaussianDrift: [Function],
  MultivariateGaussian: [Function],
  Cauchy: [Function],
  Discrete: [Function],
  Gamma: [Function],
  Exponential: [Function],
  Beta: [Function],
  Binomial: [Function],
  Multinomial: [Function],
  Poisson: [Function],
  Dirichlet: [Function],
  DirichletDrift: [Function],
  Marginal: [Function],
  Categorical: [Function],
  Delta: [Function],
  discreteSample: [Function: discreteSample],
  gaussianSample: [Function: gaussianSample],
  gammaSample: [Function: gammaSample],
  dirichletSample: [Function: dirichletSample],
  serialize: [Function],
  deserialize: [Function],
  withImportanceDist: [Function: withImportanceDist],
  isDist: [Function: isDist],
  isParams: [Function: isParams] }

> dists.Bernoulli
[Function]

> dists.Bernoulli({p: 0.5})
undefined

> dists.Delta({v: 1})
undefined

Why might this be?

dritchie commented 8 years ago

Each member of 'dist' is a constructor function, so you'd need to use new dists.Bernoulli({p: 0.5}).

stuhlmueller commented 8 years ago

Oh right, thanks!