-
Notifications
You must be signed in to change notification settings - Fork 31
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
Implement splitting of special cases from linear operators #104
Comments
NewSLO/Piecewise.mpl line 67 would be one place to start. |
Let's simplify the description above by letting
to
This change also avoids the problem that, if What if |
Very good improvement, thanks. You are correct that if |
Per discussion at #104 , the pivot equality condition may occur anywhere within the sum body, not just in a top-level piecewise. So we do it when we see the sum, not when we see the piecewise (which we may never notice). This rewrite ought to supercede the "# Reduce product(piecewise(i=3,f(i),1),i=1..10) to f(3)" in NewSLO/Piecewise.mpl , so we remove that.
This implementation of Kronecker expansion depends on eval(..., condition=true) and eval(..., condition=false) melting away piecewise. But these substitutions don't melt away Partition, so we end up with Partitions whose pieces have trivial conditions such as true and false. The way I know to avoid such Partitions is to turn Partition into piecewise not just at the top level of simplify_factor_assuming but throughout the input factor expression.
@yuriy0 the change you just reverted was in support of this issue, where Ken implemented the Kronecker expansion in a branch. Can you run the tests on that branch (with your changes merged in), to see the status? I think Ken ran into issues where things were taking too long (some products?). We need to understand the effect of Kronecker expansion on our test suite, to see if it could indeed be made into a 'by default' simplification. |
It seems the next step (towards merging kronecker_in_simplify into master) is to profile e.g. gmm_gibbs with and without the changes on this branch. |
Given a summate, such as
we have two cases: 'kh' is generic, and 'kh' is special. We recognize that, for our computation,
kh = docUpdate
is special. So we split off the computation into 2 pieces, the generic piece, and the special piece.Let's generalize (and this is also the generalization which is what I was trying to convey yesterday): Suppose we have a bunch of expressions that depend on kh (our summation variable). Let's denote these by X (i.e. X is a 'vector' of expressions).
Then what we have is
where Phi is a Hakaru program-schema with |X| holes, which we fill with the expressions from X. Let's assume that one of these expressions in X is
kh == docUpdate
. Let cons(kh == docUpdate, Y) == X. So we haveNow we can do the transformation we've been talking about:
followed by aggressive constant folding. This is a win as soon as size(t) is 4 or so. The loss is tiny otherwise, and if size(t) had been statically known to be small, unrolling would have taken care of that.
The additional advantages are that:
This transformation generalizes quite a bit more:
Note that this transformation, when generalized properly to apply to continuous domains (like R, the reals), gives us that we can ignore the value of integrands at single points (since the correction terms are both 0!). BUT it also allows us to do the same transformation when the 'background measure' is not Lebesgue but can have Dirac -- the correction terms are then crucial.
A different generalization goes from 'linear operator' to 'bigop' (in the sense of Gonthier). But that case has a caveat: one must be able to prove, statically, that the exceptional cases are non-singular (else the correction term will be undefined). Which, in our case, may actually occur: think of conditionally expressed density (say Gaussian(0,1) in 25 dimensions and Gaussian(0,2) in 1 dimension, in a 26 dimensional situation). As the density is purely positive, it is safe to perform the above transformation.
Note that the generalization to "predicate P(index) such that P^{-1}(true) is a finite set [of known size]" is actually at the root of many of the simplifications found in the literature (as far as I can tell).
This does generalize further (to various kinds of notions of partitions) -- see my 'Symbolic Domain Decompositions' paper for that. But I don't think those generalizations are (yet) useful to Hakaru. Just fun ;).
PS: one last note. 'bool2int', 'int' casts of booleans, counting on (0*x = 0) do not occur anywhere in the above. They are not needed for this simplification, and act as a strong block to generalization.
The text was updated successfully, but these errors were encountered: