Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
stuhlmueller committed Jun 23, 2016
2 parents 8052862 + a1d59b4 commit fad4487
Show file tree
Hide file tree
Showing 105 changed files with 3,705 additions and 823 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ node_modules
npm-debug.log
bundle/
docs/_build
docs/_static
docs/_templates
src/dists.js
src/inference/enumerate.js
src/inference/elbo.js
src/inference/eubo.js
src/aggregation/ScoreAggregator.js
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@ language: node_js

node_js:
- "0.12"
- "0.11"
- "0.10"
- "4"
- "5"
- "6"

env:
- TASK=default

matrix:
include:
- node_js: "5"
- node_js: "6"
env: TASK=travis-phantomjs

install:
Expand Down
2 changes: 1 addition & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var jslintSettings = {
src: [
'Gruntfile.js',
'src/header.wppl',
'src/**/!(dists|enumerate|ScoreAggregator).js'
'src/**/!(dists|enumerate|elbo|eubo|ScoreAggregator).js'
]
},
test: {
Expand Down
2 changes: 2 additions & 0 deletions docs/_static/custom.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/* don't use bold on inline code within js:function blocks */
.rst-content dl:not(.docutils) code { font-weight: normal; }
229 changes: 229 additions & 0 deletions docs/arrays.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,229 @@
Arrays
======

.. js:function:: map(fn, arr)

Returns an array obtained by mapping the function ``fn`` over array
``arr``.

::

map(function(x) { return x + 1; }, [0, 1, 2]); // => [1, 2, 3]

.. js:function:: map2(fn, arr1, arr2)

Returns an array obtained by mapping the function ``fn`` over
arrays ``arr1`` and ``arr2`` concurrently. Each application of
``fn`` has an element of ``arr1`` as its first argument and the
element with the same index in ``arr2`` as its second argument.

It is assumed that ``arr1`` and ``arr2`` are arrays of the same
length. When this is not the case the behavior of ``map2`` is
undefined.

::

var concat = function(x, y) { return x + y; };
map2(concat, ['a', 'b'], ['1', '2']); // => ['a1', 'b2']

.. js:function:: mapN(fn, n)

Returns an array obtained by mapping the function ``fn`` over the
integers ``[0,1,...,n-1]``.

::

var inc = function(x) { return x + 1; };
mapN(inc, 3); // => [1, 2, 3]

.. js:function:: mapIndexed(fn, arr)

Returns the array obtained by mapping the function ``fn`` over
array ``arr``. Each application of ``fn`` has the index of the
current element as its first argument and the element itself as its
second argument.

::

var pair = function(x, y) { return [x, y]; };
mapIndexed(pair, ['a', 'b']); // => [[0, 'a'], [1, 'b']]

.. js:function:: reduce(fn, init, arr)

Reduces array ``arr`` to a single value by applying function ``fn``
to an accumulator and each value of the array. ``init`` is the
initial value of the accumulator.

::

reduce(function(x, acc) { return x + acc; }, 0, [1, 2, 3]); // => 6

.. js:function:: sum(arr)

Computes the sum of the elements of array ``arr``.

It is assumed that each element of ``arr`` is a number.

::

sum([1, 2, 3, 4]) // => 10

.. js:function:: product(arr)

Computes the product of the elements of array ``arr``.

It is assumed that each element of ``arr`` is a number.

::

product([1, 2, 3, 4]) // => 24

.. js:function:: listMean(arr)

Computes the mean of the elements of array ``arr``.

It is assumed that ``arr`` is not empty, and that each element is a
number.

::

listMean([1, 2, 3]); // => 2

.. js:function:: listVar(arr[, mean])

Computes the variance of the elements of array ``arr``.

The ``mean`` argument is optional. When supplied it is expected to
be the mean of ``arr`` and is used to avoid recomputing the mean
internally.

It is assumed that ``arr`` is not empty, and that each element is a
number.

::

listVar([1, 2, 3]); // => 0.6666...

.. js:function:: listStdev(arr[, mean])

Computes the standard deviation of the elements of array ``arr``.

The ``mean`` argument is optional. When supplied it is expected to
be the mean of ``arr`` and is used to avoid recomputing the mean
internally.

It is assumed that ``arr`` is not empty, and that each element is a
number.

::

listStdev([1, 2, 3]); // => 0.8164...

.. js:function:: all(predicate, arr)

Returns ``true`` when all of the elements of array ``arr`` satisfy
``predicate``, and ``false`` otherwise.

::

all(function(x) { return x > 1; }, [1, 2, 3]) // => false

.. js:function:: any(predicate, arr)

Returns ``true`` when any of the elements of array ``arr`` satisfy
``predicate``, and ``false`` otherwise.

::

any(function(x) { return x > 1; }, [1, 2, 3]) // => true

.. js:function:: zip(arr1, arr2)

Combines two arrays into an array of pairs. Each pair is
represented as an array of length two.

It is assumed that ``arr1`` and ``arr2`` are arrays of the same
length. When this is not the case the behavior of ``zip`` is
undefined.

::

zip(['a', 'b'], [1, 2]); // => [['a', 1], ['b', 2]]

.. js:function:: filter(predicate, arr)

Returns a new array containing only those elements of array ``arr``
that satisfy ``predicate``.

::

filter(function(x) { return x > 1; }, [0, 1, 2, 3]); // => [2, 3]

.. js:function:: find(predicate, arr)

Returns the first element of array ``arr`` that satisfies
``predicate``. When no such element exists ``undefined`` is
returned.

::

find(function(x) { return x > 1; }, [0, 1, 2]); // => 2

.. js:function:: remove(element, arr)

Returns a new array obtained by filtering out of array ``arr``
elements not equal to ``element``.

::

remove(0, [0, -1, 0, 2, 1]); // => [-1, 2, 1]

.. js:function:: groupBy(eqv, arr)

Splits an array into sub-arrays based on pairwise equality checks
performed by the function ``eqv``.

::

var sameLength = function(x, y) { return x.length === y.length; };
groupBy(sameLength, ['a', 'ab', '', 'bc']); // => [['a'], ['ab', 'bc'], ['']]

.. js:function:: repeat(n, fn)

Returns an array of length ``n`` where each element is the result
of applying ``fn`` to zero arguments.

::

repeat(3, function() { return true; }); // => [true, true, true]

.. js:function:: sort(arr[, predicate[, fn]])

Returns a sorted array.

Elements are compared using ``<`` by default. This is equivalent to
passing ``lt`` as the ``predicate`` argument. To sort by ``>`` pass
``gt`` as the ``predicate`` argument.

To sort based on comparisons between a function of each element,
pass a function as the ``fn`` argument.

::

sort([3,2,4,1]); // => [1, 2, 3, 4]
sort([3,2,4,1], gt); // => [4, 3, 2, 1]

var length = function(x) { return x.length; };
sort(['a', 'ab', ''], lt, length); // => ['', 'a', 'ab']

.. js:function:: sortOn(arr[, fn[, predicate]])

This implements the same function as ``sort`` but with the order of
the ``predicate`` and ``fn`` parameters switched. This is
convenient when you wish to specify ``fn`` without specifying
``predicate``.

::

var length = function(x) { return x.length; };
sortOn(['a', 'ab', ''], length); // => ['', 'a', 'ab']
9 changes: 9 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@
# output. They are ignored by default.
#show_authors = False

# The default language to highlight source code in.
# http://www.sphinx-doc.org/en/stable/config.html#confval-highlight_language
highlight_language = 'javascript'

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'

Expand Down Expand Up @@ -137,6 +141,11 @@
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']

# https://obda.net/blog/custom-css-and-js-for-sphinx-generated-documentation/
html_context = {
'css_files': ['_static/custom.css']
}

# Add any extra paths that contain custom files (such as robots.txt or
# .htaccess) here, relative to this directory. These files are copied
# directly to the root of the documentation.
Expand Down
21 changes: 12 additions & 9 deletions docs/debugging.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,23 @@ WebPPL provides error messages that try to be informative.
In addition there is debugging software you can use for WebPPL programs.

To debug WebPPL programs running in Chrome, enable `pause on JavaScript
exceptions`_ in the Chrome debugger. To debug WebPPL programs running in
nodejs, use node debugger as follows:
exceptions`_ in the Chrome debugger.

To debug WebPPL programs running in nodejs, use node debugger as
follows:

1. Add ``debugger;`` statements to ``my-program.wppl`` to indicate breakpoints.

2. Run your compiled program in debug mode.
2. Run your compiled program in debug mode::

node debug path/to/webppl my-program.wppl

::
node debug /path/to/webppl/directory/webppl my-program.wppl
Note that you will need the full path to the ``webppl`` executable.
This might be in the ``lib`` folder of your ``node`` directory if
you installed with ``npm``. On many systems you can avoid entering
the path manually by using the following command::

* Note that you will need the full path to the ``webppl`` executable.
This might be in the ``lib`` folder of your ``node`` directory if
you installed with ``npm``.
node debug `which webppl` my-program.wppl

3. To navigate to your breakpoint within the debugger interface, type
``cont`` or ``c``.
Expand Down

0 comments on commit fad4487

Please sign in to comment.