Skip to content

Commit 0b935c0

Browse files
[documentation] Refactor examples and add listings captions
1 parent 4e79359 commit 0b935c0

13 files changed

+1726
-953
lines changed

docs/source/_static/custom.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
div.code-block-caption {
2+
justify-content: center;
3+
text-align: center;
4+
}
5+
6+
div.code-block-caption > span.caption-text {
7+
visibility: hidden;
8+
display: none;
9+
}

docs/source/conf.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,20 @@
4040
"IPython.sphinxext.ipython_console_highlighting",
4141
]
4242

43+
html_css_files = [
44+
'custom.css',
45+
]
46+
4347
mathjax_config = {
4448
# 'extensions': [''],
4549
# 'jax': ['input/TeX']
4650
}
4751

52+
modindex_common_prefix = ['symbolic_pymc.']
53+
54+
numfig = True
55+
numfig_secnum_depth = 1
56+
4857
# Don't auto-generate summary for class members.
4958
numpydoc_show_class_members = False
5059

@@ -76,7 +85,6 @@
7685
html_theme_options = {
7786
"navbar_links": [
7887
("Index", "index"),
79-
("Examples", "symbolic-pymc-examples"),
8088
("API", "modules"),
8189
],
8290
}

docs/source/index.rst

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,26 @@ Welcome to Symbolic PyMC's documentation!
1010
:maxdepth: 2
1111
:caption: Contents:
1212

13-
symbolic-pymc-tour.md
14-
symbolic-pymc-examples
15-
radon-example
13+
symbolic-pymc-tour
1614
modules
1715

16+
Examples
17+
========
18+
19+
.. toctree::
20+
:maxdepth: 1
21+
:caption: Theano:
22+
23+
theano-posteriors-example
24+
theano-radon-example
25+
26+
.. toctree::
27+
:maxdepth: 1
28+
:caption: TensorFlow:
29+
30+
tensorflow-radon-example
31+
tensorflow-simplification-example
32+
1833
Indices and tables
1934
==================
2035

docs/source/symbolic-pymc-tour.org

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ Tensor(MatMul):0, dtype=float32, shape=[None, 1], "MatMul:0"
9191

9292
#+end_SRC
9393

94-
The output of Listing [[tf-print-graph]] shows us the underlying operators (e.g. ~MatMul~,
94+
The output of [[tf-print-graph]] shows us the underlying operators (e.g. ~MatMul~,
9595
~Placeholder~, ~AddV2~) and their arguments.
9696

9797
To "match/search for" combinations of TensorFlow operations--or, in other words, graphs--like
@@ -188,7 +188,7 @@ TFlowMetaTensor(
188188

189189
#+end_SRC
190190

191-
In Listing [[create-meta-graph]], we created a graph of src_python[:eval never]{1} plus
191+
In [[create-meta-graph]], we created a graph of src_python[:eval never]{1} plus
192192
a src_python[:eval never]{unification} logic variable with the name src_python[:eval never]{'a'}. This
193193
wouldn't be possible with a standard TensorFlow graph.
194194

@@ -308,7 +308,7 @@ an src_python[:eval never]{etuple} can be manipulated until all of its constitue
308308
variables and meta objects are eventually replaced with valid arguments to the
309309
function/operator. At that point, the src_python[:eval never]{etuple} can be evaluated.
310310

311-
For example, in Listing [[etuple-eval-example]], we create an src_python[:eval never]{etuple}
311+
For example, in [[etuple-eval-example]], we create an src_python[:eval never]{etuple}
312312
that uses the TensorFlow function src_python[:eval never]{tf.add} with a logic variable argument.
313313
#+NAME: etuple-eval-example
314314
#+BEGIN_SRC python :exports code :results none
@@ -318,7 +318,7 @@ add_tf_pat = etuple(tf.add, x_lv, y_lv)
318318
#+END_SRC
319319

320320
Normally, it wouldn't be possible to call this function with these argument
321-
types, as demonstrated in Listing [[etuple-bad-usage-example]].
321+
types, as demonstrated in [[etuple-bad-usage-example]].
322322

323323
#+NAME: etuple-bad-usage-example
324324
#+BEGIN_SRC python :exports both :results output :wrap "SRC python :eval never"
@@ -345,7 +345,7 @@ its src_python[:eval never]{ExpressionTuple.eval_obj} property. However, after
345345
performing a simple manipulation that replaces the logic variable with valid
346346
inputs to src_python[:eval never]{tf.add}, we are able to evaluate
347347
the src_python[:eval never]{etuple} and obtain a TF Tensor result, as
348-
demonstrated in Listings [[etuple-reify-example]] and
348+
demonstrated in [[etuple-reify-example]] and
349349
[[etuple-reify-eval-print-example]].
350350

351351
#+NAME: etuple-reify-example
@@ -388,10 +388,10 @@ objects that, through the use of src_python[:eval never]{eval}, could achieve
388388
the same results--albeit without the more convenient tuple-like structuring.
389389

390390
* Meta Operators and their Parameters
391-
In Listing [[etuplize-graph-print]], the src_python[:eval never]{etuple} form of
391+
In [[etuplize-graph-print]], the src_python[:eval never]{etuple} form of
392392
our matrix multiplication graph, src_python[:eval never]{z_sexp}, produced
393393
src_python[:eval never]{symbolic_pymc.tensorflow.meta.TFlowMetaOperator}
394-
in the function/operator position. Listing [[print-etuple-operator]] prints
394+
in the function/operator position. [[print-etuple-operator]] prints
395395
only the function part of the src_python[:eval never]{etuple}.
396396

397397
#+NAME: print-etuple-operator
@@ -438,7 +438,7 @@ src_python[:eval never]{Operation}'s src_python[:eval never]{OpDef}. Notice tha
438438
src_python[:eval never]{NodeDef} in the meta operator for src_python[:eval never]{tf.matmul}
439439
has a src_python[:eval never]{dict} containing src_python[:eval never]{transpose_*} entries.
440440
These are the default values for the TF function src_python[:eval never]{tf.matmul} (see
441-
Listing [[print-tf-matmul]]).
441+
[[print-tf-matmul]]).
442442

443443
#+NAME: print-tf-matmul
444444
#+BEGIN_SRC python :exports both :results output :wrap "SRC python :eval never"
@@ -481,7 +481,7 @@ Patterns, in this case, take the form of meta graphs or S-expr graphs with the
481481
desired structure and logic variables in place of "unknown" or arbitrary terms
482482
that we might like to reference elsewhere.
483483

484-
Listing [[matmul-pattern]] represents an S-expr that evaluates to a graph in
484+
[[matmul-pattern]] represents an S-expr that evaluates to a graph in
485485
which two terms are matrix-multiplied.
486486
#+NAME: matmul-pattern
487487
#+BEGIN_SRC python :exports code :results none
@@ -497,7 +497,7 @@ matmul_pat_mt = matmul_op_mt(A_lv, B_lv)
497497
matmul_pat = etuplize(matmul_pat_mt)
498498
#+END_SRC
499499

500-
In Listing [[matmul-pattern]] we created a meta
500+
In [[matmul-pattern]] we created a meta
501501
graph, src_python[:eval never]{matmul_pat_mt}, from a meta
502502
TF src_python[:eval never]{MatMul} operator and a
503503
variable src_python[:eval never]{NodeDef}, then we applied that meta operator to
@@ -590,7 +590,7 @@ our "pattern" with the matches obtained by src_python[:eval never]{unify} that a
590590
within the variable src_python[:eval never]{s}, or we could specify our own substitutions
591591
based on that information.
592592

593-
In Listing [[matmul-pattern-reify]], we simply change the src_python[:eval never]{'name'} value in the
593+
In [[matmul-pattern-reify]], we simply change the src_python[:eval never]{'name'} value in the
594594
and create a new graph with that value. The end result is a version of the original
595595
graph, src_python[:eval never]{z_sexp}, with a new name.
596596
#+NAME: matmul-pattern-reify
@@ -684,13 +684,13 @@ and src_python[:eval never]{y_lv} mapped to their template-corresponding objects
684684
in another graph, we can reify src_python[:eval never]{output_pat} and obtain a
685685
"transformed" version of said graph.
686686

687-
Using our earlier unification results in Listing [[matmul-pattern-unify]], we only
687+
Using our earlier unification results in [[matmul-pattern-unify]], we only
688688
need to reify our output pattern, src_python[:eval never]{output_pat}, with
689689
those mappings. However, since our output pattern refers to logic variables
690690
src_python[:eval never]{x_lv} and src_python[:eval never]{y_lv}, we'll need
691691
to unify those logic variables with the appropriate terms in the graph.
692692

693-
Listing [[dist-add-unify]], unifies the remaining terms by simply extracting the
693+
[[dist-add-unify]], unifies the remaining terms by simply extracting the
694694
src_python[:eval never]{B} argument in the matrix multiply and unifying
695695
that with a pattern for tensor addition.
696696

@@ -764,7 +764,7 @@ Normally, a user will only need to construct compound goals from a basic set of
764764
primitives. Arguably, the most primitive goal is the [[https://en.wikipedia.org/wiki/Equivalence_relation][equivalence relation]]
765765
under unification denoted by src_python[:eval never]{eq} in Python.
766766

767-
In Listing [[mk-basics-eq]], we ask for all successful results/reifications (signified
767+
In [[mk-basics-eq]], we ask for all successful results/reifications (signified
768768
by the src_python[:eval never]{0} argument) of the logic variable src_python[:eval never]{var('q')} for the goal
769769
src_python[:eval never]{eq(var('q'), 1)}--i.e. unify src_python[:eval never]{var('q')} with src_python[:eval never]{1}.
770770

@@ -814,7 +814,7 @@ pprint(mk_res)
814814

815815
#+end_SRC
816816

817-
In Listing [[mk-basics-lall]], we used src_python[:eval never]{lall} to obtain the conjunction of two unification goals.
817+
In [[mk-basics-lall]], we used src_python[:eval never]{lall} to obtain the conjunction of two unification goals.
818818
Since we requested that the same logic variable be unified
819819
with both src_python[:eval never]{1} and src_python[:eval never]{2} simultaneously (i.e. in the same
820820
state), which isn't possible, we got back an empty stream of results--indicating failure.
@@ -839,7 +839,7 @@ pprint(mk_res)
839839

840840
#+end_SRC
841841

842-
The goal disjunction results in Listing [[mk-basics-lany-print]] show that the logic variable
842+
The goal disjunction results in [[mk-basics-lany-print]] show that the logic variable
843843
src_python[:eval never]{q_lv} can be unified with either src_python[:eval never]{1} *or* src_python[:eval never]{2} under the
844844
two unification goals.
845845

@@ -874,14 +874,14 @@ pprint(mk_res)
874874

875875
#+end_SRC
876876

877-
In Listing [[mk-basics-conde]], we introduced another logic
877+
In [[mk-basics-conde]], we introduced another logic
878878
variable, src_python[:eval never]{r_lv}, and requested the reified values of a list
879879
containing both logic variables. The output resembles the idea that
880880
if src_python[:eval never]{q_lv} is "equal" to src_python[:eval never]{1}, then src_python[:eval never]{r_lv} is "equal"
881881
to src_python[:eval never]{10}, etc. Unlike normal conditionals, each clause/branch isn't
882882
exclusive, instead each is realized when the goals in a branch can be successful.
883883

884-
Listing [[mk-basics-conde-exclusive]], demonstrates when src_python[:eval never]{conde} can behave more
884+
[[mk-basics-conde-exclusive]], demonstrates when src_python[:eval never]{conde} can behave more
885885
like a traditional conditional statement.
886886
#+NAME: mk-basics-conde-exclusive
887887
#+BEGIN_SRC python :exports code :results none
@@ -936,7 +936,7 @@ Tensor(AddV2):0, dtype=float32, shape=~_14, "add:0"
936936
#+end_SRC
937937

938938
We didn't need to use the goal conjunction operator src_python[:eval never]{lall} explicitly
939-
in Listing [[mk-distribute]], because all remaining goal arguments
939+
in [[mk-distribute]], because all remaining goal arguments
940940
to src_python[:eval never]{run} are automatically applied in conjunction.
941941

942942
When combinations of miniKanren goals comprise logical units, we can wrap their
@@ -999,7 +999,7 @@ Tensor(AddV2):0, dtype=~_27, shape=~_28, "AddV2:0"
999999

10001000
#+end_SRC
10011001

1002-
Now, in Listing [[mk-dist-goal-contract-distribute]] we "contract" the graph using
1002+
Now, in [[mk-dist-goal-contract-distribute]] we "contract" the graph using
10031003
the previously "expanded" results.
10041004

10051005
#+NAME: mk-dist-goal-contract-distribute
@@ -1009,12 +1009,12 @@ mk_res = run(1, q_lv, distributeo(q_lv, z_expanded_mt))
10091009
z_contracted_mt = mk_res[0]
10101010
#+END_SRC
10111011

1012-
#+NAME: mk-dist-goal-contract-distribute
1012+
#+NAME: mk-dist-goal-contract-distribute-print
10131013
#+BEGIN_SRC python :exports both :results output :wrap "SRC python :eval never"
10141014
tf_dprint(z_contracted_mt)
10151015
#+END_SRC
10161016

1017-
#+RESULTS: mk-dist-goal-contract-distribute
1017+
#+RESULTS: mk-dist-goal-contract-distribute-print
10181018
#+begin_SRC python :eval never
10191019
Tensor(MatMul):0, dtype=~_38, shape=~_42, "~_44"
10201020
| Tensor(Placeholder):0, dtype=float32, shape=[None, None], "A:0"
@@ -1034,7 +1034,7 @@ Symbolic PyMC introduces some miniKanren goals that apply other goals throughout
10341034
graphs until a fixed-point is reached. This sequence of operations is generally
10351035
necessary for graph simplification and rewriting.
10361036

1037-
In Listing [[mk-dist-goal-gapply-distribute]] we create a new graph that
1037+
In [[mk-dist-goal-gapply-distribute]] we create a new graph that
10381038
contains src_python[:eval never]{tf.matmul(A, x + y)} as a subgraph.
10391039
Using src_python[:eval never]{graph_applyo},
10401040
our src_python[:eval never]{distributeo} relation is applied all throughout the

0 commit comments

Comments
 (0)