[Tutor] constructing semi-arbitrary functions

spir denis.spir at gmail.com
Tue Feb 18 15:36:51 CET 2014


On 02/18/2014 12:02 AM, Oscar Benjamin wrote:
> 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.

I think so. However it works, the minimising algo only needs values, not names 
(but it needs to know which meaning/role each value corresponds to, indeed). It 
is also infortunate that it looks for this information in the (conceptually 
private) metadata of the function itself, instead of having a dedicated input 
slot in its interface.

d


More information about the Tutor mailing list