On Wed, Aug 7, 2013 at 11:37 AM, Guy Parsey <[email protected]> wrote:

> Hey Fred,
> I am starting to play with making a theano.Op, and in principle, linking a
> custom theano.Op to an implemented sympy function will solve all of my
> problems (at least in the sense of getting my system running, not
> necessarily speed). My initial post spoke of both mapping Piecewise and
> interpolated functions into theano; after speaking with my advisor, due to
> wanting a smoothing criterion over our piecewise datasets, I think we will
> end up treating them as interpolated functions over smoothed data sets. My
> idea for how to use an interpolation routine will be a wrapped theano.Op,
> so I am still rather curious as to how implementing Piecewise would work in
> such way that theano can manipulate it in graph form (built out of native
> theano operations).
>
> Theano will merge duplicated subexpression automatically by default. What
> is your function? If it is too "simple", for example just working on
> scalar, Theano have by default much overhead. As said for the other
> benchmark, there is tricks to remove a big part or even all of it, but it
> ask for some work on the developer.
>
>
> The basic system/functions can be described as follows; we have some
> number of species (n_0 ...n_k) and we are creating a function for the
> vector of time derivatives. The different types of expressions come about
> from the reaction rates (K_0 ..... K_l) The whole system is described
> symbolically, for symbolic determination of the jacobian (spline
> interpolated functions are wrapped with a sympy implemented function so
> that taking a symbolic derivative also yields the derivative of the
> numerical implementation). Dummy example below with three types of base
> expressions
> d(n_i)/dt = K_0*n_2*n_0 + K_1*n_3 + K_2*n_4*n_2*n_4/(sum(n_0....n_k))
> Each of the K terms can be described differently:
> --constant
> --analytical parameterized of some n_j    (Kf ~ a0*(n_j**a1)*exp(a2/n_j)
>  , a0..a2 are constants)
> --spline interpolation function of some n_j  (K_interp(n_j))
> --analytical weighted with piecewise/interpolated (new_Kf ~
> Kf*exp(-K_interp(n_j))
> I also have two energy equations, but these incorporate all of the same
> types of terms, just not in a nice summation as in the species equations.
> Any given base expression (eg. K_0*n_2*n_0) will appear in multiple time
> derivative equations, so if the interpolation is slow, it would be nice to
> get theano to recognize that it is a 'common expression.' I can make test
> cases with a few species and a few reactions (Ks), but the true systems I
> would like to be simulating will have 40-100 species and 300-2000 reaction
> rates. Are these functions too 'simple' to be sped by using theano? There
> is a lot of optimization that can be done due to the high number of shared
> expressions, so I was hoping to take advantage of the theano graph
> optimizations.
>

Theano will automatically execute only once each common exact sub
expression. This is something sure. What is not sure is not sure is common
"equivalent" but not exact sub expression. My guess with the result of the
benchmark here is that Theano should be faster then lambdify. But only
benchmark can confirm this.


> My initial test cases were using the numpy.float64 dtype, so I will switch
> it over to ndarrays if possible.
> I hope to have questions or a working spline interpolation theano.Op in
> the next few hours.
> Cheers,
> Guy
>
> Quick Codegen question: In principle, can one create a python callback
> within a compiled c code to a python function that is not compiled
> (interpolation function)?
>

>From C code, you can execute a pure python function. Theano do this for op
that have only a pure python code without any equivalent c code.

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sympy.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to