an update:
minimize() is much improved using Harald Schilly's suggestion to
provide an explicit gradient function defined with fast_float().
succeeded:
minimizing a quartic polynomial in 100 variables containing
1,100,411 terms
(in 22329s of cpu time using 100% of one stock Intel core w
64GB RAM)
failed :
on a quartic polynomial in 120 variables containing 2,217,743
terms.
The failure seems to be in fast_float(g) when g is an element in a
polynomial ring, when g contains too many terms. It's a strange
failure: the notebook's namespace gets trashed.
Anyway, the improvement to minimize() gave some useful results. I
very much appreciate the help.
Daniel Friedan
On Jul 13, 4:34 pm, Harald Schilly <[email protected]> wrote:
> On 13 Jul., 17:32, 8fjm39j <[email protected]> wrote:
>
> > One minor question: in your definition of the gradient function,
> > sage: gradfun = lambda x:np.array(map(lambda f:f(*x),
> > eq.gradient()))
> > should that be 'eq.gradient()' or should it be 'req.gradient()' ?
> > (recall that req = eq.change_ring(RDF))
>
> I only did this through a feeling, but benchmarking it revealed that
> it doesn't matter.
> You can do this via %timeit
>
> Here is an significant improvement for the gradient:
>
> sage: gradfun = lambda x:np.array(map(lambda f:f(*x), eq.gradient()))
> sage: grad = [fast_float(g) for g in eq.gradient() ]
> sage: gradfun2 = lambda x:np.array(map(lambda f:f(*x), grad))
>
> same output:
>
> sage: all(gradfun2([1]*30) == gradfun([1]*30))
> True
>
> but
>
> sage: %timeit gradfun([1]*30)
> 125 loops, best of 3: 4.7 ms per loop
> sage: %timeit gradfun2([1]*30)
> 625 loops, best of 3: 110 µs per loop
>
> ~ 42x faster!
>
> Maybe there is an even faster way ...? -> cython
>
> Also, there are different solvers wrapped, e.g. conjugate gradients.
>
> sage: minimize(lambda x : eq(*x), [0]*eq.parent().ngens(),
> gradient=gradfun2, algorithm="cg")
>
> or look directly into the scipy.optimize module.
>
> H
--
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org