optimizing parameters

671 views
Skip to first unread message

janthina

unread,
Dec 12, 2011, 5:02:40 AM12/12/11
to dadi-user

Q.1
When I use optimization functions, sometimes (1 out of 10) dadi does
not converge and never ends..

I have tried with example dataset (YRI_CEU).
And Here is part of the result.

...
9492 , -1066.24 , array([ 1.87542 , 0.0711839 ,
1.78992 , 0.929397 , 0.359968 , 0.110574 ])
9498 , -1066.24 , array([ 1.87542 , 0.0712551 ,
1.78992 , 0.928468 , 0.359968 , 0.110574 ])
9504 , -1066.24 , array([ 1.87542 , 0.0711839 ,
1.78992 , 0.928468 , 0.359968 , 0.110574 ])
9510 , -1066.24 , array([ 1.87542 , 0.0711839 ,
1.78992 , 0.928468 , 0.359968 , 0.110685 ])
9516 , -1066.24 , array([ 1.87542 , 0.0711839 ,
1.78992 , 0.929397 , 0.359968 , 0.110574 ])
9522 , -1066.24 , array([ 1.87542 , 0.0712551 ,
1.78992 , 0.928468 , 0.359968 , 0.110574 ])
9528 , -1066.24 , array([ 1.87542 , 0.0711839 ,
1.78992 , 0.928468 , 0.359968 , 0.110574 ])
...

It seems like the parameters are convergent,
but it ceaselessly returns slightly different parameters..
and never ends...
Is there any way or option to stop optimization process more
shortly...
so that I can running the process several times with different
starting point..
This is critical because I'm planning to estimate parameters of each
gene throughout the genome..


Q2.
After long iterations (about 1 or 2 days) of the optimization
process,
it ends and sometimes some parameters have negative score...
But the parameter's score printed on the screen is positive score...
something like:

on the screen: array([ 0.0813915, ... ])
in the object popt: array([ -2.11.,.. ])

I think this could be a bug, so I'm taking the parameter in the last
one printed on the screen..
Is this a bug, or mistake in modeling demographic structure..?


Gutenkunst, Ryan N - (rgutenk)

unread,
Dec 12, 2011, 6:18:48 PM12/12/11
to dadi...@googlegroups.com
Hello janthina,

Thank you for your questions!
dadi builds off of scipy's optimization routines, and their convergence
criteria do sometimes seem to fail. You can use the 'maxiter' argument to
limit the total optimization time.

>Q2.
>After long iterations (about 1 or 2 days) of the optimization
>process,
>it ends and sometimes some parameters have negative score...
>But the parameter's score printed on the screen is positive score...
>something like:
>
>on the screen: array([ 0.0813915, ... ])
>in the object popt: array([ -2.11.,.. ])
>
>I think this could be a bug, so I'm taking the parameter in the last
>one printed on the screen..
>Is this a bug, or mistake in modeling demographic structure..?

That is strange. It may be a bug in scipy's optimizers. Which optimization
routine were you using? Was it one of the _log routines? If not, did you
have a lower_bound set on that parameter?

Best,
Ryan

--
Ryan Gutenkunst
Assistant Professor
Molecular and Cellular Biology
University of Arizona
phone: (520) 626-0569
http://gutengroup.mcb.arizona.edu




janthina

unread,
Dec 12, 2011, 11:05:35 PM12/12/11
to dadi-user

The optimization routine was dadi.Inference.optimize() ..and setting
lower_bound to 1e-3...
and it is a simply bottleneck model with population size change
exponentially..

On Dec 13, 8:18 am, "Gutenkunst, Ryan N - (rgutenk)"


<rgut...@email.arizona.edu> wrote:
> Hello janthina,
>
> Thank you for your questions!
>

Gutenkunst, Ryan N - (rgutenk)

unread,
Dec 13, 2011, 5:10:50 PM12/13/11
to dadi...@googlegroups.com
Thanks Janthina,

We're hoping to replace the existing optimization routines with a more
robust solution sometime, but that will take some time. In the meantime, I
hope these issues aren't interfering with your work.

Best,
Ryan
>--
>You received this message because you are subscribed to the Google Groups
>"dadi-user" group.
>To post to this group, send email to dadi...@googlegroups.com.
>To unsubscribe from this group, send email to
>dadi-user+...@googlegroups.com.
>For more options, visit this group at
>http://groups.google.com/group/dadi-user?hl=en.

janthina

unread,
Dec 18, 2011, 3:28:13 AM12/18/11
to dadi-user
I missed one thing to report.
The bug has occurred after upgrading dadi to ver. 1.6.2.


On 12월14일, 오전7시10분, "Gutenkunst, Ryan N - (rgutenk)"


<rgut...@email.arizona.edu> wrote:
> Thanks Janthina,
>
> We're hoping to replace the existing optimization routines with a more
> robust solution sometime, but that will take some time. In the meantime, I
> hope these issues aren't interfering with your work.
>
> Best,
> Ryan
>

Gutenkunst, Ryan N - (rgutenk)

unread,
Jun 7, 2012, 3:49:59 PM6/7/12
to dadi...@googlegroups.com
Hi Nick,

Yes, unfortunately that's the optimization algorithm getting failing to properly check convergence. We're working on switching to a different system that will hopefully fix the problem.

In the mean time, please use the 'maxiter' argument to the optimization routines to cut off the optimizations after a reasonable time.

Best,
Ryan

On 6/6/12 5:02 AM, "Nicholas Crawford" <ngcra...@gmail.com> wrote:
I'm seeing the same thing (Q1) that Janthina reports when running the YRI_CEU.py example script with the optimization lines uncommented. The optimization never finishes.  Any ideas what's going on?

Currently my optimization parameters are here (after ~ 1 hour):

8226    , -1066.27    , array([ 1.87892    ,  0.0715303  ,  1.79128    ,  0.925717   ,  0.3628     ,  0.11107    ])
8232    , -1066.27    , array([ 1.87892    ,  0.0715303  ,  1.79307    ,  0.925717   ,  0.362437   ,  0.11107    ])
8238    , -1066.27    , array([ 1.8808     ,  0.0715303  ,  1.79128    ,  0.925717   ,  0.362437   ,  0.11107    ])

dadi 1.6.2
numpy 1.6.1

- Nick


> >For more options, visit this group at
> >http://groups.google.com/group/dadi-user?hl=en.
>
> --
> Ryan Gutenkunst
> Assistant Professor
> Molecular and Cellular Biology
> University of Arizona
> phone:(520) 626-0569http://gutengroup.mcb.arizona.edu

--
You received this message because you are subscribed to the Google Groups "dadi-user" group.
To view this discussion on the web visit https://groups.google.com/d/msg/dadi-user/-/oDI77NV6QbwJ.

To post to this group, send email to dadi...@googlegroups.com.
To unsubscribe from this group, send email to dadi-user+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/dadi-user?hl=en.

Gutenkunst, Ryan N - (rgutenk)

unread,
Jun 18, 2012, 1:52:41 PM6/18/12
to dadi...@googlegroups.com, Cunningham, Kathryn I - (katiec42)
Hi Laura,

The maxiter argument is a little subtle, because it's the maximum number of iterations in the optimization algorithm, not the maximum number of calls to the function being optimized. Roughly, for an optimization over P parameters,  each step of the optimization algorithm involves evaluating several gradients (which each take P function evaluations) and then a line search, which takes more function evaluations.

Given this (admittedly nonintuitive) behavior, you probably want maxiter to be relatively modest; 20 might be a good start.

If I set maxiter to 1 in the YRI_CEU.py example, the optimization typically stops after between 50 and 100 function evaluations (based on verbose=1 output). Is this the behavior you see? If not, what is the output of "import scipy; print scipy.version.version"?

Best,
Ryan

On 6/15/12 6:36 AM, "Laura" <rb.l...@gmail.com> wrote:
Hi Ryan,

I am new to dadi and Python. I have also run into this problem of not reaching convergence and tried to add the maxiter argument, but it seems that it does not respond. If I do other changes such as verbose=1 instead of len(params) I do have the optimized parameters at each iteration and not every six, but the program does not seem to recognize changes in the maxiter argument. (I have tried to set maxiter to 5000, 5000.0, 20 and 1, without the expected results)

This is the command in the script YRI_CEU.py:

popt = dadi.Inference.optimize_log(p0, data, func_ex, pts_l, 
                                   lower_bound=lower_bound,
                                   upper_bound=upper_bound,
                                   verbose=1, maxiter=1)

And this is the command in the ipython:
In [89]: popt = dadi.Inference.optimize_log(p0, data, func_ex, pts_l, 
   ....:                                    lower_bound=lower_bound,
   ....:                                    upper_bound=upper_bound,
   ....:                                    verbose=1, maxiter=1)
27      , -1475.44    , array([ 1.2007     ,  0.136576   ,  1.70538    ,  0.62976    ,  0.639977   ,  0.106308   ])
28      , -1474.75    , array([ 1.2019     ,  0.136576   ,  1.70538    ,  0.62976    ,  0.639977   ,  0.106308   ])
29      , -1476.19    , array([ 1.2007     ,  0.136713   ,  1.70538    ,  0.62976    ,  0.639977   ,  0.106308   ])
30      , -1475.84    , array([ 1.2007     ,  0.136576   ,  1.70709    ,  0.62976    ,  0.639977   ,  0.106308   ])
31      , -1475.57    , array([ 1.2007     ,  0.136576   ,  1.70538    ,  0.63039    ,  0.639977   ,  0.106308   ])

Asking around, we added the command  "" print "xxx" maxiter  "" (shown below) in Inference.py and saved it and import dadi again and rerun CEu_YRI.py, but the print never showed.

def optimize_log(p0, data, model_func, pts, lower_bound=None, upper_bound=None,
                 verbose=0, flush_delay=0.5, epsilon=1e-3, 
                 gtol=1e-5, multinom=True, maxiter=None, full_output=False,
                 func_args=[], func_kwargs={}, fixed_params=None, ll_scale=1):
    """
   (...)
    """
    args = (data, model_func, pts, lower_bound, upper_bound, verbose,
            multinom, flush_delay, func_args, func_kwargs, fixed_params, 
            ll_scale)

    p0 = _project_params_down(p0, fixed_params)
    print "xxx" maxiter
    outputs = scipy.optimize.fmin_bfgs(_object_func_log, 
                                       numpy.log(p0), epsilon=epsilon,
                                       args = args, gtol=gtol, 
                                       full_output=True,
                                       disp=False,
                                       maxiter=maxiter)

 

Do you have any thoughts on that?

Thank you very much,

Laura

--
You received this message because you are subscribed to the Google Groups "dadi-user" group.
To view this discussion on the web visit https://groups.google.com/d/msg/dadi-user/-/l_t_OxKpYFoJ.

To post to this group, send email to dadi...@googlegroups.com.
To unsubscribe from this group, send email to dadi-user+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/dadi-user?hl=en.

Laura

unread,
Jun 19, 2012, 5:26:31 AM6/19/12
to dadi...@googlegroups.com
Hi Ryan,

It was just as you said. Thanks a lot!

Cheers,
Laura
Reply all
Reply to author
Forward
0 new messages