[Tutor] constructing semi-arbitrary functions

Oscar Benjamin oscar.j.benjamin at gmail.com
Tue Feb 18 00:02:14 CET 2014


On 17 February 2014 22:15, "André Walker-Loud <walksloud at gmail.com>"
<walksloud at gmail.com> wrote:
>> This particular case is easily solved:
>>
>> def f_lambda(x,pars):
>>     return lambda x: poly(x,*pars)
>>
>> You let the closure take care of pars and return a function that takes
>> exactly one argument x.
>
> Hi Oscar,
>
> This is the opposite of what I am trying to do.  In the example, x represents the data and pars represent the parameters I want to determine, so it is the pars which I need passed into the "func_code.co_varnames" part of f.
>
> Maybe your suggestion gets me in that direction, but I don't see how.

No, you're right. I misunderstood this example.

Are you able to see/alter the source code of the 3rd party function?
As I said earlier my preferred solution would be to rewrite the
outermost part of that.

The core inner minimisation routine will (I'm guessing) be something
that really doesn't care about the names of these parameters and just
needs to know the dimensionality of the space it is exploring. If you
can access that routine directly then you can bypass the (IMO
unfortunate) interface that you're currently trying to contort your
problems into.


Oscar


More information about the Tutor mailing list