lsquares fitting and constrains for parameters (looking for positive values of parameters)



On Mon, Jan 16, 2012 at 9:12 PM,  <gwpublic at wp.pl> wrote:
>>> > If you do not need a symbolic solution,
>>>
>>> You're right. I need concrete values. (I've forgot to say it in
>>> problem statement).
>>>
>>> > you might be interested in
>>> > fmin_cobyla, which will produce the minimum of a function subject to
>>> > equality or inequality constraints.
>>>
>>> fmin_cobyla, I haven't knew about it. (btw. I see it's implemented in
>>> Scipy as well.)
>>>
>>> I try to figure out how to make it to obey constraints, with no
>>> success. Results are not positive, and even worse than
>>> lsquares_estimate.
>>>
>>> As I doing sth wrong ?
>>> Or sum equations are not fmin_cobyla's purpose, are they ?
>>>
>>
>> From what I can see, you're doing everything correctly.? I have noticed that
>> fmin_cobyla is sensitive to the initial guess.?? With your example,
>> fmin_cobyla does return positive values for the parameters, except a3, which
>> is very small and slightly negative.
>>
>> It's also possible that by giving a too-complicated expression makes cobyla
>> less efficient.? Just from looking at the data matrix, it's clear that the
>> relationship is linear (difference each y value is a constant).
>>
>> Perhaps a better example would be a real cubic with some noise added to the
>> y values.
>>
>> Ray
>
> Thanks for ensuring me I am doing everything fine.
>
> Now I know, it's question of "workarounds" and "tuning" to make all
> this stuff work as expected :).
>
> All Best,
> Greg

Hi !

I've found solution for main part of my problem and I'd like to share :).

As a reminder:
"How to fit parametrized function to data, to achieve grater than zero
parameters?"

I've started by asking about lsquare_estimate, Raymond Toy pointed fmin_cobyla.

I've found it can be done, not by constraining, but with "trick". I
think it's universal and works for many many problems, when numerical
or symbolic method does not provide way of "feeding" with constraints:

abs !

Yes, that was that simple.

So instead of fitting with lsquares_estimate expression like this:
a*x^4 + b*x^3 + d*x + e
I fit expression with all parameters after "abs" :
abs(a)*x^4 + abs(b)*x^3 + abs(d)*x + abs(e)

:)

Again - Thanks Raymond Toy for showing fmin_cobyla, I've missed it
when going thought manual :).

Cheers,
Greg