Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce a pure miniKanren graph apply/reduce relation #13

Merged

Conversation

brandonwillard
Copy link
Contributor

The added graph_reduceo can find fixed-points for reduction relations over graphs in both directions. This means graph_reduceo can find fixed-points for a given graph and sequences of graphs satisfying given fixed-points, as well as graphs satisfying "patterns"/relations between those two.

Of course the convergence of graph_reduceo depends on the relation and terms its given, but it works for strongly normalizing rewrite rules/relations and that's the baseline requirement for completely replacing—and going well beyond—Theano's optimization framework.

The general "search" performance can always be addressed with things like condp, or any other adjustments to the cond* relations that provide run-of-the-mill controlled graph traversal (e.g. depth-limited or weighed traversal). See the discussion in #6 for more details.

Otherwise, after adding tests and replacing Theano functions, this closes #6, and, with the addition of a basic collection of graph-normalizing reductions and standard algebraic relations, we should be able to close #5, as well.

@brandonwillard brandonwillard force-pushed the kanren-graph-reduction branch 4 times, most recently from cf341c7 to 30d18fe Compare March 27, 2019 00:01
@brandonwillard
Copy link
Contributor Author

The last commit provides a complete example (the conjugate update) of graph optimization exclusively in miniKanren/kanren (via meta graph objects).

The rest of this PR should only involve converting the remaining uses of the Theano optimization machinery (i.e. FunctionGraph, EquilibriumOptimizer and the like) and possibly adding some graph reductions that we've been using implicitly.

Otherwise, there are some performance concerns we could easily address with tabling and/or memoization; however, the first result from graph_applyo currently returns a fixed-point, and, since we only need that result, we should be set. Likewise, the conjugate example isn't nearly as quick as it could be, but it might be comparable to the cumulative time Theano takes to do the same.

@brandonwillard brandonwillard force-pushed the kanren-graph-reduction branch 3 times, most recently from 2af3534 to 6aa474c Compare June 2, 2019 03:14
The added `graph_reduceo` can find fixed-points for reduction relations over
graphs in both directions (i.e. find the fixed-points and sequences of graphs
satisfying fixed-points).

Closes pymc-devs#6.
@brandonwillard brandonwillard force-pushed the kanren-graph-reduction branch from 6aa474c to 1311813 Compare June 8, 2019 01:00
@brandonwillard
Copy link
Contributor Author

brandonwillard commented Jun 8, 2019

There's a quirk in the recursive calls behind lapply_anyo and/or graph_applyo that prevent graph_applyo from being called (productively) in reverse (i.e. expand—instead of reduce—from a term). See the test_graph_applyo_reverse stub for an example that should work (and does in my Scheme version(s)).

I could merge this PR, since that's not exactly the necessary—nor primary—functionality introduced by this PR (i.e. replace the Theano-based graph functions). Obviously, I would like to fix this first, but I would also like to start working on complete graph reductions, normal-forms, model rewrites, etc., in TensorFlow.

@twiecki
Copy link
Member

twiecki commented Jun 8, 2019

I'd say merge it.

@brandonwillard
Copy link
Contributor Author

Yeah, at least if we do that, I can set up some simple conjugation examples (e.g. via TF log-likelihood graphs, instead of the sample-space graphs that the PyMC3/Theano example uses).

@brandonwillard brandonwillard merged commit c044982 into pymc-devs:master Jun 8, 2019
@brandonwillard brandonwillard deleted the kanren-graph-reduction branch June 9, 2019 22:03
@brandonwillard brandonwillard added the miniKanren This issue involves miniKanren goals label Mar 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
miniKanren This issue involves miniKanren goals
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Generalize Graph Traversal and Manipulation Generalized Tensor Algebra and Graph Normalization
2 participants