Re: [Tutor] constructing semi-arbitrary functions

2014-02-20 Thread spir
On 02/20/2014 01:56 AM, André Walker-Loud walksl...@gmail.com wrote: On Feb 19, 2014, at 7:45 PM, André Walker-Loud walksl...@gmail.com wrote: OK - I have not seen an email from Peter. So I looked up the thread online, and see I did not receive half the emails on this thread :O My first

Re: [Tutor] constructing semi-arbitrary functions

2014-02-19 Thread Oscar Benjamin
On 18 February 2014 17:59, Peter Otten __pete...@web.de wrote: I don't know if the OP may use it, but there seems to be a version of minuit that allows to override the function signature: forced_parameters: tell Minuit not to do function signature detection and use this argument instead.

Re: [Tutor] constructing semi-arbitrary functions

2014-02-19 Thread Dave Angel
On 02/19/2014 07:33 AM, Oscar Benjamin wrote: At the least I don't understand why it needs both the argument names and the number of arguments as independent quantities. Surely len(names) would be the number of arguments... Or am I missing something? In the standard library, the attributes

Re: [Tutor] constructing semi-arbitrary functions

2014-02-19 Thread eryksun
On Wed, Feb 19, 2014 at 7:33 AM, Oscar Benjamin oscar.j.benja...@gmail.com wrote: I don't really understand why it works that way though. Looking here http://iminuit.github.io/iminuit/api.html#function-sig-label This API is unusual, but co_argcount and co_varnames should be available and

Re: [Tutor] constructing semi-arbitrary functions

2014-02-19 Thread André Walker-Loud walksl...@gmail.com
Hi Oscar, Is there a benefit to this method vs a standard linear least squares? It's the same except that you're using an analytic solution rather than a black box solver. OK. Interesting. I usually construct the analytic solution by just differentiating the chi^2, which sets up, I am

Re: [Tutor] constructing semi-arbitrary functions

2014-02-19 Thread André Walker-Loud walksl...@gmail.com
Hi eryksun, Indeed, I am using iminuit to interface with Minuit. That is where I am learning to make my own classes to set up my functions to pass into the minimizer. I also happened to get the string-hack to work (which requires using global variables). Instead of just copying (since it

Re: [Tutor] constructing semi-arbitrary functions

2014-02-19 Thread eryksun
On Wed, Feb 19, 2014 at 2:56 PM, André Walker-Loud walksl...@gmail.com walksl...@gmail.com wrote: I also happened to get the string-hack to work (which requires using global variables). Functions load unassigned names from the global/builtins scopes, so there's no need to declare the g*

Re: [Tutor] constructing semi-arbitrary functions

2014-02-19 Thread André Walker-Loud walksl...@gmail.com
Hi eryksun, Thanks - this is great. Also, since you are chiming in, do you have an opinion in general about which approach you prefer? The string hacking vs class method (for lack of better way to describe them)? Cheers, Andre On Feb 19, 2014, at 4:56 PM, eryksun eryk...@gmail.com wrote:

Re: [Tutor] constructing semi-arbitrary functions

2014-02-19 Thread eryksun
On Wed, Feb 19, 2014 at 6:59 PM, André Walker-Loud walksl...@gmail.com walksl...@gmail.com wrote: Also, since you are chiming in, do you have an opinion in general about which approach you prefer? The string hacking vs class method (for lack of better way to describe them)? I've never used

Re: [Tutor] constructing semi-arbitrary functions

2014-02-19 Thread André Walker-Loud walksl...@gmail.com
OK - I have not seen an email from Peter. So I looked up the thread online, and see I did not receive half the emails on this thread :O My first inclination was to blame my mac mavericks mail gmail syncing problem. but logging into gmail, I see no record of the emails there either. I

Re: [Tutor] constructing semi-arbitrary functions

2014-02-19 Thread André Walker-Loud walksl...@gmail.com
On Feb 19, 2014, at 7:45 PM, André Walker-Loud walksl...@gmail.com wrote: OK - I have not seen an email from Peter. So I looked up the thread online, and see I did not receive half the emails on this thread :O My first inclination was to blame my mac mavericks mail gmail syncing problem.

Re: [Tutor] constructing semi-arbitrary functions

2014-02-19 Thread Mark Lawrence
On 20/02/2014 00:56, André Walker-Loud walksl...@gmail.com wrote: On Feb 19, 2014, at 7:45 PM, André Walker-Loud walksl...@gmail.com wrote: OK - I have not seen an email from Peter. So I looked up the thread online, and see I did not receive half the emails on this thread :O My first

Re: [Tutor] constructing semi-arbitrary functions

2014-02-18 Thread spir
On 02/18/2014 12:02 AM, Oscar Benjamin wrote: On 17 February 2014 22:15, André Walker-Loud walksl...@gmail.com walksl...@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

Re: [Tutor] constructing semi-arbitrary functions

2014-02-18 Thread spir
On 02/17/2014 08:23 PM, André Walker-Loud walksl...@gmail.com wrote: Hello python tutors, I am utilizing a 3rd party numerical minimization routine. This routine requires an input function, which takes as arguments, only the variables with which to solve for. But I don’t want to define all

Re: [Tutor] constructing semi-arbitrary functions

2014-02-18 Thread Oscar Benjamin
On 18 February 2014 00:51, André Walker-Loud walksl...@gmail.com walksl...@gmail.com wrote: BTW if you're trying to fit the coefficients of a polynomial then a general purpose optimisation function is probably not what you want to use. I would probably solve (in a least squares sense and after

Re: [Tutor] constructing semi-arbitrary functions

2014-02-18 Thread Peter Otten
Oscar Benjamin wrote: On 17 February 2014 20:13, Peter Otten __pete...@web.de wrote: André Walker-Loud walksl...@gmail.com wrote: The 3rd party minimizer utilizes the .func_code.co_varnames and .func_code.co_argcount to determine the name and number of variables to minimize. eg.

[Tutor] constructing semi-arbitrary functions

2014-02-17 Thread André Walker-Loud walksl...@gmail.com
Hello python tutors, I am utilizing a 3rd party numerical minimization routine. This routine requires an input function, which takes as arguments, only the variables with which to solve for. But I don’t want to define all possible input functions, in a giant switch, but rather, if I know I

Re: [Tutor] constructing semi-arbitrary functions

2014-02-17 Thread Oscar Benjamin
On Feb 17, 2014 7:24 PM, quot;André Walker-Loud lt;walksl...@gmail.comgt;quot; walksl...@gmail.com wrote: Question 1: Is there a better way to accomplish (my hopefully clear) goals? I'm not sure that there is given the constraints you're under from the third party function. Question 2: In

Re: [Tutor] constructing semi-arbitrary functions

2014-02-17 Thread Peter Otten
André Walker-Loud walksl...@gmail.com wrote: Hello python tutors, I am utilizing a 3rd party numerical minimization routine. This routine requires an input function, which takes as arguments, only the variables with which to solve for. But I don’t want to define all possible input

Re: [Tutor] constructing semi-arbitrary functions

2014-02-17 Thread Oscar Benjamin
On 17 February 2014 20:13, Peter Otten __pete...@web.de wrote: André Walker-Loud walksl...@gmail.com wrote: The 3rd party minimizer utilizes the .func_code.co_varnames and .func_code.co_argcount to determine the name and number of variables to minimize. eg. = METHOD 2: use

Re: [Tutor] constructing semi-arbitrary functions

2014-02-17 Thread André Walker-Loud walksl...@gmail.com
Hi Oscar, Let me clear up my description of one point - I don’t want to pick on the third party software guys. The right solution is to change the interface of the third party function. It is poorly designed and should not be inspecting those function attributes or it should at least

Re: [Tutor] constructing semi-arbitrary functions

2014-02-17 Thread Steven D'Aprano
On Mon, Feb 17, 2014 at 07:58:00PM +, Oscar Benjamin wrote: The right solution is to change the interface of the third party function. It is poorly designed and should not be inspecting those function attributes or it should at least provide an option for you to provide that information

Re: [Tutor] constructing semi-arbitrary functions

2014-02-17 Thread Dave Angel
Peter Otten __pete...@web.de Wrote in message: André Walker-Loud walksl...@gmail.com wrote: Hello python tutors, I am utilizing a 3rd party numerical minimization routine. This routine requires an input function, which takes as arguments, only the variables with which to solve for.

Re: [Tutor] constructing semi-arbitrary functions

2014-02-17 Thread Oscar Benjamin
On 17 February 2014 21:18, André Walker-Loud walksl...@gmail.com walksl...@gmail.com wrote: What I am trying to avoid is having to write a special case for each order of polynomial I want. I tried the following def poly(x,pars): val = 0. for i,ci in enumerate(pars): val

Re: [Tutor] constructing semi-arbitrary functions

2014-02-17 Thread André Walker-Loud walksl...@gmail.com
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

Re: [Tutor] constructing semi-arbitrary functions

2014-02-17 Thread Oscar Benjamin
On 17 February 2014 22:15, André Walker-Loud walksl...@gmail.com walksl...@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

Re: [Tutor] constructing semi-arbitrary functions

2014-02-17 Thread Oscar Benjamin
On 17 February 2014 22:15, André Walker-Loud walksl...@gmail.com walksl...@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

Re: [Tutor] constructing semi-arbitrary functions

2014-02-17 Thread André Walker-Loud walksl...@gmail.com
Hi Oscar, On Feb 17, 2014, at 6:02 PM, Oscar Benjamin oscar.j.benja...@gmail.com wrote: On 17 February 2014 22:15, André Walker-Loud walksl...@gmail.com walksl...@gmail.com wrote: This particular case is easily solved: def f_lambda(x,pars): return lambda x: poly(x,*pars) You let the

Re: [Tutor] constructing semi-arbitrary functions

2014-02-17 Thread André Walker-Loud walksl...@gmail.com
Hi Oscar, On Feb 17, 2014, at 7:03 PM, Oscar Benjamin oscar.j.benja...@gmail.com wrote: On 17 February 2014 22:15, André Walker-Loud walksl...@gmail.com walksl...@gmail.com wrote: This particular case is easily solved: def f_lambda(x,pars): return lambda x: poly(x,*pars) You let