[SciPy-User] using fmin_tnc

Joon Ro joonpyro at gmail.com
Wed May 11 12:24:23 EDT 2011


Oh now I understand. So you actually have two matrices as unknown  
parameters. I'm sorry I was confused.
Then you are right. It seems you have to modify your objective function so  
it only gets one parameter argument which is one dimensional.
As you said, it seems you have to convert the matrices to a vector and  
reshape them inside the objective function.

So the documentation does say x0 is a list of floats. I haven't tried it  
but it should work with a one dimensional vector as well.  I'm not sure if  
the routine passes x as a list or not to the objective function though.

-Joon



On Wed, 11 May 2011 10:59:01 -0500, Joel Oren <yoelor at gmail.com> wrote:

> What I meant was whether or not fmin_tnc can handle numpy matrices  
> (numpy.array objects) objects as function arguments.
>
> From your example, I gather that the function can handle them. The  
> question is, as I am interested in a constrained optmization, in which  
> the matrices entries are non-negative, can >this still work?
>
> If that is the case, how do I supply the bounds for each of the two  
> matrices I'm optimizing on?
>
> It is not clear wether or not this should work, according to the  
> documentation. I can always flatten my matrices using .flatten() and  
> then reshape them whenever I'm computing the >objective function.
>
> Thanks,
> Joel.
>
> On Wed, May 11, 2011 at 11:49 AM, Joon Ro <joonpyro at gmail.com> wrote:
>> On Wed, 11 May 2011 08:55:54 -0500, Joel Oren <yoelor at gmail.com> wrote:
>>
>>> Hi,
>>>
>>> I wish to use scipy.optimize.fmin_tnc for performing a constrained  
>>> optimization of a function of 2 numpy matrices.
>>>
>>> However, according to the documentation of the method, it only accepts  
>>> lists of variables.
>>>
>>> Is there a way to still use this function without having to convert  
>>> the matrices (and the gradient of the function) to lists on every  
>>> iteration?
>>>
>>> Thanks,
>>> Joel.
>>
>> Hi,
>>
>> I did not understand what you meant by "it only accepts lists of  
>> variables" but passing arrays to the objective functions is what you do  
>> when you use those optimization routines.
>> For example, when you have a matrix of variables, X (n-by-k) and want  
>> to find parameters betas (k-by-1) which minimizes the objective  
>> function,
>> scipy.optimize.fmin_tnc(func, x0 = betas0, fprime=None, args=(X) ... )
>>
>> (where betas0 is the initial guess of betas)
>>
>> In your case, if you have two matrices X and Y, then
>>
>> scipy.optimize.fmin_tnc(func, x0 = betas0, fprime=None, args=(X, Y) ...  
>> )
>>
>> So I did not understand converting matrix to lists part. Please correct  
>> me if I'm wrong.
>>
>>>> -Joon
>>
>>
>



-- 
Using Opera's revolutionary email client: http://www.opera.com/mail/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20110511/d35909a0/attachment.html>


More information about the SciPy-User mailing list